30class TensorFixedSize :
public TensorBase<TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> > {
32 typedef TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> Self;
34 typedef typename Eigen::internal::ref_selector<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_STATIC_ALIGN_BYTES >=
Aligned),
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 constexpr 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 constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions dimensions()
const {
return m_storage.dimensions(); }
67 constexpr 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 {
80 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
81 eigen_assert(internal::indices_fit<Index>(otherIndices...));
82 return coeff(array<Index, NumIndices>{{firstIndex,
static_cast<Index
>(otherIndices)...}});
85 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(
const array<Index, NumIndices>& indices)
const {
86 eigen_internal_assert(checkIndexRange(indices));
87 return m_storage.data()[linearizedIndex(indices)];
90 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index index)
const {
91 eigen_internal_assert(index >= 0 && index < size());
92 return m_storage.data()[index];
95 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff()
const {
96 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
97 return m_storage.data()[0];
100 template <
typename... IndexTypes>
101 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 eigen_assert(internal::indices_fit<Index>(otherIndices...));
105 return coeffRef(array<Index, NumIndices>{{firstIndex,
static_cast<Index
>(otherIndices)...}});
108 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices) {
109 eigen_internal_assert(checkIndexRange(indices));
110 return m_storage.data()[linearizedIndex(indices)];
113 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) {
114 eigen_internal_assert(index >= 0 && index < size());
115 return m_storage.data()[index];
118 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef() {
119 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
120 return m_storage.data()[0];
123 template <
typename... IndexTypes>
124 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
const {
126 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
127 eigen_assert(internal::indices_fit<Index>(otherIndices...));
128 return this->operator()(array<Index, NumIndices>{{firstIndex,
static_cast<Index
>(otherIndices)...}});
131 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const {
132 eigen_assert(checkIndexRange(indices));
133 return coeff(indices);
136 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const {
137 eigen_internal_assert(index >= 0 && index < size());
141 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()()
const {
142 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
146 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const {
148 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
152 template <
typename... IndexTypes>
153 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices) {
155 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
156 eigen_assert(internal::indices_fit<Index>(otherIndices...));
157 return operator()(array<Index, NumIndices>{{firstIndex,
static_cast<Index
>(otherIndices)...}});
160 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices) {
161 eigen_assert(checkIndexRange(indices));
162 return coeffRef(indices);
165 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index index) {
166 eigen_assert(index >= 0 && index < size());
167 return coeffRef(index);
170 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()() {
171 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
175 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator[](Index index) {
177 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
178 return coeffRef(index);
181 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize() : m_storage() {}
183 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(Self&& other) : m_storage(other.m_storage) {}
185 template <
typename OtherDerived>
188 Assign assign(*
this, other.derived());
189 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
191 template <
typename OtherDerived>
194 Assign assign(*
this, other.derived());
195 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
200 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TensorFixedSize)
203 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool checkIndexRange(
const array<Index, NumIndices>& )
const {
207 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index linearizedIndex(
const array<Index, NumIndices>& indices)
const {
208 EIGEN_IF_CONSTEXPR (Options &
RowMajor) {
209 return internal::convert_index<Index>(m_storage.dimensions().IndexOfRowMajor(indices));
211 return internal::convert_index<Index>(m_storage.dimensions().IndexOfColMajor(indices));