10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H 26 template<
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;
36 typedef typename NumTraits<Scalar>::Real RealScalar;
37 typedef typename Base::CoeffReturnType CoeffReturnType;
39 static const int Options = Options_;
42 IsAligned = bool(EIGEN_MAX_ALIGN_BYTES>0),
43 Layout = Options_ & RowMajor ? RowMajor : ColMajor,
48 typedef Dimensions_ Dimensions;
49 static const std::size_t NumIndices = Dimensions::count;
52 TensorStorage<Scalar, Dimensions, Options> m_storage;
55 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank()
const {
return NumIndices; }
56 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n)
const {
return m_storage.dimensions()[n]; }
57 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_storage.dimensions(); }
58 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_storage.size(); }
59 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data() {
return m_storage.data(); }
60 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar *data()
const {
return m_storage.data(); }
65 inline Self& base() {
return *
this; }
66 inline const Self& base()
const {
return *
this; }
68 #if EIGEN_HAS_VARIADIC_TEMPLATES 69 template<
typename... IndexTypes>
70 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index firstIndex, IndexTypes... otherIndices)
const 73 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
74 return coeff(array<Index, NumIndices>{{firstIndex, otherIndices...}});
79 EIGEN_STRONG_INLINE
const Scalar& coeff(
const array<Index, NumIndices>& indices)
const 81 eigen_internal_assert(checkIndexRange(indices));
82 return m_storage.data()[linearizedIndex(indices)];
86 EIGEN_STRONG_INLINE
const Scalar& coeff(Index index)
const 88 eigen_internal_assert(index >= 0 && index < size());
89 return m_storage.data()[index];
93 EIGEN_STRONG_INLINE
const Scalar& coeff()
const 95 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
96 return m_storage.data()[0];
100 #if EIGEN_HAS_VARIADIC_TEMPLATES 101 template<
typename... IndexTypes>
102 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices)
105 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
106 return coeffRef(array<Index, NumIndices>{{firstIndex, otherIndices...}});
111 EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices)
113 eigen_internal_assert(checkIndexRange(indices));
114 return m_storage.data()[linearizedIndex(indices)];
118 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
120 eigen_internal_assert(index >= 0 && index < size());
121 return m_storage.data()[index];
125 EIGEN_STRONG_INLINE Scalar& coeffRef()
127 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
128 return m_storage.data()[0];
131 #if EIGEN_HAS_VARIADIC_TEMPLATES 132 template<
typename... IndexTypes>
133 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
const 136 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
137 return this->operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
141 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1)
const 143 if (Options&RowMajor) {
144 const Index index = i1 + i0 * m_storage.dimensions()[1];
145 return m_storage.data()[index];
147 const Index index = i0 + i1 * m_storage.dimensions()[0];
148 return m_storage.data()[index];
152 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2)
const 154 if (Options&RowMajor) {
155 const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0);
156 return m_storage.data()[index];
158 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2);
159 return m_storage.data()[index];
163 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
const 165 if (Options&RowMajor) {
166 const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0));
167 return m_storage.data()[index];
169 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3));
170 return m_storage.data()[index];
174 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const 176 if (Options&RowMajor) {
177 const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)));
178 return m_storage.data()[index];
180 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4)));
181 return m_storage.data()[index];
188 EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const 190 eigen_assert(checkIndexRange(indices));
191 return coeff(indices);
195 EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const 197 eigen_internal_assert(index >= 0 && index < size());
202 EIGEN_STRONG_INLINE
const Scalar& operator()()
const 204 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
209 EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const 212 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
216 #if EIGEN_HAS_VARIADIC_TEMPLATES 217 template<
typename... IndexTypes>
218 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
221 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
222 return operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
226 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1)
228 if (Options&RowMajor) {
229 const Index index = i1 + i0 * m_storage.dimensions()[1];
230 return m_storage.data()[index];
232 const Index index = i0 + i1 * m_storage.dimensions()[0];
233 return m_storage.data()[index];
237 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2)
239 if (Options&RowMajor) {
240 const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0);
241 return m_storage.data()[index];
243 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2);
244 return m_storage.data()[index];
248 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
250 if (Options&RowMajor) {
251 const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0));
252 return m_storage.data()[index];
254 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3));
255 return m_storage.data()[index];
259 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
261 if (Options&RowMajor) {
262 const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)));
263 return m_storage.data()[index];
265 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4)));
266 return m_storage.data()[index];
272 EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices)
274 eigen_assert(checkIndexRange(indices));
275 return coeffRef(indices);
279 EIGEN_STRONG_INLINE Scalar& operator()(Index index)
281 eigen_assert(index >= 0 && index < size());
282 return coeffRef(index);
286 EIGEN_STRONG_INLINE Scalar& operator()()
288 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
293 EIGEN_STRONG_INLINE Scalar& operator[](Index index)
296 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
297 return coeffRef(index);
307 EIGEN_STRONG_INLINE TensorFixedSize(
const Self& other)
308 : m_storage(other.m_storage)
312 #if EIGEN_HAS_RVALUE_REFERENCES 313 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(Self&& other)
314 : m_storage(other.m_storage)
319 template<
typename OtherDerived>
323 typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign;
324 Assign assign(*
this, other.derived());
325 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
327 template<
typename OtherDerived>
331 typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign;
332 Assign assign(*
this, other.derived());
333 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
337 EIGEN_STRONG_INLINE TensorFixedSize& operator=(
const TensorFixedSize& other)
341 typedef TensorAssignOp<Self, const TensorFixedSize> Assign;
342 Assign assign(*
this, other);
343 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
346 template<
typename OtherDerived>
348 EIGEN_STRONG_INLINE TensorFixedSize& operator=(
const OtherDerived& other)
352 typedef TensorAssignOp<Self, const OtherDerived> Assign;
353 Assign assign(*
this, other);
354 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
360 EIGEN_STRONG_INLINE
bool checkIndexRange(
const array<Index, NumIndices>& )
const 362 using internal::array_apply_and_reduce;
363 using internal::array_zip_and_reduce;
364 using internal::greater_equal_zero_op;
365 using internal::logical_and_op;
366 using internal::lesser_op;
376 EIGEN_STRONG_INLINE Index linearizedIndex(
const array<Index, NumIndices>& indices)
const 378 if (Options&RowMajor) {
379 return m_storage.dimensions().IndexOfRowMajor(indices);
381 return m_storage.dimensions().IndexOfColMajor(indices);
389 #endif // EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H Namespace containing all symbols from the Eigen library.
Definition: AdolcForward:45
The fixed sized version of the tensor class.
Definition: TensorFixedSize.h:27
The tensor base class.
Definition: TensorBase.h:827