Medial Code Documentation
Loading...
Searching...
No Matches
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
18namespace Eigen {
19
27template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
28 : public internal::dense_xpr_base<Derived>::type
29{
30 public:
31
32 typedef typename internal::dense_xpr_base<Derived>::type Base;
33 enum {
36 SizeAtCompileTime = Base::SizeAtCompileTime
37 };
38
39 typedef typename internal::traits<Derived>::StorageKind StorageKind;
40 typedef typename internal::traits<Derived>::Scalar Scalar;
41 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
42 typedef typename NumTraits<Scalar>::Real RealScalar;
43 typedef typename internal::conditional<
45 Scalar *,
46 const Scalar *>::type
48
49 using Base::derived;
50// using Base::RowsAtCompileTime;
51// using Base::ColsAtCompileTime;
52// using Base::SizeAtCompileTime;
53 using Base::MaxRowsAtCompileTime;
54 using Base::MaxColsAtCompileTime;
55 using Base::MaxSizeAtCompileTime;
56 using Base::IsVectorAtCompileTime;
57 using Base::Flags;
58 using Base::IsRowMajor;
59
60 using Base::rows;
61 using Base::cols;
62 using Base::size;
63 using Base::coeff;
64 using Base::coeffRef;
65 using Base::lazyAssign;
66 using Base::eval;
67
68 using Base::innerStride;
69 using Base::outerStride;
70 using Base::rowStride;
71 using Base::colStride;
72
73 // bug 217 - compile error on ICC 11.1
74 using Base::operator=;
75
76 typedef typename Base::CoeffReturnType CoeffReturnType;
77
78 EIGEN_DEVICE_FUNC inline Index rows() const { return m_rows.value(); }
79 EIGEN_DEVICE_FUNC inline Index cols() const { return m_cols.value(); }
80
87 EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_data; }
88
90 inline const Scalar& coeff(Index rowId, Index colId) const
91 {
92 return m_data[colId * colStride() + rowId * rowStride()];
93 }
94
95 EIGEN_DEVICE_FUNC
96 inline const Scalar& coeff(Index index) const
97 {
98 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
99 return m_data[index * innerStride()];
100 }
101
102 EIGEN_DEVICE_FUNC
103 inline const Scalar& coeffRef(Index rowId, Index colId) const
104 {
105 return this->m_data[colId * colStride() + rowId * rowStride()];
106 }
107
108 EIGEN_DEVICE_FUNC
109 inline const Scalar& coeffRef(Index index) const
110 {
111 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
112 return this->m_data[index * innerStride()];
113 }
114
115 template<int LoadMode>
116 inline PacketScalar packet(Index rowId, Index colId) const
117 {
118 return internal::ploadt<PacketScalar, LoadMode>
119 (m_data + (colId * colStride() + rowId * rowStride()));
120 }
121
122 template<int LoadMode>
123 inline PacketScalar packet(Index index) const
124 {
125 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
126 return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
127 }
128
129 EIGEN_DEVICE_FUNC
130 explicit inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
131 {
132 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
133 checkSanity();
134 }
135
136 EIGEN_DEVICE_FUNC
137 inline MapBase(PointerType dataPtr, Index vecSize)
138 : m_data(dataPtr),
139 m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)),
140 m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime))
141 {
142 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
143 eigen_assert(vecSize >= 0);
144 eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize);
145 checkSanity();
146 }
147
148 EIGEN_DEVICE_FUNC
149 inline MapBase(PointerType dataPtr, Index rows, Index cols)
150 : m_data(dataPtr), m_rows(rows), m_cols(cols)
151 {
152 eigen_assert( (dataPtr == 0)
153 || ( rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
154 && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)));
155 checkSanity();
156 }
157
158 #ifdef EIGEN_MAPBASE_PLUGIN
159 #include EIGEN_MAPBASE_PLUGIN
160 #endif
161
162 protected:
163
164 EIGEN_DEVICE_FUNC
165 void checkSanity() const
166 {
167#if EIGEN_MAX_ALIGN_BYTES>0
168 eigen_assert(((size_t(m_data) % EIGEN_PLAIN_ENUM_MAX(1,internal::traits<Derived>::Alignment)) == 0) && "data is not aligned");
169#endif
170 }
171
172 PointerType m_data;
173 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
174 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
175};
176
177template<typename Derived> class MapBase<Derived, WriteAccessors>
178 : public MapBase<Derived, ReadOnlyAccessors>
179{
181 public:
182
184
185 typedef typename Base::Scalar Scalar;
186 typedef typename Base::PacketScalar PacketScalar;
187 typedef typename Base::StorageIndex StorageIndex;
188 typedef typename Base::PointerType PointerType;
189
190 using Base::derived;
191 using Base::rows;
192 using Base::cols;
193 using Base::size;
194 using Base::coeff;
195 using Base::coeffRef;
196
197 using Base::innerStride;
198 using Base::outerStride;
199 using Base::rowStride;
200 using Base::colStride;
201
202 typedef typename internal::conditional<
204 Scalar,
205 const Scalar
207
209 inline const Scalar* data() const { return this->m_data; }
211 inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
212
214 inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col)
215 {
216 return this->m_data[col * colStride() + row * rowStride()];
217 }
218
220 inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
221 {
222 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
223 return this->m_data[index * innerStride()];
224 }
225
226 template<int StoreMode>
227 inline void writePacket(Index row, Index col, const PacketScalar& val)
228 {
229 internal::pstoret<Scalar, PacketScalar, StoreMode>
230 (this->m_data + (col * colStride() + row * rowStride()), val);
231 }
232
233 template<int StoreMode>
234 inline void writePacket(Index index, const PacketScalar& val)
235 {
236 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
237 internal::pstoret<Scalar, PacketScalar, StoreMode>
238 (this->m_data + index * innerStride(), val);
239 }
240
241 EIGEN_DEVICE_FUNC explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {}
242 EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {}
243 EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index rows, Index cols) : Base(dataPtr, rows, cols) {}
244
246 Derived& operator=(const MapBase& other)
247 {
248 ReadOnlyMapBase::Base::operator=(other);
249 return derived();
250 }
251
252 // In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base,
253 // see bugs 821 and 920.
254 using ReadOnlyMapBase::Base::operator=;
255};
256
257#undef EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS
258
259} // end namespace Eigen
260
261#endif // EIGEN_MAPBASE_H
EIGEN_DEVICE_FUNC const Scalar * data() const
Returns a pointer to the first coefficient of the matrix or vector.
Definition MapBase.h:87
Base class for Map and Block expression with direct access.
Definition ForwardDeclarations.h:117
Pseudo expression representing a solving operation.
Definition Solve.h:63
@ ReadOnlyAccessors
Read-only access via a member function.
Definition Constants.h:366
@ WriteAccessors
Read/write access via member functions.
Definition Constants.h:368
Definition Meta.h:34
Definition XprHelper.h:428
Definition XprHelper.h:628
Definition ForwardDeclarations.h:17
Definition Meta.h:30