From 63bcc1c0fbd03042715caf40aa090385c8fe0043 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 17 Nov 2009 10:11:27 +0100 Subject: [PATCH] adapt CwiseBinaryOp and the Sparse counter part --- Eigen/src/Core/Cwise.h | 30 +-- Eigen/src/Core/CwiseBinaryOp.h | 75 ++++-- Eigen/src/Core/CwiseUnaryOps.h | 299 ++++++++++++----------- Eigen/src/Core/MatrixBase.h | 1 + Eigen/src/Sparse/SparseBlock.h | 1 + Eigen/src/Sparse/SparseCwise.h | 30 ++- Eigen/src/Sparse/SparseCwiseBinaryOp.h | 188 ++++++-------- Eigen/src/Sparse/SparseCwiseUnaryOp.h | 127 +++------- Eigen/src/Sparse/SparseDiagonalProduct.h | 16 +- Eigen/src/Sparse/SparseExpressionMaker.h | 3 +- Eigen/src/Sparse/SparseMatrixBase.h | 15 +- Eigen/src/Sparse/SparseUtil.h | 4 - 12 files changed, 350 insertions(+), 439 deletions(-) diff --git a/Eigen/src/Core/Cwise.h b/Eigen/src/Core/Cwise.h index 4b143325e..a89fdcce7 100644 --- a/Eigen/src/Core/Cwise.h +++ b/Eigen/src/Core/Cwise.h @@ -87,7 +87,7 @@ template class Cwise template const EIGEN_CWISE_PRODUCT_RETURN_TYPE - operator*(const MatrixBase &other) const; + operator*(const AnyMatrixBase &other) const; template const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op) @@ -183,32 +183,4 @@ template class Cwise Cwise& operator=(const Cwise&); }; -/** \returns a Cwise wrapper of *this providing additional coefficient-wise operations - * - * Example: \include MatrixBase_cwise_const.cpp - * Output: \verbinclude MatrixBase_cwise_const.out - * - * \sa class Cwise, cwise() - */ -template -inline const Cwise -MatrixBase::cwise() const -{ - return derived(); -} - -/** \returns a Cwise wrapper of *this providing additional coefficient-wise operations - * - * Example: \include MatrixBase_cwise.cpp - * Output: \verbinclude MatrixBase_cwise.out - * - * \sa class Cwise, cwise() const - */ -template -inline Cwise -MatrixBase::cwise() -{ - return derived(); -} - #endif // EIGEN_CWISE_H diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index 318d302ef..3f3e563ba 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -78,13 +78,24 @@ struct ei_traits > }; }; +template +class CwiseBinaryOpImpl; + template class CwiseBinaryOp : ei_no_assignment_operator, - public MatrixBase > + public CwiseBinaryOpImpl< + BinaryOp, Lhs, Rhs, + typename ei_promote_storage_type::StorageType, + typename ei_traits::StorageType>::ret> { public: - EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp) + typedef typename CwiseBinaryOpImpl< + BinaryOp, Lhs, Rhs, + typename ei_promote_storage_type::StorageType, + typename ei_traits::StorageType>::ret>::Base Base; + EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(CwiseBinaryOp) + typedef typename ei_traits::LhsNested LhsNested; typedef typename ei_traits::RhsNested RhsNested; typedef typename ei_traits::_LhsNested _LhsNested; @@ -112,28 +123,6 @@ class CwiseBinaryOp : ei_no_assignment_operator, EIGEN_STRONG_INLINE int rows() const { return m_lhs.rows(); } EIGEN_STRONG_INLINE int cols() const { return m_lhs.cols(); } - EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const - { - return m_functor(m_lhs.coeff(row, col), m_rhs.coeff(row, col)); - } - - template - EIGEN_STRONG_INLINE PacketScalar packet(int row, int col) const - { - return m_functor.packetOp(m_lhs.template packet(row, col), m_rhs.template packet(row, col)); - } - - EIGEN_STRONG_INLINE const Scalar coeff(int index) const - { - return m_functor(m_lhs.coeff(index), m_rhs.coeff(index)); - } - - template - EIGEN_STRONG_INLINE PacketScalar packet(int index) const - { - return m_functor.packetOp(m_lhs.template packet(index), m_rhs.template packet(index)); - } - const _LhsNested& lhs() const { return m_lhs; } const _RhsNested& rhs() const { return m_rhs; } const BinaryOp& functor() const { return m_functor; } @@ -144,6 +133,42 @@ class CwiseBinaryOp : ei_no_assignment_operator, const BinaryOp m_functor; }; +template +class CwiseBinaryOpImpl + : public MatrixBase > +{ + public: + + typedef CwiseBinaryOp Derived; + EIGEN_DENSE_PUBLIC_INTERFACE( Derived ) + + EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const + { + return derived().functor()(derived().lhs().coeff(row, col), + derived().rhs().coeff(row, col)); + } + + template + EIGEN_STRONG_INLINE PacketScalar packet(int row, int col) const + { + return derived().functor().packetOp(derived().lhs().template packet(row, col), + derived().rhs().template packet(row, col)); + } + + EIGEN_STRONG_INLINE const Scalar coeff(int index) const + { + return derived().functor()(derived().lhs().coeff(index), + derived().rhs().coeff(index)); + } + + template + EIGEN_STRONG_INLINE PacketScalar packet(int index) const + { + return derived().functor().packetOp(derived().lhs().template packet(index), + derived().rhs().template packet(index)); + } +}; + /**\returns an expression of the difference of \c *this and \a other * * \note If you want to substract a given scalar from all coefficients, see Cwise::operator-(). @@ -210,7 +235,7 @@ MatrixBase::operator+=(const MatrixBase& other) template template EIGEN_STRONG_INLINE const EIGEN_CWISE_PRODUCT_RETURN_TYPE -Cwise::operator*(const MatrixBase &other) const +Cwise::operator*(const AnyMatrixBase &other) const { return EIGEN_CWISE_PRODUCT_RETURN_TYPE(_expression(), other.derived()); } diff --git a/Eigen/src/Core/CwiseUnaryOps.h b/Eigen/src/Core/CwiseUnaryOps.h index 205677a6a..442bc1670 100644 --- a/Eigen/src/Core/CwiseUnaryOps.h +++ b/Eigen/src/Core/CwiseUnaryOps.h @@ -1,158 +1,181 @@ #ifndef EIGEN_PARSED_BY_DOXYGEN - /** \internal Represents a scalar multiple of a matrix */ - typedef CwiseUnaryOp, Derived> ScalarMultipleReturnType; - /** \internal Represents a quotient of a matrix by a scalar*/ - typedef CwiseUnaryOp, Derived> ScalarQuotient1ReturnType; - /** \internal the return type of MatrixBase::conjugate() */ - typedef typename ei_meta_if::IsComplex, - const CwiseUnaryOp, Derived>, - const Derived& - >::ret ConjugateReturnType; - /** \internal the return type of MatrixBase::real() const */ - typedef typename ei_meta_if::IsComplex, - const CwiseUnaryOp, Derived>, - const Derived& - >::ret RealReturnType; - /** \internal the return type of MatrixBase::real() */ - typedef typename ei_meta_if::IsComplex, - CwiseUnaryView, Derived>, - Derived& - >::ret NonConstRealReturnType; - /** \internal the return type of MatrixBase::imag() const */ - typedef CwiseUnaryOp, Derived> ImagReturnType; - /** \internal the return type of MatrixBase::imag() */ - typedef CwiseUnaryView, Derived> NonConstImagReturnType; + +/** \internal Represents a scalar multiple of a matrix */ +typedef CwiseUnaryOp, Derived> ScalarMultipleReturnType; +/** \internal Represents a quotient of a matrix by a scalar*/ +typedef CwiseUnaryOp, Derived> ScalarQuotient1ReturnType; +/** \internal the return type of MatrixBase::conjugate() */ +typedef typename ei_meta_if::IsComplex, + const CwiseUnaryOp, Derived>, + const Derived& + >::ret ConjugateReturnType; +/** \internal the return type of MatrixBase::real() const */ +typedef typename ei_meta_if::IsComplex, + const CwiseUnaryOp, Derived>, + const Derived& + >::ret RealReturnType; +/** \internal the return type of MatrixBase::real() */ +typedef typename ei_meta_if::IsComplex, + CwiseUnaryView, Derived>, + Derived& + >::ret NonConstRealReturnType; +/** \internal the return type of MatrixBase::imag() const */ +typedef CwiseUnaryOp, Derived> ImagReturnType; +/** \internal the return type of MatrixBase::imag() */ +typedef CwiseUnaryView, Derived> NonConstImagReturnType; + #endif // not EIGEN_PARSED_BY_DOXYGEN - /** \returns an expression of the opposite of \c *this - */ - EIGEN_STRONG_INLINE const CwiseUnaryOp::Scalar>,Derived> - operator-() const { return derived(); } +/** \returns an expression of the opposite of \c *this + */ +EIGEN_STRONG_INLINE const CwiseUnaryOp::Scalar>,Derived> +operator-() const { return derived(); } - EIGEN_STRONG_INLINE Derived& operator*=(const Scalar& other) - { return *this = *this * other; } - EIGEN_STRONG_INLINE Derived& operator/=(const Scalar& other) - { return *this = *this / other; } +EIGEN_STRONG_INLINE Derived& operator*=(const Scalar& other) +{ return *this = *this * other; } +EIGEN_STRONG_INLINE Derived& operator/=(const Scalar& other) +{ return *this = *this / other; } - /** \returns an expression of \c *this scaled by the scalar factor \a scalar */ - EIGEN_STRONG_INLINE const ScalarMultipleReturnType - operator*(const Scalar& scalar) const - { - return CwiseUnaryOp, Derived> - (derived(), ei_scalar_multiple_op(scalar)); - } +/** \returns an expression of \c *this scaled by the scalar factor \a scalar */ +EIGEN_STRONG_INLINE const ScalarMultipleReturnType +operator*(const Scalar& scalar) const +{ + return CwiseUnaryOp, Derived> + (derived(), ei_scalar_multiple_op(scalar)); +} - #ifdef EIGEN_PARSED_BY_DOXYGEN - const ScalarMultipleReturnType operator*(const RealScalar& scalar) const; - #endif +#ifdef EIGEN_PARSED_BY_DOXYGEN +const ScalarMultipleReturnType operator*(const RealScalar& scalar) const; +#endif - /** \returns an expression of \c *this divided by the scalar value \a scalar */ - EIGEN_STRONG_INLINE const CwiseUnaryOp::Scalar>, Derived> - operator/(const Scalar& scalar) const - { - return CwiseUnaryOp, Derived> - (derived(), ei_scalar_quotient1_op(scalar)); - } +/** \returns an expression of \c *this divided by the scalar value \a scalar */ +EIGEN_STRONG_INLINE const CwiseUnaryOp::Scalar>, Derived> +operator/(const Scalar& scalar) const +{ + return CwiseUnaryOp, Derived> + (derived(), ei_scalar_quotient1_op(scalar)); +} - /** Overloaded for efficient real matrix times complex scalar value */ - EIGEN_STRONG_INLINE const CwiseUnaryOp >, Derived> - operator*(const std::complex& scalar) const - { - return CwiseUnaryOp >, Derived> - (*static_cast(this), ei_scalar_multiple2_op >(scalar)); - } +/** Overloaded for efficient real matrix times complex scalar value */ +EIGEN_STRONG_INLINE const CwiseUnaryOp >, Derived> +operator*(const std::complex& scalar) const +{ + return CwiseUnaryOp >, Derived> + (*static_cast(this), ei_scalar_multiple2_op >(scalar)); +} - inline friend const ScalarMultipleReturnType - operator*(const Scalar& scalar, const MatrixBase& matrix) - { return matrix*scalar; } +inline friend const ScalarMultipleReturnType +operator*(const Scalar& scalar, const Self& matrix) +{ return matrix*scalar; } - inline friend const CwiseUnaryOp >, Derived> - operator*(const std::complex& scalar, const MatrixBase& matrix) - { return matrix*scalar; } +inline friend const CwiseUnaryOp >, Derived> +operator*(const std::complex& scalar, const Self& matrix) +{ return matrix*scalar; } - /** \returns an expression of *this with the \a Scalar type casted to - * \a NewScalar. - * - * The template parameter \a NewScalar is the type we are casting the scalars to. - * - * \sa class CwiseUnaryOp - */ - template - typename ei_cast_return_type::Scalar, NewType>, Derived> >::type - cast() const - { - return derived(); - } +/** \returns an expression of *this with the \a Scalar type casted to + * \a NewScalar. + * + * The template parameter \a NewScalar is the type we are casting the scalars to. + * + * \sa class CwiseUnaryOp + */ +template +typename ei_cast_return_type::Scalar, NewType>, Derived> >::type +cast() const +{ + return derived(); +} - /** \returns an expression of the complex conjugate of \c *this. - * - * \sa adjoint() */ - EIGEN_STRONG_INLINE ConjugateReturnType - conjugate() const - { - return ConjugateReturnType(derived()); - } +/** \returns an expression of the complex conjugate of \c *this. + * + * \sa adjoint() */ +EIGEN_STRONG_INLINE ConjugateReturnType +conjugate() const +{ + return ConjugateReturnType(derived()); +} - /** \returns a read-only expression of the real part of \c *this. - * - * \sa imag() */ - EIGEN_STRONG_INLINE RealReturnType - real() const { return derived(); } +/** \returns a read-only expression of the real part of \c *this. + * + * \sa imag() */ +EIGEN_STRONG_INLINE RealReturnType +real() const { return derived(); } - /** \returns an read-only expression of the imaginary part of \c *this. - * - * \sa real() */ - EIGEN_STRONG_INLINE const ImagReturnType - imag() const { return derived(); } +/** \returns an read-only expression of the imaginary part of \c *this. + * + * \sa real() */ +EIGEN_STRONG_INLINE const ImagReturnType +imag() const { return derived(); } - /** \returns an expression of a custom coefficient-wise unary operator \a func of *this - * - * The template parameter \a CustomUnaryOp is the type of the functor - * of the custom unary operator. - * - * Example: - * \include class_CwiseUnaryOp.cpp - * Output: \verbinclude class_CwiseUnaryOp.out - * - * \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, Cwise::abs - */ - template - EIGEN_STRONG_INLINE const CwiseUnaryOp - unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const - { - return CwiseUnaryOp(derived(), func); - } +/** \returns an expression of a custom coefficient-wise unary operator \a func of *this + * + * The template parameter \a CustomUnaryOp is the type of the functor + * of the custom unary operator. + * + * Example: + * \include class_CwiseUnaryOp.cpp + * Output: \verbinclude class_CwiseUnaryOp.out + * + * \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, Cwise::abs + */ +template +EIGEN_STRONG_INLINE const CwiseUnaryOp +unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const +{ + return CwiseUnaryOp(derived(), func); +} - /** \returns an expression of a custom coefficient-wise unary operator \a func of *this - * - * The template parameter \a CustomUnaryOp is the type of the functor - * of the custom unary operator. - * - * Example: - * \include class_CwiseUnaryOp.cpp - * Output: \verbinclude class_CwiseUnaryOp.out - * - * \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, Cwise::abs - */ - template - EIGEN_STRONG_INLINE const CwiseUnaryView - unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const - { - return CwiseUnaryView(derived(), func); - } +/** \returns an expression of a custom coefficient-wise unary operator \a func of *this + * + * The template parameter \a CustomUnaryOp is the type of the functor + * of the custom unary operator. + * + * Example: + * \include class_CwiseUnaryOp.cpp + * Output: \verbinclude class_CwiseUnaryOp.out + * + * \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, Cwise::abs + */ +template +EIGEN_STRONG_INLINE const CwiseUnaryView +unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const +{ + return CwiseUnaryView(derived(), func); +} - /** \returns a non const expression of the real part of \c *this. - * - * \sa imag() */ - EIGEN_STRONG_INLINE NonConstRealReturnType - real() { return derived(); } +/** \returns a non const expression of the real part of \c *this. + * + * \sa imag() */ +EIGEN_STRONG_INLINE NonConstRealReturnType +real() { return derived(); } - /** \returns a non const expression of the imaginary part of \c *this. - * - * \sa real() */ - EIGEN_STRONG_INLINE NonConstImagReturnType - imag() { return derived(); } +/** \returns a non const expression of the imaginary part of \c *this. + * + * \sa real() */ +EIGEN_STRONG_INLINE NonConstImagReturnType +imag() { return derived(); } - const Cwise cwise() const; - Cwise cwise(); +/** \returns a Cwise wrapper of *this providing additional coefficient-wise operations + * + * Example: \include MatrixBase_cwise_const.cpp + * Output: \verbinclude MatrixBase_cwise_const.out + * + * \sa class Cwise, cwise() + */ +inline const Cwise cwise() const +{ + return derived(); +} + +/** \returns a Cwise wrapper of *this providing additional coefficient-wise operations + * + * Example: \include MatrixBase_cwise.cpp + * Output: \verbinclude MatrixBase_cwise.out + * + * \sa class Cwise, cwise() const + */ +inline Cwise cwise() +{ + return derived(); +} diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 55915d3e1..f7ace714a 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -62,6 +62,7 @@ template class MatrixBase { public: #ifndef EIGEN_PARSED_BY_DOXYGEN + typedef MatrixBase Self; using ei_special_scalar_op_base::Scalar, typename NumTraits::Scalar>::Real>::operator*; diff --git a/Eigen/src/Sparse/SparseBlock.h b/Eigen/src/Sparse/SparseBlock.h index 6659a88e2..7f2e05c4d 100644 --- a/Eigen/src/Sparse/SparseBlock.h +++ b/Eigen/src/Sparse/SparseBlock.h @@ -30,6 +30,7 @@ template struct ei_traits > { typedef typename ei_traits::Scalar Scalar; + typedef typename ei_traits::StorageType StorageType; enum { IsRowMajor = (int(MatrixType::Flags)&RowMajorBit)==RowMajorBit, Flags = MatrixType::Flags, diff --git a/Eigen/src/Sparse/SparseCwise.h b/Eigen/src/Sparse/SparseCwise.h index dd745fe7c..4c041d019 100644 --- a/Eigen/src/Sparse/SparseCwise.h +++ b/Eigen/src/Sparse/SparseCwise.h @@ -23,6 +23,8 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . +#if 0 + #ifndef EIGEN_SPARSE_CWISE_H #define EIGEN_SPARSE_CWISE_H @@ -158,18 +160,20 @@ template class SparseCwise ExpressionTypeNested m_matrix; }; -template -inline const SparseCwise -SparseMatrixBase::cwise() const -{ - return derived(); -} - -template -inline SparseCwise -SparseMatrixBase::cwise() -{ - return derived(); -} +// template +// inline const SparseCwise +// SparseMatrixBase::cwise() const +// { +// return derived(); +// } +// +// template +// inline SparseCwise +// SparseMatrixBase::cwise() +// { +// return derived(); +// } #endif // EIGEN_SPARSE_CWISE_H + +#endif diff --git a/Eigen/src/Sparse/SparseCwiseBinaryOp.h b/Eigen/src/Sparse/SparseCwiseBinaryOp.h index 2dcd6b944..fdc0fb17f 100644 --- a/Eigen/src/Sparse/SparseCwiseBinaryOp.h +++ b/Eigen/src/Sparse/SparseCwiseBinaryOp.h @@ -42,72 +42,56 @@ // 4 - dense op dense product dense // generic dense -template -struct ei_traits > -{ - typedef typename ei_result_of< - BinaryOp( - typename Lhs::Scalar, - typename Rhs::Scalar - ) - >::type Scalar; - typedef typename Lhs::Nested LhsNested; - typedef typename Rhs::Nested RhsNested; - typedef typename ei_unref::type _LhsNested; - typedef typename ei_unref::type _RhsNested; - enum { - LhsCoeffReadCost = _LhsNested::CoeffReadCost, - RhsCoeffReadCost = _RhsNested::CoeffReadCost, - LhsFlags = _LhsNested::Flags, - RhsFlags = _RhsNested::Flags, - RowsAtCompileTime = Lhs::RowsAtCompileTime, - ColsAtCompileTime = Lhs::ColsAtCompileTime, - MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime, - MaxColsAtCompileTime = Lhs::MaxColsAtCompileTime, - Flags = (int(LhsFlags) | int(RhsFlags)) & HereditaryBits, - CoeffReadCost = LhsCoeffReadCost + RhsCoeffReadCost + ei_functor_traits::Cost - }; -}; +// template +// struct ei_traits > +// { +// typedef typename ei_result_of< +// BinaryOp( +// typename Lhs::Scalar, +// 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; +// typedef typename ei_unref::type _RhsNested; +// enum { +// LhsCoeffReadCost = _LhsNested::CoeffReadCost, +// RhsCoeffReadCost = _RhsNested::CoeffReadCost, +// LhsFlags = _LhsNested::Flags, +// RhsFlags = _RhsNested::Flags, +// RowsAtCompileTime = Lhs::RowsAtCompileTime, +// ColsAtCompileTime = Lhs::ColsAtCompileTime, +// MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime, +// MaxColsAtCompileTime = Lhs::MaxColsAtCompileTime, +// Flags = (int(LhsFlags) | int(RhsFlags)) & HereditaryBits, +// CoeffReadCost = LhsCoeffReadCost + RhsCoeffReadCost + ei_functor_traits::Cost +// }; +// }; + +template<> struct ei_promote_storage_type +{ typedef Sparse ret; }; + +template<> struct ei_promote_storage_type +{ typedef Sparse ret; }; template -class SparseCwiseBinaryOp : ei_no_assignment_operator, - public SparseMatrixBase > +class CwiseBinaryOpImpl + : public SparseMatrixBase > { public: class InnerIterator; - EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseCwiseBinaryOp) - typedef typename ei_traits::LhsNested LhsNested; - typedef typename ei_traits::RhsNested RhsNested; - typedef typename ei_unref::type _LhsNested; - typedef typename ei_unref::type _RhsNested; + typedef CwiseBinaryOp Derived; + EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) +// typedef typename ei_traits::LhsNested LhsNested; +// typedef typename ei_traits::RhsNested RhsNested; +// typedef typename ei_unref::type _LhsNested; +// typedef typename ei_unref::type _RhsNested; - EIGEN_STRONG_INLINE SparseCwiseBinaryOp(const Lhs& lhs, const Rhs& rhs, const BinaryOp& func = BinaryOp()) - : m_lhs(lhs), m_rhs(rhs), m_functor(func) - { - EIGEN_STATIC_ASSERT((_LhsNested::Flags&RowMajorBit)==(_RhsNested::Flags&RowMajorBit), - BOTH_MATRICES_MUST_HAVE_THE_SAME_STORAGE_ORDER) - EIGEN_STATIC_ASSERT((ei_functor_allows_mixing_real_and_complex::ret - ? int(ei_is_same_type::ret) - : int(ei_is_same_type::ret)), - YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - // require the sizes to match - EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs) - ei_assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols()); - } - - EIGEN_STRONG_INLINE int rows() const { return m_lhs.rows(); } - EIGEN_STRONG_INLINE int cols() const { return m_lhs.cols(); } - - EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; } - EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; } - EIGEN_STRONG_INLINE const BinaryOp& functor() const { return m_functor; } - - protected: - const LhsNested m_lhs; - const RhsNested m_rhs; - const BinaryOp m_functor; }; template -class SparseCwiseBinaryOp::InnerIterator - : public ei_sparse_cwise_binary_op_inner_iterator_selector::InnerIterator> +class CwiseBinaryOpImpl::InnerIterator + : public ei_sparse_cwise_binary_op_inner_iterator_selector::InnerIterator> { public: typedef ei_sparse_cwise_binary_op_inner_iterator_selector< BinaryOp,Lhs,Rhs, InnerIterator> Base; - EIGEN_STRONG_INLINE InnerIterator(const SparseCwiseBinaryOp& binOp, int outer) - : Base(binOp,outer) + EIGEN_STRONG_INLINE InnerIterator(const CwiseBinaryOpImpl& binOp, int outer) + : Base(binOp.derived(),outer) {} }; @@ -141,7 +125,7 @@ class SparseCwiseBinaryOp::InnerIterator template class ei_sparse_cwise_binary_op_inner_iterator_selector { - typedef SparseCwiseBinaryOp CwiseBinaryXpr; + typedef CwiseBinaryOp CwiseBinaryXpr; typedef typename ei_traits::Scalar Scalar; typedef typename ei_traits::_LhsNested _LhsNested; typedef typename ei_traits::_RhsNested _RhsNested; @@ -204,7 +188,7 @@ template class ei_sparse_cwise_binary_op_inner_iterator_selector, Lhs, Rhs, Derived, IsSparse, IsSparse> { typedef ei_scalar_product_op BinaryFunc; - typedef SparseCwiseBinaryOp CwiseBinaryXpr; + typedef CwiseBinaryOp CwiseBinaryXpr; typedef typename CwiseBinaryXpr::Scalar Scalar; typedef typename ei_traits::_LhsNested _LhsNested; typedef typename _LhsNested::InnerIterator LhsIterator; @@ -257,7 +241,7 @@ template class ei_sparse_cwise_binary_op_inner_iterator_selector, Lhs, Rhs, Derived, IsSparse, IsDense> { typedef ei_scalar_product_op BinaryFunc; - typedef SparseCwiseBinaryOp CwiseBinaryXpr; + typedef CwiseBinaryOp CwiseBinaryXpr; typedef typename CwiseBinaryXpr::Scalar Scalar; typedef typename ei_traits::_LhsNested _LhsNested; typedef typename ei_traits::RhsNested RhsNested; @@ -297,7 +281,7 @@ template class ei_sparse_cwise_binary_op_inner_iterator_selector, Lhs, Rhs, Derived, IsDense, IsSparse> { typedef ei_scalar_product_op BinaryFunc; - typedef SparseCwiseBinaryOp CwiseBinaryXpr; + typedef CwiseBinaryOp CwiseBinaryXpr; typedef typename CwiseBinaryXpr::Scalar Scalar; typedef typename ei_traits::_RhsNested _RhsNested; typedef typename _RhsNested::InnerIterator RhsIterator; @@ -337,11 +321,11 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector, template template -EIGEN_STRONG_INLINE const SparseCwiseBinaryOp::Scalar>, +EIGEN_STRONG_INLINE const CwiseBinaryOp::Scalar>, Derived, OtherDerived> SparseMatrixBase::operator-(const SparseMatrixBase &other) const { - return SparseCwiseBinaryOp, + return CwiseBinaryOp, Derived, OtherDerived>(derived(), other.derived()); } @@ -355,10 +339,10 @@ SparseMatrixBase::operator-=(const SparseMatrixBase &othe template template -EIGEN_STRONG_INLINE const SparseCwiseBinaryOp::Scalar>, Derived, OtherDerived> +EIGEN_STRONG_INLINE const CwiseBinaryOp::Scalar>, Derived, OtherDerived> SparseMatrixBase::operator+(const SparseMatrixBase &other) const { - return SparseCwiseBinaryOp, Derived, OtherDerived>(derived(), other.derived()); + return CwiseBinaryOp, Derived, OtherDerived>(derived(), other.derived()); } template @@ -369,21 +353,21 @@ SparseMatrixBase::operator+=(const SparseMatrixBase& othe return *this = derived() + other.derived(); } -template -template -EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE -SparseCwise::operator*(const SparseMatrixBase &other) const -{ - return EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE(_expression(), other.derived()); -} - -template -template -EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE -SparseCwise::operator*(const MatrixBase &other) const -{ - return EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE(_expression(), other.derived()); -} +// template +// template +// EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE +// SparseCwise::operator*(const SparseMatrixBase &other) const +// { +// return EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE(_expression(), other.derived()); +// } +// +// template +// template +// EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE +// SparseCwise::operator*(const MatrixBase &other) const +// { +// return EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE(_expression(), other.derived()); +// } // template // template @@ -401,42 +385,12 @@ SparseCwise::operator*(const MatrixBase &other) co // return EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)(_expression(), other.derived()); // } -template -template -inline ExpressionType& SparseCwise::operator*=(const SparseMatrixBase &other) -{ - return m_matrix.const_cast_derived() = _expression() * other.derived(); -} - // template // template -// inline ExpressionType& SparseCwise::operator/=(const SparseMatrixBase &other) +// inline ExpressionType& SparseCwise::operator*=(const SparseMatrixBase &other) // { -// return m_matrix.const_cast_derived() = *this / other; +// return m_matrix.const_cast_derived() = _expression() * other.derived(); // } -template -template -EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op) -SparseCwise::min(const SparseMatrixBase &other) const -{ - return EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op)(_expression(), other.derived()); -} - -template -template -EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op) -SparseCwise::max(const SparseMatrixBase &other) const -{ - return EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op)(_expression(), other.derived()); -} - -// template -// template -// EIGEN_STRONG_INLINE const CwiseBinaryOp -// SparseMatrixBase::binaryExpr(const SparseMatrixBase &other, const CustomBinaryOp& func) const -// { -// return CwiseBinaryOp(derived(), other.derived(), func); -// } #endif // EIGEN_SPARSE_CWISE_BINARY_OP_H diff --git a/Eigen/src/Sparse/SparseCwiseUnaryOp.h b/Eigen/src/Sparse/SparseCwiseUnaryOp.h index ea9d444ae..9480a39eb 100644 --- a/Eigen/src/Sparse/SparseCwiseUnaryOp.h +++ b/Eigen/src/Sparse/SparseCwiseUnaryOp.h @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // -// Copyright (C) 2008 Gael Guennebaud +// Copyright (C) 2008-2009 Gael Guennebaud // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -39,7 +39,7 @@ // }; template -class CwiseUnaryOpImp +class CwiseUnaryOpImpl : public SparseMatrixBase > { public: @@ -55,12 +55,12 @@ template class CwiseUnaryOpImpl::InnerIterator { typedef typename CwiseUnaryOpImpl::Scalar Scalar; - typedef typename ei_traits::_MatrixTypeNested _MatrixTypeNested; + typedef typename ei_traits::_MatrixTypeNested _MatrixTypeNested; typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator; public: - EIGEN_STRONG_INLINE InnerIterator(const SparseCwiseUnaryOp& unaryOp, int outer) - : m_iter(unaryOp.nestedExpression(),outer), m_functor(unaryOp._functor()) + EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryOpImpl& unaryOp, int outer) + : m_iter(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived()._functor()) {} EIGEN_STRONG_INLINE InnerIterator& operator++() @@ -80,7 +80,7 @@ class CwiseUnaryOpImpl::InnerIterator }; template -class CwiseUnaryOpImp +class CwiseUnaryViewImpl : public SparseMatrixBase > { public: @@ -96,18 +96,19 @@ template class CwiseUnaryViewImpl::InnerIterator { typedef typename CwiseUnaryViewImpl::Scalar Scalar; - typedef typename ei_traits::_MatrixTypeNested _MatrixTypeNested; + typedef typename ei_traits::_MatrixTypeNested _MatrixTypeNested; typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator; public: EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryViewImpl& unaryView, int outer) - : m_iter(unaryView.nestedExpression(),outer), m_functor(unaryView._functor()) + : m_iter(unaryView.derived().nestedExpression(),outer), m_functor(unaryView.derived()._functor()) {} EIGEN_STRONG_INLINE InnerIterator& operator++() { ++m_iter; return *this; } EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_iter.value()); } + EIGEN_STRONG_INLINE Scalar& valueRef() { return m_functor(m_iter.valueRef()); } EIGEN_STRONG_INLINE int index() const { return m_iter.index(); } EIGEN_STRONG_INLINE int row() const { return m_iter.row(); } @@ -117,97 +118,27 @@ class CwiseUnaryViewImpl::InnerIterator protected: MatrixTypeIterator m_iter; - const UnaryOp m_functor; + const ViewOp m_functor; }; - -/* -template -template -EIGEN_STRONG_INLINE const SparseCwiseUnaryOp -SparseMatrixBase::unaryExpr(const CustomUnaryOp& func) const -{ - return SparseCwiseUnaryOp(derived(), func); -} - -template -EIGEN_STRONG_INLINE const SparseCwiseUnaryOp::Scalar>,Derived> -SparseMatrixBase::operator-() const -{ - return derived(); -} - -template -EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs_op) -SparseCwise::abs() const -{ - return _expression(); -} - -template -EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs2_op) -SparseCwise::abs2() const -{ - return _expression(); -} - -template -EIGEN_STRONG_INLINE typename SparseMatrixBase::ConjugateReturnType -SparseMatrixBase::conjugate() const -{ - return ConjugateReturnType(derived()); -} - -template -EIGEN_STRONG_INLINE const typename SparseMatrixBase::RealReturnType -SparseMatrixBase::real() const { return derived(); } - -template -EIGEN_STRONG_INLINE const typename SparseMatrixBase::ImagReturnType -SparseMatrixBase::imag() const { return derived(); } - -template -template -EIGEN_STRONG_INLINE const SparseCwiseUnaryOp::Scalar, NewType>, Derived> -SparseMatrixBase::cast() const -{ - return derived(); -} - -template -EIGEN_STRONG_INLINE const SparseCwiseUnaryOp::Scalar>, Derived> -SparseMatrixBase::operator*(const Scalar& scalar) const -{ - return SparseCwiseUnaryOp, Derived> - (derived(), ei_scalar_multiple_op(scalar)); -} - -template -EIGEN_STRONG_INLINE const SparseCwiseUnaryOp::Scalar>, Derived> -SparseMatrixBase::operator/(const Scalar& scalar) const -{ - return SparseCwiseUnaryOp, Derived> - (derived(), ei_scalar_quotient1_op(scalar)); -} - -template -EIGEN_STRONG_INLINE Derived& -SparseMatrixBase::operator*=(const Scalar& other) -{ - for (int j=0; j -EIGEN_STRONG_INLINE Derived& -SparseMatrixBase::operator/=(const Scalar& other) -{ - for (int j=0; j +// EIGEN_STRONG_INLINE Derived& +// SparseMatrixBase::operator*=(const Scalar& other) +// { +// for (int j=0; j +// EIGEN_STRONG_INLINE Derived& +// SparseMatrixBase::operator/=(const Scalar& other) +// { +// for (int j=0; j class ei_sparse_diagonal_product_inner_iterator_selector - : public SparseCwiseUnaryOp,Rhs>::InnerIterator + : public CwiseUnaryOp,Rhs>::InnerIterator { - typedef typename SparseCwiseUnaryOp,Rhs>::InnerIterator Base; + typedef typename CwiseUnaryOp,Rhs>::InnerIterator Base; public: inline ei_sparse_diagonal_product_inner_iterator_selector( const SparseDiagonalProductType& expr, int outer) @@ -120,12 +120,12 @@ class ei_sparse_diagonal_product_inner_iterator_selector template class ei_sparse_diagonal_product_inner_iterator_selector - : public SparseCwiseBinaryOp< + : public CwiseBinaryOp< ei_scalar_product_op, SparseInnerVectorSet, typename Lhs::DiagonalVectorType>::InnerIterator { - typedef typename SparseCwiseBinaryOp< + typedef typename CwiseBinaryOp< ei_scalar_product_op, SparseInnerVectorSet, typename Lhs::DiagonalVectorType>::InnerIterator Base; @@ -139,9 +139,9 @@ class ei_sparse_diagonal_product_inner_iterator_selector template class ei_sparse_diagonal_product_inner_iterator_selector - : public SparseCwiseUnaryOp,Lhs>::InnerIterator + : public CwiseUnaryOp,Lhs>::InnerIterator { - typedef typename SparseCwiseUnaryOp,Lhs>::InnerIterator Base; + typedef typename CwiseUnaryOp,Lhs>::InnerIterator Base; public: inline ei_sparse_diagonal_product_inner_iterator_selector( const SparseDiagonalProductType& expr, int outer) @@ -152,12 +152,12 @@ class ei_sparse_diagonal_product_inner_iterator_selector template class ei_sparse_diagonal_product_inner_iterator_selector - : public SparseCwiseBinaryOp< + : public CwiseBinaryOp< ei_scalar_product_op, SparseInnerVectorSet, NestByValue > >::InnerIterator { - typedef typename SparseCwiseBinaryOp< + typedef typename CwiseBinaryOp< ei_scalar_product_op, SparseInnerVectorSet, NestByValue > >::InnerIterator Base; diff --git a/Eigen/src/Sparse/SparseExpressionMaker.h b/Eigen/src/Sparse/SparseExpressionMaker.h index 1fdcbb1f2..a0b140685 100644 --- a/Eigen/src/Sparse/SparseExpressionMaker.h +++ b/Eigen/src/Sparse/SparseExpressionMaker.h @@ -21,7 +21,7 @@ // You should have received a copy of the GNU Lesser General Public // License and a copy of the GNU General Public License along with // Eigen. If not, see . - +#if 0 #ifndef EIGEN_SPARSE_EXPRESSIONMAKER_H #define EIGEN_SPARSE_EXPRESSIONMAKER_H @@ -46,3 +46,4 @@ struct MakeCwiseBinaryOp // TODO complete the list #endif // EIGEN_SPARSE_EXPRESSIONMAKER_H +#endif \ No newline at end of file diff --git a/Eigen/src/Sparse/SparseMatrixBase.h b/Eigen/src/Sparse/SparseMatrixBase.h index cc13c329e..6a2618a92 100644 --- a/Eigen/src/Sparse/SparseMatrixBase.h +++ b/Eigen/src/Sparse/SparseMatrixBase.h @@ -45,7 +45,7 @@ template class SparseMatrixBase : public AnyMatrixBase::Scalar Scalar; typedef typename ei_packet_traits::type PacketScalar; -// typedef typename Derived::InnerIterator InnerIterator; + typedef SparseMatrixBase Self; enum { @@ -108,7 +108,7 @@ template class SparseMatrixBase : public AnyMatrixBase, Derived> ImagReturnType; /** \internal the return type of MatrixBase::adjoint() */ typedef typename ei_meta_if::IsComplex, - SparseCwiseUnaryOp, SparseNestByValue > >, + CwiseUnaryOp, SparseNestByValue > >, Transpose >::ret AdjointReturnType; @@ -127,6 +127,9 @@ template class SparseMatrixBase : public AnyMatrixBase::ret CoeffReturnType; + /** \internal Represents a matrix with all coefficients equal to one another*/ + typedef CwiseNullaryOp,Matrix > ConstantReturnType; + /** type of the equivalent square matrix */ typedef Matrix SquareMatrixType; @@ -289,11 +292,11 @@ template class SparseMatrixBase : public AnyMatrixBase::Scalar>,Derived> operator-() const; template - const SparseCwiseBinaryOp::Scalar>, Derived, OtherDerived> + const CwiseBinaryOp::Scalar>, Derived, OtherDerived> operator+(const SparseMatrixBase &other) const; template - const SparseCwiseBinaryOp::Scalar>, Derived, OtherDerived> + const CwiseBinaryOp::Scalar>, Derived, OtherDerived> operator-(const SparseMatrixBase &other) const; template @@ -517,8 +520,8 @@ template class SparseMatrixBase : public AnyMatrixBase - const SparseCwiseUnaryOp::Scalar, NewType>, Derived> cast() const; +// template +// const SparseCwiseUnaryOp::Scalar, NewType>, Derived> cast() const; /** \returns the matrix or vector obtained by evaluating this expression. * diff --git a/Eigen/src/Sparse/SparseUtil.h b/Eigen/src/Sparse/SparseUtil.h index 5ae3ebc7a..d3a9862a2 100644 --- a/Eigen/src/Sparse/SparseUtil.h +++ b/Eigen/src/Sparse/SparseUtil.h @@ -123,11 +123,7 @@ template class SparseVector; template class MappedSparseMatrix; template class SparseNestByValue; -// template class SparseTranspose; template class SparseInnerVectorSet; -template class SparseCwise; -template class SparseCwiseUnaryOp; -template class SparseCwiseBinaryOp; template class SparseFlagged; template class SparseTriangular;