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::traits<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 
27 template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
28  : public internal::dense_xpr_base<Derived>::type
29 {
30  public:
31 
33  enum {
36  SizeAtCompileTime = Base::SizeAtCompileTime
37  };
38 
44  typedef typename internal::conditional<
46  Scalar *,
47  const Scalar *>::type
49 
50  using Base::derived;
51 // using Base::RowsAtCompileTime;
52 // using Base::ColsAtCompileTime;
53 // using Base::SizeAtCompileTime;
54  using Base::MaxRowsAtCompileTime;
55  using Base::MaxColsAtCompileTime;
56  using Base::MaxSizeAtCompileTime;
57  using Base::IsVectorAtCompileTime;
58  using Base::Flags;
59  using Base::IsRowMajor;
60 
61  using Base::rows;
62  using Base::cols;
63  using Base::size;
64  using Base::coeff;
65  using Base::coeffRef;
66  using Base::lazyAssign;
67  using Base::eval;
68 
69  using Base::innerStride;
70  using Base::outerStride;
71  using Base::rowStride;
72  using Base::colStride;
73 
74  // bug 217 - compile error on ICC 11.1
75  using Base::operator=;
76 
77  typedef typename Base::CoeffReturnType CoeffReturnType;
78 
79  inline Index rows() const { return m_rows.value(); }
80  inline Index cols() const { return m_cols.value(); }
81 
88  inline const Scalar* data() const { return m_data; }
89 
90  inline const Scalar& coeff(Index rowId, Index colId) const
91  {
92  return m_data[colId * colStride() + rowId * rowStride()];
93  }
94 
95  inline const Scalar& coeff(Index index) const
96  {
98  return m_data[index * innerStride()];
99  }
100 
101  inline const Scalar& coeffRef(Index rowId, Index colId) const
102  {
103  return this->m_data[colId * colStride() + rowId * rowStride()];
104  }
105 
106  inline const Scalar& coeffRef(Index index) const
107  {
109  return this->m_data[index * innerStride()];
110  }
111 
112  template<int LoadMode>
113  inline PacketScalar packet(Index rowId, Index colId) const
114  {
115  return internal::ploadt<PacketScalar, LoadMode>
116  (m_data + (colId * colStride() + rowId * rowStride()));
117  }
118 
119  template<int LoadMode>
120  inline PacketScalar packet(Index index) const
121  {
123  return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
124  }
125 
126  inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
127  {
129  checkSanity();
130  }
131 
132  inline MapBase(PointerType dataPtr, Index vecSize)
133  : m_data(dataPtr),
134  m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)),
135  m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime))
136  {
138  eigen_assert(vecSize >= 0);
139  eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize);
140  checkSanity();
141  }
142 
143  inline MapBase(PointerType dataPtr, Index nbRows, Index nbCols)
144  : m_data(dataPtr), m_rows(nbRows), m_cols(nbCols)
145  {
146  eigen_assert( (dataPtr == 0)
147  || ( nbRows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == nbRows)
148  && nbCols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == nbCols)));
149  checkSanity();
150  }
151 
152  protected:
153 
154  void checkSanity() const
155  {
158  PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
160  && "data is not aligned");
161  }
162 
166 };
167 
168 template<typename Derived> class MapBase<Derived, WriteAccessors>
169  : public MapBase<Derived, ReadOnlyAccessors>
170 {
171  public:
172 
174 
175  typedef typename Base::Scalar Scalar;
176  typedef typename Base::PacketScalar PacketScalar;
177  typedef typename Base::Index Index;
178  typedef typename Base::PointerType PointerType;
179 
180  using Base::derived;
181  using Base::rows;
182  using Base::cols;
183  using Base::size;
184  using Base::coeff;
185  using Base::coeffRef;
186 
187  using Base::innerStride;
188  using Base::outerStride;
189  using Base::rowStride;
190  using Base::colStride;
191 
192  typedef typename internal::conditional<
194  Scalar,
195  const Scalar
197 
198  inline const Scalar* data() const { return this->m_data; }
199  inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
200 
201  inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col)
202  {
203  return this->m_data[col * colStride() + row * rowStride()];
204  }
205 
206  inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
207  {
209  return this->m_data[index * innerStride()];
210  }
211 
212  template<int StoreMode>
213  inline void writePacket(Index row, Index col, const PacketScalar& val)
214  {
215  internal::pstoret<Scalar, PacketScalar, StoreMode>
216  (this->m_data + (col * colStride() + row * rowStride()), val);
217  }
218 
219  template<int StoreMode>
220  inline void writePacket(Index index, const PacketScalar& val)
221  {
223  internal::pstoret<Scalar, PacketScalar, StoreMode>
224  (this->m_data + index * innerStride(), val);
225  }
226 
227  explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {}
228  inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {}
229  inline MapBase(PointerType dataPtr, Index nbRows, Index nbCols) : Base(dataPtr, nbRows, nbCols) {}
230 
231  Derived& operator=(const MapBase& other)
232  {
233  Base::Base::operator=(other);
234  return derived();
235  }
236 
237  using Base::Base::operator=;
238 };
239 
240 } // end namespace Eigen
241 
242 #endif // EIGEN_MAPBASE_H
MapBase(PointerType dataPtr, Index nbRows, Index nbCols)
Definition: MapBase.h:143
Base::CoeffReturnType CoeffReturnType
Definition: MapBase.h:77
const internal::variable_if_dynamic< Index, ColsAtCompileTime > m_cols
Definition: MapBase.h:165
internal::packet_traits< Scalar >::type PacketScalar
Definition: MapBase.h:42
Base class for Map and Block expression with direct access.
const Scalar * data() const
Definition: MapBase.h:198
ScalarWithConstIfNotLvalue & coeffRef(Index index)
Definition: MapBase.h:206
MapBase(PointerType dataPtr, Index vecSize)
Definition: MapBase.h:132
void writePacket(Index index, const PacketScalar &val)
Definition: MapBase.h:220
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
PacketScalar packet(Index rowId, Index colId) const
Definition: MapBase.h:113
MapBase(PointerType dataPtr, Index vecSize)
Definition: MapBase.h:228
internal::traits< Derived >::Index Index
Definition: MapBase.h:40
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
const Scalar & coeff(Index index) const
Definition: MapBase.h:95
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:111
internal::dense_xpr_base< Derived >::type Base
Definition: MapBase.h:32
const unsigned int PacketAccessBit
const Scalar & coeffRef(Index rowId, Index colId) const
Definition: MapBase.h:101
const unsigned int AlignedBit
void writePacket(Index row, Index col, const PacketScalar &val)
Definition: MapBase.h:213
const Scalar & coeff(Index rowId, Index colId) const
Definition: MapBase.h:90
MapBase(PointerType dataPtr, Index nbRows, Index nbCols)
Definition: MapBase.h:229
internal::conditional< bool(internal::is_lvalue< Derived >::value), Scalar *, const Scalar * >::type PointerType
Definition: MapBase.h:48
PacketScalar packet(Index index) const
Definition: MapBase.h:120
#define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE)
Definition: StaticAssert.h:131
#define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
Definition: MapBase.h:14
MapBase< Derived, ReadOnlyAccessors > Base
Definition: MapBase.h:173
ScalarWithConstIfNotLvalue & coeffRef(Index row, Index col)
Definition: MapBase.h:201
internal::traits< Derived >::StorageKind StorageKind
Definition: MapBase.h:39
RowXpr row(Index i)
Definition: BlockMethods.h:725
const internal::variable_if_dynamic< Index, RowsAtCompileTime > m_rows
Definition: MapBase.h:164
#define EIGEN_IMPLIES(a, b)
const Scalar & coeffRef(Index index) const
Definition: MapBase.h:106
ColXpr col(Index i)
Definition: BlockMethods.h:708
internal::traits< Derived >::Scalar Scalar
Definition: MapBase.h:41
#define eigen_assert(x)
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:126
NumTraits< Scalar >::Real RealScalar
Definition: MapBase.h:43
Derived & operator=(const MapBase &other)
Definition: MapBase.h:231
ScalarWithConstIfNotLvalue * data()
Definition: MapBase.h:199
internal::conditional< internal::is_lvalue< Derived >::value, Scalar, const Scalar >::type ScalarWithConstIfNotLvalue
Definition: MapBase.h:196


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:49