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 | |
parent | a89b22f352ce3685e6aa93b1f1c0be9a1efa0d5b (diff) |
Experiment the ET refactoring on Transpose for Dense and Sparse storages.
All tests work fine.
Diffstat (limited to 'Eigen/src/Core')
-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 |
12 files changed, 142 insertions, 57 deletions
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 |