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 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
29 namespace internal {
30 template <typename ExpressionType>
31 struct traits<ArrayWrapper<ExpressionType> > : public traits<remove_all_t<typename ExpressionType::Nested> > {
32  typedef ArrayXpr XprKind;
33  // Let's remove NestByRefBit
34  enum {
37  Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
38  };
39 };
40 } // namespace internal
41 
42 template <typename ExpressionType>
43 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> > {
44  public:
48  typedef internal::remove_all_t<ExpressionType> NestedExpression;
49 
50  typedef std::conditional_t<internal::is_lvalue<ExpressionType>::value, Scalar, const Scalar>
52 
53  typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
54 
55  using Base::coeffRef;
56 
58 
62  return m_expression.outerStride();
63  }
65  return m_expression.innerStride();
66  }
67 
69  EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_expression.data(); }
70 
71  EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const {
72  return m_expression.coeffRef(rowId, colId);
73  }
74 
75  EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { return m_expression.coeffRef(index); }
76 
77  template <typename Dest>
78  EIGEN_DEVICE_FUNC inline void evalTo(Dest& dst) const {
79  dst = m_expression;
80  }
81 
83  return m_expression;
84  }
85 
88  EIGEN_DEVICE_FUNC void resize(Index newSize) { m_expression.resize(newSize); }
92 
93  protected:
95 };
96 
108 namespace internal {
109 template <typename ExpressionType>
110 struct traits<MatrixWrapper<ExpressionType> > : public traits<remove_all_t<typename ExpressionType::Nested> > {
112  // Let's remove NestByRefBit
113  enum {
116  Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
117  };
118 };
119 } // namespace internal
120 
121 template <typename ExpressionType>
122 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> > {
123  public:
127  typedef internal::remove_all_t<ExpressionType> NestedExpression;
128 
129  typedef std::conditional_t<internal::is_lvalue<ExpressionType>::value, Scalar, const Scalar>
131 
132  typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
133 
134  using Base::coeffRef;
135 
136  EIGEN_DEVICE_FUNC explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
137 
141  return m_expression.outerStride();
142  }
144  return m_expression.innerStride();
145  }
146 
148  EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_expression.data(); }
149 
150  EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const {
151  return m_expression.derived().coeffRef(rowId, colId);
152  }
153 
154  EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { return m_expression.coeffRef(index); }
155 
157  return m_expression;
158  }
159 
162  EIGEN_DEVICE_FUNC void resize(Index newSize) { m_expression.resize(newSize); }
166 
167  protected:
169 };
170 
171 } // end namespace Eigen
172 
173 #endif // EIGEN_ARRAYWRAPPER_H
#define EIGEN_NOEXCEPT
Definition: Macros.h:1267
#define EIGEN_CONSTEXPR
Definition: Macros.h:758
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1171
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Macro to manually inherit assignment operators. This is necessary, because the implicitly defined ass...
Definition: Macros.h:1126
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:44
EIGEN_DEVICE_FUNC MatrixWrapper< ArrayWrapper< ExpressionType > > matrix()
Definition: ArrayBase.h:141
Expression of a mathematical vector or matrix as an array object.
Definition: ArrayWrapper.h:43
EIGEN_DEVICE_FUNC void resize(Index newSize)
Definition: ArrayWrapper.h:88
NestedExpressionType m_expression
Definition: ArrayWrapper.h:94
constexpr EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue * data()
Definition: ArrayWrapper.h:68
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index index) const
Definition: ArrayWrapper.h:75
constexpr EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: ArrayWrapper.h:69
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT
Definition: ArrayWrapper.h:61
EIGEN_DEVICE_FUNC void evalTo(Dest &dst) const
Definition: ArrayWrapper.h:78
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerStride() const EIGEN_NOEXCEPT
Definition: ArrayWrapper.h:64
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index rowId, Index colId) const
Definition: ArrayWrapper.h:71
std::conditional_t< internal::is_lvalue< ExpressionType >::value, Scalar, const Scalar > ScalarWithConstIfNotLvalue
Definition: ArrayWrapper.h:51
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: ArrayWrapper.h:60
internal::ref_selector< ExpressionType >::non_const_type NestedExpressionType
Definition: ArrayWrapper.h:53
ArrayBase< ArrayWrapper > Base
Definition: ArrayWrapper.h:45
EIGEN_DEVICE_FUNC void resize(Index rows, Index cols)
Definition: ArrayWrapper.h:91
internal::remove_all_t< ExpressionType > NestedExpression
Definition: ArrayWrapper.h:48
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: ArrayWrapper.h:59
EIGEN_DEVICE_FUNC const internal::remove_all_t< NestedExpressionType > & nestedExpression() const
Definition: ArrayWrapper.h:82
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:62
EIGEN_DEVICE_FUNC CoeffReturnType value() const
Definition: DenseBase.h:481
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
EIGEN_DEVICE_FUNC MatrixBase< MatrixWrapper< ExpressionType > > & matrix()
Definition: MatrixBase.h:315
Expression of an array as a mathematical vector or matrix.
Definition: ArrayWrapper.h:122
EIGEN_DEVICE_FUNC void resize(Index newSize)
Definition: ArrayWrapper.h:162
MatrixBase< MatrixWrapper< ExpressionType > > Base
Definition: ArrayWrapper.h:124
constexpr EIGEN_DEVICE_FUNC ScalarWithConstIfNotLvalue * data()
Definition: ArrayWrapper.h:147
EIGEN_DEVICE_FUNC void resize(Index rows, Index cols)
Definition: ArrayWrapper.h:165
std::conditional_t< internal::is_lvalue< ExpressionType >::value, Scalar, const Scalar > ScalarWithConstIfNotLvalue
Definition: ArrayWrapper.h:130
constexpr EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: ArrayWrapper.h:148
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: ArrayWrapper.h:139
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: ArrayWrapper.h:138
EIGEN_DEVICE_FUNC const internal::remove_all_t< NestedExpressionType > & nestedExpression() const
Definition: ArrayWrapper.h:156
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index index) const
Definition: ArrayWrapper.h:154
internal::remove_all_t< ExpressionType > NestedExpression
Definition: ArrayWrapper.h:127
NestedExpressionType m_expression
Definition: ArrayWrapper.h:168
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerStride() const EIGEN_NOEXCEPT
Definition: ArrayWrapper.h:143
internal::ref_selector< ExpressionType >::non_const_type NestedExpressionType
Definition: ArrayWrapper.h:132
EIGEN_DEVICE_FUNC const Scalar & coeffRef(Index rowId, Index colId) const
Definition: ArrayWrapper.h:150
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT
Definition: ArrayWrapper.h:140
const unsigned int LvalueBit
Definition: Constants.h:148
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
const unsigned int NestByRefBit
Definition: Constants.h:173
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56
Definition: Eigen_Colamd.h:49
Definition: Constants.h:537
Definition: Constants.h:534
Definition: XprHelper.h:819
ArrayXpr XprKind
Definition: ArrayWrapper.h:32
MatrixXpr XprKind
Definition: ArrayWrapper.h:111
Definition: ForwardDeclarations.h:21