Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
Eigen  3.3.9
MapBase.h
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 
42  typedef typename internal::dense_xpr_base<Derived>::type Base;
43  enum {
44  RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
45  ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
46  InnerStrideAtCompileTime = internal::traits<Derived>::InnerStrideAtCompileTime,
47  SizeAtCompileTime = Base::SizeAtCompileTime
48  };
49 
50  typedef typename internal::traits<Derived>::StorageKind StorageKind;
51  typedef typename internal::traits<Derived>::Scalar Scalar;
52  typedef typename internal::packet_traits<Scalar>::type PacketScalar;
53  typedef typename NumTraits<Scalar>::Real RealScalar;
54  typedef typename internal::conditional<
55  bool(internal::is_lvalue<Derived>::value),
56  Scalar *,
57  const Scalar *>::type
58  PointerType;
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 
90  EIGEN_DEVICE_FUNC inline Index rows() const { return m_rows.value(); }
92  EIGEN_DEVICE_FUNC inline Index cols() const { return m_cols.value(); }
93 
100  EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_data; }
101 
103  EIGEN_DEVICE_FUNC
104  inline const Scalar& coeff(Index rowId, Index colId) const
105  {
106  return m_data[colId * colStride() + rowId * rowStride()];
107  }
108 
110  EIGEN_DEVICE_FUNC
111  inline const Scalar& coeff(Index index) const
112  {
113  EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
114  return m_data[index * innerStride()];
115  }
116 
118  EIGEN_DEVICE_FUNC
119  inline const Scalar& coeffRef(Index rowId, Index colId) const
120  {
121  return this->m_data[colId * colStride() + rowId * rowStride()];
122  }
123 
125  EIGEN_DEVICE_FUNC
126  inline const Scalar& coeffRef(Index index) const
127  {
128  EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
129  return this->m_data[index * innerStride()];
130  }
131 
133  template<int LoadMode>
134  inline PacketScalar packet(Index rowId, Index colId) const
135  {
136  return internal::ploadt<PacketScalar, LoadMode>
137  (m_data + (colId * colStride() + rowId * rowStride()));
138  }
139 
141  template<int LoadMode>
142  inline PacketScalar packet(Index index) const
143  {
144  EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
145  return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
146  }
147 
149  EIGEN_DEVICE_FUNC
150  explicit inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
151  {
152  EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
153  checkSanity<Derived>();
154  }
155 
157  EIGEN_DEVICE_FUNC
158  inline MapBase(PointerType dataPtr, Index vecSize)
159  : m_data(dataPtr),
160  m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)),
161  m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime))
162  {
163  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
164  eigen_assert(vecSize >= 0);
165  eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize);
166  checkSanity<Derived>();
167  }
168 
170  EIGEN_DEVICE_FUNC
171  inline MapBase(PointerType dataPtr, Index rows, Index cols)
172  : m_data(dataPtr), m_rows(rows), m_cols(cols)
173  {
174  eigen_assert( (dataPtr == 0)
175  || ( rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
176  && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)));
177  checkSanity<Derived>();
178  }
179 
180  #ifdef EIGEN_MAPBASE_PLUGIN
181  #include EIGEN_MAPBASE_PLUGIN
182  #endif
183 
184  protected:
185  EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase)
186  EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase)
187 
188  template<typename T>
189  EIGEN_DEVICE_FUNC
190  void checkSanity(typename internal::enable_if<(internal::traits<T>::Alignment>0),void*>::type = 0) const
191  {
192 #if EIGEN_MAX_ALIGN_BYTES>0
193  // innerStride() is not set yet when this function is called, so we optimistically assume the lowest plausible value:
194  const Index minInnerStride = InnerStrideAtCompileTime == Dynamic ? 1 : Index(InnerStrideAtCompileTime);
195  EIGEN_ONLY_USED_FOR_DEBUG(minInnerStride);
196  eigen_assert(( ((internal::UIntPtr(m_data) % internal::traits<Derived>::Alignment) == 0)
197  || (cols() * rows() * minInnerStride * sizeof(Scalar)) < internal::traits<Derived>::Alignment ) && "data is not aligned");
198 #endif
199  }
200 
201  template<typename T>
202  EIGEN_DEVICE_FUNC
203  void checkSanity(typename internal::enable_if<internal::traits<T>::Alignment==0,void*>::type = 0) const
204  {}
205 
206  PointerType m_data;
207  const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
208  const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
209 };
210 
221 template<typename Derived> class MapBase<Derived, WriteAccessors>
222  : public MapBase<Derived, ReadOnlyAccessors>
223 {
225  public:
226 
228 
229  typedef typename Base::Scalar Scalar;
230  typedef typename Base::PacketScalar PacketScalar;
231  typedef typename Base::StorageIndex StorageIndex;
232  typedef typename Base::PointerType PointerType;
233 
234  using Base::derived;
235  using Base::rows;
236  using Base::cols;
237  using Base::size;
238  using Base::coeff;
239  using Base::coeffRef;
240 
241  using Base::innerStride;
242  using Base::outerStride;
243  using Base::rowStride;
244  using Base::colStride;
245 
246  typedef typename internal::conditional<
247  internal::is_lvalue<Derived>::value,
248  Scalar,
249  const Scalar
250  >::type ScalarWithConstIfNotLvalue;
251 
252  EIGEN_DEVICE_FUNC
253  inline const Scalar* data() const { return this->m_data; }
254  EIGEN_DEVICE_FUNC
255  inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
256 
257  EIGEN_DEVICE_FUNC
258  inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col)
259  {
260  return this->m_data[col * colStride() + row * rowStride()];
261  }
262 
263  EIGEN_DEVICE_FUNC
264  inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
265  {
266  EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
267  return this->m_data[index * innerStride()];
268  }
269 
270  template<int StoreMode>
271  inline void writePacket(Index row, Index col, const PacketScalar& val)
272  {
273  internal::pstoret<Scalar, PacketScalar, StoreMode>
274  (this->m_data + (col * colStride() + row * rowStride()), val);
275  }
276 
277  template<int StoreMode>
278  inline void writePacket(Index index, const PacketScalar& val)
279  {
280  EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
281  internal::pstoret<Scalar, PacketScalar, StoreMode>
282  (this->m_data + index * innerStride(), val);
283  }
284 
285  EIGEN_DEVICE_FUNC explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {}
286  EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {}
287  EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index rows, Index cols) : Base(dataPtr, rows, cols) {}
288 
289  EIGEN_DEVICE_FUNC
290  Derived& operator=(const MapBase& other)
291  {
292  ReadOnlyMapBase::Base::operator=(other);
293  return derived();
294  }
295 
296  // In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base,
297  // see bugs 821 and 920.
298  using ReadOnlyMapBase::Base::operator=;
299  protected:
300  EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase)
301  EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase)
302 };
303 
304 #undef EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS
305 
306 } // end namespace Eigen
307 
308 #endif // EIGEN_MAPBASE_H
Eigen::MapBase< Derived, ReadOnlyAccessors >::data
const Scalar * data() const
Definition: MapBase.h:100
Eigen
Namespace containing all symbols from the Eigen library.
Definition: Core:309
Eigen::MapBase< Derived, ReadOnlyAccessors >::coeff
const Scalar & coeff(Index rowId, Index colId) const
Definition: MapBase.h:104
Eigen::MapBase< Derived, ReadOnlyAccessors >::coeff
const Scalar & coeff(Index index) const
Definition: MapBase.h:111
Eigen::MapBase< Derived, ReadOnlyAccessors >::cols
Index cols() const
Definition: MapBase.h:92
Eigen::MapBase< Derived, ReadOnlyAccessors >::coeffRef
const Scalar & coeffRef(Index index) const
Definition: MapBase.h:126
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:21
Eigen::MapBase< Derived, ReadOnlyAccessors >::coeffRef
const Scalar & coeffRef(Index rowId, Index colId) const
Definition: MapBase.h:119
Eigen::ReadOnlyAccessors
@ ReadOnlyAccessors
Definition: Constants.h:366
Eigen::MapBase< Derived, ReadOnlyAccessors >
Base class for dense Map and Block expression with direct access.
Definition: MapBase.h:39
Eigen::WriteAccessors
@ WriteAccessors
Definition: Constants.h:368
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:151
Eigen::MapBase< Derived, ReadOnlyAccessors >::rows
Index rows() const
Definition: MapBase.h:90
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33