10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_MAP_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_MAP_H 22 template<
typename PlainObjectType,
int Options_>
class TensorMap :
public TensorBase<TensorMap<PlainObjectType, Options_> >
25 typedef TensorMap<PlainObjectType, Options_> Self;
26 typedef typename PlainObjectType::Base Base;
27 typedef typename Eigen::internal::nested<Self>::type Nested;
28 typedef typename internal::traits<PlainObjectType>::StorageKind StorageKind;
29 typedef typename internal::traits<PlainObjectType>::Index Index;
30 typedef typename internal::traits<PlainObjectType>::Scalar Scalar;
31 typedef typename NumTraits<Scalar>::Real RealScalar;
32 typedef typename Base::CoeffReturnType CoeffReturnType;
39 typedef Scalar* PointerType;
40 typedef PointerType PointerArgType;
42 static const int Options = Options_;
44 static const Index NumIndices = PlainObjectType::NumIndices;
45 typedef typename PlainObjectType::Dimensions Dimensions;
48 IsAligned = ((int(Options_)&Aligned)==Aligned),
49 Layout = PlainObjectType::Layout,
55 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr) : m_data(dataPtr), m_dimensions() {
57 EIGEN_STATIC_ASSERT((0 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
60 #if EIGEN_HAS_VARIADIC_TEMPLATES 61 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
62 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index firstDimension, IndexTypes... otherDimensions) : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) {
64 EIGEN_STATIC_ASSERT((
sizeof...(otherDimensions) + 1 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
68 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index firstDimension) : m_data(dataPtr), m_dimensions(firstDimension) {
70 EIGEN_STATIC_ASSERT((1 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
73 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index dim1, Index dim2) : m_data(dataPtr), m_dimensions(dim1, dim2) {
74 EIGEN_STATIC_ASSERT(2 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
77 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index dim1, Index dim2, Index dim3) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3) {
78 EIGEN_STATIC_ASSERT(3 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
81 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index dim1, Index dim2, Index dim3, Index dim4) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3, dim4) {
82 EIGEN_STATIC_ASSERT(4 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
85 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) {
86 EIGEN_STATIC_ASSERT(5 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
90 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr,
const array<Index, NumIndices>& dimensions)
91 : m_data(dataPtr), m_dimensions(dimensions)
94 template <
typename Dimensions>
95 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr,
const Dimensions& dimensions)
96 : m_data(dataPtr), m_dimensions(dimensions)
99 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PlainObjectType& tensor)
100 : m_data(tensor.data()), m_dimensions(tensor.dimensions())
104 EIGEN_STRONG_INLINE Index rank()
const {
return m_dimensions.rank(); }
106 EIGEN_STRONG_INLINE Index dimension(Index n)
const {
return m_dimensions[n]; }
108 EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
110 EIGEN_STRONG_INLINE Index size()
const {
return m_dimensions.TotalSize(); }
112 EIGEN_STRONG_INLINE Scalar* data() {
return m_data; }
114 EIGEN_STRONG_INLINE
const Scalar* data()
const {
return m_data; }
117 EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const 120 if (PlainObjectType::Options&RowMajor) {
121 const Index index = m_dimensions.IndexOfRowMajor(indices);
122 return m_data[index];
124 const Index index = m_dimensions.IndexOfColMajor(indices);
125 return m_data[index];
130 EIGEN_STRONG_INLINE
const Scalar& operator()()
const 132 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
137 EIGEN_STRONG_INLINE const Scalar& operator()(Index index)
const 139 eigen_internal_assert(index >= 0 && index < size());
140 return m_data[index];
143 #if EIGEN_HAS_VARIADIC_TEMPLATES 144 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
145 EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
const 147 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
148 if (PlainObjectType::Options&RowMajor) {
149 const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
150 return m_data[index];
152 const Index index = m_dimensions.IndexOfColMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
153 return m_data[index];
158 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1)
const 160 if (PlainObjectType::Options&RowMajor) {
161 const Index index = i1 + i0 * m_dimensions[1];
162 return m_data[index];
164 const Index index = i0 + i1 * m_dimensions[0];
165 return m_data[index];
169 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2)
const 171 if (PlainObjectType::Options&RowMajor) {
172 const Index index = i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0);
173 return m_data[index];
175 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * i2);
176 return m_data[index];
180 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
const 182 if (PlainObjectType::Options&RowMajor) {
183 const Index index = i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0));
184 return m_data[index];
186 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * i3));
187 return m_data[index];
191 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const 193 if (PlainObjectType::Options&RowMajor) {
194 const Index index = i4 + m_dimensions[4] * (i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0)));
195 return m_data[index];
197 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * (i3 + m_dimensions[3] * i4)));
198 return m_data[index];
204 EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices)
207 if (PlainObjectType::Options&RowMajor) {
208 const Index index = m_dimensions.IndexOfRowMajor(indices);
209 return m_data[index];
211 const Index index = m_dimensions.IndexOfColMajor(indices);
212 return m_data[index];
217 EIGEN_STRONG_INLINE Scalar& operator()()
219 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
224 EIGEN_STRONG_INLINE Scalar& operator()(Index index)
226 eigen_internal_assert(index >= 0 && index < size());
227 return m_data[index];
230 #if EIGEN_HAS_VARIADIC_TEMPLATES 231 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
232 EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
234 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.");
235 const std::size_t NumDims =
sizeof...(otherIndices) + 2;
236 if (PlainObjectType::Options&RowMajor) {
237 const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
238 return m_data[index];
240 const Index index = m_dimensions.IndexOfColMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
241 return m_data[index];
246 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1)
248 if (PlainObjectType::Options&RowMajor) {
249 const Index index = i1 + i0 * m_dimensions[1];
250 return m_data[index];
252 const Index index = i0 + i1 * m_dimensions[0];
253 return m_data[index];
257 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2)
259 if (PlainObjectType::Options&RowMajor) {
260 const Index index = i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0);
261 return m_data[index];
263 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * i2);
264 return m_data[index];
268 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
270 if (PlainObjectType::Options&RowMajor) {
271 const Index index = i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0));
272 return m_data[index];
274 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * i3));
275 return m_data[index];
279 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
281 if (PlainObjectType::Options&RowMajor) {
282 const Index index = i4 + m_dimensions[4] * (i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0)));
283 return m_data[index];
285 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * (i3 + m_dimensions[3] * i4)));
286 return m_data[index];
291 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Self& operator=(
const Self& other)
293 typedef TensorAssignOp<Self, const Self> Assign;
294 Assign assign(*
this, other);
295 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
299 template<
typename OtherDerived>
300 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
301 Self& operator=(
const OtherDerived& other)
303 typedef TensorAssignOp<Self, const OtherDerived> Assign;
304 Assign assign(*
this, other);
305 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
311 Dimensions m_dimensions;
316 #endif // EIGEN_CXX11_TENSOR_TENSOR_MAP_H Namespace containing all symbols from the Eigen library.
Definition: AdolcForward:45