10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H 23 template<
typename Str
ides,
typename XprType>
24 struct traits<TensorInflationOp<Strides, XprType> > :
public traits<XprType>
26 typedef typename XprType::Scalar Scalar;
27 typedef traits<XprType> XprTraits;
28 typedef typename packet_traits<Scalar>::type Packet;
29 typedef typename XprTraits::StorageKind StorageKind;
30 typedef typename XprTraits::Index Index;
31 typedef typename XprType::Nested Nested;
32 typedef typename remove_reference<Nested>::type _Nested;
33 static const int NumDimensions = XprTraits::NumDimensions;
34 static const int Layout = XprTraits::Layout;
37 template<
typename Str
ides,
typename XprType>
38 struct eval<TensorInflationOp<Strides, XprType>,
Eigen::Dense>
40 typedef const TensorInflationOp<Strides, XprType>& type;
43 template<
typename Str
ides,
typename XprType>
44 struct nested<TensorInflationOp<Strides, XprType>, 1, typename eval<TensorInflationOp<Strides, XprType> >::type>
46 typedef TensorInflationOp<Strides, XprType> type;
51 template<
typename Str
ides,
typename XprType>
52 class TensorInflationOp :
public TensorBase<TensorInflationOp<Strides, XprType>, ReadOnlyAccessors>
55 typedef typename Eigen::internal::traits<TensorInflationOp>::Scalar Scalar;
56 typedef typename Eigen::internal::traits<TensorInflationOp>::Packet Packet;
57 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
58 typedef typename XprType::CoeffReturnType CoeffReturnType;
59 typedef typename XprType::PacketReturnType PacketReturnType;
60 typedef typename Eigen::internal::nested<TensorInflationOp>::type Nested;
61 typedef typename Eigen::internal::traits<TensorInflationOp>::StorageKind StorageKind;
62 typedef typename Eigen::internal::traits<TensorInflationOp>::Index Index;
64 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorInflationOp(
const XprType& expr,
const Strides& strides)
65 : m_xpr(expr), m_strides(strides) {}
68 const Strides& strides()
const {
return m_strides; }
71 const typename internal::remove_all<typename XprType::Nested>::type&
72 expression()
const {
return m_xpr; }
75 typename XprType::Nested m_xpr;
76 const Strides m_strides;
80 template<
typename Str
ides,
typename ArgType,
typename Device>
81 struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device>
83 typedef TensorInflationOp<Strides, ArgType> XprType;
84 typedef typename XprType::Index Index;
85 static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value;
86 typedef DSizes<Index, NumDims> Dimensions;
90 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
92 Layout = TensorEvaluator<ArgType, Device>::Layout,
96 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(
const XprType& op,
const Device& device)
97 : m_impl(op.expression(), device), m_strides(op.strides())
99 m_dimensions = m_impl.dimensions();
101 for (
int i = 0; i < NumDims; ++i) {
102 m_dimensions[i] = (m_dimensions[i] - 1) * op.strides()[i] + 1;
106 for (
int i = 0; i < NumDims; ++i) {
107 m_fastStrides[i] = internal::TensorIntDivisor<Index>(m_strides[i]);
110 const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions();
111 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
112 m_outputStrides[0] = 1;
113 m_inputStrides[0] = 1;
114 for (
int i = 1; i < NumDims; ++i) {
115 m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1];
116 m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1];
119 m_outputStrides[NumDims-1] = 1;
120 m_inputStrides[NumDims-1] = 1;
121 for (
int i = NumDims - 2; i >= 0; --i) {
122 m_outputStrides[i] = m_outputStrides[i+1] * m_dimensions[i+1];
123 m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1];
128 typedef typename XprType::Scalar Scalar;
129 typedef typename XprType::CoeffReturnType CoeffReturnType;
130 typedef typename XprType::PacketReturnType PacketReturnType;
132 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
134 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(Scalar* ) {
135 m_impl.evalSubExprsIfNeeded(NULL);
138 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup() {
144 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool getInputIndex(Index index, Index* inputIndex)
const 146 eigen_assert(index < dimensions().TotalSize());
148 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
149 for (
int i = NumDims - 1; i > 0; --i) {
150 const Index idx = index / m_outputStrides[i];
151 if (idx != idx / m_fastStrides[i] * m_strides[i]) {
154 *inputIndex += idx / m_strides[i] * m_inputStrides[i];
155 index -= idx * m_outputStrides[i];
157 if (index != index / m_fastStrides[0] * m_strides[0]) {
160 *inputIndex += index / m_strides[0];
163 for (
int i = 0; i < NumDims - 1; ++i) {
164 const Index idx = index / m_outputStrides[i];
165 if (idx != idx / m_fastStrides[i] * m_strides[i]) {
168 *inputIndex += idx / m_strides[i] * m_inputStrides[i];
169 index -= idx * m_outputStrides[i];
171 if (index != index / m_fastStrides[NumDims-1] * m_strides[NumDims-1]) {
174 *inputIndex += index / m_strides[NumDims - 1];
179 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const 181 Index inputIndex = 0;
182 if (getInputIndex(index, &inputIndex)) {
183 return m_impl.coeff(inputIndex);
191 template<
int LoadMode>
192 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const 194 const int packetSize = internal::unpacket_traits<PacketReturnType>::size;
195 EIGEN_STATIC_ASSERT(packetSize > 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
196 eigen_assert(index+packetSize-1 < dimensions().TotalSize());
198 EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[packetSize];
199 for (
int i = 0; i < packetSize; ++i) {
200 values[i] = coeff(index+i);
202 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
206 EIGEN_DEVICE_FUNC Scalar* data()
const {
return NULL; }
209 Dimensions m_dimensions;
210 array<Index, NumDims> m_outputStrides;
211 array<Index, NumDims> m_inputStrides;
212 TensorEvaluator<ArgType, Device> m_impl;
213 const Strides m_strides;
214 array<internal::TensorIntDivisor<Index>, NumDims> m_fastStrides;
219 #endif // EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H Namespace containing all symbols from the Eigen library.
Definition: CXX11Meta.h:13