29class TensorFixedSize :
public TensorBase<TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> > {
31 typedef TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> Self;
33 typedef typename Eigen::internal::nested<Self>::type Nested;
34 typedef typename internal::traits<Self>::StorageKind StorageKind;
35 typedef typename internal::traits<Self>::Index Index;
36 typedef Scalar_ Scalar;
38 typedef typename Base::CoeffReturnType CoeffReturnType;
40 static constexpr int Options = Options_;
44 IsAligned = bool(EIGEN_MAX_ALIGN_BYTES > 0),
45 PacketAccess = (internal::packet_traits<Scalar>::size > 1),
47 PreferBlockAccess =
false,
53 typedef internal::TensorBlockNotImplemented TensorBlock;
56 typedef Dimensions_ Dimensions;
57 static constexpr std::size_t NumIndices = Dimensions::count;
60 TensorStorage<Scalar, Dimensions, Options> m_storage;
63 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank()
const {
return NumIndices; }
64 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n)
const {
return m_storage.dimensions()[n]; }
65 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions dimensions()
const {
return m_storage.dimensions(); }
66 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_storage.size(); }
67 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar* data() {
return m_storage.data(); }
68 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar* data()
const {
return m_storage.data(); }
73 inline Self& base() {
return *
this; }
74 inline const Self& base()
const {
return *
this; }
76 template <
typename... IndexTypes>
77 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index firstIndex, IndexTypes... otherIndices)
const {
79 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
80 return coeff(array<Index, NumIndices>{{firstIndex, otherIndices...}});
83 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(
const array<Index, NumIndices>& indices)
const {
84 eigen_internal_assert(checkIndexRange(indices));
85 return m_storage.data()[linearizedIndex(indices)];
88 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index index)
const {
89 eigen_internal_assert(index >= 0 && index < size());
90 return m_storage.data()[index];
93 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff()
const {
94 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
95 return m_storage.data()[0];
98 template <
typename... IndexTypes>
99 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices) {
101 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
102 return coeffRef(array<Index, NumIndices>{{firstIndex, otherIndices...}});
105 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices) {
106 eigen_internal_assert(checkIndexRange(indices));
107 return m_storage.data()[linearizedIndex(indices)];
110 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) {
111 eigen_internal_assert(index >= 0 && index < size());
112 return m_storage.data()[index];
115 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef() {
116 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
117 return m_storage.data()[0];
120 template <
typename... IndexTypes>
121 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
const {
123 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
124 return this->operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
127 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(
const array<Index, NumIndices>& indices)
const {
128 eigen_assert(checkIndexRange(indices));
129 return coeff(indices);
132 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const {
133 eigen_internal_assert(index >= 0 && index < size());
137 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()()
const {
138 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
142 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const {
144 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
148 template <
typename... IndexTypes>
149 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices) {
151 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
152 return operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
155 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(
const array<Index, NumIndices>& indices) {
156 eigen_assert(checkIndexRange(indices));
157 return coeffRef(indices);
160 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index index) {
161 eigen_assert(index >= 0 && index < size());
162 return coeffRef(index);
165 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()() {
166 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
170 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator[](Index index) {
172 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
173 return coeffRef(index);
176 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize() : m_storage() {}
178 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(
const Self& other) : Base(other), m_storage(other.m_storage) {}
180 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(Self&& other) : m_storage(other.m_storage) {}
182 template <
typename OtherDerived>
185 Assign assign(*
this, other.derived());
186 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
188 template <
typename OtherDerived>
191 Assign assign(*
this, other.derived());
192 internal::TensorExecutor<const Assign, DefaultDevice>::run(assign, DefaultDevice());
197 EIGEN_TENSOR_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(TensorFixedSize)
200 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool checkIndexRange(
const array<Index, NumIndices>& )
const {
201 using internal::array_apply_and_reduce;
202 using internal::array_zip_and_reduce;
203 using internal::greater_equal_zero_op;
204 using internal::lesser_op;
205 using internal::logical_and_op;
214 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index linearizedIndex(
const array<Index, NumIndices>& indices)
const {
216 return m_storage.dimensions().IndexOfRowMajor(indices);
218 return m_storage.dimensions().IndexOfColMajor(indices);