30class TensorFixedSize :
public TensorBase<TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> > {
32 using Self = TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType>;
34 using Nested =
typename Eigen::internal::ref_selector<Self>::type;
35 using StorageKind =
typename internal::traits<Self>::StorageKind;
36 using Index =
typename internal::traits<Self>::Index;
37 using Scalar = Scalar_;
39 using CoeffReturnType =
typename Base::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 using TensorBlock = internal::TensorBlockNotImplemented;
57 using 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; }
66 static constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension() {
67 EIGEN_STATIC_ASSERT(0 <= N && N < NumIndices, INVALID_DIMENSION);
68 return Dimensions{}[N];
70 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(Index n)
const {
71 eigen_assert(0 <= n && n <
static_cast<Index
>(NumIndices));
72 return m_storage.dimensions()[n];
74 constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions dimensions()
const {
return m_storage.dimensions(); }
75 constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_storage.size(); }
76 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar* data() {
return m_storage.data(); }
77 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar* data()
const {
return m_storage.data(); }
82 inline Self& base() {
return *
this; }
83 inline const Self& base()
const {
return *
this; }
85 template <
typename... IndexTypes>
86 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index firstIndex, IndexTypes... otherIndices)
const {
88 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
89 eigen_assert(internal::indices_fit<Index>(otherIndices...));
90 return coeff(array<Index, NumIndices>{{firstIndex,
static_cast<Index
>(otherIndices)...}});
93 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(
const array<Index, NumIndices>& indices)
const {
94 eigen_internal_assert(checkIndexRange(indices));
95 return m_storage.data()[linearizedIndex(indices)];
98 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index index)
const {
99 eigen_internal_assert(index >= 0 && index < size());
100 return m_storage.data()[index];
103 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff()
const {
104 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
105 return m_storage.data()[0];
108 template <
typename... IndexTypes>
109 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 eigen_assert(internal::indices_fit<Index>(otherIndices...));
113 return coeffRef(array<Index, NumIndices>{{firstIndex,
static_cast<Index
>(otherIndices)...}});
116 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices) {
117 eigen_internal_assert(checkIndexRange(indices));
118 return m_storage.data()[linearizedIndex(indices)];
121 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) {
122 eigen_internal_assert(index >= 0 && index < size());
123 return m_storage.data()[index];
126 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef() {
127 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
128 return m_storage.data()[0];
131 template <
typename... IndexTypes>
132 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
const {
134 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
135 eigen_assert(internal::indices_fit<Index>(otherIndices...));
136 return this->operator()(array<Index, NumIndices>{{firstIndex,
static_cast<Index
>(otherIndices)...}});
139 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const {
140 eigen_assert(checkIndexRange(indices));
141 return coeff(indices);
144 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const {
145 eigen_internal_assert(index >= 0 && index < size());
149 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()()
const {
150 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
154 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const {
156 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
160 template <
typename... IndexTypes>
161 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices) {
163 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
164 eigen_assert(internal::indices_fit<Index>(otherIndices...));
165 return operator()(array<Index, NumIndices>{{firstIndex,
static_cast<Index
>(otherIndices)...}});
168 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices) {
169 eigen_assert(checkIndexRange(indices));
170 return coeffRef(indices);
173 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index index) {
174 eigen_assert(index >= 0 && index < size());
175 return coeffRef(index);
178 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()() {
179 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
183 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator[](Index index) {
185 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
186 return coeffRef(index);
189 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize() : m_storage() {}
191 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(Self&& other) : m_storage(other.m_storage) {}
193 template <
typename OtherDerived>
196 Assign assign(*
this, other.derived());
197 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
199 template <
typename OtherDerived>
202 Assign assign(*
this, other.derived());
203 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
208 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TensorFixedSize)
211 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool checkIndexRange(
const array<Index, NumIndices>& )
const {
215 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index linearizedIndex(
const array<Index, NumIndices>& indices)
const {
216 EIGEN_IF_CONSTEXPR (Options &
RowMajor) {
217 return internal::convert_index<Index>(m_storage.dimensions().IndexOfRowMajor(indices));
219 return internal::convert_index<Index>(m_storage.dimensions().IndexOfColMajor(indices));