26class TensorFixedSize :
public TensorBase<TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> > {
28 typedef TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> Self;
30 typedef typename Eigen::internal::nested<Self>::type Nested;
31 typedef typename internal::traits<Self>::StorageKind StorageKind;
32 typedef typename internal::traits<Self>::Index Index;
33 typedef Scalar_ Scalar;
35 typedef typename Base::CoeffReturnType CoeffReturnType;
37 static const int Options = Options_;
40 IsAligned = bool(EIGEN_MAX_ALIGN_BYTES>0),
41 PacketAccess = (internal::packet_traits<Scalar>::size > 1),
43 PreferBlockAccess =
false,
50 typedef internal::TensorBlockNotImplemented TensorBlock;
53 typedef Dimensions_ Dimensions;
54 static const std::size_t NumIndices = Dimensions::count;
57 TensorStorage<Scalar, Dimensions, Options> m_storage;
60 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank()
const {
return NumIndices; }
61 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n)
const {
return m_storage.dimensions()[n]; }
62 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions dimensions()
const {
return m_storage.dimensions(); }
63 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_storage.size(); }
64 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data() {
return m_storage.data(); }
65 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar *data()
const {
return m_storage.data(); }
70 inline Self& base() {
return *
this; }
71 inline const Self& base()
const {
return *
this; }
73#if EIGEN_HAS_VARIADIC_TEMPLATES
74 template<
typename... IndexTypes>
75 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index firstIndex, IndexTypes... otherIndices)
const
78 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
79 return coeff(array<Index, NumIndices>{{firstIndex, otherIndices...}});
84 EIGEN_STRONG_INLINE
const Scalar& coeff(
const array<Index, NumIndices>& indices)
const
86 eigen_internal_assert(checkIndexRange(indices));
87 return m_storage.data()[linearizedIndex(indices)];
91 EIGEN_STRONG_INLINE
const Scalar& coeff(Index index)
const
93 eigen_internal_assert(index >= 0 && index < size());
94 return m_storage.data()[index];
98 EIGEN_STRONG_INLINE
const Scalar& coeff()
const
100 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
101 return m_storage.data()[0];
105#if EIGEN_HAS_VARIADIC_TEMPLATES
106 template<
typename... IndexTypes>
107 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices)
110 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
111 return coeffRef(array<Index, NumIndices>{{firstIndex, otherIndices...}});
116 EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices)
118 eigen_internal_assert(checkIndexRange(indices));
119 return m_storage.data()[linearizedIndex(indices)];
123 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
125 eigen_internal_assert(index >= 0 && index < size());
126 return m_storage.data()[index];
130 EIGEN_STRONG_INLINE Scalar& coeffRef()
132 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
133 return m_storage.data()[0];
136#if EIGEN_HAS_VARIADIC_TEMPLATES
137 template<
typename... IndexTypes>
138 EIGEN_DEVICE_FUNC 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 return this->operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
146 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1)
const
149 const Index index = i1 + i0 * m_storage.dimensions()[1];
150 return m_storage.data()[index];
152 const Index index = i0 + i1 * m_storage.dimensions()[0];
153 return m_storage.data()[index];
157 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2)
const
160 const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0);
161 return m_storage.data()[index];
163 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2);
164 return m_storage.data()[index];
168 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
const
171 const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0));
172 return m_storage.data()[index];
174 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3));
175 return m_storage.data()[index];
179 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const
182 const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)));
183 return m_storage.data()[index];
185 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4)));
186 return m_storage.data()[index];
193 EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const
195 eigen_assert(checkIndexRange(indices));
196 return coeff(indices);
200 EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const
202 eigen_internal_assert(index >= 0 && index < size());
207 EIGEN_STRONG_INLINE
const Scalar& operator()()
const
209 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
214 EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const
217 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
221#if EIGEN_HAS_VARIADIC_TEMPLATES
222 template<
typename... IndexTypes>
223 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
226 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
227 return operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
231 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1)
234 const Index index = i1 + i0 * m_storage.dimensions()[1];
235 return m_storage.data()[index];
237 const Index index = i0 + i1 * m_storage.dimensions()[0];
238 return m_storage.data()[index];
242 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2)
245 const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0);
246 return m_storage.data()[index];
248 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2);
249 return m_storage.data()[index];
253 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
256 const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0));
257 return m_storage.data()[index];
259 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3));
260 return m_storage.data()[index];
264 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
267 const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)));
268 return m_storage.data()[index];
270 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4)));
271 return m_storage.data()[index];
277 EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices)
279 eigen_assert(checkIndexRange(indices));
280 return coeffRef(indices);
284 EIGEN_STRONG_INLINE Scalar& operator()(Index index)
286 eigen_assert(index >= 0 && index < size());
287 return coeffRef(index);
291 EIGEN_STRONG_INLINE Scalar& operator()()
293 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
298 EIGEN_STRONG_INLINE Scalar& operator[](Index index)
301 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
302 return coeffRef(index);
306 EIGEN_STRONG_INLINE TensorFixedSize()
312 EIGEN_STRONG_INLINE TensorFixedSize(
const Self& other)
313 : m_storage(other.m_storage)
317#if EIGEN_HAS_RVALUE_REFERENCES
318 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(Self&& other)
319 : m_storage(other.m_storage)
324 template<
typename OtherDerived>
329 Assign assign(*
this, other.derived());
330 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
332 template<
typename OtherDerived>
337 Assign assign(*
this, other.derived());
338 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
343 EIGEN_TENSOR_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(TensorFixedSize)
348 EIGEN_STRONG_INLINE
bool checkIndexRange(
const array<Index, NumIndices>& )
const
350 using internal::array_apply_and_reduce;
351 using internal::array_zip_and_reduce;
352 using internal::greater_equal_zero_op;
353 using internal::logical_and_op;
354 using internal::lesser_op;
364 EIGEN_STRONG_INLINE Index linearizedIndex(
const array<Index, NumIndices>& indices)
const
367 return m_storage.dimensions().IndexOfRowMajor(indices);
369 return m_storage.dimensions().IndexOfColMajor(indices);