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 internal::packet_traits<Scalar>::type Packet;
37 typedef typename NumTraits<Scalar>::Real RealScalar;
38 typedef typename Base::CoeffReturnType CoeffReturnType;
40 static const int Options = Options_;
43 IsAligned = bool(EIGEN_MAX_ALIGN_BYTES>0),
44 PacketAccess = (internal::packet_traits<Scalar>::size > 1),
45 Layout = Options_ & RowMajor ? RowMajor : ColMajor,
49 typedef Dimensions_ Dimensions;
50 static const std::size_t NumIndices = Dimensions::count;
53 TensorStorage<Scalar, Dimensions, Options> m_storage;
56 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank()
const {
return NumIndices; }
57 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n)
const {
return m_storage.dimensions()[n]; }
58 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_storage.dimensions(); }
59 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_storage.size(); }
60 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data() {
return m_storage.data(); }
61 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar *data()
const {
return m_storage.data(); }
66 inline Self& base() {
return *
this; }
67 inline const Self& base()
const {
return *
this; }
69 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES 70 template<
typename... IndexTypes>
71 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index firstIndex, IndexTypes... otherIndices)
const 74 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
75 return coeff(array<Index, NumIndices>{{firstIndex, otherIndices...}});
80 EIGEN_STRONG_INLINE
const Scalar& coeff(
const array<Index, NumIndices>& indices)
const 82 eigen_internal_assert(checkIndexRange(indices));
83 return m_storage.data()[linearizedIndex(indices)];
87 EIGEN_STRONG_INLINE
const Scalar& coeff(Index index)
const 89 eigen_internal_assert(index >= 0 && index < size());
90 return m_storage.data()[index];
94 EIGEN_STRONG_INLINE
const Scalar& coeff()
const 96 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
97 return m_storage.data()[0];
101 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES 102 template<
typename... IndexTypes>
103 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices)
106 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
107 return coeffRef(array<Index, NumIndices>{{firstIndex, otherIndices...}});
112 EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices)
114 eigen_internal_assert(checkIndexRange(indices));
115 return m_storage.data()[linearizedIndex(indices)];
119 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
121 eigen_internal_assert(index >= 0 && index < size());
122 return m_storage.data()[index];
126 EIGEN_STRONG_INLINE Scalar& coeffRef()
128 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
129 return m_storage.data()[0];
133 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES 134 template<
typename... IndexTypes>
135 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
const 138 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
139 return this->operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
144 EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const 146 eigen_assert(checkIndexRange(indices));
147 return coeff(indices);
151 EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const 153 eigen_internal_assert(index >= 0 && index < size());
158 EIGEN_STRONG_INLINE
const Scalar& operator()()
const 160 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
165 EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const 168 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
172 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES 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...}});
183 EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices)
185 eigen_assert(checkIndexRange(indices));
186 return coeffRef(indices);
190 EIGEN_STRONG_INLINE Scalar& operator()(Index index)
192 eigen_assert(index >= 0 && index < size());
193 return coeffRef(index);
197 EIGEN_STRONG_INLINE Scalar& operator()()
199 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
204 EIGEN_STRONG_INLINE Scalar& operator[](Index index)
207 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
208 return coeffRef(index);
218 EIGEN_STRONG_INLINE TensorFixedSize(
const Self& other)
219 : m_storage(other.m_storage)
223 #ifdef EIGEN_HAVE_RVALUE_REFERENCES 224 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(Self&& other)
225 : m_storage(other.m_storage)
230 template<
typename OtherDerived>
234 typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign;
235 Assign assign(*
this, other.derived());
236 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
238 template<
typename OtherDerived>
242 typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign;
243 Assign assign(*
this, other.derived());
244 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
248 EIGEN_STRONG_INLINE TensorFixedSize& operator=(
const TensorFixedSize& other)
252 typedef TensorAssignOp<Self, const TensorFixedSize> Assign;
253 Assign assign(*
this, other);
254 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
257 template<
typename OtherDerived>
259 EIGEN_STRONG_INLINE TensorFixedSize& operator=(
const OtherDerived& other)
263 typedef TensorAssignOp<Self, const OtherDerived> Assign;
264 Assign assign(*
this, other);
265 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
271 EIGEN_STRONG_INLINE
bool checkIndexRange(
const array<Index, NumIndices>& )
const 273 using internal::array_apply_and_reduce;
274 using internal::array_zip_and_reduce;
275 using internal::greater_equal_zero_op;
276 using internal::logical_and_op;
277 using internal::lesser_op;
287 EIGEN_STRONG_INLINE Index linearizedIndex(
const array<Index, NumIndices>& indices)
const 289 if (Options&RowMajor) {
290 return m_storage.dimensions().IndexOfRowMajor(indices);
292 return m_storage.dimensions().IndexOfColMajor(indices);
300 #endif // EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H Namespace containing all symbols from the Eigen library.
Definition: CXX11Meta.h:13
The fixed sized version of the tensor class.
Definition: TensorFixedSize.h:27
The tensor base class.
Definition: TensorForwardDeclarations.h:19