Eigen  3.3.3
ArrayWrapper.h
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
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     using Base::coeffRef;
00058 
00059     EIGEN_DEVICE_FUNC
00060     explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
00061 
00062     EIGEN_DEVICE_FUNC
00063     inline Index rows() const { return m_expression.rows(); }
00064     EIGEN_DEVICE_FUNC
00065     inline Index cols() const { return m_expression.cols(); }
00066     EIGEN_DEVICE_FUNC
00067     inline Index outerStride() const { return m_expression.outerStride(); }
00068     EIGEN_DEVICE_FUNC
00069     inline Index innerStride() const { return m_expression.innerStride(); }
00070 
00071     EIGEN_DEVICE_FUNC
00072     inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
00073     EIGEN_DEVICE_FUNC
00074     inline const Scalar* data() const { return m_expression.data(); }
00075 
00076     EIGEN_DEVICE_FUNC
00077     inline const Scalar& coeffRef(Index rowId, Index colId) const
00078     {
00079       return m_expression.coeffRef(rowId, colId);
00080     }
00081 
00082     EIGEN_DEVICE_FUNC
00083     inline const Scalar& coeffRef(Index index) const
00084     {
00085       return m_expression.coeffRef(index);
00086     }
00087 
00088     template<typename Dest>
00089     EIGEN_DEVICE_FUNC
00090     inline void evalTo(Dest& dst) const { dst = m_expression; }
00091 
00092     const typename internal::remove_all<NestedExpressionType>::type& 
00093     EIGEN_DEVICE_FUNC
00094     nestedExpression() const 
00095     {
00096       return m_expression;
00097     }
00098 
00101     EIGEN_DEVICE_FUNC
00102     void resize(Index newSize) { m_expression.resize(newSize); }
00105     EIGEN_DEVICE_FUNC
00106     void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
00107 
00108   protected:
00109     NestedExpressionType m_expression;
00110 };
00111 
00123 namespace internal {
00124 template<typename ExpressionType>
00125 struct traits<MatrixWrapper<ExpressionType> >
00126  : public traits<typename remove_all<typename ExpressionType::Nested>::type >
00127 {
00128   typedef MatrixXpr XprKind;
00129   // Let's remove NestByRefBit
00130   enum {
00131     Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
00132     Flags = Flags0 & ~NestByRefBit
00133   };
00134 };
00135 }
00136 
00137 template<typename ExpressionType>
00138 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
00139 {
00140   public:
00141     typedef MatrixBase<MatrixWrapper<ExpressionType> > Base;
00142     EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
00143     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
00144     typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
00145 
00146     typedef typename internal::conditional<
00147                        internal::is_lvalue<ExpressionType>::value,
00148                        Scalar,
00149                        const Scalar
00150                      >::type ScalarWithConstIfNotLvalue;
00151 
00152     typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
00153 
00154     using Base::coeffRef;
00155 
00156     EIGEN_DEVICE_FUNC
00157     explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
00158 
00159     EIGEN_DEVICE_FUNC
00160     inline Index rows() const { return m_expression.rows(); }
00161     EIGEN_DEVICE_FUNC
00162     inline Index cols() const { return m_expression.cols(); }
00163     EIGEN_DEVICE_FUNC
00164     inline Index outerStride() const { return m_expression.outerStride(); }
00165     EIGEN_DEVICE_FUNC
00166     inline Index innerStride() const { return m_expression.innerStride(); }
00167 
00168     EIGEN_DEVICE_FUNC
00169     inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
00170     EIGEN_DEVICE_FUNC
00171     inline const Scalar* data() const { return m_expression.data(); }
00172 
00173     EIGEN_DEVICE_FUNC
00174     inline const Scalar& coeffRef(Index rowId, Index colId) const
00175     {
00176       return m_expression.derived().coeffRef(rowId, colId);
00177     }
00178 
00179     EIGEN_DEVICE_FUNC
00180     inline const Scalar& coeffRef(Index index) const
00181     {
00182       return m_expression.coeffRef(index);
00183     }
00184 
00185     EIGEN_DEVICE_FUNC
00186     const typename internal::remove_all<NestedExpressionType>::type& 
00187     nestedExpression() const 
00188     {
00189       return m_expression;
00190     }
00191 
00194     EIGEN_DEVICE_FUNC
00195     void resize(Index newSize) { m_expression.resize(newSize); }
00198     EIGEN_DEVICE_FUNC
00199     void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
00200 
00201   protected:
00202     NestedExpressionType m_expression;
00203 };
00204 
00205 } // end namespace Eigen
00206 
00207 #endif // EIGEN_ARRAYWRAPPER_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends