File indexing completed on 2025-01-18 09:56:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_ARRAYWRAPPER_H
0011 #define EIGEN_ARRAYWRAPPER_H
0012
0013 namespace Eigen {
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 namespace internal {
0027 template<typename ExpressionType>
0028 struct traits<ArrayWrapper<ExpressionType> >
0029 : public traits<typename remove_all<typename ExpressionType::Nested>::type >
0030 {
0031 typedef ArrayXpr XprKind;
0032
0033 enum {
0034 Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
0035 LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
0036 Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
0037 };
0038 };
0039 }
0040
0041 template<typename ExpressionType>
0042 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
0043 {
0044 public:
0045 typedef ArrayBase<ArrayWrapper> Base;
0046 EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
0047 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
0048 typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
0049
0050 typedef typename internal::conditional<
0051 internal::is_lvalue<ExpressionType>::value,
0052 Scalar,
0053 const Scalar
0054 >::type ScalarWithConstIfNotLvalue;
0055
0056 typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
0057
0058 using Base::coeffRef;
0059
0060 EIGEN_DEVICE_FUNC
0061 explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
0062
0063 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0064 inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
0065 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0066 inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
0067 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0068 inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
0069 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0070 inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
0071
0072 EIGEN_DEVICE_FUNC
0073 inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
0074 EIGEN_DEVICE_FUNC
0075 inline const Scalar* data() const { return m_expression.data(); }
0076
0077 EIGEN_DEVICE_FUNC
0078 inline const Scalar& coeffRef(Index rowId, Index colId) const
0079 {
0080 return m_expression.coeffRef(rowId, colId);
0081 }
0082
0083 EIGEN_DEVICE_FUNC
0084 inline const Scalar& coeffRef(Index index) const
0085 {
0086 return m_expression.coeffRef(index);
0087 }
0088
0089 template<typename Dest>
0090 EIGEN_DEVICE_FUNC
0091 inline void evalTo(Dest& dst) const { dst = m_expression; }
0092
0093 EIGEN_DEVICE_FUNC
0094 const typename internal::remove_all<NestedExpressionType>::type&
0095 nestedExpression() const
0096 {
0097 return m_expression;
0098 }
0099
0100
0101
0102 EIGEN_DEVICE_FUNC
0103 void resize(Index newSize) { m_expression.resize(newSize); }
0104
0105
0106 EIGEN_DEVICE_FUNC
0107 void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
0108
0109 protected:
0110 NestedExpressionType m_expression;
0111 };
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 namespace internal {
0125 template<typename ExpressionType>
0126 struct traits<MatrixWrapper<ExpressionType> >
0127 : public traits<typename remove_all<typename ExpressionType::Nested>::type >
0128 {
0129 typedef MatrixXpr XprKind;
0130
0131 enum {
0132 Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
0133 LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
0134 Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
0135 };
0136 };
0137 }
0138
0139 template<typename ExpressionType>
0140 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
0141 {
0142 public:
0143 typedef MatrixBase<MatrixWrapper<ExpressionType> > Base;
0144 EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
0145 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
0146 typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
0147
0148 typedef typename internal::conditional<
0149 internal::is_lvalue<ExpressionType>::value,
0150 Scalar,
0151 const Scalar
0152 >::type ScalarWithConstIfNotLvalue;
0153
0154 typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
0155
0156 using Base::coeffRef;
0157
0158 EIGEN_DEVICE_FUNC
0159 explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
0160
0161 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0162 inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
0163 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0164 inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
0165 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0166 inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
0167 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0168 inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
0169
0170 EIGEN_DEVICE_FUNC
0171 inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
0172 EIGEN_DEVICE_FUNC
0173 inline const Scalar* data() const { return m_expression.data(); }
0174
0175 EIGEN_DEVICE_FUNC
0176 inline const Scalar& coeffRef(Index rowId, Index colId) const
0177 {
0178 return m_expression.derived().coeffRef(rowId, colId);
0179 }
0180
0181 EIGEN_DEVICE_FUNC
0182 inline const Scalar& coeffRef(Index index) const
0183 {
0184 return m_expression.coeffRef(index);
0185 }
0186
0187 EIGEN_DEVICE_FUNC
0188 const typename internal::remove_all<NestedExpressionType>::type&
0189 nestedExpression() const
0190 {
0191 return m_expression;
0192 }
0193
0194
0195
0196 EIGEN_DEVICE_FUNC
0197 void resize(Index newSize) { m_expression.resize(newSize); }
0198
0199
0200 EIGEN_DEVICE_FUNC
0201 void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
0202
0203 protected:
0204 NestedExpressionType m_expression;
0205 };
0206
0207 }
0208
0209 #endif