10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_MAP_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_MAP_H 23 template<
typename PlainObjectType,
int Options_,
template <
class>
class MakePointer_>
class TensorMap :
public TensorBase<TensorMap<PlainObjectType, Options_, MakePointer_> >
32 typedef TensorMap<PlainObjectType, Options_, MakePointer_> Self;
33 typedef TensorBase<TensorMap<PlainObjectType, Options_, MakePointer_> > Base;
35 typedef typename Eigen::internal::remove_reference<typename Eigen::internal::nested<Self>::type>::type Nested;
37 typedef typename Eigen::internal::nested<Self>::type Nested;
39 typedef typename internal::traits<PlainObjectType>::StorageKind StorageKind;
40 typedef typename internal::traits<PlainObjectType>::Index Index;
41 typedef typename internal::traits<PlainObjectType>::Scalar Scalar;
42 typedef typename NumTraits<Scalar>::Real RealScalar;
43 typedef typename PlainObjectType::Base::CoeffReturnType CoeffReturnType;
45 typedef typename MakePointer_<Scalar>::Type PointerType;
46 typedef typename MakePointer_<Scalar>::ConstType PointerConstType;
52 typedef typename internal::conditional<
53 bool(internal::is_lvalue<PlainObjectType>::value),
56 >::type StoragePointerType;
61 typedef typename internal::conditional<
62 bool(internal::is_lvalue<PlainObjectType>::value),
65 >::type StorageRefType;
67 static const int Options = Options_;
69 static const Index NumIndices = PlainObjectType::NumIndices;
70 typedef typename PlainObjectType::Dimensions Dimensions;
74 Layout = PlainObjectType::Layout,
80 EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr) : m_data(dataPtr), m_dimensions() {
82 EIGEN_STATIC_ASSERT((0 == NumIndices || NumIndices ==
Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
85 #if EIGEN_HAS_VARIADIC_TEMPLATES 86 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
87 EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index firstDimension, IndexTypes... otherDimensions) : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) {
89 EIGEN_STATIC_ASSERT((
sizeof...(otherDimensions) + 1 == NumIndices || NumIndices ==
Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
93 EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index firstDimension) : m_data(dataPtr), m_dimensions(firstDimension) {
95 EIGEN_STATIC_ASSERT((1 == NumIndices || NumIndices ==
Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
98 EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index dim1, Index dim2) : m_data(dataPtr), m_dimensions(dim1, dim2) {
99 EIGEN_STATIC_ASSERT(2 == NumIndices || NumIndices ==
Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
102 EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index dim1, Index dim2, Index dim3) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3) {
103 EIGEN_STATIC_ASSERT(3 == NumIndices || NumIndices ==
Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
106 EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index dim1, Index dim2, Index dim3, Index dim4) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3, dim4) {
107 EIGEN_STATIC_ASSERT(4 == NumIndices || NumIndices ==
Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
110 EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index dim1, Index dim2, Index dim3, Index dim4, Index dim5) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3, dim4, dim5) {
111 EIGEN_STATIC_ASSERT(5 == NumIndices || NumIndices ==
Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
115 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr,
const array<Index, NumIndices>& dimensions)
116 : m_data(dataPtr), m_dimensions(dimensions)
119 template <
typename Dimensions>
120 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr,
const Dimensions& dimensions)
121 : m_data(dataPtr), m_dimensions(dimensions)
124 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PlainObjectType& tensor)
125 : m_data(tensor.data()), m_dimensions(tensor.dimensions())
129 EIGEN_STRONG_INLINE Index rank()
const {
return m_dimensions.rank(); }
131 EIGEN_STRONG_INLINE Index dimension(Index n)
const {
return m_dimensions[n]; }
133 EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
135 EIGEN_STRONG_INLINE Index size()
const {
return m_dimensions.TotalSize(); }
137 EIGEN_STRONG_INLINE StoragePointerType data() {
return m_data; }
139 EIGEN_STRONG_INLINE StoragePointerType data()
const {
return m_data; }
142 EIGEN_STRONG_INLINE StorageRefType operator()(
const array<Index, NumIndices>& indices)
const 145 if (PlainObjectType::Options&
RowMajor) {
146 const Index index = m_dimensions.IndexOfRowMajor(indices);
147 return m_data[index];
149 const Index index = m_dimensions.IndexOfColMajor(indices);
150 return m_data[index];
155 EIGEN_STRONG_INLINE StorageRefType operator()()
const 157 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
162 EIGEN_STRONG_INLINE StorageRefType operator()(Index index)
const 164 eigen_internal_assert(index >= 0 && index < size());
165 return m_data[index];
168 #if EIGEN_HAS_VARIADIC_TEMPLATES 169 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
170 EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
const 172 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
174 if (PlainObjectType::Options&RowMajor) {
175 const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
176 return m_data[index];
178 const Index index = m_dimensions.IndexOfColMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
179 return m_data[index];
184 EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1)
const 186 if (PlainObjectType::Options&RowMajor) {
187 const Index index = i1 + i0 * m_dimensions[1];
188 return m_data[index];
190 const Index index = i0 + i1 * m_dimensions[0];
191 return m_data[index];
195 EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2)
const 197 if (PlainObjectType::Options&RowMajor) {
198 const Index index = i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0);
199 return m_data[index];
201 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * i2);
202 return m_data[index];
206 EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2, Index i3)
const 208 if (PlainObjectType::Options&RowMajor) {
209 const Index index = i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0));
210 return m_data[index];
212 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * i3));
213 return m_data[index];
217 EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const 219 if (PlainObjectType::Options&RowMajor) {
220 const Index index = i4 + m_dimensions[4] * (i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0)));
221 return m_data[index];
223 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * (i3 + m_dimensions[3] * i4)));
224 return m_data[index];
230 EIGEN_STRONG_INLINE StorageRefType operator()(
const array<Index, NumIndices>& indices)
233 if (PlainObjectType::Options&RowMajor) {
234 const Index index = m_dimensions.IndexOfRowMajor(indices);
235 return m_data[index];
237 const Index index = m_dimensions.IndexOfColMajor(indices);
238 return m_data[index];
243 EIGEN_STRONG_INLINE StorageRefType operator()()
245 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
250 EIGEN_STRONG_INLINE StorageRefType operator()(Index index)
252 eigen_internal_assert(index >= 0 && index < size());
253 return m_data[index];
256 #if EIGEN_HAS_VARIADIC_TEMPLATES 257 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
258 EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
260 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.");
262 const std::size_t NumDims =
sizeof...(otherIndices) + 2;
263 if (PlainObjectType::Options&RowMajor) {
264 const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
265 return m_data[index];
267 const Index index = m_dimensions.IndexOfColMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
268 return m_data[index];
273 EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1)
275 if (PlainObjectType::Options&RowMajor) {
276 const Index index = i1 + i0 * m_dimensions[1];
277 return m_data[index];
279 const Index index = i0 + i1 * m_dimensions[0];
280 return m_data[index];
284 EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2)
286 if (PlainObjectType::Options&RowMajor) {
287 const Index index = 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);
291 return m_data[index];
295 EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2, Index i3)
297 if (PlainObjectType::Options&RowMajor) {
298 const Index index = i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0));
299 return m_data[index];
301 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * i3));
302 return m_data[index];
306 EIGEN_STRONG_INLINE StorageRefType operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
308 if (PlainObjectType::Options&RowMajor) {
309 const Index index = i4 + m_dimensions[4] * (i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0)));
310 return m_data[index];
312 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * (i3 + m_dimensions[3] * i4)));
313 return m_data[index];
318 EIGEN_TENSOR_INHERIT_ASSIGNMENT_OPERATORS(TensorMap)
321 StoragePointerType m_data;
322 Dimensions m_dimensions;
327 #endif // EIGEN_CXX11_TENSOR_TENSOR_MAP_H static const Eigen::internal::all_t all
Namespace containing all symbols from the Eigen library.