10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_MAP_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_MAP_H
13 #include "./InternalHeaderCheck.h"
31 template<
typename PlainObjectType,
int Options_,
template <
class>
class MakePointer_>
class TensorMap :
public TensorBase<TensorMap<PlainObjectType, Options_, MakePointer_> >
37 typedef std::remove_reference_t<typename Eigen::internal::nested<Self>::type> Nested;
39 typedef typename Eigen::internal::nested<Self>::type Nested;
41 typedef typename internal::traits<PlainObjectType>::StorageKind StorageKind;
42 typedef typename internal::traits<PlainObjectType>::Index Index;
43 typedef typename internal::traits<PlainObjectType>::Scalar Scalar;
45 typedef typename PlainObjectType::Base::CoeffReturnType CoeffReturnType;
47 typedef typename MakePointer_<Scalar>::Type PointerType;
48 typedef typename MakePointer_<Scalar>::ConstType PointerConstType;
54 typedef std::conditional_t<
55 bool(internal::is_lvalue<PlainObjectType>::value),
63 typedef std::conditional_t<
64 bool(internal::is_lvalue<PlainObjectType>::value),
69 static constexpr
int Options = Options_;
71 static constexpr Index NumIndices = PlainObjectType::NumIndices;
72 typedef typename PlainObjectType::Dimensions Dimensions;
74 static constexpr
int Layout = PlainObjectType::Layout;
82 EIGEN_STRONG_INLINE
TensorMap(StoragePointerType dataPtr) : m_data(dataPtr), m_dimensions() {
84 EIGEN_STATIC_ASSERT((0 == NumIndices || NumIndices ==
Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
87 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
88 EIGEN_STRONG_INLINE
TensorMap(StoragePointerType dataPtr, Index firstDimension, IndexTypes... otherDimensions) : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) {
90 EIGEN_STATIC_ASSERT((
sizeof...(otherDimensions) + 1 == NumIndices || NumIndices ==
Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
93 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorMap(StoragePointerType dataPtr,
const array<Index, NumIndices>& dimensions)
94 : m_data(dataPtr), m_dimensions(dimensions)
97 template <
typename Dimensions>
98 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorMap(StoragePointerType dataPtr,
const Dimensions& dimensions)
99 : m_data(dataPtr), m_dimensions(dimensions)
102 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorMap(PlainObjectType& tensor)
103 : m_data(tensor.data()), m_dimensions(tensor.dimensions())
107 EIGEN_STRONG_INLINE Index rank()
const {
return m_dimensions.rank(); }
109 EIGEN_STRONG_INLINE Index dimension(Index n)
const {
return m_dimensions[n]; }
111 EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
113 EIGEN_STRONG_INLINE Index size()
const {
return m_dimensions.TotalSize(); }
115 EIGEN_STRONG_INLINE StoragePointerType data() {
return m_data; }
117 EIGEN_STRONG_INLINE StoragePointerType data()
const {
return m_data; }
120 EIGEN_STRONG_INLINE StorageRefType operator()(
const array<Index, NumIndices>& indices)
const
123 if (PlainObjectType::Options&
RowMajor) {
124 const Index index = m_dimensions.IndexOfRowMajor(indices);
125 return m_data[index];
127 const Index index = m_dimensions.IndexOfColMajor(indices);
128 return m_data[index];
133 EIGEN_STRONG_INLINE StorageRefType operator()()
const
135 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
140 EIGEN_STRONG_INLINE StorageRefType operator()(Index index)
const
142 eigen_internal_assert(index >= 0 && index < size());
143 return m_data[index];
146 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
147 EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
const
149 EIGEN_STATIC_ASSERT(
sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
151 if (PlainObjectType::Options&
RowMajor) {
152 const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
153 return m_data[index];
155 const Index index = m_dimensions.IndexOfColMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
156 return m_data[index];
161 EIGEN_STRONG_INLINE StorageRefType operator()(
const array<Index, NumIndices>& indices)
164 if (PlainObjectType::Options&
RowMajor) {
165 const Index index = m_dimensions.IndexOfRowMajor(indices);
166 return m_data[index];
168 const Index index = m_dimensions.IndexOfColMajor(indices);
169 return m_data[index];
174 EIGEN_STRONG_INLINE StorageRefType operator()()
176 EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
181 EIGEN_STRONG_INLINE StorageRefType operator()(Index index)
183 eigen_internal_assert(index >= 0 && index < size());
184 return m_data[index];
187 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
188 EIGEN_STRONG_INLINE StorageRefType operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
190 static_assert(
sizeof...(otherIndices) + 2 == NumIndices || NumIndices ==
Dynamic,
"Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
192 const std::size_t NumDims =
sizeof...(otherIndices) + 2;
193 if (PlainObjectType::Options&
RowMajor) {
194 const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
195 return m_data[index];
197 const Index index = m_dimensions.IndexOfColMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
198 return m_data[index];
202 EIGEN_TENSOR_INHERIT_ASSIGNMENT_OPERATORS(
TensorMap)
205 StoragePointerType m_data;
206 Dimensions m_dimensions;
The tensor base class.
Definition: TensorForwardDeclarations.h:58
A tensor expression mapping an existing array of data.
Definition: TensorMap.h:32
static const Eigen::internal::all_t all
Namespace containing all symbols from the Eigen library.