MOAB
4.9.3pre
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2009-2010 Gael Guennebaud <[email protected]> 00005 // 00006 // This Source Code Form is subject to the terms of the Mozilla 00007 // Public License v. 2.0. If a copy of the MPL was not distributed 00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00009 00010 #ifndef EIGEN_ARRAYWRAPPER_H 00011 #define EIGEN_ARRAYWRAPPER_H 00012 00013 namespace Eigen { 00014 00026 namespace internal { 00027 template<typename ExpressionType> 00028 struct traits<ArrayWrapper<ExpressionType> > 00029 : public traits<typename remove_all<typename ExpressionType::Nested>::type > 00030 { 00031 typedef ArrayXpr XprKind; 00032 // Let's remove NestByRefBit 00033 enum { 00034 Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags, 00035 Flags = Flags0 & ~NestByRefBit 00036 }; 00037 }; 00038 } 00039 00040 template<typename ExpressionType> 00041 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> > 00042 { 00043 public: 00044 typedef ArrayBase<ArrayWrapper> Base; 00045 EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper) 00046 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper) 00047 typedef typename internal::remove_all<ExpressionType>::type NestedExpression; 00048 00049 typedef typename internal::conditional< 00050 internal::is_lvalue<ExpressionType>::value, 00051 Scalar, 00052 const Scalar 00053 >::type ScalarWithConstIfNotLvalue; 00054 00055 typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType; 00056 00057 EIGEN_DEVICE_FUNC 00058 explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {} 00059 00060 EIGEN_DEVICE_FUNC 00061 inline Index rows() const { return m_expression.rows(); } 00062 EIGEN_DEVICE_FUNC 00063 inline Index cols() const { return m_expression.cols(); } 00064 EIGEN_DEVICE_FUNC 00065 inline Index outerStride() const { return m_expression.outerStride(); } 00066 EIGEN_DEVICE_FUNC 00067 inline Index innerStride() const { return m_expression.innerStride(); } 00068 00069 EIGEN_DEVICE_FUNC 00070 inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } 00071 EIGEN_DEVICE_FUNC 00072 inline const Scalar* data() const { return m_expression.data(); } 00073 00074 EIGEN_DEVICE_FUNC 00075 inline CoeffReturnType coeff(Index rowId, Index colId) const 00076 { 00077 return m_expression.coeff(rowId, colId); 00078 } 00079 00080 EIGEN_DEVICE_FUNC 00081 inline Scalar& coeffRef(Index rowId, Index colId) 00082 { 00083 return m_expression.coeffRef(rowId, colId); 00084 } 00085 00086 EIGEN_DEVICE_FUNC 00087 inline const Scalar& coeffRef(Index rowId, Index colId) const 00088 { 00089 return m_expression.coeffRef(rowId, colId); 00090 } 00091 00092 EIGEN_DEVICE_FUNC 00093 inline CoeffReturnType coeff(Index index) const 00094 { 00095 return m_expression.coeff(index); 00096 } 00097 00098 EIGEN_DEVICE_FUNC 00099 inline Scalar& coeffRef(Index index) 00100 { 00101 return m_expression.coeffRef(index); 00102 } 00103 00104 EIGEN_DEVICE_FUNC 00105 inline const Scalar& coeffRef(Index index) const 00106 { 00107 return m_expression.coeffRef(index); 00108 } 00109 00110 template<int LoadMode> 00111 inline const PacketScalar packet(Index rowId, Index colId) const 00112 { 00113 return m_expression.template packet<LoadMode>(rowId, colId); 00114 } 00115 00116 template<int LoadMode> 00117 inline void writePacket(Index rowId, Index colId, const PacketScalar& val) 00118 { 00119 m_expression.template writePacket<LoadMode>(rowId, colId, val); 00120 } 00121 00122 template<int LoadMode> 00123 inline const PacketScalar packet(Index index) const 00124 { 00125 return m_expression.template packet<LoadMode>(index); 00126 } 00127 00128 template<int LoadMode> 00129 inline void writePacket(Index index, const PacketScalar& val) 00130 { 00131 m_expression.template writePacket<LoadMode>(index, val); 00132 } 00133 00134 template<typename Dest> 00135 EIGEN_DEVICE_FUNC 00136 inline void evalTo(Dest& dst) const { dst = m_expression; } 00137 00138 const typename internal::remove_all<NestedExpressionType>::type& 00139 EIGEN_DEVICE_FUNC 00140 nestedExpression() const 00141 { 00142 return m_expression; 00143 } 00144 00147 EIGEN_DEVICE_FUNC 00148 void resize(Index newSize) { m_expression.resize(newSize); } 00151 EIGEN_DEVICE_FUNC 00152 void resize(Index rows, Index cols) { m_expression.resize(rows,cols); } 00153 00154 protected: 00155 NestedExpressionType m_expression; 00156 }; 00157 00169 namespace internal { 00170 template<typename ExpressionType> 00171 struct traits<MatrixWrapper<ExpressionType> > 00172 : public traits<typename remove_all<typename ExpressionType::Nested>::type > 00173 { 00174 typedef MatrixXpr XprKind; 00175 // Let's remove NestByRefBit 00176 enum { 00177 Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags, 00178 Flags = Flags0 & ~NestByRefBit 00179 }; 00180 }; 00181 } 00182 00183 template<typename ExpressionType> 00184 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> > 00185 { 00186 public: 00187 typedef MatrixBase<MatrixWrapper<ExpressionType> > Base; 00188 EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper) 00189 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper) 00190 typedef typename internal::remove_all<ExpressionType>::type NestedExpression; 00191 00192 typedef typename internal::conditional< 00193 internal::is_lvalue<ExpressionType>::value, 00194 Scalar, 00195 const Scalar 00196 >::type ScalarWithConstIfNotLvalue; 00197 00198 typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType; 00199 00200 EIGEN_DEVICE_FUNC 00201 explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {} 00202 00203 EIGEN_DEVICE_FUNC 00204 inline Index rows() const { return m_expression.rows(); } 00205 EIGEN_DEVICE_FUNC 00206 inline Index cols() const { return m_expression.cols(); } 00207 EIGEN_DEVICE_FUNC 00208 inline Index outerStride() const { return m_expression.outerStride(); } 00209 EIGEN_DEVICE_FUNC 00210 inline Index innerStride() const { return m_expression.innerStride(); } 00211 00212 EIGEN_DEVICE_FUNC 00213 inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } 00214 EIGEN_DEVICE_FUNC 00215 inline const Scalar* data() const { return m_expression.data(); } 00216 00217 EIGEN_DEVICE_FUNC 00218 inline CoeffReturnType coeff(Index rowId, Index colId) const 00219 { 00220 return m_expression.coeff(rowId, colId); 00221 } 00222 00223 EIGEN_DEVICE_FUNC 00224 inline Scalar& coeffRef(Index rowId, Index colId) 00225 { 00226 return m_expression.coeffRef(rowId, colId); 00227 } 00228 00229 EIGEN_DEVICE_FUNC 00230 inline const Scalar& coeffRef(Index rowId, Index colId) const 00231 { 00232 return m_expression.derived().coeffRef(rowId, colId); 00233 } 00234 00235 EIGEN_DEVICE_FUNC 00236 inline CoeffReturnType coeff(Index index) const 00237 { 00238 return m_expression.coeff(index); 00239 } 00240 00241 EIGEN_DEVICE_FUNC 00242 inline Scalar& coeffRef(Index index) 00243 { 00244 return m_expression.coeffRef(index); 00245 } 00246 00247 EIGEN_DEVICE_FUNC 00248 inline const Scalar& coeffRef(Index index) const 00249 { 00250 return m_expression.coeffRef(index); 00251 } 00252 00253 template<int LoadMode> 00254 inline const PacketScalar packet(Index rowId, Index colId) const 00255 { 00256 return m_expression.template packet<LoadMode>(rowId, colId); 00257 } 00258 00259 template<int LoadMode> 00260 inline void writePacket(Index rowId, Index colId, const PacketScalar& val) 00261 { 00262 m_expression.template writePacket<LoadMode>(rowId, colId, val); 00263 } 00264 00265 template<int LoadMode> 00266 inline const PacketScalar packet(Index index) const 00267 { 00268 return m_expression.template packet<LoadMode>(index); 00269 } 00270 00271 template<int LoadMode> 00272 inline void writePacket(Index index, const PacketScalar& val) 00273 { 00274 m_expression.template writePacket<LoadMode>(index, val); 00275 } 00276 00277 EIGEN_DEVICE_FUNC 00278 const typename internal::remove_all<NestedExpressionType>::type& 00279 nestedExpression() const 00280 { 00281 return m_expression; 00282 } 00283 00286 EIGEN_DEVICE_FUNC 00287 void resize(Index newSize) { m_expression.resize(newSize); } 00290 EIGEN_DEVICE_FUNC 00291 void resize(Index rows, Index cols) { m_expression.resize(rows,cols); } 00292 00293 protected: 00294 NestedExpressionType m_expression; 00295 }; 00296 00297 } // end namespace Eigen 00298 00299 #endif // EIGEN_ARRAYWRAPPER_H