10#ifndef EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H
11#define EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H
26template<
typename Scalar_,
typename Dimensions_,
int Options_,
typename IndexType>
32 typedef typename Eigen::internal::nested<Self>::type Nested;
33 typedef typename internal::traits<Self>::StorageKind StorageKind;
34 typedef typename internal::traits<Self>::Index Index;
35 typedef Scalar_ Scalar;
37 typedef typename Base::CoeffReturnType CoeffReturnType;
39 static const int Options = Options_;
42 IsAligned = bool(EIGEN_MAX_ALIGN_BYTES>0),
43 PacketAccess = (internal::packet_traits<Scalar>::size > 1),
45 PreferBlockAccess =
false,
52 typedef internal::TensorBlockNotImplemented TensorBlock;
55 typedef Dimensions_ Dimensions;
56 static const std::size_t NumIndices = Dimensions::count;
59 TensorStorage<Scalar, Dimensions, Options> m_storage;
62 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank()
const {
return NumIndices; }
63 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n)
const {
return m_storage.dimensions()[n]; }
64 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_storage.dimensions(); }
65 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_storage.size(); }
66 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data() {
return m_storage.data(); }
67 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar *data()
const {
return m_storage.data(); }
72 inline Self& base() {
return *
this; }
73 inline const Self& base()
const {
return *
this; }
75#if EIGEN_HAS_VARIADIC_TEMPLATES
76 template<
typename... IndexTypes>
77 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index firstIndex, IndexTypes... otherIndices)
const
80 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
81 return coeff(array<Index, NumIndices>{{firstIndex, otherIndices...}});
86 EIGEN_STRONG_INLINE
const Scalar& coeff(
const array<Index, NumIndices>& indices)
const
88 eigen_internal_assert(checkIndexRange(indices));
89 return m_storage.data()[linearizedIndex(indices)];
93 EIGEN_STRONG_INLINE
const Scalar& coeff(Index index)
const
95 eigen_internal_assert(index >= 0 && index < size());
96 return m_storage.data()[index];
100 EIGEN_STRONG_INLINE
const Scalar& coeff()
const
102 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
103 return m_storage.data()[0];
107#if EIGEN_HAS_VARIADIC_TEMPLATES
108 template<
typename... IndexTypes>
109 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices)
112 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
113 return coeffRef(array<Index, NumIndices>{{firstIndex, otherIndices...}});
118 EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices)
120 eigen_internal_assert(checkIndexRange(indices));
121 return m_storage.data()[linearizedIndex(indices)];
125 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
127 eigen_internal_assert(index >= 0 && index < size());
128 return m_storage.data()[index];
132 EIGEN_STRONG_INLINE Scalar& coeffRef()
134 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
135 return m_storage.data()[0];
138#if EIGEN_HAS_VARIADIC_TEMPLATES
139 template<
typename... IndexTypes>
140 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
const
143 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
144 return this->operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
148 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1)
const
151 const Index index = i1 + i0 * m_storage.dimensions()[1];
152 return m_storage.data()[index];
154 const Index index = i0 + i1 * m_storage.dimensions()[0];
155 return m_storage.data()[index];
159 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2)
const
162 const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0);
163 return m_storage.data()[index];
165 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2);
166 return m_storage.data()[index];
170 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
const
173 const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0));
174 return m_storage.data()[index];
176 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3));
177 return m_storage.data()[index];
181 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const
184 const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)));
185 return m_storage.data()[index];
187 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4)));
188 return m_storage.data()[index];
195 EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const
197 eigen_assert(checkIndexRange(indices));
198 return coeff(indices);
202 EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const
204 eigen_internal_assert(index >= 0 && index < size());
209 EIGEN_STRONG_INLINE
const Scalar& operator()()
const
211 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
216 EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const
219 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
223#if EIGEN_HAS_VARIADIC_TEMPLATES
224 template<
typename... IndexTypes>
225 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
228 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
229 return operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
233 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1)
236 const Index index = i1 + i0 * m_storage.dimensions()[1];
237 return m_storage.data()[index];
239 const Index index = i0 + i1 * m_storage.dimensions()[0];
240 return m_storage.data()[index];
244 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2)
247 const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0);
248 return m_storage.data()[index];
250 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2);
251 return m_storage.data()[index];
255 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
258 const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0));
259 return m_storage.data()[index];
261 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3));
262 return m_storage.data()[index];
266 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
269 const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)));
270 return m_storage.data()[index];
272 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4)));
273 return m_storage.data()[index];
279 EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices)
281 eigen_assert(checkIndexRange(indices));
282 return coeffRef(indices);
286 EIGEN_STRONG_INLINE Scalar& operator()(Index index)
288 eigen_assert(index >= 0 && index < size());
289 return coeffRef(index);
293 EIGEN_STRONG_INLINE Scalar& operator()()
295 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
300 EIGEN_STRONG_INLINE Scalar& operator[](Index index)
303 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
304 return coeffRef(index);
315 : m_storage(other.m_storage)
319#if EIGEN_HAS_RVALUE_REFERENCES
321 : m_storage(other.m_storage)
326 template<
typename OtherDerived>
330 typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign;
331 Assign assign(*
this, other.derived());
332 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
334 template<
typename OtherDerived>
338 typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign;
339 Assign assign(*
this, other.derived());
340 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
350 EIGEN_STRONG_INLINE
bool checkIndexRange(
const array<Index, NumIndices>& )
const
352 using internal::array_apply_and_reduce;
353 using internal::array_zip_and_reduce;
354 using internal::greater_equal_zero_op;
355 using internal::logical_and_op;
356 using internal::lesser_op;
366 EIGEN_STRONG_INLINE Index linearizedIndex(
const array<Index, NumIndices>& indices)
const
369 return m_storage.dimensions().IndexOfRowMajor(indices);
371 return m_storage.dimensions().IndexOfColMajor(indices);
The tensor base class.
Definition: TensorForwardDeclarations.h:56
The fixed sized version of the tensor class.
Definition: TensorFixedSize.h:28
Namespace containing all symbols from the Eigen library.