10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H
13 #include "./InternalHeaderCheck.h"
28 template<
typename Scalar_,
typename Dimensions_,
int Options_,
typename IndexType>
34 typedef typename Eigen::internal::nested<Self>::type Nested;
35 typedef typename internal::traits<Self>::StorageKind StorageKind;
36 typedef typename internal::traits<Self>::Index Index;
37 typedef Scalar_ Scalar;
39 typedef typename Base::CoeffReturnType CoeffReturnType;
41 static constexpr
int Options = Options_;
45 IsAligned = bool(EIGEN_MAX_ALIGN_BYTES>0),
46 PacketAccess = (internal::packet_traits<Scalar>::size > 1),
48 PreferBlockAccess =
false,
54 typedef internal::TensorBlockNotImplemented TensorBlock;
57 typedef Dimensions_ Dimensions;
58 static constexpr std::size_t NumIndices = Dimensions::count;
61 TensorStorage<Scalar, Dimensions, Options> m_storage;
64 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank()
const {
return NumIndices; }
65 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n)
const {
return m_storage.dimensions()[n]; }
66 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions dimensions()
const {
return m_storage.dimensions(); }
67 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_storage.size(); }
68 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data() {
return m_storage.data(); }
69 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar *data()
const {
return m_storage.data(); }
74 inline Self& base() {
return *
this; }
75 inline const Self& base()
const {
return *
this; }
77 template<
typename... IndexTypes>
78 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index firstIndex, IndexTypes... otherIndices)
const
81 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
82 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 template<
typename... IndexTypes>
108 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices)
111 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
112 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 template<
typename... IndexTypes>
137 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
const
140 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
141 return this->operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
145 EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const
147 eigen_assert(checkIndexRange(indices));
148 return coeff(indices);
152 EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const
154 eigen_internal_assert(index >= 0 && index < size());
159 EIGEN_STRONG_INLINE
const Scalar& operator()()
const
161 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
166 EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const
169 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
173 template<
typename... IndexTypes>
174 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
177 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
178 return operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
182 EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices)
184 eigen_assert(checkIndexRange(indices));
185 return coeffRef(indices);
189 EIGEN_STRONG_INLINE Scalar& operator()(Index index)
191 eigen_assert(index >= 0 && index < size());
192 return coeffRef(index);
196 EIGEN_STRONG_INLINE Scalar& operator()()
198 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
203 EIGEN_STRONG_INLINE Scalar& operator[](Index index)
206 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
207 return coeffRef(index);
218 :
Base(other), m_storage(other.m_storage)
223 : m_storage(other.m_storage)
227 template<
typename OtherDerived>
231 typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign;
232 Assign assign(*
this, other.derived());
233 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
235 template<
typename OtherDerived>
239 typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign;
240 Assign assign(*
this, other.derived());
241 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
251 EIGEN_STRONG_INLINE
bool checkIndexRange(
const array<Index, NumIndices>& )
const
253 using internal::array_apply_and_reduce;
254 using internal::array_zip_and_reduce;
255 using internal::greater_equal_zero_op;
256 using internal::logical_and_op;
257 using internal::lesser_op;
267 EIGEN_STRONG_INLINE Index linearizedIndex(
const array<Index, NumIndices>& indices)
const
270 return m_storage.dimensions().IndexOfRowMajor(indices);
272 return m_storage.dimensions().IndexOfColMajor(indices);
The tensor base class.
Definition: TensorForwardDeclarations.h:58
The fixed sized version of the tensor class.
Definition: TensorFixedSize.h:30
Namespace containing all symbols from the Eigen library.