25class 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),
46 typedef Dimensions_ Dimensions;
47 static const std::size_t NumIndices = Dimensions::count;
50 TensorStorage<Scalar, Dimensions, Options> m_storage;
53 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank()
const {
return NumIndices; }
54 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n)
const {
return m_storage.dimensions()[n]; }
55 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_storage.dimensions(); }
56 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_storage.size(); }
57 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data() {
return m_storage.data(); }
58 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar *data()
const {
return m_storage.data(); }
63 inline Self& base() {
return *
this; }
64 inline const Self& base()
const {
return *
this; }
66#if EIGEN_HAS_VARIADIC_TEMPLATES
67 template<
typename... IndexTypes>
68 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index firstIndex, IndexTypes... otherIndices)
const
71 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
72 return coeff(array<Index, NumIndices>{{firstIndex, otherIndices...}});
77 EIGEN_STRONG_INLINE
const Scalar& coeff(
const array<Index, NumIndices>& indices)
const
79 eigen_internal_assert(checkIndexRange(indices));
80 return m_storage.data()[linearizedIndex(indices)];
84 EIGEN_STRONG_INLINE
const Scalar& coeff(Index index)
const
86 eigen_internal_assert(index >= 0 && index < size());
87 return m_storage.data()[index];
91 EIGEN_STRONG_INLINE
const Scalar& coeff()
const
93 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
94 return m_storage.data()[0];
98#if EIGEN_HAS_VARIADIC_TEMPLATES
99 template<
typename... IndexTypes>
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices)
103 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
104 return coeffRef(array<Index, NumIndices>{{firstIndex, otherIndices...}});
109 EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices)
111 eigen_internal_assert(checkIndexRange(indices));
112 return m_storage.data()[linearizedIndex(indices)];
116 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
118 eigen_internal_assert(index >= 0 && index < size());
119 return m_storage.data()[index];
123 EIGEN_STRONG_INLINE Scalar& coeffRef()
125 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
126 return m_storage.data()[0];
129#if EIGEN_HAS_VARIADIC_TEMPLATES
130 template<
typename... IndexTypes>
131 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
const
134 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
135 return this->operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
139 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1)
const
142 const Index index = i1 + i0 * m_storage.dimensions()[1];
143 return m_storage.data()[index];
145 const Index index = i0 + i1 * m_storage.dimensions()[0];
146 return m_storage.data()[index];
150 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2)
const
153 const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0);
154 return m_storage.data()[index];
156 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2);
157 return m_storage.data()[index];
161 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
const
164 const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0));
165 return m_storage.data()[index];
167 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3));
168 return m_storage.data()[index];
172 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const
175 const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)));
176 return m_storage.data()[index];
178 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4)));
179 return m_storage.data()[index];
186 EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const
188 eigen_assert(checkIndexRange(indices));
189 return coeff(indices);
193 EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const
195 eigen_internal_assert(index >= 0 && index < size());
200 EIGEN_STRONG_INLINE
const Scalar& operator()()
const
202 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
207 EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const
210 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
214#if EIGEN_HAS_VARIADIC_TEMPLATES
215 template<
typename... IndexTypes>
216 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
219 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
220 return operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
224 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1)
227 const Index index = i1 + i0 * m_storage.dimensions()[1];
228 return m_storage.data()[index];
230 const Index index = i0 + i1 * m_storage.dimensions()[0];
231 return m_storage.data()[index];
235 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2)
238 const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0);
239 return m_storage.data()[index];
241 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2);
242 return m_storage.data()[index];
246 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
249 const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0));
250 return m_storage.data()[index];
252 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3));
253 return m_storage.data()[index];
257 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
260 const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)));
261 return m_storage.data()[index];
263 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4)));
264 return m_storage.data()[index];
270 EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices)
272 eigen_assert(checkIndexRange(indices));
273 return coeffRef(indices);
277 EIGEN_STRONG_INLINE Scalar& operator()(Index index)
279 eigen_assert(index >= 0 && index < size());
280 return coeffRef(index);
284 EIGEN_STRONG_INLINE Scalar& operator()()
286 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
291 EIGEN_STRONG_INLINE Scalar& operator[](Index index)
294 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
295 return coeffRef(index);
299 EIGEN_STRONG_INLINE TensorFixedSize()
305 EIGEN_STRONG_INLINE TensorFixedSize(
const Self& other)
306 : m_storage(other.m_storage)
310#if EIGEN_HAS_RVALUE_REFERENCES
311 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(Self&& other)
312 : m_storage(other.m_storage)
317 template<
typename OtherDerived>
322 Assign assign(*
this, other.derived());
323 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
325 template<
typename OtherDerived>
330 Assign assign(*
this, other.derived());
331 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
335 EIGEN_STRONG_INLINE TensorFixedSize& operator=(
const TensorFixedSize& other)
340 Assign assign(*
this, other);
341 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
344 template<
typename OtherDerived>
346 EIGEN_STRONG_INLINE TensorFixedSize& operator=(
const OtherDerived& other)
351 Assign assign(*
this, other);
352 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
358 EIGEN_STRONG_INLINE
bool checkIndexRange(
const array<Index, NumIndices>& )
const
360 using internal::array_apply_and_reduce;
361 using internal::array_zip_and_reduce;
362 using internal::greater_equal_zero_op;
363 using internal::logical_and_op;
364 using internal::lesser_op;
374 EIGEN_STRONG_INLINE Index linearizedIndex(
const array<Index, NumIndices>& indices)
const
377 return m_storage.dimensions().IndexOfRowMajor(indices);
379 return m_storage.dimensions().IndexOfColMajor(indices);