11 #ifndef EIGEN_CXX11_TENSOR_TENSOR_H 12 #define EIGEN_CXX11_TENSOR_TENSOR_H 62 template<
typename Scalar_,
int NumIndices_,
int Options_,
typename IndexType_>
71 typedef Scalar_ Scalar;
73 typedef typename Base::CoeffReturnType CoeffReturnType;
76 IsAligned = bool(EIGEN_MAX_ALIGN_BYTES>0) & !(Options_&
DontAlign),
82 static const int Options = Options_;
83 static const int NumIndices = NumIndices_;
89 #ifdef EIGEN_HAS_SFINAE 90 template<
typename CustomIndices>
91 struct isOfNormalIndex{
92 static const bool is_array = internal::is_base_of<array<Index, NumIndices>, CustomIndices>::value;
94 static const bool value = is_array | is_int;
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank()
const {
return NumIndices; }
101 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n)
const {
return m_storage.dimensions()[n]; }
102 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_storage.dimensions(); }
103 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_storage.size(); }
104 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data() {
return m_storage.data(); }
105 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar *data()
const {
return m_storage.data(); }
110 inline Self& base() {
return *
this; }
111 inline const Self& base()
const {
return *
this; }
113 #if EIGEN_HAS_VARIADIC_TEMPLATES 114 template<
typename... IndexTypes>
115 EIGEN_DEVICE_FUNC
inline const Scalar& coeff(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
const 118 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
126 eigen_internal_assert(checkIndexRange(indices));
127 return m_storage.data()[linearizedIndex(indices)];
131 #ifdef EIGEN_HAS_SFINAE 132 template<
typename CustomIndices,
133 EIGEN_SFINAE_ENABLE_IF( !(isOfNormalIndex<CustomIndices>::value) )
135 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(CustomIndices& indices)
const 137 return coeff(internal::customIndices2Array<Index,NumIndices>(indices));
141 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff()
const 143 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
144 return m_storage.data()[0];
147 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeff(Index index)
const 149 eigen_internal_assert(index >= 0 && index < size());
150 return m_storage.data()[index];
153 #if EIGEN_HAS_VARIADIC_TEMPLATES 154 template<
typename... IndexTypes>
155 inline Scalar& coeffRef(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
158 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
166 eigen_internal_assert(checkIndexRange(indices));
167 return m_storage.data()[linearizedIndex(indices)];
171 #ifdef EIGEN_HAS_SFINAE 172 template<
typename CustomIndices,
173 EIGEN_SFINAE_ENABLE_IF( !(isOfNormalIndex<CustomIndices>::value) )
175 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(CustomIndices& indices)
177 return coeffRef(internal::customIndices2Array<Index,NumIndices>(indices));
181 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef()
183 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
184 return m_storage.data()[0];
187 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
189 eigen_internal_assert(index >= 0 && index < size());
190 return m_storage.data()[index];
193 #if EIGEN_HAS_VARIADIC_TEMPLATES 194 template<
typename... IndexTypes>
195 inline const Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
const 198 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
203 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1)
const 208 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2)
const 213 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
const 218 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const 225 #ifdef EIGEN_HAS_SFINAE 226 template<
typename CustomIndices,
227 EIGEN_SFINAE_ENABLE_IF( !(isOfNormalIndex<CustomIndices>::value) )
229 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(CustomIndices& indices)
const 231 return coeff(internal::customIndices2Array<Index,NumIndices>(indices));
238 return coeff(indices);
241 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()(Index index)
const 243 eigen_internal_assert(index >= 0 && index < size());
247 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator()()
const 249 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
253 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& operator[](Index index)
const 256 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE);
260 #if EIGEN_HAS_VARIADIC_TEMPLATES 261 template<
typename... IndexTypes>
262 inline Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
265 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
270 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1)
275 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2)
280 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
285 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
294 return coeffRef(indices);
298 #ifdef EIGEN_HAS_SFINAE 299 template<
typename CustomIndices,
300 EIGEN_SFINAE_ENABLE_IF( !(isOfNormalIndex<CustomIndices>::value) )
302 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(CustomIndices& indices)
304 return coeffRef(internal::customIndices2Array<Index,NumIndices>(indices));
308 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index index)
310 eigen_assert(index >= 0 && index < size());
311 return coeffRef(index);
314 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()()
316 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
320 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator[](Index index)
323 EIGEN_STATIC_ASSERT(NumIndices == 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
324 return coeffRef(index);
328 EIGEN_STRONG_INLINE
Tensor()
334 EIGEN_STRONG_INLINE Tensor(
const Self& other)
335 : m_storage(other.m_storage)
339 #if EIGEN_HAS_VARIADIC_TEMPLATES 340 template<
typename... IndexTypes>
341 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index firstDimension, IndexTypes... otherDimensions)
342 : m_storage(firstDimension, otherDimensions...)
345 EIGEN_STATIC_ASSERT(
sizeof...(otherDimensions) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
348 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit Tensor(Index dim1)
351 EIGEN_STATIC_ASSERT(1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
353 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index dim1, Index dim2)
356 EIGEN_STATIC_ASSERT(2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
358 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index dim1, Index dim2, Index dim3)
361 EIGEN_STATIC_ASSERT(3 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
363 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index dim1, Index dim2, Index dim3, Index dim4)
364 : m_storage(dim1*dim2*dim3*dim4,
array<Index, 4>(dim1, dim2, dim3, dim4))
366 EIGEN_STATIC_ASSERT(4 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
368 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index dim1, Index dim2, Index dim3, Index dim4, Index dim5)
369 : m_storage(dim1*dim2*dim3*dim4*dim5,
array<Index, 5>(dim1, dim2, dim3, dim4, dim5))
371 EIGEN_STATIC_ASSERT(5 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
377 : m_storage(
internal::array_prod(dimensions), dimensions)
379 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
382 template<
typename OtherDerived>
387 Assign assign(*
this, other.derived());
391 template<
typename OtherDerived>
396 Assign assign(*
this, other.derived());
402 EIGEN_STRONG_INLINE Tensor& operator=(
const Tensor& other)
405 Assign assign(*
this, other);
410 template<
typename OtherDerived>
412 EIGEN_STRONG_INLINE Tensor& operator=(
const OtherDerived& other)
415 Assign assign(*
this, other);
421 #if EIGEN_HAS_VARIADIC_TEMPLATES 422 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
423 void resize(Index firstDimension, IndexTypes... otherDimensions)
426 EIGEN_STATIC_ASSERT(
sizeof...(otherDimensions) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
435 Index size = Index(1);
436 for (i = 0; i < NumIndices; i++) {
438 size *= dimensions[i];
440 #ifdef EIGEN_INITIALIZE_COEFFS 441 bool size_changed = size != this->size();
442 m_storage.resize(size, dimensions);
443 if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
445 m_storage.resize(size, dimensions);
452 for (
int i = 0; i < NumIndices; ++i) {
453 dims[i] = dimensions[i];
461 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
466 #ifdef EIGEN_HAS_SFINAE 467 template<
typename CustomDimension,
468 EIGEN_SFINAE_ENABLE_IF( !(isOfNormalIndex<CustomDimension>::value) )
470 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void resize(CustomDimension& dimensions)
472 resize(internal::customIndices2Array<Index,NumIndices>(dimensions));
476 #ifndef EIGEN_EMULATE_CXX11_META_H 477 template <
typename std::ptrdiff_t... Indices>
481 for (
int i = 0; i < NumIndices; ++i) {
482 dims[i] =
static_cast<Index
>(dimensions[i]);
487 template <std::
size_t V1, std::
size_t V2, std::
size_t V3, std::
size_t V4, std::
size_t V5>
491 for (
int i = 0; i < NumIndices; ++i) {
492 dims[i] =
static_cast<Index
>(dimensions[i]);
502 using internal::array_apply_and_reduce;
503 using internal::array_zip_and_reduce;
510 array_apply_and_reduce<logical_and_op, greater_equal_zero_op>(indices) &&
512 array_zip_and_reduce<logical_and_op, lesser_op>(indices, m_storage.dimensions());
518 return m_storage.dimensions().IndexOfRowMajor(indices);
520 return m_storage.dimensions().IndexOfColMajor(indices);
527 #endif // EIGEN_CXX11_TENSOR_TENSOR_H Definition: TensorExecutor.h:27
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:320
Don't require alignment for the matrix itself (the array of coefficients, if dynamically allocated...
Definition: Constants.h:326
Definition: TensorDimensions.h:261
Definition: PlainObjectBase.h:29
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:28
Definition: TensorAssign.h:60
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
EIGEN_DEVICE_FUNC void resize(const Sizes< Indices... > &dimensions)
Custom Dimension.
Definition: Tensor.h:479
Definition: TensorDimensions.h:93
Definition: EmulateCXX11Meta.h:252
Definition: TensorDeviceDefault.h:17
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(const array< Index, NumIndices > &dimensions)
Normal Dimension.
Definition: Tensor.h:376
EIGEN_DEVICE_FUNC void resize(const array< Index, NumIndices > &dimensions)
Normal Dimension.
Definition: Tensor.h:432
The tensor base class.
Definition: TensorBase.h:827
Definition: EmulateArray.h:21
Definition: EmulateCXX11Meta.h:219
Definition: BandTriangularSolver.h:13
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:322
Definition: EmulateCXX11Meta.h:232
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
Definition: ForwardDeclarations.h:17
The tensor class.
Definition: Tensor.h:63