ArrayWrapper.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) 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 {
35  Flags = Flags0 & ~NestByRefBit
36  };
37 };
38 }
39 
40 template<typename ExpressionType>
41 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
42 {
43  public:
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
54 
55  typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
56 
57  using Base::coeffRef;
58 
59  EIGEN_DEVICE_FUNC
60  explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
61 
62  EIGEN_DEVICE_FUNC
63  inline Index rows() const { return m_expression.rows(); }
64  EIGEN_DEVICE_FUNC
65  inline Index cols() const { return m_expression.cols(); }
66  EIGEN_DEVICE_FUNC
67  inline Index outerStride() const { return m_expression.outerStride(); }
68  EIGEN_DEVICE_FUNC
69  inline Index innerStride() const { return m_expression.innerStride(); }
70 
71  EIGEN_DEVICE_FUNC
72  inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
73  EIGEN_DEVICE_FUNC
74  inline const Scalar* data() const { return m_expression.data(); }
75 
76  EIGEN_DEVICE_FUNC
77  inline const Scalar& coeffRef(Index rowId, Index colId) const
78  {
79  return m_expression.coeffRef(rowId, colId);
80  }
81 
82  EIGEN_DEVICE_FUNC
83  inline const Scalar& coeffRef(Index index) const
84  {
85  return m_expression.coeffRef(index);
86  }
87 
88  template<typename Dest>
89  EIGEN_DEVICE_FUNC
90  inline void evalTo(Dest& dst) const { dst = m_expression; }
91 
93  EIGEN_DEVICE_FUNC
95  {
96  return m_expression;
97  }
98 
101  EIGEN_DEVICE_FUNC
102  void resize(Index newSize) { m_expression.resize(newSize); }
105  EIGEN_DEVICE_FUNC
106  void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
107 
108  protected:
110 };
111 
123 namespace internal {
124 template<typename ExpressionType>
125 struct traits<MatrixWrapper<ExpressionType> >
126  : public traits<typename remove_all<typename ExpressionType::Nested>::type >
127 {
129  // Let's remove NestByRefBit
130  enum {
132  Flags = Flags0 & ~NestByRefBit
133  };
134 };
135 }
136 
137 template<typename ExpressionType>
138 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
139 {
140  public:
144  typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
145 
146  typedef typename internal::conditional<
147  internal::is_lvalue<ExpressionType>::value,
148  Scalar,
149  const Scalar
151 
152  typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
153 
154  using Base::coeffRef;
155 
156  EIGEN_DEVICE_FUNC
157  explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
158 
159  EIGEN_DEVICE_FUNC
160  inline Index rows() const { return m_expression.rows(); }
161  EIGEN_DEVICE_FUNC
162  inline Index cols() const { return m_expression.cols(); }
163  EIGEN_DEVICE_FUNC
164  inline Index outerStride() const { return m_expression.outerStride(); }
165  EIGEN_DEVICE_FUNC
166  inline Index innerStride() const { return m_expression.innerStride(); }
167 
168  EIGEN_DEVICE_FUNC
169  inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
170  EIGEN_DEVICE_FUNC
171  inline const Scalar* data() const { return m_expression.data(); }
172 
173  EIGEN_DEVICE_FUNC
174  inline const Scalar& coeffRef(Index rowId, Index colId) const
175  {
176  return m_expression.derived().coeffRef(rowId, colId);
177  }
178 
179  EIGEN_DEVICE_FUNC
180  inline const Scalar& coeffRef(Index index) const
181  {
182  return m_expression.coeffRef(index);
183  }
184 
185  EIGEN_DEVICE_FUNC
188  {
189  return m_expression;
190  }
191 
194  EIGEN_DEVICE_FUNC
195  void resize(Index newSize) { m_expression.resize(newSize); }
198  EIGEN_DEVICE_FUNC
199  void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
200 
201  protected:
203 };
204 
205 } // end namespace Eigen
206 
207 #endif // EIGEN_ARRAYWRAPPER_H
EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue * data()
Definition: ArrayWrapper.h:72
NestedExpressionType m_expression
Definition: ArrayWrapper.h:202
internal::remove_all< ExpressionType >::type NestedExpression
Definition: ArrayWrapper.h:47
EIGEN_DEVICE_FUNC void resize(Index rows, Index cols)
Definition: ArrayWrapper.h:106
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:66
EIGEN_DEVICE_FUNC Index outerStride() const
Definition: ArrayWrapper.h:67
EIGEN_DEVICE_FUNC Index rows() const
Definition: ArrayWrapper.h:160
Expression of a mathematical vector or matrix as an array object.
Definition: ArrayWrapper.h:41
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index index) const
Definition: ArrayWrapper.h:180
EIGEN_DEVICE_FUNC void resize(Index newSize)
Definition: ArrayWrapper.h:102
Definition: LDLT.h:16
MatrixBase< MatrixWrapper< ExpressionType > > Base
Definition: ArrayWrapper.h:141
EIGEN_DEVICE_FUNC const internal::remove_all< NestedExpressionType >::type & nestedExpression() const
Definition: ArrayWrapper.h:187
Expression of an array as a mathematical vector or matrix.
Definition: ArrayBase.h:15
NestedExpressionType m_expression
Definition: ArrayWrapper.h:109
EIGEN_DEVICE_FUNC Index cols() const
Definition: ArrayWrapper.h:65
EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: ArrayWrapper.h:74
EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: ArrayWrapper.h:171
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index rowId, Index colId) const
Definition: ArrayWrapper.h:174
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index rowId, Index colId) const
Definition: ArrayWrapper.h:77
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index index) const
Definition: ArrayWrapper.h:83
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: Macros.h:838
ArrayBase< ArrayWrapper > Base
Definition: ArrayWrapper.h:44
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
internal::remove_all< ExpressionType >::type NestedExpression
Definition: ArrayWrapper.h:144
EIGEN_DEVICE_FUNC Index innerStride() const
Definition: ArrayWrapper.h:69
EIGEN_DEVICE_FUNC void resize(Index newSize)
Definition: ArrayWrapper.h:195
const unsigned int NestByRefBit
Definition: Constants.h:164
EIGEN_DEVICE_FUNC Index outerStride() const
Definition: ArrayWrapper.h:164
const internal::remove_all< NestedExpressionType >::type &EIGEN_DEVICE_FUNC nestedExpression() const
Definition: ArrayWrapper.h:94
EIGEN_DEVICE_FUNC void resize(Index rows, Index cols)
Definition: ArrayWrapper.h:199
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:866
EIGEN_DEVICE_FUNC Index cols() const
Definition: ArrayWrapper.h:162
EIGEN_DEVICE_FUNC void evalTo(Dest &dst) const
Definition: ArrayWrapper.h:90
EIGEN_DEVICE_FUNC Index innerStride() const
Definition: ArrayWrapper.h:166
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
EIGEN_DEVICE_FUNC Index rows() const
Definition: ArrayWrapper.h:63
EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue * data()
Definition: ArrayWrapper.h:169


co_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:00:38