From 2a3a6fe45e8207840c2b3295d823f941e51d392a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 16 Nov 2009 18:19:08 +0100 Subject: [PATCH] Experiment the ET refactoring on Transpose for Dense and Sparse storages. All tests work fine. --- Eigen/src/Array/Replicate.h | 1 + Eigen/src/Array/Reverse.h | 1 + Eigen/src/Array/VectorwiseOp.h | 1 + Eigen/src/Core/Block.h | 1 + Eigen/src/Core/CwiseBinaryOp.h | 2 + Eigen/src/Core/Diagonal.h | 1 + Eigen/src/Core/DiagonalProduct.h | 1 + Eigen/src/Core/Matrix.h | 3 +- Eigen/src/Core/MatrixBase.h | 9 +- Eigen/src/Core/Minor.h | 7 +- Eigen/src/Core/ProductBase.h | 2 + Eigen/src/Core/Transpose.h | 126 +++++++++++++--------- Eigen/src/Core/products/GeneralUnrolled.h | 6 +- Eigen/src/Core/util/Macros.h | 92 +++++++++++----- Eigen/src/Core/util/XprHelper.h | 7 ++ Eigen/src/Geometry/Homogeneous.h | 1 + Eigen/src/Sparse/DynamicSparseMatrix.h | 1 + Eigen/src/Sparse/SparseMatrix.h | 1 + Eigen/src/Sparse/SparseMatrixBase.h | 22 +++- Eigen/src/Sparse/SparseTranspose.h | 52 +++++---- Eigen/src/Sparse/SparseUtil.h | 22 +++- Eigen/src/Sparse/SparseVector.h | 1 + 22 files changed, 244 insertions(+), 116 deletions(-) diff --git a/Eigen/src/Array/Replicate.h b/Eigen/src/Array/Replicate.h index 478c0bf68..079d59d59 100644 --- a/Eigen/src/Array/Replicate.h +++ b/Eigen/src/Array/Replicate.h @@ -42,6 +42,7 @@ template struct ei_traits > { typedef typename MatrixType::Scalar Scalar; + typedef typename ei_traits::StorageType StorageType; typedef typename ei_nested::type MatrixTypeNested; typedef typename ei_unref::type _MatrixTypeNested; enum { diff --git a/Eigen/src/Array/Reverse.h b/Eigen/src/Array/Reverse.h index 4807bea55..d19c68ef9 100644 --- a/Eigen/src/Array/Reverse.h +++ b/Eigen/src/Array/Reverse.h @@ -45,6 +45,7 @@ template struct ei_traits > { typedef typename MatrixType::Scalar Scalar; + typedef typename ei_traits::StorageType StorageType; typedef typename ei_nested::type MatrixTypeNested; typedef typename ei_unref::type _MatrixTypeNested; enum { diff --git a/Eigen/src/Array/VectorwiseOp.h b/Eigen/src/Array/VectorwiseOp.h index 880567212..241105635 100644 --- a/Eigen/src/Array/VectorwiseOp.h +++ b/Eigen/src/Array/VectorwiseOp.h @@ -50,6 +50,7 @@ template struct ei_traits > { typedef typename MemberOp::result_type Scalar; + typedef typename ei_traits::StorageType StorageType; typedef typename MatrixType::Scalar InputScalar; typedef typename ei_nested::type MatrixTypeNested; typedef typename ei_cleantype::type _MatrixTypeNested; diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 5fffdcb01..9b0ada19b 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -67,6 +67,7 @@ struct ei_traits::Scalar Scalar; typedef typename ei_nested::type MatrixTypeNested; typedef typename ei_unref::type _MatrixTypeNested; + typedef typename ei_traits::StorageType StorageType; enum{ RowsAtCompileTime = BlockRows, ColsAtCompileTime = BlockCols, diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index 875bc9aa5..318d302ef 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -54,6 +54,8 @@ struct ei_traits > typename Rhs::Scalar ) >::type Scalar; + typedef typename ei_promote_storage_type::StorageType, + typename ei_traits::StorageType>::ret StorageType; typedef typename Lhs::Nested LhsNested; typedef typename Rhs::Nested RhsNested; typedef typename ei_unref::type _LhsNested; diff --git a/Eigen/src/Core/Diagonal.h b/Eigen/src/Core/Diagonal.h index f2bc8566e..25aa9cd4c 100644 --- a/Eigen/src/Core/Diagonal.h +++ b/Eigen/src/Core/Diagonal.h @@ -46,6 +46,7 @@ template struct ei_traits > { typedef typename MatrixType::Scalar Scalar; + typedef typename ei_traits::StorageType StorageType; typedef typename ei_nested::type MatrixTypeNested; typedef typename ei_unref::type _MatrixTypeNested; enum { diff --git a/Eigen/src/Core/DiagonalProduct.h b/Eigen/src/Core/DiagonalProduct.h index fb3b11bdd..42e2e948d 100644 --- a/Eigen/src/Core/DiagonalProduct.h +++ b/Eigen/src/Core/DiagonalProduct.h @@ -30,6 +30,7 @@ template struct ei_traits > { typedef typename ei_scalar_product_traits::ReturnType Scalar; + typedef typename ei_traits::StorageType StorageType; enum { RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 11d73f0c4..04fbcc59d 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -118,6 +118,7 @@ template > { typedef _Scalar Scalar; + typedef Dense StorageType; enum { RowsAtCompileTime = _Rows, ColsAtCompileTime = _Cols, @@ -320,7 +321,7 @@ class Matrix */ template EIGEN_STRONG_INLINE void resizeLike(const MatrixBase& other) - { + { if(RowsAtCompileTime == 1) { ei_assert(other.isVector()); diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 8078b75b0..17fdf10f2 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -28,7 +28,7 @@ /** \class MatrixBase * - * \brief Base class for all matrices, vectors, and expressions + * \brief Base class for all dense matrices, vectors, and expressions * * This class is the base that is inherited by all matrix, vector, and expression * types. Most of the Eigen API is contained in this class. Other important classes for @@ -51,6 +51,9 @@ } * \endcode */ + +struct Dense {}; + template class MatrixBase #ifndef EIGEN_PARSED_BY_DOXYGEN : public ei_special_scalar_op_base::Scalar, @@ -639,7 +642,7 @@ template class MatrixBase const CwiseBinaryOp binaryExpr(const MatrixBase &other, const CustomBinaryOp& func = CustomBinaryOp()) const; - + Scalar sum() const; Scalar mean() const; Scalar trace() const; @@ -819,7 +822,7 @@ template class MatrixBase INVALID_MATRIXBASE_TEMPLATE_PARAMETERS) #endif } - + private: explicit MatrixBase(int); MatrixBase(int,int); diff --git a/Eigen/src/Core/Minor.h b/Eigen/src/Core/Minor.h index ab058b187..1db60b002 100644 --- a/Eigen/src/Core/Minor.h +++ b/Eigen/src/Core/Minor.h @@ -25,7 +25,7 @@ #ifndef EIGEN_MINOR_H #define EIGEN_MINOR_H -/** \nonstableyet +/** \nonstableyet * \class Minor * * \brief Expression of a minor @@ -42,6 +42,7 @@ template struct ei_traits > { typedef typename MatrixType::Scalar Scalar; + typedef typename ei_traits::StorageType StorageType; typedef typename ei_nested::type MatrixTypeNested; typedef typename ei_unref::type _MatrixTypeNested; enum { @@ -93,7 +94,7 @@ template class Minor const int m_row, m_col; }; -/** \nonstableyet +/** \nonstableyet * \return an expression of the (\a row, \a col)-minor of *this, * i.e. an expression constructed from *this by removing the specified * row and column. @@ -110,7 +111,7 @@ MatrixBase::minor(int row, int col) return Minor(derived(), row, col); } -/** \nonstableyet +/** \nonstableyet * This is the const version of minor(). */ template inline const Minor diff --git a/Eigen/src/Core/ProductBase.h b/Eigen/src/Core/ProductBase.h index 57183ac52..68cff12d3 100644 --- a/Eigen/src/Core/ProductBase.h +++ b/Eigen/src/Core/ProductBase.h @@ -34,6 +34,8 @@ struct ei_traits > typedef typename ei_cleantype<_Lhs>::type Lhs; typedef typename ei_cleantype<_Rhs>::type Rhs; typedef typename ei_scalar_product_traits::ReturnType Scalar; + typedef typename ei_promote_storage_type::StorageType, + typename ei_traits::StorageType>::ret StorageType; enum { RowsAtCompileTime = ei_traits::RowsAtCompileTime, ColsAtCompileTime = ei_traits::ColsAtCompileTime, 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 > typedef typename MatrixType::Scalar Scalar; typedef typename ei_nested::type MatrixTypeNested; typedef typename ei_unref::type _MatrixTypeNested; + typedef typename ei_traits::StorageType StorageType; enum { RowsAtCompileTime = MatrixType::ColsAtCompileTime, ColsAtCompileTime = MatrixType::RowsAtCompileTime, @@ -56,12 +57,15 @@ struct ei_traits > }; }; +template class TransposeImpl; + template class Transpose - : public MatrixBase > + : public TransposeImpl::StorageType> { public: - EIGEN_GENERIC_PUBLIC_INTERFACE(Transpose) + typedef typename TransposeImpl::StorageType>::Base Base; + EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(Transpose) inline Transpose(const MatrixType& matrix) : m_matrix(matrix) {} @@ -69,62 +73,86 @@ template 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(); } - - inline Scalar& coeffRef(int row, int col) - { - return m_matrix.const_cast_derived().coeffRef(col, row); - } - - inline Scalar& coeffRef(int index) - { - return m_matrix.const_cast_derived().coeffRef(index); - } - - inline const CoeffReturnType coeff(int row, int col) const - { - return m_matrix.coeff(col, row); - } - - inline const CoeffReturnType coeff(int index) const - { - return m_matrix.coeff(index); - } - - template - inline const PacketScalar packet(int row, int col) const - { - return m_matrix.template packet(col, row); - } - - template - inline void writePacket(int row, int col, const PacketScalar& x) - { - m_matrix.const_cast_derived().template writePacket(col, row, x); - } - - template - inline const PacketScalar packet(int index) const - { - return m_matrix.template packet(index); - } - - template - inline void writePacket(int index, const PacketScalar& x) - { - m_matrix.const_cast_derived().template writePacket(index, x); - } /** \internal used for introspection */ const typename ei_cleantype::type& _expression() const { return m_matrix; } + const typename ei_cleantype::type& + nestedExpression() const { return m_matrix; } + + typename ei_cleantype::type& + nestedExpression() { return m_matrix.const_cast_derived(); } + protected: const typename MatrixType::Nested m_matrix; }; + +template class TransposeImpl + : public MatrixBase > +{ + const typename ei_cleantype::type& matrix() const + { return derived().nestedExpression(); } + typename ei_cleantype::type& matrix() + { return derived().nestedExpression(); } + + public: + + //EIGEN_DENSE_PUBLIC_INTERFACE(TransposeImpl,MatrixBase >) + EIGEN_DENSE_PUBLIC_INTERFACE(Transpose) + +// EIGEN_EXPRESSION_IMPL_COMMON(MatrixBase >) + + 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 matrix().const_cast_derived().coeffRef(col, row); + } + + inline Scalar& coeffRef(int index) + { + return matrix().const_cast_derived().coeffRef(index); + } + + inline const CoeffReturnType coeff(int row, int col) const + { + return matrix().coeff(col, row); + } + + inline const CoeffReturnType coeff(int index) const + { + return matrix().coeff(index); + } + + template + inline const PacketScalar packet(int row, int col) const + { + return matrix().template packet(col, row); + } + + template + inline void writePacket(int row, int col, const PacketScalar& x) + { + matrix().const_cast_derived().template writePacket(col, row, x); + } + + template + inline const PacketScalar packet(int index) const + { + return matrix().template packet(index); + } + + template + inline void writePacket(int index, const PacketScalar& x) + { + matrix().const_cast_derived().template writePacket(index, x); + } +}; + /** \returns an expression of the transpose of *this. * * Example: \include MatrixBase_transpose.cpp diff --git a/Eigen/src/Core/products/GeneralUnrolled.h b/Eigen/src/Core/products/GeneralUnrolled.h index 7241976a8..72a61354e 100644 --- a/Eigen/src/Core/products/GeneralUnrolled.h +++ b/Eigen/src/Core/products/GeneralUnrolled.h @@ -32,7 +32,7 @@ /* Since the all the dimensions of the product are small, here we can rely * on the generic Assign mechanism to evaluate the product per coeff (or packet). - * + * * Note that here the inner-loops should always be unrolled. */ @@ -48,7 +48,9 @@ struct ei_traits > typedef typename ei_cleantype::type _LhsNested; typedef typename ei_cleantype::type _RhsNested; typedef typename ei_scalar_product_traits::ReturnType Scalar; - + typedef typename ei_promote_storage_type::StorageType, + typename ei_traits<_RhsNested>::StorageType>::ret StorageType; + enum { LhsCoeffReadCost = _LhsNested::CoeffReadCost, RhsCoeffReadCost = _RhsNested::CoeffReadCost, diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index a94300de3..6758d5766 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -263,43 +263,79 @@ using Eigen::ei_cos; #if defined(_MSC_VER) && (!defined(__INTEL_COMPILER)) #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \ -using Base::operator =; + using Base::operator =; #else #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \ -using Base::operator =; \ -EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) \ -{ \ - Base::operator=(other); \ - return *this; \ -} + using Base::operator =; \ + EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) \ + { \ + Base::operator=(other); \ + return *this; \ + } #endif #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \ -using Base::operator +=; \ -using Base::operator -=; \ -using Base::operator *=; \ -using Base::operator /=; \ -EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) + using Base::operator +=; \ + using Base::operator -=; \ + using Base::operator *=; \ + using Base::operator /=; \ + EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) #define _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, BaseClass) \ -typedef BaseClass Base; \ -typedef typename Eigen::ei_traits::Scalar Scalar; \ -typedef typename Eigen::NumTraits::Real RealScalar; \ -typedef typename Base::PacketScalar PacketScalar; \ -typedef typename Base::CoeffReturnType CoeffReturnType; \ -typedef typename Eigen::ei_nested::type Nested; \ -enum { RowsAtCompileTime = Eigen::ei_traits::RowsAtCompileTime, \ - ColsAtCompileTime = Eigen::ei_traits::ColsAtCompileTime, \ - MaxRowsAtCompileTime = Eigen::ei_traits::MaxRowsAtCompileTime, \ - MaxColsAtCompileTime = Eigen::ei_traits::MaxColsAtCompileTime, \ - Flags = Eigen::ei_traits::Flags, \ - CoeffReadCost = Eigen::ei_traits::CoeffReadCost, \ - SizeAtCompileTime = Base::SizeAtCompileTime, \ - MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \ - IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; + typedef BaseClass Base; \ + typedef typename Eigen::ei_traits::Scalar Scalar; \ + typedef typename Eigen::NumTraits::Real RealScalar; \ + typedef typename Base::PacketScalar PacketScalar; \ + typedef typename Base::CoeffReturnType CoeffReturnType; \ + typedef typename Eigen::ei_nested::type Nested; \ + enum { RowsAtCompileTime = Eigen::ei_traits::RowsAtCompileTime, \ + ColsAtCompileTime = Eigen::ei_traits::ColsAtCompileTime, \ + MaxRowsAtCompileTime = Eigen::ei_traits::MaxRowsAtCompileTime, \ + MaxColsAtCompileTime = Eigen::ei_traits::MaxColsAtCompileTime, \ + Flags = Eigen::ei_traits::Flags, \ + CoeffReadCost = Eigen::ei_traits::CoeffReadCost, \ + SizeAtCompileTime = Base::SizeAtCompileTime, \ + MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \ + IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ -_EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase) + _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase) + +#define EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(Derived) \ + typedef typename Eigen::ei_traits::Scalar Scalar; \ + typedef typename Eigen::NumTraits::Real RealScalar; \ + typedef typename Base::CoeffReturnType CoeffReturnType; \ + typedef typename Eigen::ei_nested::type Nested; \ + enum { RowsAtCompileTime = Eigen::ei_traits::RowsAtCompileTime, \ + ColsAtCompileTime = Eigen::ei_traits::ColsAtCompileTime, \ + Flags = Eigen::ei_traits::Flags, \ + CoeffReadCost = Eigen::ei_traits::CoeffReadCost, \ + SizeAtCompileTime = Base::SizeAtCompileTime, \ + MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \ + IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; + + +#define _EIGEN_DENSE_PUBLIC_INTERFACE(Derived, BaseClass) \ + typedef BaseClass Base; \ + typedef typename Eigen::ei_traits::Scalar Scalar; \ + typedef typename Eigen::NumTraits::Real RealScalar; \ + typedef typename Base::PacketScalar PacketScalar; \ + typedef typename Base::CoeffReturnType CoeffReturnType; \ + typedef typename Eigen::ei_nested::type Nested; \ + enum { RowsAtCompileTime = Eigen::ei_traits::RowsAtCompileTime, \ + ColsAtCompileTime = Eigen::ei_traits::ColsAtCompileTime, \ + MaxRowsAtCompileTime = Eigen::ei_traits::MaxRowsAtCompileTime, \ + MaxColsAtCompileTime = Eigen::ei_traits::MaxColsAtCompileTime, \ + Flags = Eigen::ei_traits::Flags, \ + CoeffReadCost = Eigen::ei_traits::CoeffReadCost, \ + SizeAtCompileTime = Base::SizeAtCompileTime, \ + MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \ + IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \ + using Base::derived; + +#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \ + _EIGEN_DENSE_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase) + #define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b) #define EIGEN_SIZE_MIN(a,b) (((int)a == 1 || (int)b == 1) ? 1 \ diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index be4266f85..6f8b6d633 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -268,4 +268,11 @@ template struct ei_cast_return_type const XprType&,CastType>::ret type; }; +template struct ei_promote_storage_type; + +template struct ei_promote_storage_type +{ + typedef A ret; +}; + #endif // EIGEN_XPRHELPER_H diff --git a/Eigen/src/Geometry/Homogeneous.h b/Eigen/src/Geometry/Homogeneous.h index 035d213b7..17fbdd85d 100644 --- a/Eigen/src/Geometry/Homogeneous.h +++ b/Eigen/src/Geometry/Homogeneous.h @@ -43,6 +43,7 @@ template struct ei_traits > { typedef typename MatrixType::Scalar Scalar; + typedef typename ei_traits::StorageType StorageType; typedef typename ei_nested::type MatrixTypeNested; typedef typename ei_unref::type _MatrixTypeNested; enum { diff --git a/Eigen/src/Sparse/DynamicSparseMatrix.h b/Eigen/src/Sparse/DynamicSparseMatrix.h index 6a5cd070e..f68f53709 100644 --- a/Eigen/src/Sparse/DynamicSparseMatrix.h +++ b/Eigen/src/Sparse/DynamicSparseMatrix.h @@ -46,6 +46,7 @@ template struct ei_traits > { typedef _Scalar Scalar; + typedef Sparse StorageType; enum { RowsAtCompileTime = Dynamic, ColsAtCompileTime = Dynamic, diff --git a/Eigen/src/Sparse/SparseMatrix.h b/Eigen/src/Sparse/SparseMatrix.h index af3b5e5eb..f42fb4199 100644 --- a/Eigen/src/Sparse/SparseMatrix.h +++ b/Eigen/src/Sparse/SparseMatrix.h @@ -45,6 +45,7 @@ template struct ei_traits > { typedef _Scalar Scalar; + typedef Sparse StorageType; enum { RowsAtCompileTime = Dynamic, ColsAtCompileTime = Dynamic, diff --git a/Eigen/src/Sparse/SparseMatrixBase.h b/Eigen/src/Sparse/SparseMatrixBase.h index 61e8adea3..043fe07b2 100644 --- a/Eigen/src/Sparse/SparseMatrixBase.h +++ b/Eigen/src/Sparse/SparseMatrixBase.h @@ -36,11 +36,15 @@ * * */ + +struct Sparse {}; + template class SparseMatrixBase : public AnyMatrixBase { public: typedef typename ei_traits::Scalar Scalar; + typedef typename ei_packet_traits::type PacketScalar; // typedef typename Derived::InnerIterator InnerIterator; enum { @@ -86,7 +90,11 @@ template class SparseMatrixBase : public AnyMatrixBase class SparseMatrixBase : public AnyMatrixBase, Derived> ImagReturnType; /** \internal the return type of MatrixBase::adjoint() */ typedef typename ei_meta_if::IsComplex, - SparseCwiseUnaryOp, SparseNestByValue > >, - SparseTranspose + SparseCwiseUnaryOp, SparseNestByValue > >, + Transpose >::ret AdjointReturnType; #ifndef EIGEN_PARSED_BY_DOXYGEN @@ -113,6 +121,10 @@ template class SparseMatrixBase : public AnyMatrixBase::Real RealScalar; + /** \internal the return type of coeff() + */ + typedef typename ei_meta_if<_HasDirectAccess, const Scalar&, Scalar>::ret CoeffReturnType; + /** type of the equivalent square matrix */ typedef Matrix SquareMatrixType; @@ -353,8 +365,8 @@ template class SparseMatrixBase : public AnyMatrixBase transpose() { return derived(); } - const SparseTranspose transpose() const { return derived(); } + Transpose transpose() { return derived(); } + const Transpose transpose() const { return derived(); } // void transposeInPlace(); const AdjointReturnType adjoint() const { return transpose().nestByValue(); } diff --git a/Eigen/src/Sparse/SparseTranspose.h b/Eigen/src/Sparse/SparseTranspose.h index 9a702739d..20db99c96 100644 --- a/Eigen/src/Sparse/SparseTranspose.h +++ b/Eigen/src/Sparse/SparseTranspose.h @@ -25,64 +25,72 @@ #ifndef EIGEN_SPARSETRANSPOSE_H #define EIGEN_SPARSETRANSPOSE_H -template -struct ei_traits > : ei_traits > -{}; +// template +// struct ei_traits > : ei_traits > +// {}; -template class SparseTranspose - : public SparseMatrixBase > +template class TransposeImpl + : public SparseMatrixBase > { + const typename ei_cleantype::type& matrix() const + { return derived().nestedExpression(); } + typename ei_cleantype::type& matrix() + { return derived().nestedExpression(); } + public: - EIGEN_GENERIC_PUBLIC_INTERFACE(SparseTranspose) + +// _EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(TransposeImpl,SparseMatrixBase >) +// EIGEN_EXPRESSION_IMPL_COMMON(SparseMatrixBase >) + EIGEN_SPARSE_PUBLIC_INTERFACE(Transpose) class InnerIterator; class ReverseInnerIterator; - inline SparseTranspose(const MatrixType& matrix) : m_matrix(matrix) {} +// inline SparseTranspose(const MatrixType& matrix) : m_matrix(matrix) {} //EIGEN_INHERIT_ASSIGNMENT_OPERATORS(SparseTranspose) - inline int rows() const { return m_matrix.cols(); } - inline int cols() const { return m_matrix.rows(); } - inline int nonZeros() const { return m_matrix.nonZeros(); } +// inline int rows() const { return m_matrix.cols(); } +// inline int cols() const { return m_matrix.rows(); } + inline int nonZeros() const { return matrix().nonZeros(); } // FIXME should be keep them ? 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 const Scalar coeff(int row, int col) const - { return m_matrix.coeff(col, row); } + { return matrix().coeff(col, row); } inline const Scalar coeff(int index) const - { return m_matrix.coeff(index); } + { return matrix().coeff(index); } inline Scalar& coeffRef(int index) - { return m_matrix.const_cast_derived().coeffRef(index); } + { return matrix().const_cast_derived().coeffRef(index); } - protected: - const typename MatrixType::Nested m_matrix; +// protected: +// const typename MatrixType::Nested m_matrix; }; -template class SparseTranspose::InnerIterator : public MatrixType::InnerIterator +template class TransposeImpl::InnerIterator : public MatrixType::InnerIterator { typedef typename MatrixType::InnerIterator Base; public: - EIGEN_STRONG_INLINE InnerIterator(const SparseTranspose& trans, int outer) - : Base(trans.m_matrix, outer) + EIGEN_STRONG_INLINE InnerIterator(const TransposeImpl& trans, int outer) + : Base(trans.matrix(), outer) {} inline int row() const { return Base::col(); } inline int col() const { return Base::row(); } }; -template class SparseTranspose::ReverseInnerIterator : public MatrixType::ReverseInnerIterator +template class TransposeImpl::ReverseInnerIterator : public MatrixType::ReverseInnerIterator { typedef typename MatrixType::ReverseInnerIterator Base; public: - EIGEN_STRONG_INLINE ReverseInnerIterator(const SparseTranspose& xpr, int outer) - : Base(xpr.m_matrix, outer) + EIGEN_STRONG_INLINE ReverseInnerIterator(const TransposeImpl& xpr, int outer) + : Base(xpr.matrix(), outer) {} inline int row() const { return Base::col(); } inline int col() const { return Base::row(); } diff --git a/Eigen/src/Sparse/SparseUtil.h b/Eigen/src/Sparse/SparseUtil.h index b5fc7c7b7..5ae3ebc7a 100644 --- a/Eigen/src/Sparse/SparseUtil.h +++ b/Eigen/src/Sparse/SparseUtil.h @@ -69,7 +69,23 @@ enum { RowsAtCompileTime = Eigen::ei_traits::RowsAtCompileTime, \ IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; #define EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived) \ -_EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase) + _EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase) + +#define _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, BaseClass) \ + typedef BaseClass Base; \ + typedef typename Eigen::ei_traits::Scalar Scalar; \ + typedef typename Eigen::NumTraits::Real RealScalar; \ + typedef typename Eigen::ei_nested::type Nested; \ + enum { RowsAtCompileTime = Eigen::ei_traits::RowsAtCompileTime, \ + ColsAtCompileTime = Eigen::ei_traits::ColsAtCompileTime, \ + Flags = Eigen::ei_traits::Flags, \ + CoeffReadCost = Eigen::ei_traits::CoeffReadCost, \ + SizeAtCompileTime = Base::SizeAtCompileTime, \ + IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \ + using Base::derived; + +#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \ + _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase) enum SparseBackend { DefaultBackend, @@ -107,7 +123,7 @@ template class SparseVector; template class MappedSparseMatrix; template class SparseNestByValue; -template class SparseTranspose; +// template class SparseTranspose; template class SparseInnerVectorSet; template class SparseCwise; template class SparseCwiseUnaryOp; @@ -127,7 +143,7 @@ const int RandomAccessPattern = 0x8 | OuterRandomAccessPattern | InnerRand // const int AccessPatternNotSupported = 0x0; // const int AccessPatternSupported = 0x1; -// +// // template struct ei_support_access_pattern // { // enum { ret = (int(ei_traits::SupportedAccessPatterns) & AccessPattern) == AccessPattern diff --git a/Eigen/src/Sparse/SparseVector.h b/Eigen/src/Sparse/SparseVector.h index 122b1888e..fae186534 100644 --- a/Eigen/src/Sparse/SparseVector.h +++ b/Eigen/src/Sparse/SparseVector.h @@ -38,6 +38,7 @@ template struct ei_traits > { typedef _Scalar Scalar; + typedef Sparse StorageType; enum { IsColVector = _Options & RowMajorBit ? 0 : 1,