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 internal::packet_traits<Scalar>::type Packet;
32 typedef typename NumTraits<Scalar>::Real RealScalar;
33 typedef typename Base::CoeffReturnType CoeffReturnType;
40 typedef Scalar* PointerType;
41 typedef PointerType PointerArgType;
43 static const int Options = Options_;
45 static const Index NumIndices = PlainObjectType::NumIndices;
46 typedef typename PlainObjectType::Dimensions Dimensions;
49 IsAligned = ((int(Options_)&Aligned)==Aligned),
50 PacketAccess = (internal::packet_traits<Scalar>::size > 1),
51 Layout = PlainObjectType::Layout,
56 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr) : m_data(dataPtr), m_dimensions() {
58 EIGEN_STATIC_ASSERT((0 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
61 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES
62 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
63 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index firstDimension, IndexTypes... otherDimensions) : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) {
65 EIGEN_STATIC_ASSERT((
sizeof...(otherDimensions) + 1 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
69 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index firstDimension) : m_data(dataPtr), m_dimensions(firstDimension) {
71 EIGEN_STATIC_ASSERT((1 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
74 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index dim1, Index dim2) : m_data(dataPtr), m_dimensions(dim1, dim2) {
75 EIGEN_STATIC_ASSERT(2 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
78 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index dim1, Index dim2, Index dim3) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3) {
79 EIGEN_STATIC_ASSERT(3 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
82 EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index dim1, Index dim2, Index dim3, Index dim4) : m_data(dataPtr), m_dimensions(dim1, dim2, dim3, dim4) {
83 EIGEN_STATIC_ASSERT(4 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
86 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) {
87 EIGEN_STATIC_ASSERT(5 == NumIndices || NumIndices == Dynamic, YOU_MADE_A_PROGRAMMING_MISTAKE)
91 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr,
const array<Index, NumIndices>& dimensions)
92 : m_data(dataPtr), m_dimensions(dimensions)
95 template <
typename Dimensions>
96 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr,
const Dimensions& dimensions)
97 : m_data(dataPtr), m_dimensions(dimensions)
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PlainObjectType& tensor)
101 : m_data(tensor.data()), m_dimensions(tensor.dimensions())
105 EIGEN_STRONG_INLINE Index rank()
const {
return m_dimensions.rank(); }
107 EIGEN_STRONG_INLINE Index dimension(Index n)
const {
return m_dimensions[n]; }
109 EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
111 EIGEN_STRONG_INLINE Index size()
const {
return m_dimensions.TotalSize(); }
113 EIGEN_STRONG_INLINE Scalar* data() {
return m_data; }
115 EIGEN_STRONG_INLINE
const Scalar* data()
const {
return m_data; }
118 EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const
121 if (PlainObjectType::Options&RowMajor) {
122 const Index index = m_dimensions.IndexOfRowMajor(indices);
123 return m_data[index];
125 const Index index = m_dimensions.IndexOfColMajor(indices);
126 return m_data[index];
131 EIGEN_STRONG_INLINE
const Scalar& operator()()
const
133 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
137 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES
138 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
139 EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
const
141 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
142 if (PlainObjectType::Options&RowMajor) {
143 const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, otherIndices...}});
144 return m_data[index];
146 const Index index = m_dimensions.IndexOfColMajor(array<Index, NumIndices>{{firstIndex, otherIndices...}});
147 return m_data[index];
152 EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const
154 eigen_internal_assert(index >= 0 && index < size());
155 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)
223 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES
224 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
225 EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
227 static_assert(
sizeof...(otherIndices) + 1 == NumIndices || NumIndices == Dynamic,
"Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
228 const std::size_t NumDims =
sizeof...(otherIndices) + 1;
229 if (PlainObjectType::Options&RowMajor) {
230 const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumDims>{{firstIndex, otherIndices...}});
231 return m_data[index];
233 const Index index = m_dimensions.IndexOfColMajor(array<Index, NumDims>{{firstIndex, otherIndices...}});
234 return m_data[index];
239 EIGEN_STRONG_INLINE Scalar& operator()(Index index)
241 eigen_internal_assert(index >= 0 && index < size());
242 return m_data[index];
245 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1)
247 if (PlainObjectType::Options&RowMajor) {
248 const Index index = i1 + i0 * m_dimensions[1];
249 return m_data[index];
251 const Index index = i0 + i1 * m_dimensions[0];
252 return m_data[index];
256 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2)
258 if (PlainObjectType::Options&RowMajor) {
259 const Index index = i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0);
260 return m_data[index];
262 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * i2);
263 return m_data[index];
267 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
269 if (PlainObjectType::Options&RowMajor) {
270 const Index index = i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0));
271 return m_data[index];
273 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * i3));
274 return m_data[index];
278 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
280 if (PlainObjectType::Options&RowMajor) {
281 const Index index = i4 + m_dimensions[4] * (i3 + m_dimensions[3] * (i2 + m_dimensions[2] * (i1 + m_dimensions[1] * i0)));
282 return m_data[index];
284 const Index index = i0 + m_dimensions[0] * (i1 + m_dimensions[1] * (i2 + m_dimensions[2] * (i3 + m_dimensions[3] * i4)));
285 return m_data[index];
290 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Self& operator=(
const Self& other)
292 typedef TensorAssignOp<Self, const Self> Assign;
293 Assign assign(*
this, other);
294 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
298 template<
typename OtherDerived>
299 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
300 Self& operator=(
const OtherDerived& other)
302 typedef TensorAssignOp<Self, const OtherDerived> Assign;
303 Assign assign(*
this, other);
304 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
310 Dimensions m_dimensions;
315 #endif // EIGEN_CXX11_TENSOR_TENSOR_MAP_H
Namespace containing all symbols from the Eigen library.
Definition: CXX11Meta.h:13