33class TensorMap :
public TensorBase<TensorMap<PlainObjectType, Options_, MakePointer_> > {
35 typedef TensorMap<PlainObjectType, Options_, MakePointer_> Self;
38 typedef std::remove_reference_t<typename Eigen::internal::nested<Self>::type> Nested;
40 typedef typename Eigen::internal::nested<Self>::type Nested;
42 typedef typename internal::traits<PlainObjectType>::StorageKind StorageKind;
43 typedef typename internal::traits<PlainObjectType>::Index Index;
44 typedef typename internal::traits<PlainObjectType>::Scalar Scalar;
46 typedef typename PlainObjectType::Base::CoeffReturnType CoeffReturnType;
48 typedef typename MakePointer_<Scalar>::Type PointerType;
49 typedef typename MakePointer_<Scalar>::ConstType PointerConstType;
55 typedef std::conditional_t<bool(internal::is_lvalue<PlainObjectType>::value),
64 typedef std::conditional_t<bool(internal::is_lvalue<PlainObjectType>::value), Scalar&,
const Scalar&> StorageRefType;
66 static constexpr int Options = Options_;
68 static constexpr Index NumIndices = PlainObjectType::NumIndices;
69 typedef typename PlainObjectType::Dimensions Dimensions;
71 static constexpr int Layout = PlainObjectType::Layout;
72 enum { IsAligned = ((int(Options_) &
Aligned) ==
Aligned), CoordAccess =
true, RawAccess =
true };
74 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr) : m_data(dataPtr), m_dimensions() {
76 EIGEN_STATIC_ASSERT((0 == NumIndices || NumIndices ==
Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
79 template <
typename... IndexTypes>
80 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index firstDimension,
81 IndexTypes... otherDimensions)
82 : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) {
84 EIGEN_STATIC_ASSERT((
sizeof...(otherDimensions) + 1 == NumIndices || NumIndices ==
Dynamic),
85 YOU_MADE_A_PROGRAMMING_MISTAKE)
88 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr,
89 const array<Index, NumIndices>& dimensions)
90 : m_data(dataPtr), m_dimensions(dimensions) {}
92 template <
typename Dimensions>
93 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr,
const Dimensions& dimensions)
94 : m_data(dataPtr), m_dimensions(dimensions) {}
96 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PlainObjectType& tensor)
97 : m_data(tensor.data()), m_dimensions(tensor.dimensions()) {}
99 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank()
const {
return m_dimensions.rank(); }
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(Index n)
const {
return m_dimensions[n]; }
101 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
102 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_dimensions.TotalSize(); }
103 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StoragePointerType data() {
return m_data; }
104 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StoragePointerType data()
const {
return m_data; }
106 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(
const array<Index, NumIndices>& indices)
const {
108 if (PlainObjectType::Options &
RowMajor) {
109 const Index index = m_dimensions.IndexOfRowMajor(indices);
110 return m_data[index];
112 const Index index = m_dimensions.IndexOfColMajor(indices);
113 return m_data[index];
117 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()()
const {
118 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
122 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(Index index)
const {
123 eigen_internal_assert(index >= 0 && index < size());
124 return m_data[index];
127 template <
typename... IndexTypes>
128 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex,
129 IndexTypes... otherIndices)
const {
130 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
132 if (PlainObjectType::Options &
RowMajor) {
134 m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
135 return m_data[index];
138 m_dimensions.IndexOfColMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
139 return m_data[index];
143 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(
const array<Index, NumIndices>& indices) {
145 if (PlainObjectType::Options &
RowMajor) {
146 const Index index = m_dimensions.IndexOfRowMajor(indices);
147 return m_data[index];
149 const Index index = m_dimensions.IndexOfColMajor(indices);
150 return m_data[index];
154 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()() {
155 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
159 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(Index index) {
160 eigen_internal_assert(index >= 0 && index < size());
161 return m_data[index];
164 template <
typename... IndexTypes>
165 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex,
166 IndexTypes... otherIndices) {
167 static_assert(
sizeof...(otherIndices) + 2 == NumIndices || NumIndices ==
Dynamic,
168 "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
170 const std::size_t NumDims =
sizeof...(otherIndices) + 2;
171 if (PlainObjectType::Options &
RowMajor) {
173 m_dimensions.IndexOfRowMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
174 return m_data[index];
177 m_dimensions.IndexOfColMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
178 return m_data[index];
182 EIGEN_TENSOR_INHERIT_ASSIGNMENT_OPERATORS(TensorMap)
185 StoragePointerType m_data;
186 Dimensions m_dimensions;