TR-mbed 1.0
Loading...
Searching...
No Matches
TensorFixedSize.h
Go to the documentation of this file.
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H
11#define EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H
12
13namespace Eigen {
14
26template<typename Scalar_, typename Dimensions_, int Options_, typename IndexType>
27class TensorFixedSize : public TensorBase<TensorFixedSize<Scalar_, Dimensions_, Options_, IndexType> >
28{
29 public:
35 typedef Scalar_ Scalar;
38
39 static const int Options = Options_;
40
41 enum {
44 BlockAccess = false,
46 Layout = Options_ & RowMajor ? RowMajor : ColMajor,
48 RawAccess = true
49 };
50
51 //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
53 //===--------------------------------------------------------------------===//
54
55 typedef Dimensions_ Dimensions;
56 static const std::size_t NumIndices = Dimensions::count;
57
58 protected:
60
61 public:
68
69 // This makes EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
70 // work, because that uses base().coeffRef() - and we don't yet
71 // implement a similar class hierarchy
72 inline Self& base() { return *this; }
73 inline const Self& base() const { return *this; }
74
75#if EIGEN_HAS_VARIADIC_TEMPLATES
76 template<typename... IndexTypes>
77 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(Index firstIndex, IndexTypes... otherIndices) const
78 {
79 // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor.
80 EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
81 return coeff(array<Index, NumIndices>{{firstIndex, otherIndices...}});
82 }
83#endif
84
87 {
89 return m_storage.data()[linearizedIndex(indices)];
90 }
91
94 {
95 eigen_internal_assert(index >= 0 && index < size());
96 return m_storage.data()[index];
97 }
98
101 {
102 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
103 return m_storage.data()[0];
104 }
105
106
107#if EIGEN_HAS_VARIADIC_TEMPLATES
108 template<typename... IndexTypes>
109 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices)
110 {
111 // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor.
112 EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
113 return coeffRef(array<Index, NumIndices>{{firstIndex, otherIndices...}});
114 }
115#endif
116
123
126 {
127 eigen_internal_assert(index >= 0 && index < size());
128 return m_storage.data()[index];
129 }
130
133 {
134 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
135 return m_storage.data()[0];
136 }
137
138#if EIGEN_HAS_VARIADIC_TEMPLATES
139 template<typename... IndexTypes>
140 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices) const
141 {
142 // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor.
143 EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
144 return this->operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
145 }
146#else
149 {
150 if (Options&RowMajor) {
151 const Index index = i1 + i0 * m_storage.dimensions()[1];
152 return m_storage.data()[index];
153 } else {
154 const Index index = i0 + i1 * m_storage.dimensions()[0];
155 return m_storage.data()[index];
156 }
157 }
160 {
161 if (Options&RowMajor) {
162 const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0);
163 return m_storage.data()[index];
164 } else {
165 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2);
166 return m_storage.data()[index];
167 }
168 }
171 {
172 if (Options&RowMajor) {
173 const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0));
174 return m_storage.data()[index];
175 } else {
176 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3));
177 return m_storage.data()[index];
178 }
179 }
182 {
183 if (Options&RowMajor) {
184 const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)));
185 return m_storage.data()[index];
186 } else {
187 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4)));
188 return m_storage.data()[index];
189 }
190 }
191#endif
192
193
196 {
198 return coeff(indices);
199 }
200
203 {
204 eigen_internal_assert(index >= 0 && index < size());
205 return coeff(index);
206 }
207
210 {
211 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
212 return coeff();
213 }
214
217 {
218 // The bracket operator is only for vectors, use the parenthesis operator instead.
219 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
220 return coeff(index);
221 }
222
223#if EIGEN_HAS_VARIADIC_TEMPLATES
224 template<typename... IndexTypes>
225 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
226 {
227 // The number of indices used to access a tensor coefficient must be equal to the rank of the tensor.
228 EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
229 return operator()(array<Index, NumIndices>{{firstIndex, otherIndices...}});
230 }
231#else
234 {
235 if (Options&RowMajor) {
236 const Index index = i1 + i0 * m_storage.dimensions()[1];
237 return m_storage.data()[index];
238 } else {
239 const Index index = i0 + i1 * m_storage.dimensions()[0];
240 return m_storage.data()[index];
241 }
242 }
245 {
246 if (Options&RowMajor) {
247 const Index index = i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0);
248 return m_storage.data()[index];
249 } else {
250 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * i2);
251 return m_storage.data()[index];
252 }
253 }
256 {
257 if (Options&RowMajor) {
258 const Index index = i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0));
259 return m_storage.data()[index];
260 } else {
261 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * i3));
262 return m_storage.data()[index];
263 }
264 }
267 {
268 if (Options&RowMajor) {
269 const Index index = i4 + m_storage.dimensions()[4] * (i3 + m_storage.dimensions()[3] * (i2 + m_storage.dimensions()[2] * (i1 + m_storage.dimensions()[1] * i0)));
270 return m_storage.data()[index];
271 } else {
272 const Index index = i0 + m_storage.dimensions()[0] * (i1 + m_storage.dimensions()[1] * (i2 + m_storage.dimensions()[2] * (i3 + m_storage.dimensions()[3] * i4)));
273 return m_storage.data()[index];
274 }
275 }
276#endif
277
280 {
282 return coeffRef(indices);
283 }
284
287 {
288 eigen_assert(index >= 0 && index < size());
289 return coeffRef(index);
290 }
291
294 {
295 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
296 return coeffRef();
297 }
298
301 {
302 // The bracket operator is only for vectors, use the parenthesis operator instead
303 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
304 return coeffRef(index);
305 }
306
312
315 : m_storage(other.m_storage)
316 {
317 }
318
319#if EIGEN_HAS_RVALUE_REFERENCES
321 : m_storage(other.m_storage)
322 {
323 }
324#endif
325
326 template<typename OtherDerived>
334 template<typename OtherDerived>
342
343 // FIXME: check that the dimensions of other match the dimensions of *this.
344 // Unfortunately this isn't possible yet when the rhs is an expression.
346
347
348 protected:
351 {
357
358 return true;
359 // check whether the indices are all >= 0
360 /* array_apply_and_reduce<logical_and_op, greater_equal_zero_op>(indices) &&
361 // check whether the indices fit in the dimensions
362 array_zip_and_reduce<logical_and_op, lesser_op>(indices, m_storage.dimensions());*/
363 }
364
367 {
368 if (Options&RowMajor) {
369 return m_storage.dimensions().IndexOfRowMajor(indices);
370 } else {
371 return m_storage.dimensions().IndexOfColMajor(indices);
372 }
373 }
374};
375
376
377} // end namespace Eigen
378
379#endif // EIGEN_CXX11_TENSOR_TENSOR_FIXED_SIZE_H
int n
Definition BiCGSTAB_simple.cpp:1
#define EIGEN_MAX_ALIGN_BYTES
Definition ConfigureVectorization.h:175
#define eigen_internal_assert(x)
Definition Macros.h:1043
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define eigen_assert(x)
Definition Macros.h:1037
#define EIGEN_STRONG_INLINE
Definition Macros.h:917
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition StaticAssert.h:127
#define EIGEN_TENSOR_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
Definition TensorMacros.h:84
SCALAR Scalar
Definition bench_gemm.cpp:46
Definition TensorAssign.h:62
The tensor base class.
Definition TensorBase.h:973
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & derived()
Definition TensorBase.h:1169
The fixed sized version of the tensor class.
Definition TensorFixedSize.h:28
@ BlockAccess
Definition TensorFixedSize.h:44
@ PreferBlockAccess
Definition TensorFixedSize.h:45
@ RawAccess
Definition TensorFixedSize.h:48
@ Layout
Definition TensorFixedSize.h:46
@ IsAligned
Definition TensorFixedSize.h:42
@ PacketAccess
Definition TensorFixedSize.h:43
@ CoordAccess
Definition TensorFixedSize.h:47
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(const TensorBase< OtherDerived, WriteAccessors > &other)
Definition TensorFixedSize.h:336
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index index)
Definition TensorFixedSize.h:125
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
Definition TensorFixedSize.h:66
TensorBase< TensorFixedSize< Scalar_, Dimensions_, Options_, IndexType > > Base
Definition TensorFixedSize.h:31
Scalar_ Scalar
Definition TensorFixedSize.h:35
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(const Self &other)
Definition TensorFixedSize.h:314
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(const array< Index, NumIndices > &indices)
Definition TensorFixedSize.h:118
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(Index index) const
Definition TensorFixedSize.h:93
TensorStorage< Scalar, Dimensions, Options > m_storage
Definition TensorFixedSize.h:59
static const std::size_t NumIndices
Definition TensorFixedSize.h:56
Eigen::internal::nested< Self >::type Nested
Definition TensorFixedSize.h:32
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition TensorFixedSize.h:64
internal::TensorBlockNotImplemented TensorBlock
Definition TensorFixedSize.h:52
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator()(Index index)
Definition TensorFixedSize.h:286
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & operator()(Index i0, Index i1) const
Definition TensorFixedSize.h:148
Base::CoeffReturnType CoeffReturnType
Definition TensorFixedSize.h:37
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator()(const array< Index, NumIndices > &indices)
Definition TensorFixedSize.h:279
TensorFixedSize< Scalar_, Dimensions_, Options_, IndexType > Self
Definition TensorFixedSize.h:30
const Self & base() const
Definition TensorFixedSize.h:73
static const int Options
Definition TensorFixedSize.h:39
Self & base()
Definition TensorFixedSize.h:72
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator()()
Definition TensorFixedSize.h:293
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
Definition TensorFixedSize.h:65
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize()
Definition TensorFixedSize.h:308
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const
Definition TensorFixedSize.h:62
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator()(Index i0, Index i1)
Definition TensorFixedSize.h:233
internal::traits< Self >::Index Index
Definition TensorFixedSize.h:34
Dimensions_ Dimensions
Definition TensorFixedSize.h:55
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
Definition TensorFixedSize.h:63
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & operator()(Index i0, Index i1, Index i2, Index i3) const
Definition TensorFixedSize.h:170
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator()(Index i0, Index i1, Index i2)
Definition TensorFixedSize.h:244
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & operator()(const array< Index, NumIndices > &indices) const
Definition TensorFixedSize.h:195
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & operator()() const
Definition TensorFixedSize.h:209
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator[](Index index)
Definition TensorFixedSize.h:300
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorFixedSize(const TensorBase< OtherDerived, ReadOnlyAccessors > &other)
Definition TensorFixedSize.h:328
internal::traits< Self >::StorageKind StorageKind
Definition TensorFixedSize.h:33
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff() const
Definition TensorFixedSize.h:100
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & operator()(Index i0, Index i1, Index i2) const
Definition TensorFixedSize.h:159
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
Definition TensorFixedSize.h:266
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool checkIndexRange(const array< Index, NumIndices > &) const
Definition TensorFixedSize.h:350
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & operator[](Index index) const
Definition TensorFixedSize.h:216
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & operator()(Index i0, Index i1, Index i2, Index i3, Index i4) const
Definition TensorFixedSize.h:181
NumTraits< Scalar >::Real RealScalar
Definition TensorFixedSize.h:36
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index linearizedIndex(const array< Index, NumIndices > &indices) const
Definition TensorFixedSize.h:366
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & operator()(Index index) const
Definition TensorFixedSize.h:202
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef()
Definition TensorFixedSize.h:132
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator()(Index i0, Index i1, Index i2, Index i3)
Definition TensorFixedSize.h:255
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(const array< Index, NumIndices > &indices) const
Definition TensorFixedSize.h:86
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Definition TensorFixedSize.h:67
Definition TensorStorage.h:40
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T * data()
Definition TensorStorage.h:54
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex size() const
Definition TensorStorage.h:66
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const FixedDimensions & dimensions()
Definition TensorStorage.h:59
Definition EmulateArray.h:21
Definition TensorBlock.h:617
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Expression &expr, const Device &device=Device())
Definition TensorExecutor.h:96
@ ColMajor
Definition Constants.h:319
@ RowMajor
Definition Constants.h:321
constexpr EIGEN_STRONG_INLINE auto array_zip_and_reduce(array< A, N > a, array< B, N > b) -> decltype(h_array_zip_and_reduce< Reducer, Op, A, B, N >(a, b, typename gen_numeric_list< int, N >::type()))
Definition CXX11Meta.h:434
constexpr EIGEN_STRONG_INLINE auto array_apply_and_reduce(array< A, N > a) -> decltype(h_array_apply_and_reduce< Reducer, Op, A, N >(a, typename gen_numeric_list< int, N >::type()))
Definition CXX11Meta.h:462
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Definition TensorDeviceDefault.h:17
Definition CXX11Meta.h:315
Definition CXX11Meta.h:306
Definition CXX11Meta.h:301
Definition GenericPacketMath.h:107
Definition ForwardDeclarations.h:17