Eigen  3.2.93
ArrayWrapper.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_ARRAYWRAPPER_H
11 #define EIGEN_ARRAYWRAPPER_H
12 
13 namespace Eigen {
14 
26 namespace internal {
27 template<typename ExpressionType>
28 struct traits<ArrayWrapper<ExpressionType> >
29  : public traits<typename remove_all<typename ExpressionType::Nested>::type >
30 {
31  typedef ArrayXpr XprKind;
32  // Let's remove NestByRefBit
33  enum {
34  Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
35  Flags = Flags0 & ~NestByRefBit
36  };
37 };
38 }
39 
40 template<typename ExpressionType>
41 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
42 {
43  public:
45  EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
46  EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
47  typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
48 
49  typedef typename internal::conditional<
50  internal::is_lvalue<ExpressionType>::value,
51  Scalar,
52  const Scalar
53  >::type ScalarWithConstIfNotLvalue;
54 
55  typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
56 
57  EIGEN_DEVICE_FUNC
58  explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
59 
60  EIGEN_DEVICE_FUNC
61  inline Index rows() const { return m_expression.rows(); }
62  EIGEN_DEVICE_FUNC
63  inline Index cols() const { return m_expression.cols(); }
64  EIGEN_DEVICE_FUNC
65  inline Index outerStride() const { return m_expression.outerStride(); }
66  EIGEN_DEVICE_FUNC
67  inline Index innerStride() const { return m_expression.innerStride(); }
68 
69  EIGEN_DEVICE_FUNC
70  inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
71  EIGEN_DEVICE_FUNC
72  inline const Scalar* data() const { return m_expression.data(); }
73 
74  EIGEN_DEVICE_FUNC
75  inline CoeffReturnType coeff(Index rowId, Index colId) const
76  {
77  return m_expression.coeff(rowId, colId);
78  }
79 
80  EIGEN_DEVICE_FUNC
81  inline Scalar& coeffRef(Index rowId, Index colId)
82  {
83  return m_expression.coeffRef(rowId, colId);
84  }
85 
86  EIGEN_DEVICE_FUNC
87  inline const Scalar& coeffRef(Index rowId, Index colId) const
88  {
89  return m_expression.coeffRef(rowId, colId);
90  }
91 
92  EIGEN_DEVICE_FUNC
93  inline CoeffReturnType coeff(Index index) const
94  {
95  return m_expression.coeff(index);
96  }
97 
98  EIGEN_DEVICE_FUNC
99  inline Scalar& coeffRef(Index index)
100  {
101  return m_expression.coeffRef(index);
102  }
103 
104  EIGEN_DEVICE_FUNC
105  inline const Scalar& coeffRef(Index index) const
106  {
107  return m_expression.coeffRef(index);
108  }
109 
110  template<int LoadMode>
111  inline const PacketScalar packet(Index rowId, Index colId) const
112  {
113  return m_expression.template packet<LoadMode>(rowId, colId);
114  }
115 
116  template<int LoadMode>
117  inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
118  {
119  m_expression.template writePacket<LoadMode>(rowId, colId, val);
120  }
121 
122  template<int LoadMode>
123  inline const PacketScalar packet(Index index) const
124  {
125  return m_expression.template packet<LoadMode>(index);
126  }
127 
128  template<int LoadMode>
129  inline void writePacket(Index index, const PacketScalar& val)
130  {
131  m_expression.template writePacket<LoadMode>(index, val);
132  }
133 
134  template<typename Dest>
135  EIGEN_DEVICE_FUNC
136  inline void evalTo(Dest& dst) const { dst = m_expression; }
137 
138  const typename internal::remove_all<NestedExpressionType>::type&
139  EIGEN_DEVICE_FUNC
140  nestedExpression() const
141  {
142  return m_expression;
143  }
144 
147  EIGEN_DEVICE_FUNC
148  void resize(Index newSize) { m_expression.resize(newSize); }
151  EIGEN_DEVICE_FUNC
152  void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
153 
154  protected:
155  NestedExpressionType m_expression;
156 };
157 
169 namespace internal {
170 template<typename ExpressionType>
171 struct traits<MatrixWrapper<ExpressionType> >
172  : public traits<typename remove_all<typename ExpressionType::Nested>::type >
173 {
174  typedef MatrixXpr XprKind;
175  // Let's remove NestByRefBit
176  enum {
177  Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
178  Flags = Flags0 & ~NestByRefBit
179  };
180 };
181 }
182 
183 template<typename ExpressionType>
184 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
185 {
186  public:
188  EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
189  EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
190  typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
191 
192  typedef typename internal::conditional<
193  internal::is_lvalue<ExpressionType>::value,
194  Scalar,
195  const Scalar
196  >::type ScalarWithConstIfNotLvalue;
197 
198  typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
199 
200  EIGEN_DEVICE_FUNC
201  explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
202 
203  EIGEN_DEVICE_FUNC
204  inline Index rows() const { return m_expression.rows(); }
205  EIGEN_DEVICE_FUNC
206  inline Index cols() const { return m_expression.cols(); }
207  EIGEN_DEVICE_FUNC
208  inline Index outerStride() const { return m_expression.outerStride(); }
209  EIGEN_DEVICE_FUNC
210  inline Index innerStride() const { return m_expression.innerStride(); }
211 
212  EIGEN_DEVICE_FUNC
213  inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
214  EIGEN_DEVICE_FUNC
215  inline const Scalar* data() const { return m_expression.data(); }
216 
217  EIGEN_DEVICE_FUNC
218  inline CoeffReturnType coeff(Index rowId, Index colId) const
219  {
220  return m_expression.coeff(rowId, colId);
221  }
222 
223  EIGEN_DEVICE_FUNC
224  inline Scalar& coeffRef(Index rowId, Index colId)
225  {
226  return m_expression.coeffRef(rowId, colId);
227  }
228 
229  EIGEN_DEVICE_FUNC
230  inline const Scalar& coeffRef(Index rowId, Index colId) const
231  {
232  return m_expression.derived().coeffRef(rowId, colId);
233  }
234 
235  EIGEN_DEVICE_FUNC
236  inline CoeffReturnType coeff(Index index) const
237  {
238  return m_expression.coeff(index);
239  }
240 
241  EIGEN_DEVICE_FUNC
242  inline Scalar& coeffRef(Index index)
243  {
244  return m_expression.coeffRef(index);
245  }
246 
247  EIGEN_DEVICE_FUNC
248  inline const Scalar& coeffRef(Index index) const
249  {
250  return m_expression.coeffRef(index);
251  }
252 
253  template<int LoadMode>
254  inline const PacketScalar packet(Index rowId, Index colId) const
255  {
256  return m_expression.template packet<LoadMode>(rowId, colId);
257  }
258 
259  template<int LoadMode>
260  inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
261  {
262  m_expression.template writePacket<LoadMode>(rowId, colId, val);
263  }
264 
265  template<int LoadMode>
266  inline const PacketScalar packet(Index index) const
267  {
268  return m_expression.template packet<LoadMode>(index);
269  }
270 
271  template<int LoadMode>
272  inline void writePacket(Index index, const PacketScalar& val)
273  {
274  m_expression.template writePacket<LoadMode>(index, val);
275  }
276 
277  EIGEN_DEVICE_FUNC
278  const typename internal::remove_all<NestedExpressionType>::type&
279  nestedExpression() const
280  {
281  return m_expression;
282  }
283 
286  EIGEN_DEVICE_FUNC
287  void resize(Index newSize) { m_expression.resize(newSize); }
290  EIGEN_DEVICE_FUNC
291  void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
292 
293  protected:
294  NestedExpressionType m_expression;
295 };
296 
297 } // end namespace Eigen
298 
299 #endif // EIGEN_ARRAYWRAPPER_H
void resize(Index newSize)
Definition: ArrayWrapper.h:287
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:66
Expression of a mathematical vector or matrix as an array object.
Definition: ArrayWrapper.h:41
Namespace containing all symbols from the Eigen library.
Definition: Core:271
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
void resize(Index rows, Index cols)
Definition: ArrayWrapper.h:291
Definition: Constants.h:506
Expression of an array as a mathematical vector or matrix.
Definition: ArrayBase.h:15
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
void resize(Index rows, Index cols)
Definition: ArrayWrapper.h:152
Definition: Eigen_Colamd.h:50
void resize(Index newSize)
Definition: ArrayWrapper.h:148
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48