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 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];
93 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES
94 template<
typename... IndexTypes>
95 inline Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices)
98 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
99 return coeffRef(array<Index, NumIndices>{{firstIndex, otherIndices...}});
104 EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices)
106 eigen_internal_assert(checkIndexRange(indices));
107 return m_storage.data()[linearizedIndex(indices)];
111 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
113 eigen_internal_assert(index >= 0 && index < size());
114 return m_storage.data()[index];
117 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES
118 template<
typename... IndexTypes>
119 inline const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
const
122 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
123 return this->operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
128 EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const
130 eigen_assert(checkIndexRange(indices));
131 return coeff(indices);
135 EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const
137 eigen_internal_assert(index >= 0 && index < size());
142 EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const
145 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
149 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES
150 template<
typename... IndexTypes>
151 inline Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
154 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
155 return operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
160 EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices)
162 eigen_assert(checkIndexRange(indices));
163 return coeffRef(indices);
167 EIGEN_STRONG_INLINE Scalar& operator()(Index index)
169 eigen_assert(index >= 0 && index < size());
170 return coeffRef(index);
174 EIGEN_STRONG_INLINE Scalar& operator[](Index index)
177 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
178 return coeffRef(index);
188 EIGEN_STRONG_INLINE TensorFixedSize(
const Self& other)
189 : m_storage(other.m_storage)
193 #ifdef EIGEN_HAVE_RVALUE_REFERENCES
194 inline TensorFixedSize(Self&& other)
195 : m_storage(other.m_storage)
200 template<
typename OtherDerived>
204 typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign;
205 Assign assign(*
this, other.derived());
206 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
208 template<
typename OtherDerived>
212 typedef TensorAssignOp<TensorFixedSize, const OtherDerived> Assign;
213 Assign assign(*
this, other.derived());
214 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
218 EIGEN_STRONG_INLINE TensorFixedSize& operator=(
const TensorFixedSize& other)
222 typedef TensorAssignOp<Self, const TensorFixedSize> Assign;
223 Assign assign(*
this, other);
224 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
227 template<
typename OtherDerived>
229 EIGEN_STRONG_INLINE TensorFixedSize& operator=(
const OtherDerived& other)
233 typedef TensorAssignOp<Self, const OtherDerived> Assign;
234 Assign assign(*
this, other);
235 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
241 EIGEN_STRONG_INLINE
bool checkIndexRange(
const array<Index, NumIndices>& )
const
243 using internal::array_apply_and_reduce;
244 using internal::array_zip_and_reduce;
245 using internal::greater_equal_zero_op;
246 using internal::logical_and_op;
247 using internal::lesser_op;
257 EIGEN_STRONG_INLINE Index linearizedIndex(
const array<Index, NumIndices>& indices)
const
259 if (Options&RowMajor) {
260 return m_storage.dimensions().IndexOfRowMajor(indices);
262 return m_storage.dimensions().IndexOfColMajor(indices);
270 #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