Eigen  5.0.1
 
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 <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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_ARRAYWRAPPER_H
12#define EIGEN_ARRAYWRAPPER_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
29
30namespace internal {
31template <typename ExpressionType>
32struct traits<ArrayWrapper<ExpressionType> > : public traits<remove_all_t<typename ExpressionType::Nested> > {
33 using XprKind = ArrayXpr;
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} // namespace internal
42
43template <typename ExpressionType>
44class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> > {
45 public:
46 using Base = ArrayBase<ArrayWrapper>;
47 EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
48 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
49 using NestedExpression = internal::remove_all_t<ExpressionType>;
50
51 using ScalarWithConstIfNotLvalue =
52 std::conditional_t<internal::is_lvalue<ExpressionType>::value, Scalar, const Scalar>;
53
54 using NestedExpressionType = typename internal::ref_selector<ExpressionType>::non_const_type;
55
56 using Base::coeffRef;
57
58 EIGEN_DEVICE_FUNC constexpr explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix)
59 : m_expression(matrix) {}
60
61 EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return m_expression.rows(); }
62 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return m_expression.cols(); }
63 EIGEN_DEVICE_FUNC constexpr Index outerStride() const noexcept { return m_expression.outerStride(); }
64 EIGEN_DEVICE_FUNC constexpr Index innerStride() const noexcept { return m_expression.innerStride(); }
65
66 EIGEN_DEVICE_FUNC constexpr ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
67 EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_expression.data(); }
68
69 EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const {
70 return m_expression.coeffRef(rowId, colId);
71 }
72
73 EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { return m_expression.coeffRef(index); }
74
75 template <typename Dest>
76 EIGEN_DEVICE_FUNC inline void evalTo(Dest& dst) const {
77 dst = m_expression;
78 }
79
80 EIGEN_DEVICE_FUNC constexpr const internal::remove_all_t<NestedExpressionType>& nestedExpression() const {
81 return m_expression;
82 }
83
86 EIGEN_DEVICE_FUNC void resize(Index newSize) { m_expression.resize(newSize); }
89 EIGEN_DEVICE_FUNC void resize(Index rows, Index cols) { m_expression.resize(rows, cols); }
90
91 protected:
92 NestedExpressionType m_expression;
93};
94
105
106namespace internal {
107template <typename ExpressionType>
108struct traits<MatrixWrapper<ExpressionType> > : public traits<remove_all_t<typename ExpressionType::Nested> > {
109 using XprKind = MatrixXpr;
110 // Let's remove NestByRefBit
111 enum {
112 Flags0 = traits<remove_all_t<typename ExpressionType::Nested> >::Flags,
113 LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
114 Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
115 };
116};
117} // namespace internal
118
119template <typename ExpressionType>
120class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> > {
121 public:
122 using Base = MatrixBase<MatrixWrapper<ExpressionType>>;
123 EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
124 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
125 using NestedExpression = internal::remove_all_t<ExpressionType>;
126
127 using ScalarWithConstIfNotLvalue =
128 std::conditional_t<internal::is_lvalue<ExpressionType>::value, Scalar, const Scalar>;
129
130 using NestedExpressionType = typename internal::ref_selector<ExpressionType>::non_const_type;
131
132 using Base::coeffRef;
133
134 EIGEN_DEVICE_FUNC constexpr explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
135
136 EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return m_expression.rows(); }
137 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return m_expression.cols(); }
138 EIGEN_DEVICE_FUNC constexpr Index outerStride() const noexcept { return m_expression.outerStride(); }
139 EIGEN_DEVICE_FUNC constexpr Index innerStride() const noexcept { return m_expression.innerStride(); }
140
141 EIGEN_DEVICE_FUNC constexpr ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
142 EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_expression.data(); }
143
144 EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const {
145 return m_expression.derived().coeffRef(rowId, colId);
146 }
147
148 EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { return m_expression.coeffRef(index); }
149
150 EIGEN_DEVICE_FUNC constexpr const internal::remove_all_t<NestedExpressionType>& nestedExpression() const {
151 return m_expression;
152 }
153
156 EIGEN_DEVICE_FUNC void resize(Index newSize) { m_expression.resize(newSize); }
159 EIGEN_DEVICE_FUNC void resize(Index rows, Index cols) { m_expression.resize(rows, cols); }
160
161 protected:
162 NestedExpressionType m_expression;
163};
164
165} // end namespace Eigen
166
167#endif // EIGEN_ARRAYWRAPPER_H
constexpr MatrixWrapper< ArrayWrapper< ExpressionType > > matrix()
Definition ArrayBase.h:177
void resize(Index rows, Index cols)
Definition ArrayWrapper.h:89
void resize(Index newSize)
Definition ArrayWrapper.h:86
typename internal::traits< ArrayWrapper< ExpressionType > >::Scalar Scalar
Definition DenseBase.h:63
void resize(Index newSize)
Definition ArrayWrapper.h:156
void resize(Index rows, Index cols)
Definition ArrayWrapper.h:159
constexpr unsigned int LvalueBit
Definition Constants.h:149