Eigen  5.0.1-dev+60122df6
 
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
10#ifndef EIGEN_ARRAYWRAPPER_H
11#define EIGEN_ARRAYWRAPPER_H
12
13// IWYU pragma: private
14#include "./InternalHeaderCheck.h"
15
16namespace Eigen {
17
28
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:
45 typedef ArrayBase<ArrayWrapper> Base;
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 constexpr Index rows() const noexcept { return m_expression.rows(); }
60 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return m_expression.cols(); }
61 EIGEN_DEVICE_FUNC constexpr Index outerStride() const noexcept { return m_expression.outerStride(); }
62 EIGEN_DEVICE_FUNC constexpr Index innerStride() const noexcept { return m_expression.innerStride(); }
63
64 EIGEN_DEVICE_FUNC constexpr ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
65 EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_expression.data(); }
66
67 EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const {
68 return m_expression.coeffRef(rowId, colId);
69 }
70
71 EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { return m_expression.coeffRef(index); }
72
73 template <typename Dest>
74 EIGEN_DEVICE_FUNC inline void evalTo(Dest& dst) const {
75 dst = m_expression;
76 }
77
78 EIGEN_DEVICE_FUNC const internal::remove_all_t<NestedExpressionType>& nestedExpression() const {
79 return m_expression;
80 }
81
84 EIGEN_DEVICE_FUNC void resize(Index newSize) { m_expression.resize(newSize); }
87 EIGEN_DEVICE_FUNC void resize(Index rows, Index cols) { m_expression.resize(rows, cols); }
88
89 protected:
90 NestedExpressionType m_expression;
91};
92
103
104namespace internal {
105template <typename ExpressionType>
106struct traits<MatrixWrapper<ExpressionType> > : public traits<remove_all_t<typename ExpressionType::Nested> > {
107 typedef MatrixXpr XprKind;
108 // Let's remove NestByRefBit
109 enum {
110 Flags0 = traits<remove_all_t<typename ExpressionType::Nested> >::Flags,
111 LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
112 Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
113 };
114};
115} // namespace internal
116
117template <typename ExpressionType>
118class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> > {
119 public:
120 typedef MatrixBase<MatrixWrapper<ExpressionType> > Base;
121 EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
122 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
123 typedef internal::remove_all_t<ExpressionType> NestedExpression;
124
125 typedef std::conditional_t<internal::is_lvalue<ExpressionType>::value, Scalar, const Scalar>
126 ScalarWithConstIfNotLvalue;
127
128 typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
129
130 using Base::coeffRef;
131
132 EIGEN_DEVICE_FUNC explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
133
134 EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return m_expression.rows(); }
135 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return m_expression.cols(); }
136 EIGEN_DEVICE_FUNC constexpr Index outerStride() const noexcept { return m_expression.outerStride(); }
137 EIGEN_DEVICE_FUNC constexpr Index innerStride() const noexcept { return m_expression.innerStride(); }
138
139 EIGEN_DEVICE_FUNC constexpr ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
140 EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_expression.data(); }
141
142 EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const {
143 return m_expression.derived().coeffRef(rowId, colId);
144 }
145
146 EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { return m_expression.coeffRef(index); }
147
148 EIGEN_DEVICE_FUNC const internal::remove_all_t<NestedExpressionType>& nestedExpression() const {
149 return m_expression;
150 }
151
154 EIGEN_DEVICE_FUNC void resize(Index newSize) { m_expression.resize(newSize); }
157 EIGEN_DEVICE_FUNC void resize(Index rows, Index cols) { m_expression.resize(rows, cols); }
158
159 protected:
160 NestedExpressionType m_expression;
161};
162
163} // end namespace Eigen
164
165#endif // EIGEN_ARRAYWRAPPER_H
MatrixWrapper< ArrayWrapper< ExpressionType > > matrix()
Definition ArrayBase.h:176
void resize(Index rows, Index cols)
Definition ArrayWrapper.h:87
void resize(Index newSize)
Definition ArrayWrapper.h:84
internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:62
void resize(Index newSize)
Definition ArrayWrapper.h:154
void resize(Index rows, Index cols)
Definition ArrayWrapper.h:157
const unsigned int LvalueBit
Definition Constants.h:148
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82