34class TensorMap :
public TensorBase<TensorMap<PlainObjectType, Options_, MakePointer_> > {
36 typedef TensorMap<PlainObjectType, Options_, MakePointer_> Self;
39 typedef std::remove_reference_t<typename Eigen::internal::ref_selector<Self>::type> Nested;
41 typedef typename Eigen::internal::ref_selector<Self>::type Nested;
43 typedef typename internal::traits<PlainObjectType>::StorageKind StorageKind;
44 typedef typename internal::traits<PlainObjectType>::Index Index;
45 typedef typename internal::traits<PlainObjectType>::Scalar Scalar;
47 typedef typename PlainObjectType::Base::CoeffReturnType CoeffReturnType;
49 typedef typename MakePointer_<Scalar>::Type PointerType;
50 typedef typename MakePointer_<Scalar>::ConstType PointerConstType;
56 typedef std::conditional_t<bool(internal::is_lvalue<PlainObjectType>::value),
65 typedef std::conditional_t<bool(internal::is_lvalue<PlainObjectType>::value), Scalar&,
const Scalar&> StorageRefType;
67 static constexpr int Options = Options_;
69 static constexpr Index NumIndices = PlainObjectType::NumIndices;
70 typedef typename PlainObjectType::Dimensions Dimensions;
72 static constexpr int Layout = PlainObjectType::Layout;
73 enum { IsAligned = ((int(Options_) &
Aligned) ==
Aligned), CoordAccess =
true, RawAccess =
true };
75 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr) : m_data(dataPtr), m_dimensions() {
77 EIGEN_STATIC_ASSERT((0 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
80 template <
typename... IndexTypes>
81 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index firstDimension,
82 IndexTypes... otherDimensions)
83 : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) {
85 EIGEN_STATIC_ASSERT((
sizeof...(otherDimensions) + 1 == NumIndices || NumIndices == Dynamic),
86 YOU_MADE_A_PROGRAMMING_MISTAKE)
89 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr,
90 const array<Index, NumIndices>& dimensions)
91 : m_data(dataPtr), m_dimensions(dimensions) {}
93 template <
typename Dimensions>
94 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr,
const Dimensions& dimensions)
95 : m_data(dataPtr), m_dimensions(dimensions) {}
97 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(PlainObjectType& tensor)
98 : m_data(tensor.data()), m_dimensions(tensor.dimensions()) {}
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank()
const {
return m_dimensions.rank(); }
101 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(Index n)
const {
return m_dimensions[n]; }
102 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
103 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_dimensions.TotalSize(); }
104 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StoragePointerType data() {
return m_data; }
105 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StoragePointerType data()
const {
return m_data; }
107 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(
const array<Index, NumIndices>& indices)
const {
108 EIGEN_IF_CONSTEXPR (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)
131 eigen_assert(internal::indices_fit<Index>(otherIndices...));
132 EIGEN_IF_CONSTEXPR (PlainObjectType::Options &
RowMajor) {
133 const Index index = m_dimensions.IndexOfRowMajor(
134 array<Index, NumIndices>{{firstIndex, secondIndex,
static_cast<Index
>(otherIndices)...}});
135 return m_data[index];
137 const Index index = m_dimensions.IndexOfColMajor(
138 array<Index, NumIndices>{{firstIndex, secondIndex,
static_cast<Index
>(otherIndices)...}});
139 return m_data[index];
143 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(
const array<Index, NumIndices>& indices) {
144 EIGEN_IF_CONSTEXPR (PlainObjectType::Options &
RowMajor) {
145 const Index index = m_dimensions.IndexOfRowMajor(indices);
146 return m_data[index];
148 const Index index = m_dimensions.IndexOfColMajor(indices);
149 return m_data[index];
153 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()() {
154 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
158 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(Index index) {
159 eigen_internal_assert(index >= 0 && index < size());
160 return m_data[index];
163 template <
typename... IndexTypes>
164 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex,
165 IndexTypes... otherIndices) {
166 static_assert(
sizeof...(otherIndices) + 2 == NumIndices || NumIndices == Dynamic,
167 "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
168 eigen_assert(internal::indices_fit<Index>(otherIndices...));
169 const std::size_t NumDims =
sizeof...(otherIndices) + 2;
170 EIGEN_IF_CONSTEXPR (PlainObjectType::Options &
RowMajor) {
171 const Index index = m_dimensions.IndexOfRowMajor(
172 array<Index, NumDims>{{firstIndex, secondIndex,
static_cast<Index
>(otherIndices)...}});
173 return m_data[index];
175 const Index index = m_dimensions.IndexOfColMajor(
176 array<Index, NumDims>{{firstIndex, secondIndex,
static_cast<Index
>(otherIndices)...}});
177 return m_data[index];
181 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TensorMap)
184 StoragePointerType m_data;
185 Dimensions m_dimensions;