34class TensorMap :
public TensorBase<TensorMap<PlainObjectType, Options_, MakePointer_> > {
36 using Self = TensorMap<PlainObjectType, Options_, MakePointer_>;
39 using Nested = std::remove_reference_t<typename Eigen::internal::ref_selector<Self>::type>;
41 using Nested =
typename Eigen::internal::ref_selector<Self>::type;
43 using StorageKind =
typename internal::traits<PlainObjectType>::StorageKind;
44 using Index =
typename internal::traits<PlainObjectType>::Index;
45 using Scalar =
typename internal::traits<PlainObjectType>::Scalar;
47 using CoeffReturnType =
typename PlainObjectType::Base::CoeffReturnType;
49 using PointerType =
typename MakePointer_<Scalar>::Type;
50 using PointerConstType =
typename MakePointer_<Scalar>::ConstType;
56 using StoragePointerType = std::conditional_t<bool(internal::is_lvalue<PlainObjectType>::value),
64 using StorageRefType = std::conditional_t<bool(internal::is_lvalue<PlainObjectType>::value), Scalar&,
const Scalar&>;
66 static constexpr int Options = Options_;
68 static constexpr Index NumIndices = PlainObjectType::NumIndices;
69 using Dimensions =
typename PlainObjectType::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 NumIndices; }
101 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension()
const {
102 EIGEN_STATIC_ASSERT(0 <= N && N < NumIndices, INVALID_DIMENSION);
103 return m_dimensions[N];
105 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(Index n)
const {
106 eigen_assert(0 <= n && n < NumIndices);
107 return m_dimensions[n];
109 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
110 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_dimensions.TotalSize(); }
111 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StoragePointerType data() {
return m_data; }
112 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StoragePointerType data()
const {
return m_data; }
114 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(
const array<Index, NumIndices>& indices)
const {
115 EIGEN_IF_CONSTEXPR (PlainObjectType::Options &
RowMajor) {
116 const Index index = m_dimensions.IndexOfRowMajor(indices);
117 return m_data[index];
119 const Index index = m_dimensions.IndexOfColMajor(indices);
120 return m_data[index];
124 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()()
const {
125 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
129 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(Index index)
const {
130 eigen_internal_assert(index >= 0 && index < size());
131 return m_data[index];
134 template <
typename... IndexTypes>
135 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex,
136 IndexTypes... otherIndices)
const {
137 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
138 eigen_assert(internal::indices_fit<Index>(otherIndices...));
139 EIGEN_IF_CONSTEXPR (PlainObjectType::Options &
RowMajor) {
140 const Index index = m_dimensions.IndexOfRowMajor(
141 array<Index, NumIndices>{{firstIndex, secondIndex,
static_cast<Index
>(otherIndices)...}});
142 return m_data[index];
144 const Index index = m_dimensions.IndexOfColMajor(
145 array<Index, NumIndices>{{firstIndex, secondIndex,
static_cast<Index
>(otherIndices)...}});
146 return m_data[index];
150 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(
const array<Index, NumIndices>& indices) {
151 EIGEN_IF_CONSTEXPR (PlainObjectType::Options &
RowMajor) {
152 const Index index = m_dimensions.IndexOfRowMajor(indices);
153 return m_data[index];
155 const Index index = m_dimensions.IndexOfColMajor(indices);
156 return m_data[index];
160 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()() {
161 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
165 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(Index index) {
166 eigen_internal_assert(index >= 0 && index < size());
167 return m_data[index];
170 template <
typename... IndexTypes>
171 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex,
172 IndexTypes... otherIndices) {
173 static_assert(
sizeof...(otherIndices) + 2 == NumIndices || NumIndices == Dynamic,
174 "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
175 eigen_assert(internal::indices_fit<Index>(otherIndices...));
176 const std::size_t NumDims =
sizeof...(otherIndices) + 2;
177 EIGEN_IF_CONSTEXPR (PlainObjectType::Options &
RowMajor) {
178 const Index index = m_dimensions.IndexOfRowMajor(
179 array<Index, NumDims>{{firstIndex, secondIndex,
static_cast<Index
>(otherIndices)...}});
180 return m_data[index];
182 const Index index = m_dimensions.IndexOfColMajor(
183 array<Index, NumDims>{{firstIndex, secondIndex,
static_cast<Index
>(otherIndices)...}});
184 return m_data[index];
188 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TensorMap)
191 StoragePointerType m_data;
192 Dimensions m_dimensions;