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 | |
parent | a89b22f352ce3685e6aa93b1f1c0be9a1efa0d5b (diff) |
Experiment the ET refactoring on Transpose for Dense and Sparse storages.
All tests work fine.
Diffstat (limited to 'Eigen/src')
-rw-r--r-- | Eigen/src/Array/Replicate.h | 1 | ||||
-rw-r--r-- | Eigen/src/Array/Reverse.h | 1 | ||||
-rw-r--r-- | Eigen/src/Array/VectorwiseOp.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/Block.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseBinaryOp.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/Diagonal.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/DiagonalProduct.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/Matrix.h | 3 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixBase.h | 9 | ||||
-rw-r--r-- | Eigen/src/Core/Minor.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/ProductBase.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/Transpose.h | 68 | ||||
-rw-r--r-- | Eigen/src/Core/products/GeneralUnrolled.h | 6 | ||||
-rw-r--r-- | Eigen/src/Core/util/Macros.h | 92 | ||||
-rw-r--r-- | Eigen/src/Core/util/XprHelper.h | 7 | ||||
-rw-r--r-- | Eigen/src/Geometry/Homogeneous.h | 1 | ||||
-rw-r--r-- | Eigen/src/Sparse/DynamicSparseMatrix.h | 1 | ||||
-rw-r--r-- | Eigen/src/Sparse/SparseMatrix.h | 1 | ||||
-rw-r--r-- | Eigen/src/Sparse/SparseMatrixBase.h | 22 | ||||
-rw-r--r-- | Eigen/src/Sparse/SparseTranspose.h | 52 | ||||
-rw-r--r-- | Eigen/src/Sparse/SparseUtil.h | 22 | ||||
-rw-r--r-- | Eigen/src/Sparse/SparseVector.h | 1 |
22 files changed, 215 insertions, 87 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<typename MatrixType,int RowFactor,int ColFactor> struct ei_traits<Replicate<MatrixType,RowFactor,ColFactor> > { typedef typename MatrixType::Scalar Scalar; + typedef typename ei_traits<MatrixType>::StorageType StorageType; typedef typename ei_nested<MatrixType>::type MatrixTypeNested; typedef typename ei_unref<MatrixTypeNested>::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<typename MatrixType, int Direction> struct ei_traits<Reverse<MatrixType, Direction> > { typedef typename MatrixType::Scalar Scalar; + typedef typename ei_traits<MatrixType>::StorageType StorageType; typedef typename ei_nested<MatrixType>::type MatrixTypeNested; typedef typename ei_unref<MatrixTypeNested>::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<typename MatrixType, typename MemberOp, int Direction> struct ei_traits<PartialReduxExpr<MatrixType, MemberOp, Direction> > { typedef typename MemberOp::result_type Scalar; + typedef typename ei_traits<MatrixType>::StorageType StorageType; typedef typename MatrixType::Scalar InputScalar; typedef typename ei_nested<MatrixType>::type MatrixTypeNested; typedef typename ei_cleantype<MatrixTypeNested>::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<Block<MatrixType, BlockRows, BlockCols, _PacketAccess, _DirectA typedef typename ei_traits<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 = 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<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > typename Rhs::Scalar ) >::type Scalar; + typedef typename ei_promote_storage_type<typename ei_traits<Lhs>::StorageType, + typename ei_traits<Rhs>::StorageType>::ret StorageType; typedef typename Lhs::Nested LhsNested; typedef typename Rhs::Nested RhsNested; typedef typename ei_unref<LhsNested>::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<typename MatrixType, int Index> struct ei_traits<Diagonal<MatrixType,Index> > { typedef typename MatrixType::Scalar Scalar; + typedef typename ei_traits<MatrixType>::StorageType StorageType; typedef typename ei_nested<MatrixType>::type MatrixTypeNested; typedef typename ei_unref<MatrixTypeNested>::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<typename MatrixType, typename DiagonalType, int ProductOrder> struct ei_traits<DiagonalProduct<MatrixType, DiagonalType, ProductOrder> > { typedef typename ei_scalar_product_traits<typename MatrixType::Scalar, typename DiagonalType::Scalar>::ReturnType Scalar; + typedef typename ei_traits<MatrixType>::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<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > { typedef _Scalar Scalar; + typedef Dense StorageType; enum { RowsAtCompileTime = _Rows, ColsAtCompileTime = _Cols, @@ -320,7 +321,7 @@ class Matrix */ template<typename OtherDerived> EIGEN_STRONG_INLINE void resizeLike(const MatrixBase<OtherDerived>& 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<typename Derived> class MatrixBase #ifndef EIGEN_PARSED_BY_DOXYGEN : public ei_special_scalar_op_base<Derived,typename ei_traits<Derived>::Scalar, @@ -639,7 +642,7 @@ template<typename Derived> class MatrixBase const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived> binaryExpr(const MatrixBase<OtherDerived> &other, const CustomBinaryOp& func = CustomBinaryOp()) const; - + Scalar sum() const; Scalar mean() const; Scalar trace() const; @@ -819,7 +822,7 @@ template<typename Derived> 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<typename MatrixType> struct ei_traits<Minor<MatrixType> > { typedef typename MatrixType::Scalar Scalar; + typedef typename ei_traits<MatrixType>::StorageType StorageType; typedef typename ei_nested<MatrixType>::type MatrixTypeNested; typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested; enum { @@ -93,7 +94,7 @@ template<typename MatrixType> 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<Derived>::minor(int row, int col) return Minor<Derived>(derived(), row, col); } -/** \nonstableyet +/** \nonstableyet * This is the const version of minor(). */ template<typename Derived> inline const Minor<Derived> 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<ProductBase<Derived,_Lhs,_Rhs> > typedef typename ei_cleantype<_Lhs>::type Lhs; typedef typename ei_cleantype<_Rhs>::type Rhs; typedef typename ei_scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType Scalar; + typedef typename ei_promote_storage_type<typename ei_traits<Lhs>::StorageType, + typename ei_traits<Rhs>::StorageType>::ret StorageType; enum { RowsAtCompileTime = ei_traits<Lhs>::RowsAtCompileTime, ColsAtCompileTime = ei_traits<Rhs>::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<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. 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<GeneralProduct<LhsNested,RhsNested,UnrolledProduct> > typedef typename ei_cleantype<LhsNested>::type _LhsNested; typedef typename ei_cleantype<RhsNested>::type _RhsNested; typedef typename ei_scalar_product_traits<typename _LhsNested::Scalar, typename _RhsNested::Scalar>::ReturnType Scalar; - + typedef typename ei_promote_storage_type<typename ei_traits<_LhsNested>::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<Derived>::Scalar Scalar; \ -typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ -typedef typename Base::PacketScalar PacketScalar; \ -typedef typename Base::CoeffReturnType CoeffReturnType; \ -typedef typename Eigen::ei_nested<Derived>::type Nested; \ -enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ - ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ - MaxRowsAtCompileTime = Eigen::ei_traits<Derived>::MaxRowsAtCompileTime, \ - MaxColsAtCompileTime = Eigen::ei_traits<Derived>::MaxColsAtCompileTime, \ - Flags = Eigen::ei_traits<Derived>::Flags, \ - CoeffReadCost = Eigen::ei_traits<Derived>::CoeffReadCost, \ - SizeAtCompileTime = Base::SizeAtCompileTime, \ - MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \ - IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; + typedef BaseClass Base; \ + typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \ + typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ + typedef typename Base::PacketScalar PacketScalar; \ + typedef typename Base::CoeffReturnType CoeffReturnType; \ + typedef typename Eigen::ei_nested<Derived>::type Nested; \ + enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ + ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ + MaxRowsAtCompileTime = Eigen::ei_traits<Derived>::MaxRowsAtCompileTime, \ + MaxColsAtCompileTime = Eigen::ei_traits<Derived>::MaxColsAtCompileTime, \ + Flags = Eigen::ei_traits<Derived>::Flags, \ + CoeffReadCost = Eigen::ei_traits<Derived>::CoeffReadCost, \ + SizeAtCompileTime = Base::SizeAtCompileTime, \ + MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \ + IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ -_EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase<Derived>) + _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase<Derived>) + +#define EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(Derived) \ + typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \ + typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ + typedef typename Base::CoeffReturnType CoeffReturnType; \ + typedef typename Eigen::ei_nested<Derived>::type Nested; \ + enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ + ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ + Flags = Eigen::ei_traits<Derived>::Flags, \ + CoeffReadCost = Eigen::ei_traits<Derived>::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<Derived>::Scalar Scalar; \ + typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ + typedef typename Base::PacketScalar PacketScalar; \ + typedef typename Base::CoeffReturnType CoeffReturnType; \ + typedef typename Eigen::ei_nested<Derived>::type Nested; \ + enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ + ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ + MaxRowsAtCompileTime = Eigen::ei_traits<Derived>::MaxRowsAtCompileTime, \ + MaxColsAtCompileTime = Eigen::ei_traits<Derived>::MaxColsAtCompileTime, \ + Flags = Eigen::ei_traits<Derived>::Flags, \ + CoeffReadCost = Eigen::ei_traits<Derived>::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<Derived>) + #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<typename XprType, typename CastType> struct ei_cast_return_type const XprType&,CastType>::ret type; }; +template <typename A, typename B> struct ei_promote_storage_type; + +template <typename A> struct ei_promote_storage_type<A,A> +{ + 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<typename MatrixType,int Direction> struct ei_traits<Homogeneous<MatrixType,Direction> > { typedef typename MatrixType::Scalar Scalar; + typedef typename ei_traits<MatrixType>::StorageType StorageType; typedef typename ei_nested<MatrixType>::type MatrixTypeNested; typedef typename ei_unref<MatrixTypeNested>::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<typename _Scalar, int _Flags> struct ei_traits<DynamicSparseMatrix<_Scalar, _Flags> > { 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<typename _Scalar, int _Options> struct ei_traits<SparseMatrix<_Scalar, _Options> > { 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<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived> { public: typedef typename ei_traits<Derived>::Scalar Scalar; + typedef typename ei_packet_traits<Scalar>::type PacketScalar; // typedef typename Derived::InnerIterator InnerIterator; enum { @@ -86,7 +90,11 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived * this expression. */ - IsRowMajor = Flags&RowMajorBit ? 1 : 0 + IsRowMajor = Flags&RowMajorBit ? 1 : 0, + + #ifndef EIGEN_PARSED_BY_DOXYGEN + _HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0 // workaround sunCC + #endif }; /** \internal the return type of MatrixBase::conjugate() */ @@ -100,8 +108,8 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived typedef SparseCwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType; /** \internal the return type of MatrixBase::adjoint() */ typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex, - SparseCwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, SparseNestByValue<Eigen::SparseTranspose<Derived> > >, - SparseTranspose<Derived> + SparseCwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, SparseNestByValue<Eigen::Transpose<Derived> > >, + Transpose<Derived> >::ret AdjointReturnType; #ifndef EIGEN_PARSED_BY_DOXYGEN @@ -113,6 +121,10 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived */ typedef typename NumTraits<Scalar>::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<Scalar,EIGEN_ENUM_MAX(RowsAtCompileTime,ColsAtCompileTime), EIGEN_ENUM_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType; @@ -353,8 +365,8 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived // const PlainMatrixType normalized() const; // void normalize(); - SparseTranspose<Derived> transpose() { return derived(); } - const SparseTranspose<Derived> transpose() const { return derived(); } + Transpose<Derived> transpose() { return derived(); } + const Transpose<Derived> 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<typename MatrixType> -struct ei_traits<SparseTranspose<MatrixType> > : ei_traits<Transpose<MatrixType> > -{}; +// template<typename MatrixType> +// struct ei_traits<SparseTranspose<MatrixType> > : ei_traits<Transpose<MatrixType> > +// {}; -template<typename MatrixType> class SparseTranspose - : public SparseMatrixBase<SparseTranspose<MatrixType> > +template<typename MatrixType> class TransposeImpl<MatrixType,Sparse> + : public SparseMatrixBase<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_GENERIC_PUBLIC_INTERFACE(SparseTranspose) + +// _EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(TransposeImpl,SparseMatrixBase<Transpose<MatrixType> >) +// EIGEN_EXPRESSION_IMPL_COMMON(SparseMatrixBase<Transpose<MatrixType> >) + EIGEN_SPARSE_PUBLIC_INTERFACE(Transpose<MatrixType>) 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<typename MatrixType> class SparseTranspose<MatrixType>::InnerIterator : public MatrixType::InnerIterator +template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::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<typename MatrixType> class SparseTranspose<MatrixType>::ReverseInnerIterator : public MatrixType::ReverseInnerIterator +template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::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<Derived>::RowsAtCompileTime, \ IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; #define EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived) \ -_EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>) + _EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>) + +#define _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, BaseClass) \ + typedef BaseClass Base; \ + typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \ + typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ + typedef typename Eigen::ei_nested<Derived>::type Nested; \ + enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ + ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ + Flags = Eigen::ei_traits<Derived>::Flags, \ + CoeffReadCost = Eigen::ei_traits<Derived>::CoeffReadCost, \ + SizeAtCompileTime = Base::SizeAtCompileTime, \ + IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \ + using Base::derived; + +#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \ + _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>) enum SparseBackend { DefaultBackend, @@ -107,7 +123,7 @@ template<typename _Scalar, int _Flags = 0> class SparseVector; template<typename _Scalar, int _Flags = 0> class MappedSparseMatrix; template<typename MatrixType> class SparseNestByValue; -template<typename MatrixType> class SparseTranspose; +// template<typename MatrixType> class SparseTranspose; template<typename MatrixType, int Size> class SparseInnerVectorSet; template<typename Derived> class SparseCwise; template<typename UnaryOp, typename MatrixType> class SparseCwiseUnaryOp; @@ -127,7 +143,7 @@ const int RandomAccessPattern = 0x8 | OuterRandomAccessPattern | InnerRand // const int AccessPatternNotSupported = 0x0; // const int AccessPatternSupported = 0x1; -// +// // template<typename MatrixType, int AccessPattern> struct ei_support_access_pattern // { // enum { ret = (int(ei_traits<MatrixType>::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<typename _Scalar, int _Options> struct ei_traits<SparseVector<_Scalar, _Options> > { typedef _Scalar Scalar; + typedef Sparse StorageType; enum { IsColVector = _Options & RowMajorBit ? 0 : 1, |