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 {
46  SizeAtCompileTime = Base::SizeAtCompileTime
47  };
48 
53  typedef typename internal::conditional<
55  Scalar *,
56  const Scalar *>::type
58 
59  using Base::derived;
60 // using Base::RowsAtCompileTime;
61 // using Base::ColsAtCompileTime;
62 // using Base::SizeAtCompileTime;
63  using Base::MaxRowsAtCompileTime;
64  using Base::MaxColsAtCompileTime;
65  using Base::MaxSizeAtCompileTime;
66  using Base::IsVectorAtCompileTime;
67  using Base::Flags;
68  using Base::IsRowMajor;
69 
70  using Base::rows;
71  using Base::cols;
72  using Base::size;
73  using Base::coeff;
74  using Base::coeffRef;
75  using Base::lazyAssign;
76  using Base::eval;
77 
78  using Base::innerStride;
79  using Base::outerStride;
80  using Base::rowStride;
81  using Base::colStride;
82 
83  // bug 217 - compile error on ICC 11.1
84  using Base::operator=;
85 
86  typedef typename Base::CoeffReturnType CoeffReturnType;
87 
89  EIGEN_DEVICE_FUNC inline Index rows() const { return m_rows.value(); }
91  EIGEN_DEVICE_FUNC inline Index cols() const { return m_cols.value(); }
92 
99  EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_data; }
100 
102  EIGEN_DEVICE_FUNC
103  inline const Scalar& coeff(Index rowId, Index colId) const
104  {
105  return m_data[colId * colStride() + rowId * rowStride()];
106  }
107 
109  EIGEN_DEVICE_FUNC
110  inline const Scalar& coeff(Index index) const
111  {
113  return m_data[index * innerStride()];
114  }
115 
117  EIGEN_DEVICE_FUNC
118  inline const Scalar& coeffRef(Index rowId, Index colId) const
119  {
120  return this->m_data[colId * colStride() + rowId * rowStride()];
121  }
122 
124  EIGEN_DEVICE_FUNC
125  inline const Scalar& coeffRef(Index index) const
126  {
128  return this->m_data[index * innerStride()];
129  }
130 
132  template<int LoadMode>
133  inline PacketScalar packet(Index rowId, Index colId) const
134  {
135  return internal::ploadt<PacketScalar, LoadMode>
136  (m_data + (colId * colStride() + rowId * rowStride()));
137  }
138 
140  template<int LoadMode>
141  inline PacketScalar packet(Index index) const
142  {
144  return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
145  }
146 
148  EIGEN_DEVICE_FUNC
149  explicit inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
150  {
152  checkSanity<Derived>();
153  }
154 
156  EIGEN_DEVICE_FUNC
157  inline MapBase(PointerType dataPtr, Index vecSize)
158  : m_data(dataPtr),
159  m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)),
160  m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime))
161  {
163  eigen_assert(vecSize >= 0);
164  eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize);
165  checkSanity<Derived>();
166  }
167 
169  EIGEN_DEVICE_FUNC
170  inline MapBase(PointerType dataPtr, Index rows, Index cols)
171  : m_data(dataPtr), m_rows(rows), m_cols(cols)
172  {
173  eigen_assert( (dataPtr == 0)
174  || ( rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
175  && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)));
176  checkSanity<Derived>();
177  }
178 
179  #ifdef EIGEN_MAPBASE_PLUGIN
180  #include EIGEN_MAPBASE_PLUGIN
181  #endif
182 
183  protected:
184 
185  template<typename T>
186  EIGEN_DEVICE_FUNC
187  void checkSanity(typename internal::enable_if<(internal::traits<T>::Alignment>0),void*>::type = 0) const
188  {
189 #if EIGEN_MAX_ALIGN_BYTES>0
191  || (cols() * rows() * innerStride() * sizeof(Scalar)) < internal::traits<Derived>::Alignment ) && "data is not aligned");
192 #endif
193  }
194 
195  template<typename T>
196  EIGEN_DEVICE_FUNC
197  void checkSanity(typename internal::enable_if<internal::traits<T>::Alignment==0,void*>::type = 0) const
198  {}
199 
203 };
204 
215 template<typename Derived> class MapBase<Derived, WriteAccessors>
216  : public MapBase<Derived, ReadOnlyAccessors>
217 {
219  public:
220 
222 
223  typedef typename Base::Scalar Scalar;
224  typedef typename Base::PacketScalar PacketScalar;
225  typedef typename Base::StorageIndex StorageIndex;
226  typedef typename Base::PointerType PointerType;
227 
228  using Base::derived;
229  using Base::rows;
230  using Base::cols;
231  using Base::size;
232  using Base::coeff;
233  using Base::coeffRef;
234 
235  using Base::innerStride;
236  using Base::outerStride;
237  using Base::rowStride;
238  using Base::colStride;
239 
240  typedef typename internal::conditional<
242  Scalar,
243  const Scalar
245 
246  EIGEN_DEVICE_FUNC
247  inline const Scalar* data() const { return this->m_data; }
248  EIGEN_DEVICE_FUNC
249  inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
250 
251  EIGEN_DEVICE_FUNC
252  inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col)
253  {
254  return this->m_data[col * colStride() + row * rowStride()];
255  }
256 
257  EIGEN_DEVICE_FUNC
258  inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
259  {
261  return this->m_data[index * innerStride()];
262  }
263 
264  template<int StoreMode>
265  inline void writePacket(Index row, Index col, const PacketScalar& val)
266  {
267  internal::pstoret<Scalar, PacketScalar, StoreMode>
268  (this->m_data + (col * colStride() + row * rowStride()), val);
269  }
270 
271  template<int StoreMode>
272  inline void writePacket(Index index, const PacketScalar& val)
273  {
275  internal::pstoret<Scalar, PacketScalar, StoreMode>
276  (this->m_data + index * innerStride(), val);
277  }
278 
279  EIGEN_DEVICE_FUNC explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {}
280  EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {}
281  EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index rows, Index cols) : Base(dataPtr, rows, cols) {}
282 
283  EIGEN_DEVICE_FUNC
284  Derived& operator=(const MapBase& other)
285  {
286  ReadOnlyMapBase::Base::operator=(other);
287  return derived();
288  }
289 
290  // In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base,
291  // see bugs 821 and 920.
292  using ReadOnlyMapBase::Base::operator=;
293 };
294 
295 #undef EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS
296 
297 } // end namespace Eigen
298 
299 #endif // EIGEN_MAPBASE_H
Base::CoeffReturnType CoeffReturnType
Definition: MapBase.h:86
const internal::variable_if_dynamic< Index, ColsAtCompileTime > m_cols
Definition: MapBase.h:202
internal::packet_traits< Scalar >::type PacketScalar
Definition: MapBase.h:51
EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: MapBase.h:247
EIGEN_DEVICE_FUNC const Scalar & coeff(Index rowId, Index colId) const
Definition: MapBase.h:103
void writePacket(Index index, const PacketScalar &val)
Definition: MapBase.h:272
Definition: LDLT.h:16
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
PacketScalar packet(Index rowId, Index colId) const
Definition: MapBase.h:133
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr, Index vecSize)
Definition: MapBase.h:157
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
internal::dense_xpr_base< Derived >::type Base
Definition: MapBase.h:42
EIGEN_DEVICE_FUNC void checkSanity(typename internal::enable_if<(internal::traits< T >::Alignment >0), void * >::type=0) const
Definition: MapBase.h:187
std::size_t UIntPtr
Definition: Meta.h:51
EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue & coeffRef(Index index)
Definition: MapBase.h:258
void writePacket(Index row, Index col, const PacketScalar &val)
Definition: MapBase.h:265
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
Definition: BlockMethods.h:838
Base class for dense Map and Block expression with direct access.
Definition: MapBase.h:37
EIGEN_DEVICE_FUNC void checkSanity(typename internal::enable_if< internal::traits< T >::Alignment==0, void * >::type=0) const
Definition: MapBase.h:197
internal::conditional< bool(internal::is_lvalue< Derived >::value), Scalar *, const Scalar * >::type PointerType
Definition: MapBase.h:57
PacketScalar packet(Index index) const
Definition: MapBase.h:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
EIGEN_DEVICE_FUNC Derived & operator=(const MapBase &other)
Definition: MapBase.h:284
#define eigen_assert(x)
Definition: Macros.h:577
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). */.
Definition: BlockMethods.h:859
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr, Index vecSize)
Definition: MapBase.h:280
#define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE)
Definition: StaticAssert.h:142
MapBase< Derived, ReadOnlyAccessors > ReadOnlyMapBase
Definition: MapBase.h:218
#define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
Definition: MapBase.h:14
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr)
Definition: MapBase.h:279
EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue * data()
Definition: MapBase.h:249
MapBase< Derived, ReadOnlyAccessors > Base
Definition: MapBase.h:221
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr, Index rows, Index cols)
Definition: MapBase.h:170
internal::traits< Derived >::StorageKind StorageKind
Definition: MapBase.h:49
const internal::variable_if_dynamic< Index, RowsAtCompileTime > m_rows
Definition: MapBase.h:201
EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: MapBase.h:99
EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue & coeffRef(Index row, Index col)
Definition: MapBase.h:252
EIGEN_DEVICE_FUNC Index cols() const
Definition: MapBase.h:91
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr)
Definition: MapBase.h:149
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index index) const
Definition: MapBase.h:125
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index rowId, Index colId) const
Definition: MapBase.h:118
EIGEN_DEVICE_FUNC MapBase(PointerType dataPtr, Index rows, Index cols)
Definition: MapBase.h:281
const int Dynamic
Definition: Constants.h:21
internal::traits< Derived >::Scalar Scalar
Definition: MapBase.h:50
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:137
NumTraits< Scalar >::Real RealScalar
Definition: MapBase.h:52
EIGEN_DEVICE_FUNC Index rows() const
Definition: MapBase.h:89
internal::conditional< internal::is_lvalue< Derived >::value, Scalar, const Scalar >::type ScalarWithConstIfNotLvalue
Definition: MapBase.h:244
EIGEN_DEVICE_FUNC const Scalar & coeff(Index index) const
Definition: MapBase.h:110


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:23