diff options
author | Gael Guennebaud <g.gael@free.fr> | 2009-11-16 18:19:08 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2009-11-16 18:19:08 +0100 |
commit | 2a3a6fe45e8207840c2b3295d823f941e51d392a (patch) | |
tree | b0654b244462e1e6e4cdb0386c573a71104c3b49 /Eigen/src/Core/Transpose.h | |
parent | a89b22f352ce3685e6aa93b1f1c0be9a1efa0d5b (diff) |
Experiment the ET refactoring on Transpose for Dense and Sparse storages.
All tests work fine.
Diffstat (limited to 'Eigen/src/Core/Transpose.h')
-rw-r--r-- | Eigen/src/Core/Transpose.h | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 990aa3807..71821008e 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -43,6 +43,7 @@ struct ei_traits<Transpose<MatrixType> > typedef typename MatrixType::Scalar Scalar; typedef typename ei_nested<MatrixType>::type MatrixTypeNested; typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested; + typedef typename ei_traits<MatrixType>::StorageType StorageType; enum { RowsAtCompileTime = MatrixType::ColsAtCompileTime, ColsAtCompileTime = MatrixType::RowsAtCompileTime, @@ -56,12 +57,15 @@ struct ei_traits<Transpose<MatrixType> > }; }; +template<typename MatrixType, typename StorageType> class TransposeImpl; + template<typename MatrixType> class Transpose - : public MatrixBase<Transpose<MatrixType> > + : public TransposeImpl<MatrixType,typename ei_traits<MatrixType>::StorageType> { public: - EIGEN_GENERIC_PUBLIC_INTERFACE(Transpose) + typedef typename TransposeImpl<MatrixType,typename ei_traits<MatrixType>::StorageType>::Base Base; + EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(Transpose) inline Transpose(const MatrixType& matrix) : m_matrix(matrix) {} @@ -69,60 +73,84 @@ template<typename MatrixType> class Transpose inline int rows() const { return m_matrix.cols(); } inline int cols() const { return m_matrix.rows(); } - inline int stride() const { return m_matrix.stride(); } - inline Scalar* data() { return m_matrix.data(); } - inline const Scalar* data() const { return m_matrix.data(); } + + /** \internal used for introspection */ + const typename ei_cleantype<typename MatrixType::Nested>::type& + _expression() const { return m_matrix; } + + const typename ei_cleantype<typename MatrixType::Nested>::type& + nestedExpression() const { return m_matrix; } + + typename ei_cleantype<typename MatrixType::Nested>::type& + nestedExpression() { return m_matrix.const_cast_derived(); } + + protected: + const typename MatrixType::Nested m_matrix; +}; + + +template<typename MatrixType> class TransposeImpl<MatrixType,Dense> + : public MatrixBase<Transpose<MatrixType> > +{ + const typename ei_cleantype<typename MatrixType::Nested>::type& matrix() const + { return derived().nestedExpression(); } + typename ei_cleantype<typename MatrixType::Nested>::type& matrix() + { return derived().nestedExpression(); } + + public: + + //EIGEN_DENSE_PUBLIC_INTERFACE(TransposeImpl,MatrixBase<Transpose<MatrixType> >) + EIGEN_DENSE_PUBLIC_INTERFACE(Transpose<MatrixType>) + +// EIGEN_EXPRESSION_IMPL_COMMON(MatrixBase<Transpose<MatrixType> >) + + inline int stride() const { return matrix().stride(); } + inline Scalar* data() { return matrix().data(); } + inline const Scalar* data() const { return matrix().data(); } inline Scalar& coeffRef(int row, int col) { - return m_matrix.const_cast_derived().coeffRef(col, row); + return matrix().const_cast_derived().coeffRef(col, row); } inline Scalar& coeffRef(int index) { - return m_matrix.const_cast_derived().coeffRef(index); + return matrix().const_cast_derived().coeffRef(index); } inline const CoeffReturnType coeff(int row, int col) const { - return m_matrix.coeff(col, row); + return matrix().coeff(col, row); } inline const CoeffReturnType coeff(int index) const { - return m_matrix.coeff(index); + return matrix().coeff(index); } template<int LoadMode> inline const PacketScalar packet(int row, int col) const { - return m_matrix.template packet<LoadMode>(col, row); + return matrix().template packet<LoadMode>(col, row); } template<int LoadMode> inline void writePacket(int row, int col, const PacketScalar& x) { - m_matrix.const_cast_derived().template writePacket<LoadMode>(col, row, x); + matrix().const_cast_derived().template writePacket<LoadMode>(col, row, x); } template<int LoadMode> inline const PacketScalar packet(int index) const { - return m_matrix.template packet<LoadMode>(index); + return matrix().template packet<LoadMode>(index); } template<int LoadMode> inline void writePacket(int index, const PacketScalar& x) { - m_matrix.const_cast_derived().template writePacket<LoadMode>(index, x); + matrix().const_cast_derived().template writePacket<LoadMode>(index, x); } - - /** \internal used for introspection */ - const typename ei_cleantype<typename MatrixType::Nested>::type& - _expression() const { return m_matrix; } - - protected: - const typename MatrixType::Nested m_matrix; }; /** \returns an expression of the transpose of *this. |