Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
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 <[email protected]>
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
16namespace Eigen {
17
29namespace internal {
30template <typename ExpressionType>
31struct traits<ArrayWrapper<ExpressionType> > : public traits<remove_all_t<typename ExpressionType::Nested> > {
32 typedef ArrayXpr XprKind;
33 // Let's remove NestByRefBit
34 enum {
35 Flags0 = traits<remove_all_t<typename ExpressionType::Nested> >::Flags,
36 LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
37 Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
38 };
39};
40} // namespace internal
41
42template <typename ExpressionType>
43class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> > {
44 public:
46 EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
47 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
48 typedef internal::remove_all_t<ExpressionType> NestedExpression;
49
50 typedef std::conditional_t<internal::is_lvalue<ExpressionType>::value, Scalar, const Scalar>
51 ScalarWithConstIfNotLvalue;
52
53 typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
54
55 using Base::coeffRef;
56
57 EIGEN_DEVICE_FUNC explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
58
59 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
60 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
61 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT {
62 return m_expression.outerStride();
63 }
64 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT {
65 return m_expression.innerStride();
66 }
67
68 EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
69 EIGEN_DEVICE_FUNC inline 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
82 EIGEN_DEVICE_FUNC const internal::remove_all_t<NestedExpressionType>& nestedExpression() const {
83 return m_expression;
84 }
85
88 EIGEN_DEVICE_FUNC void resize(Index newSize) { m_expression.resize(newSize); }
91 EIGEN_DEVICE_FUNC void resize(Index rows, Index cols) { m_expression.resize(rows, cols); }
92
93 protected:
94 NestedExpressionType m_expression;
95};
96
108namespace internal {
109template <typename ExpressionType>
110struct traits<MatrixWrapper<ExpressionType> > : public traits<remove_all_t<typename ExpressionType::Nested> > {
111 typedef MatrixXpr XprKind;
112 // Let's remove NestByRefBit
113 enum {
114 Flags0 = traits<remove_all_t<typename ExpressionType::Nested> >::Flags,
115 LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
116 Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
117 };
118};
119} // namespace internal
120
121template <typename ExpressionType>
122class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> > {
123 public:
125 EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
126 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
127 typedef internal::remove_all_t<ExpressionType> NestedExpression;
128
129 typedef std::conditional_t<internal::is_lvalue<ExpressionType>::value, Scalar, const Scalar>
130 ScalarWithConstIfNotLvalue;
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
138 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
139 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
140 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT {
141 return m_expression.outerStride();
142 }
143 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT {
144 return m_expression.innerStride();
145 }
146
147 EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
148 EIGEN_DEVICE_FUNC inline 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
156 EIGEN_DEVICE_FUNC const internal::remove_all_t<NestedExpressionType>& nestedExpression() const {
157 return m_expression;
158 }
159
162 EIGEN_DEVICE_FUNC void resize(Index newSize) { m_expression.resize(newSize); }
165 EIGEN_DEVICE_FUNC void resize(Index rows, Index cols) { m_expression.resize(rows, cols); }
166
167 protected:
168 NestedExpressionType m_expression;
169};
170
171} // end namespace Eigen
172
173#endif // EIGEN_ARRAYWRAPPER_H
Base class for all 1D and 2D array, and related expressions.
Definition ArrayBase.h:44
MatrixWrapper< ArrayWrapper< ExpressionType > > matrix()
Definition ArrayBase.h:141
Expression of a mathematical vector or matrix as an array object.
Definition ArrayWrapper.h:43
void resize(Index rows, Index cols)
Definition ArrayWrapper.h:91
void resize(Index newSize)
Definition ArrayWrapper.h:88
internal::traits< ArrayWrapper< ExpressionType > >::Scalar Scalar
Definition DenseBase.h:62
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:122
void resize(Index newSize)
Definition ArrayWrapper.h:162
void resize(Index rows, Index cols)
Definition ArrayWrapper.h:165
const unsigned int LvalueBit
Definition Constants.h:148
Namespace containing all symbols from the Eigen library.
Definition Core:137
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:83