Eigen  3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)
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 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
28 namespace internal {
29 template<typename ExpressionType>
30 struct traits<ArrayWrapper<ExpressionType> >
31  : public traits<remove_all_t<typename ExpressionType::Nested> >
32 {
33  typedef ArrayXpr XprKind;
34  // Let's remove NestByRefBit
35  enum {
36  Flags0 = traits<remove_all_t<typename ExpressionType::Nested> >::Flags,
37  LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
38  Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
39  };
40 };
41 }
42 
43 template<typename ExpressionType>
44 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
45 {
46  public:
48  EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
49  EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
50  typedef internal::remove_all_t<ExpressionType> NestedExpression;
51 
52  typedef std::conditional_t<
53  internal::is_lvalue<ExpressionType>::value,
54  Scalar,
55  const Scalar
56  > ScalarWithConstIfNotLvalue;
57 
58  typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
59 
60  using Base::coeffRef;
61 
62  EIGEN_DEVICE_FUNC
63  explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
64 
65  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
66  inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
67  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
68  inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
69  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
70  inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
71  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
72  inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
73 
74  EIGEN_DEVICE_FUNC
75  inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
76  EIGEN_DEVICE_FUNC
77  inline const Scalar* data() const { return m_expression.data(); }
78 
79  EIGEN_DEVICE_FUNC
80  inline const Scalar& coeffRef(Index rowId, Index colId) const
81  {
82  return m_expression.coeffRef(rowId, colId);
83  }
84 
85  EIGEN_DEVICE_FUNC
86  inline const Scalar& coeffRef(Index index) const
87  {
88  return m_expression.coeffRef(index);
89  }
90 
91  template<typename Dest>
92  EIGEN_DEVICE_FUNC
93  inline void evalTo(Dest& dst) const { dst = m_expression; }
94 
95  EIGEN_DEVICE_FUNC
96  const internal::remove_all_t<NestedExpressionType>&
97  nestedExpression() const
98  {
99  return m_expression;
100  }
101 
104  EIGEN_DEVICE_FUNC
105  void resize(Index newSize) { m_expression.resize(newSize); }
108  EIGEN_DEVICE_FUNC
109  void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
110 
111  protected:
112  NestedExpressionType m_expression;
113 };
114 
126 namespace internal {
127 template<typename ExpressionType>
128 struct traits<MatrixWrapper<ExpressionType> >
129  : public traits<remove_all_t<typename ExpressionType::Nested> >
130 {
131  typedef MatrixXpr XprKind;
132  // Let's remove NestByRefBit
133  enum {
134  Flags0 = traits<remove_all_t<typename ExpressionType::Nested> >::Flags,
135  LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
136  Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
137  };
138 };
139 }
140 
141 template<typename ExpressionType>
142 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
143 {
144  public:
146  EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
147  EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
148  typedef internal::remove_all_t<ExpressionType> NestedExpression;
149 
150  typedef std::conditional_t<
151  internal::is_lvalue<ExpressionType>::value,
152  Scalar,
153  const Scalar
154  > ScalarWithConstIfNotLvalue;
155 
156  typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
157 
158  using Base::coeffRef;
159 
160  EIGEN_DEVICE_FUNC
161  explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
162 
163  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
164  inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
165  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
166  inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
167  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
168  inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
169  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
170  inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
171 
172  EIGEN_DEVICE_FUNC
173  inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
174  EIGEN_DEVICE_FUNC
175  inline const Scalar* data() const { return m_expression.data(); }
176 
177  EIGEN_DEVICE_FUNC
178  inline const Scalar& coeffRef(Index rowId, Index colId) const
179  {
180  return m_expression.derived().coeffRef(rowId, colId);
181  }
182 
183  EIGEN_DEVICE_FUNC
184  inline const Scalar& coeffRef(Index index) const
185  {
186  return m_expression.coeffRef(index);
187  }
188 
189  EIGEN_DEVICE_FUNC
190  const internal::remove_all_t<NestedExpressionType>&
191  nestedExpression() const
192  {
193  return m_expression;
194  }
195 
198  EIGEN_DEVICE_FUNC
199  void resize(Index newSize) { m_expression.resize(newSize); }
202  EIGEN_DEVICE_FUNC
203  void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
204 
205  protected:
206  NestedExpressionType m_expression;
207 };
208 
209 } // end namespace Eigen
210 
211 #endif // EIGEN_ARRAYWRAPPER_H
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:43
MatrixWrapper< ArrayWrapper< ExpressionType > > matrix()
Definition: ArrayBase.h:150
Expression of a mathematical vector or matrix as an array object.
Definition: ArrayWrapper.h:45
void resize(Index rows, Index cols)
Definition: ArrayWrapper.h:109
void resize(Index newSize)
Definition: ArrayWrapper.h:105
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:61
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
Expression of an array as a mathematical vector or matrix.
Definition: ArrayWrapper.h:143
void resize(Index newSize)
Definition: ArrayWrapper.h:199
void resize(Index rows, Index cols)
Definition: ArrayWrapper.h:203
const unsigned int LvalueBit
Definition: Constants.h:146
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41