MapBase.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_MAPBASE_H
12 #define EIGEN_MAPBASE_H
13 
14 #define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) \
15  EIGEN_STATIC_ASSERT((int(internal::evaluator<Derived>::Flags) & LinearAccessBit) || Derived::IsVectorAtCompileTime, \
16  YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT)
17 
18 namespace Eigen {
19 
37 template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
38  : public internal::dense_xpr_base<Derived>::type
39 {
40  public:
41 
43  enum {
47  SizeAtCompileTime = Base::SizeAtCompileTime
48  };
49 
54  typedef typename internal::conditional<
56  Scalar *,
57  const Scalar *>::type
59 
60  using Base::derived;
61 // using Base::RowsAtCompileTime;
62 // using Base::ColsAtCompileTime;
63 // using Base::SizeAtCompileTime;
64  using Base::MaxRowsAtCompileTime;
65  using Base::MaxColsAtCompileTime;
66  using Base::MaxSizeAtCompileTime;
67  using Base::IsVectorAtCompileTime;
68  using Base::Flags;
69  using Base::IsRowMajor;
70 
71  using Base::rows;
72  using Base::cols;
73  using Base::size;
74  using Base::coeff;
75  using Base::coeffRef;
76  using Base::lazyAssign;
77  using Base::eval;
78 
79  using Base::innerStride;
80  using Base::outerStride;
81  using Base::rowStride;
82  using Base::colStride;
83 
84  // bug 217 - compile error on ICC 11.1
85  using Base::operator=;
86 
87  typedef typename Base::CoeffReturnType CoeffReturnType;
88 
91  inline Index rows() const EIGEN_NOEXCEPT { return m_rows.value(); }
94  inline Index cols() const EIGEN_NOEXCEPT { return m_cols.value(); }
95 
102  EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_data; }
103 
106  inline const Scalar& coeff(Index rowId, Index colId) const
107  {
108  return m_data[colId * colStride() + rowId * rowStride()];
109  }
110 
113  inline const Scalar& coeff(Index index) const
114  {
116  return m_data[index * innerStride()];
117  }
118 
121  inline const Scalar& coeffRef(Index rowId, Index colId) const
122  {
123  return this->m_data[colId * colStride() + rowId * rowStride()];
124  }
125 
128  inline const Scalar& coeffRef(Index index) const
129  {
131  return this->m_data[index * innerStride()];
132  }
133 
135  template<int LoadMode>
136  inline PacketScalar packet(Index rowId, Index colId) const
137  {
138  return internal::ploadt<PacketScalar, LoadMode>
139  (m_data + (colId * colStride() + rowId * rowStride()));
140  }
141 
143  template<int LoadMode>
144  inline PacketScalar packet(Index index) const
145  {
147  return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
148  }
149 
152  explicit inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
153  {
155  checkSanity<Derived>();
156  }
157 
160  inline MapBase(PointerType dataPtr, Index vecSize)
161  : m_data(dataPtr),
162  m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)),
163  m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime))
164  {
166  eigen_assert(vecSize >= 0);
167  eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize);
168  checkSanity<Derived>();
169  }
170 
174  : m_data(dataPtr), m_rows(rows), m_cols(cols)
175  {
176  eigen_assert( (dataPtr == 0)
177  || ( rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
178  && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)));
179  checkSanity<Derived>();
180  }
181 
182  #ifdef EIGEN_MAPBASE_PLUGIN
183  #include EIGEN_MAPBASE_PLUGIN
184  #endif
185 
186  protected:
189 
190  template<typename T>
193  {
194 #if EIGEN_MAX_ALIGN_BYTES>0
195  // innerStride() is not set yet when this function is called, so we optimistically assume the lowest plausible value:
196  const Index minInnerStride = InnerStrideAtCompileTime == Dynamic ? 1 : Index(InnerStrideAtCompileTime);
197  EIGEN_ONLY_USED_FOR_DEBUG(minInnerStride);
199  || (cols() * rows() * minInnerStride * sizeof(Scalar)) < internal::traits<Derived>::Alignment ) && "data is not aligned");
200 #endif
201  }
202 
203  template<typename T>
206  {}
207 
211 };
212 
223 template<typename Derived> class MapBase<Derived, WriteAccessors>
224  : public MapBase<Derived, ReadOnlyAccessors>
225 {
227  public:
228 
230 
231  typedef typename Base::Scalar Scalar;
232  typedef typename Base::PacketScalar PacketScalar;
233  typedef typename Base::StorageIndex StorageIndex;
234  typedef typename Base::PointerType PointerType;
235 
236  using Base::derived;
237  using Base::rows;
238  using Base::cols;
239  using Base::size;
240  using Base::coeff;
241  using Base::coeffRef;
242 
243  using Base::innerStride;
244  using Base::outerStride;
245  using Base::rowStride;
246  using Base::colStride;
247 
248  typedef typename internal::conditional<
250  Scalar,
251  const Scalar
253 
255  inline const Scalar* data() const { return this->m_data; }
257  inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
258 
261  {
262  return this->m_data[col * colStride() + row * rowStride()];
263  }
264 
267  {
269  return this->m_data[index * innerStride()];
270  }
271 
272  template<int StoreMode>
273  inline void writePacket(Index row, Index col, const PacketScalar& val)
274  {
275  internal::pstoret<Scalar, PacketScalar, StoreMode>
276  (this->m_data + (col * colStride() + row * rowStride()), val);
277  }
278 
279  template<int StoreMode>
280  inline void writePacket(Index index, const PacketScalar& val)
281  {
283  internal::pstoret<Scalar, PacketScalar, StoreMode>
284  (this->m_data + index * innerStride(), val);
285  }
286 
287  EIGEN_DEVICE_FUNC explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {}
288  EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {}
289  EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index rows, Index cols) : Base(dataPtr, rows, cols) {}
290 
292  Derived& operator=(const MapBase& other)
293  {
294  ReadOnlyMapBase::Base::operator=(other);
295  return derived();
296  }
297 
298  // In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base,
299  // see bugs 821 and 920.
300  using ReadOnlyMapBase::Base::operator=;
301  protected:
304 };
305 
306 #undef EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS
307 
308 } // end namespace Eigen
309 
310 #endif // EIGEN_MAPBASE_H
Eigen::MapBase< Derived, ReadOnlyAccessors >::MapBase
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr)
Definition: MapBase.h:152
Eigen::internal::variable_if_dynamic< Index, RowsAtCompileTime >
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen::MapBase< Derived, ReadOnlyAccessors >::Base
internal::dense_xpr_base< Derived >::type Base
Definition: MapBase.h:42
Eigen::MapBase< Derived, WriteAccessors >::PacketScalar
Base::PacketScalar PacketScalar
Definition: MapBase.h:232
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::MapBase< Derived, ReadOnlyAccessors >::RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: MapBase.h:53
col
m col(1)
Eigen::internal::UIntPtr
std::size_t UIntPtr
Definition: Meta.h:92
Eigen::MapBase< Derived, ReadOnlyAccessors >::checkSanity
EIGEN_DEVICE_FUNC void checkSanity(typename internal::enable_if< internal::traits< T >::Alignment==0, void * >::type=0) const
Definition: MapBase.h:205
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR
#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived)
Definition: Macros.h:1247
Eigen::MapBase< Derived, ReadOnlyAccessors >::coeff
const EIGEN_DEVICE_FUNC Scalar & coeff(Index index) const
Definition: MapBase.h:113
Eigen::MapBase< Derived, WriteAccessors >::data
EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue * data()
Definition: MapBase.h:257
Eigen::MapBase< Derived, ReadOnlyAccessors >::m_cols
const internal::variable_if_dynamic< Index, ColsAtCompileTime > m_cols
Definition: MapBase.h:210
Eigen::internal::dense_xpr_base
Definition: XprHelper.h:483
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
Eigen::internal::is_lvalue
Definition: XprHelper.h:659
Eigen::MapBase< Derived, ReadOnlyAccessors >::packet
PacketScalar packet(Index rowId, Index colId) const
Definition: MapBase.h:136
Eigen::MapBase< Derived, WriteAccessors >::operator=
EIGEN_DEVICE_FUNC Derived & operator=(const MapBase &other)
Definition: MapBase.h:292
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
type
Definition: pytypes.h:1525
Eigen::MapBase< Derived, WriteAccessors >::ReadOnlyMapBase
MapBase< Derived, ReadOnlyAccessors > ReadOnlyMapBase
Definition: MapBase.h:226
Eigen::MapBase< Derived, WriteAccessors >::MapBase
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr)
Definition: MapBase.h:287
EIGEN_STATIC_ASSERT_VECTOR_ONLY
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:142
Eigen::MapBase< Derived, ReadOnlyAccessors >::m_rows
const internal::variable_if_dynamic< Index, RowsAtCompileTime > m_rows
Definition: MapBase.h:209
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
EIGEN_ONLY_USED_FOR_DEBUG
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
Definition: Macros.h:1049
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::MapBase< Derived, ReadOnlyAccessors >::coeff
const EIGEN_DEVICE_FUNC Scalar & coeff(Index rowId, Index colId) const
Definition: MapBase.h:106
Eigen::MapBase< Derived, ReadOnlyAccessors >::StorageKind
internal::traits< Derived >::StorageKind StorageKind
Definition: MapBase.h:50
EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS
#define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
Definition: MapBase.h:14
Eigen::MapBase< Derived, ReadOnlyAccessors >::PointerType
internal::conditional< bool(internal::is_lvalue< Derived >::value), Scalar *, const Scalar * >::type PointerType
Definition: MapBase.h:58
Eigen::MapBase
Definition: ForwardDeclarations.h:112
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
Eigen::MapBase< Derived, ReadOnlyAccessors >::rows
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: MapBase.h:91
Eigen::MapBase< Derived, ReadOnlyAccessors >::MapBase
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr, Index rows, Index cols)
Definition: MapBase.h:173
Eigen::MapBase< Derived, WriteAccessors >::MapBase
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr, Index rows, Index cols)
Definition: MapBase.h:289
Eigen::MapBase< Derived, ReadOnlyAccessors >::coeffRef
const EIGEN_DEVICE_FUNC Scalar & coeffRef(Index index) const
Definition: MapBase.h:128
Eigen::Triplet< double >
Eigen::MapBase< Derived, WriteAccessors >::PointerType
Base::PointerType PointerType
Definition: MapBase.h:234
Eigen::ReadOnlyAccessors
@ ReadOnlyAccessors
Definition: Constants.h:376
EIGEN_DEFAULT_COPY_CONSTRUCTOR
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
Definition: Macros.h:1221
Eigen::MapBase< Derived, WriteAccessors >::writePacket
void writePacket(Index index, const PacketScalar &val)
Definition: MapBase.h:280
Eigen::MapBase< Derived, ReadOnlyAccessors >::cols
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: MapBase.h:94
Eigen::MapBase< Derived, ReadOnlyAccessors >::coeffRef
const EIGEN_DEVICE_FUNC Scalar & coeffRef(Index rowId, Index colId) const
Definition: MapBase.h:121
Eigen::MapBase< Derived, ReadOnlyAccessors >::checkSanity
EIGEN_DEVICE_FUNC void checkSanity(typename internal::enable_if<(internal::traits< T >::Alignment >0), void * >::type=0) const
Definition: MapBase.h:192
Eigen::MapBase< Derived, WriteAccessors >::Scalar
Base::Scalar Scalar
Definition: MapBase.h:231
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::MapBase< Derived, ReadOnlyAccessors >
Base class for dense Map and Block expression with direct access.
Definition: MapBase.h:37
Eigen::MapBase< Derived, ReadOnlyAccessors >::m_data
PointerType m_data
Definition: MapBase.h:208
Eigen::MapBase< Derived, WriteAccessors >::data
const EIGEN_DEVICE_FUNC Scalar * data() const
Definition: MapBase.h:255
row
m row(1)
Eigen::internal::conditional
Definition: Meta.h:109
Eigen::MapBase< Derived, ReadOnlyAccessors >::PacketScalar
internal::packet_traits< Scalar >::type PacketScalar
Definition: MapBase.h:52
Eigen::MapBase< Derived, WriteAccessors >::StorageIndex
Base::StorageIndex StorageIndex
Definition: MapBase.h:233
EIGEN_NOEXCEPT
#define EIGEN_NOEXCEPT
Definition: Macros.h:1418
Eigen::MapBase< Derived, ReadOnlyAccessors >::Scalar
internal::traits< Derived >::Scalar Scalar
Definition: MapBase.h:51
Eigen::internal::enable_if
Definition: Meta.h:273
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
Base
Definition: test_virtual_functions.cpp:156
Eigen::MapBase< Derived, ReadOnlyAccessors >::packet
PacketScalar packet(Index index) const
Definition: MapBase.h:144
Eigen::MapBase< Derived, ReadOnlyAccessors >::data
const EIGEN_DEVICE_FUNC Scalar * data() const
Definition: MapBase.h:102
EIGEN_STATIC_ASSERT_FIXED_SIZE
#define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE)
Definition: StaticAssert.h:147
Eigen::WriteAccessors
@ WriteAccessors
Definition: Constants.h:378
Eigen::MapBase< Derived, WriteAccessors >::writePacket
void writePacket(Index row, Index col, const PacketScalar &val)
Definition: MapBase.h:273
Eigen::MapBase< Derived, WriteAccessors >::coeffRef
EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue & coeffRef(Index row, Index col)
Definition: MapBase.h:260
Eigen::MapBase< Derived, ReadOnlyAccessors >::MapBase
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr, Index vecSize)
Definition: MapBase.h:160
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
eval
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:38
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Eigen::MapBase< Derived, WriteAccessors >::coeffRef
EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue & coeffRef(Index index)
Definition: MapBase.h:266
Eigen::MapBase< Derived, WriteAccessors >::ScalarWithConstIfNotLvalue
internal::conditional< internal::is_lvalue< Derived >::value, Scalar, const Scalar >::type ScalarWithConstIfNotLvalue
Definition: MapBase.h:252
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::MapBase< Derived, WriteAccessors >::MapBase
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr, Index vecSize)
Definition: MapBase.h:288
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::MapBase< Derived, ReadOnlyAccessors >::CoeffReturnType
Base::CoeffReturnType CoeffReturnType
Definition: MapBase.h:87
Eigen::MapBase< Derived, WriteAccessors >::Base
MapBase< Derived, ReadOnlyAccessors > Base
Definition: MapBase.h:229


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:56