10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_MAP_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_MAP_H 21 template<
typename PlainObjectType,
int Options_,
template <
class>
class MakePointer_>
class TensorMap :
public TensorBase<TensorMap<PlainObjectType, Options_, MakePointer_> >
30 typedef TensorMap<PlainObjectType, Options_, MakePointer_> Self;
31 typedef typename PlainObjectType::Base Base;
33 typedef typename internal::traits<PlainObjectType>::StorageKind StorageKind;
34 typedef typename internal::traits<PlainObjectType>::Index Index;
35 typedef typename internal::traits<PlainObjectType>::Scalar Scalar;
36 typedef typename NumTraits<Scalar>::Real RealScalar;
37 typedef typename Base::CoeffReturnType CoeffReturnType;
44 typedef typename MakePointer_<Scalar>::Type PointerType;
45 typedef PointerType PointerArgType;
47 static const int Options = Options_;
49 static const Index NumIndices = PlainObjectType::NumIndices;
50 typedef typename PlainObjectType::Dimensions Dimensions;
54 Layout = PlainObjectType::Layout,
60 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr) : m_data(dataPtr), m_dimensions() {
62 EIGEN_STATIC_ASSERT((0 == NumIndices || NumIndices ==
Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
65 #if EIGEN_HAS_VARIADIC_TEMPLATES 66 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
67 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index firstDimension, IndexTypes... otherDimensions) : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) {
69 EIGEN_STATIC_ASSERT((
sizeof...(otherDimensions) + 1 == NumIndices || NumIndices ==
Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
73 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index firstDimension) : m_data(dataPtr), m_dimensions(firstDimension) {
75 EIGEN_STATIC_ASSERT((1 == NumIndices || NumIndices ==
Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
78 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index dim1, Index dim2) : m_data(dataPtr), m_dimensions(dim1, dim2) {
79 EIGEN_STATIC_ASSERT(2 == NumIndices || NumIndices ==
Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
82 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index dim1, Index dim2, Index dim3) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3) {
83 EIGEN_STATIC_ASSERT(3 == NumIndices || NumIndices ==
Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
86 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index dim1, Index dim2, Index dim3, Index dim4) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3, dim4) {
87 EIGEN_STATIC_ASSERT(4 == NumIndices || NumIndices ==
Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
90 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index dim1, Index dim2, Index dim3, Index dim4, Index dim5) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3, dim4, dim5) {
91 EIGEN_STATIC_ASSERT(5 == NumIndices || NumIndices ==
Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
95 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr,
const array<Index, NumIndices>& dimensions)
96 : m_data(dataPtr), m_dimensions(dimensions)
99 template <
typename Dimensions>
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr,
const Dimensions& dimensions)
101 : m_data(dataPtr), m_dimensions(dimensions)
104 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PlainObjectType& tensor)
105 : m_data(tensor.data()), m_dimensions(tensor.dimensions())
109 EIGEN_STRONG_INLINE Index rank()
const {
return m_dimensions.rank(); }
111 EIGEN_STRONG_INLINE Index dimension(Index n)
const {
return m_dimensions[n]; }
113 EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
115 EIGEN_STRONG_INLINE Index size()
const {
return m_dimensions.TotalSize(); }
117 EIGEN_STRONG_INLINE PointerType data() {
return m_data; }
119 EIGEN_STRONG_INLINE
const PointerType data()
const {
return m_data; }
122 EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const 125 if (PlainObjectType::Options&
RowMajor) {
126 const Index index = m_dimensions.IndexOfRowMajor(indices);
127 return m_data[index];
129 const Index index = m_dimensions.IndexOfColMajor(indices);
130 return m_data[index];
135 EIGEN_STRONG_INLINE
const Scalar& operator()()
const 137 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
142 EIGEN_STRONG_INLINE const Scalar& operator()(Index index)
const 144 eigen_internal_assert(index >= 0 && index < size());
145 return m_data[index];
148 #if EIGEN_HAS_VARIADIC_TEMPLATES 149 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
150 EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
const 152 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
153 if (PlainObjectType::Options&RowMajor) {
154 const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
155 return m_data[index];
157 const Index index = m_dimensions.IndexOfColMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
158 return m_data[index];
163 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1)
const 165 if (PlainObjectType::Options&RowMajor) {
166 const Index index = i1 + i0 * m_dimensions[1];
167 return m_data[index];
169 const Index index = i0 + i1 * m_dimensions[0];
170 return m_data[index];
174 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2)
const 176 if (PlainObjectType::Options&RowMajor) {
177 const Index index = i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0);
178 return m_data[index];
180 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * i2);
181 return m_data[index];
185 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
const 187 if (PlainObjectType::Options&RowMajor) {
188 const Index index = i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0));
189 return m_data[index];
191 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * i3));
192 return m_data[index];
196 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const 198 if (PlainObjectType::Options&RowMajor) {
199 const Index index = i4 + m_dimensions[4] * (i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0)));
200 return m_data[index];
202 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * (i3 + m_dimensions[3] * i4)));
203 return m_data[index];
209 EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices)
212 if (PlainObjectType::Options&RowMajor) {
213 const Index index = m_dimensions.IndexOfRowMajor(indices);
214 return m_data[index];
216 const Index index = m_dimensions.IndexOfColMajor(indices);
217 return m_data[index];
222 EIGEN_STRONG_INLINE Scalar& operator()()
224 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
229 EIGEN_STRONG_INLINE Scalar& operator()(Index index)
231 eigen_internal_assert(index >= 0 && index < size());
232 return m_data[index];
235 #if EIGEN_HAS_VARIADIC_TEMPLATES 236 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
237 EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
239 static_assert(
sizeof...(otherIndices) + 2 == NumIndices || NumIndices ==
Dynamic,
"Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
240 const std::size_t NumDims =
sizeof...(otherIndices) + 2;
241 if (PlainObjectType::Options&RowMajor) {
242 const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
243 return m_data[index];
245 const Index index = m_dimensions.IndexOfColMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
246 return m_data[index];
251 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1)
253 if (PlainObjectType::Options&RowMajor) {
254 const Index index = i1 + i0 * m_dimensions[1];
255 return m_data[index];
257 const Index index = i0 + i1 * m_dimensions[0];
258 return m_data[index];
262 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2)
264 if (PlainObjectType::Options&RowMajor) {
265 const Index index = i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0);
266 return m_data[index];
268 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * i2);
269 return m_data[index];
273 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
275 if (PlainObjectType::Options&RowMajor) {
276 const Index index = i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0));
277 return m_data[index];
279 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * i3));
280 return m_data[index];
284 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
286 if (PlainObjectType::Options&RowMajor) {
287 const Index index = i4 + m_dimensions[4] * (i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0)));
288 return m_data[index];
290 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * (i3 + m_dimensions[3] * i4)));
291 return m_data[index];
296 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Self& operator=(
const Self& other)
298 typedef TensorAssignOp<Self, const Self> Assign;
299 Assign assign(*
this, other);
300 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
304 template<
typename OtherDerived>
305 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
306 Self& operator=(
const OtherDerived& other)
308 typedef TensorAssignOp<Self, const OtherDerived> Assign;
309 Assign assign(*
this, other);
310 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
315 typename MakePointer_<Scalar>::Type m_data;
316 Dimensions m_dimensions;
321 #endif // EIGEN_CXX11_TENSOR_TENSOR_MAP_H Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Definition: Constants.h:235
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:322
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55