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