diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index 03011800c..e5a91ca04 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -56,13 +56,17 @@ struct ei_traits > }; }; +template +class CwiseUnaryOpImpl; + template class CwiseUnaryOp : ei_no_assignment_operator, - public MatrixBase > + public CwiseUnaryOpImpl::StorageType> { public: - EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp) + typedef typename CwiseUnaryOpImpl::StorageType>::Base Base; + EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(CwiseUnaryOp) inline CwiseUnaryOp(const MatrixType& mat, const UnaryOp& func = UnaryOp()) : m_matrix(mat), m_functor(func) {} @@ -70,28 +74,6 @@ class CwiseUnaryOp : ei_no_assignment_operator, EIGEN_STRONG_INLINE int rows() const { return m_matrix.rows(); } EIGEN_STRONG_INLINE int cols() const { return m_matrix.cols(); } - EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const - { - return m_functor(m_matrix.coeff(row, col)); - } - - template - EIGEN_STRONG_INLINE PacketScalar packet(int row, int col) const - { - return m_functor.packetOp(m_matrix.template packet(row, col)); - } - - EIGEN_STRONG_INLINE const Scalar coeff(int index) const - { - return m_functor(m_matrix.coeff(index)); - } - - template - EIGEN_STRONG_INLINE PacketScalar packet(int index) const - { - return m_functor.packetOp(m_matrix.template packet(index)); - } - /** \internal used for introspection */ const UnaryOp& _functor() const { return m_functor; } @@ -99,38 +81,52 @@ class CwiseUnaryOp : ei_no_assignment_operator, 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; const UnaryOp m_functor; }; -/** \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 -template -EIGEN_STRONG_INLINE const CwiseUnaryOp -MatrixBase::unaryExpr(const CustomUnaryOp& func) const +template +class CwiseUnaryOpImpl : public MatrixBase > { - return CwiseUnaryOp(derived(), func); -} + const typename ei_cleantype::type& matrix() const + { return derived().nestedExpression(); } + typename ei_cleantype::type& matrix() + { return derived().nestedExpression(); } -/** \returns an expression of the opposite of \c *this - */ -template -EIGEN_STRONG_INLINE const CwiseUnaryOp::Scalar>,Derived> -MatrixBase::operator-() const -{ - return derived(); -} + public: + + typedef CwiseUnaryOp Derived; + EIGEN_DENSE_PUBLIC_INTERFACE( Derived ) + + EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const + { + return derived()._functor()(matrix().coeff(row, col)); + } + + template + EIGEN_STRONG_INLINE PacketScalar packet(int row, int col) const + { + return derived()._functor().packetOp(matrix().template packet(row, col)); + } + + EIGEN_STRONG_INLINE const Scalar coeff(int index) const + { + return derived()._functor()(matrix().coeff(index)); + } + + template + EIGEN_STRONG_INLINE PacketScalar packet(int index) const + { + return derived()._functor().packetOp(matrix().template packet(index)); + } +}; /** \returns an expression of the coefficient-wise absolute value of \c *this * @@ -160,49 +156,6 @@ Cwise::abs2() const return _expression(); } -/** \returns an expression of the complex conjugate of \c *this. - * - * \sa adjoint() */ -template -EIGEN_STRONG_INLINE typename MatrixBase::ConjugateReturnType -MatrixBase::conjugate() const -{ - return ConjugateReturnType(derived()); -} - -/** \returns a read-only expression of the real part of \c *this. - * - * \sa imag() */ -template -EIGEN_STRONG_INLINE typename MatrixBase::RealReturnType -MatrixBase::real() const { return derived(); } - -/** \returns an read-only expression of the imaginary part of \c *this. - * - * \sa real() */ -template -EIGEN_STRONG_INLINE const typename MatrixBase::ImagReturnType -MatrixBase::imag() 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 -template -EIGEN_STRONG_INLINE -typename ei_cast_return_type< - Derived, - const CwiseUnaryOp::Scalar, NewType>, Derived> - >::type -MatrixBase::cast() const -{ - return derived(); -} - /** \returns an expression of the coefficient-wise exponential of *this. * * Example: \include Cwise_exp.cpp @@ -231,47 +184,4 @@ Cwise::log() const return _expression(); } - -/** \returns an expression of \c *this scaled by the scalar factor \a scalar */ -template -EIGEN_STRONG_INLINE const typename MatrixBase::ScalarMultipleReturnType -MatrixBase::operator*(const Scalar& scalar) const -{ - return CwiseUnaryOp, Derived> - (derived(), ei_scalar_multiple_op(scalar)); -} - -/** Overloaded for efficient real matrix times complex scalar value */ -template -EIGEN_STRONG_INLINE const CwiseUnaryOp::Scalar, - std::complex::Scalar> >, Derived> -MatrixBase::operator*(const std::complex& scalar) const -{ - return CwiseUnaryOp >, Derived> - (*static_cast(this), ei_scalar_multiple2_op >(scalar)); -} - -/** \returns an expression of \c *this divided by the scalar value \a scalar */ -template -EIGEN_STRONG_INLINE const CwiseUnaryOp::Scalar>, Derived> -MatrixBase::operator/(const Scalar& scalar) const -{ - return CwiseUnaryOp, Derived> - (derived(), ei_scalar_quotient1_op(scalar)); -} - -template -EIGEN_STRONG_INLINE Derived& -MatrixBase::operator*=(const Scalar& other) -{ - return *this = *this * other; -} - -template -EIGEN_STRONG_INLINE Derived& -MatrixBase::operator/=(const Scalar& other) -{ - return *this = *this / other; -} - #endif // EIGEN_CWISE_UNARY_OP_H diff --git a/Eigen/src/Core/CwiseUnaryOps.h b/Eigen/src/Core/CwiseUnaryOps.h new file mode 100644 index 000000000..205677a6a --- /dev/null +++ b/Eigen/src/Core/CwiseUnaryOps.h @@ -0,0 +1,158 @@ + +#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; +#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(); } + + 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)); + } + + #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)); + } + + /** 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 CwiseUnaryOp >, Derived> + operator*(const std::complex& scalar, const MatrixBase& 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 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 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 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 imaginary part of \c *this. + * + * \sa real() */ + EIGEN_STRONG_INLINE NonConstImagReturnType + imag() { return derived(); } + + const Cwise cwise() const; + Cwise cwise(); diff --git a/Eigen/src/Core/CwiseUnaryView.h b/Eigen/src/Core/CwiseUnaryView.h index 580344379..b21fa56c6 100644 --- a/Eigen/src/Core/CwiseUnaryView.h +++ b/Eigen/src/Core/CwiseUnaryView.h @@ -52,12 +52,17 @@ struct ei_traits > }; }; +template +class CwiseUnaryViewImpl; + template -class CwiseUnaryView : public MatrixBase > +class CwiseUnaryView : ei_no_assignment_operator, + public CwiseUnaryViewImpl::StorageType> { public: - EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView) + typedef typename CwiseUnaryViewImpl::StorageType>::Base Base; + EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(CwiseUnaryView) inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp()) : m_matrix(mat), m_functor(func) {} @@ -67,25 +72,14 @@ class CwiseUnaryView : public MatrixBase > EIGEN_STRONG_INLINE int rows() const { return m_matrix.rows(); } EIGEN_STRONG_INLINE int cols() const { return m_matrix.cols(); } - EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const - { - return m_functor(m_matrix.coeff(row, col)); - } + /** \internal used for introspection */ + const ViewOp& _functor() const { return m_functor; } - EIGEN_STRONG_INLINE const Scalar coeff(int index) const - { - return m_functor(m_matrix.coeff(index)); - } + const typename ei_cleantype::type& + nestedExpression() const { return m_matrix; } - EIGEN_STRONG_INLINE Scalar& coeffRef(int row, int col) - { - return m_functor(m_matrix.const_cast_derived().coeffRef(row, col)); - } - - EIGEN_STRONG_INLINE Scalar& coeffRef(int index) - { - return m_functor(m_matrix.const_cast_derived().coeffRef(index)); - } + typename ei_cleantype::type& + nestedExpression() { return m_matrix.const_cast_derived(); } protected: // FIXME changed from MatrixType::Nested because of a weird compilation error with sun CC @@ -93,37 +87,40 @@ class CwiseUnaryView : public MatrixBase > const ViewOp m_functor; }; -/** \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 -template -EIGEN_STRONG_INLINE const CwiseUnaryView -MatrixBase::unaryViewExpr(const CustomViewOp& func) const +template +class CwiseUnaryViewImpl : public MatrixBase > { - return CwiseUnaryView(derived(), func); -} + const typename ei_cleantype::type& matrix() const + { return derived().nestedExpression(); } + typename ei_cleantype::type& matrix() + { return derived().nestedExpression(); } + + public: + + typedef CwiseUnaryView Derived; + EIGEN_DENSE_PUBLIC_INTERFACE( Derived ) + + EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const + { + return derived()._functor()(matrix().coeff(row, col)); + } + + EIGEN_STRONG_INLINE const Scalar coeff(int index) const + { + return derived()._functor()(matrix().coeff(index)); + } + + EIGEN_STRONG_INLINE Scalar& coeffRef(int row, int col) + { + return derived()._functor()(matrix().const_cast_derived().coeffRef(row, col)); + } + + EIGEN_STRONG_INLINE Scalar& coeffRef(int index) + { + return derived()._functor()(matrix().const_cast_derived().coeffRef(index)); + } +}; -/** \returns a non const expression of the real part of \c *this. - * - * \sa imag() */ -template -EIGEN_STRONG_INLINE typename MatrixBase::NonConstRealReturnType -MatrixBase::real() { return derived(); } -/** \returns a non const expression of the imaginary part of \c *this. - * - * \sa real() */ -template -EIGEN_STRONG_INLINE typename MatrixBase::NonConstImagReturnType -MatrixBase::imag() { return derived(); } #endif // EIGEN_CWISE_UNARY_VIEW_H diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 17fdf10f2..55915d3e1 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -226,29 +226,6 @@ template class MatrixBase /** \internal Represents a matrix with all coefficients equal to one another*/ typedef CwiseNullaryOp,Derived> ConstantReturnType; - /** \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 the return type of MatrixBase::adjoint() */ typedef typename ei_meta_if::IsComplex, CwiseUnaryOp, NestByValue > >, @@ -268,6 +245,7 @@ template class MatrixBase ei_traits::ColsAtCompileTime> BasisReturnType; #endif // not EIGEN_PARSED_BY_DOXYGEN + #include "CwiseUnaryOps.h" /** Copies \a other into *this. \returns a reference to *this. */ template @@ -363,8 +341,6 @@ template class MatrixBase Scalar& w(); - const CwiseUnaryOp::Scalar>,Derived> operator-() const; - template const CwiseBinaryOp::Scalar>, Derived, OtherDerived> operator+(const MatrixBase &other) const; @@ -378,27 +354,6 @@ template class MatrixBase template Derived& operator-=(const MatrixBase& other); - Derived& operator*=(const Scalar& other); - Derived& operator/=(const Scalar& other); - - const ScalarMultipleReturnType operator*(const Scalar& scalar) const; - #ifdef EIGEN_PARSED_BY_DOXYGEN - const ScalarMultipleReturnType operator*(const RealScalar& scalar) const; - #endif - const CwiseUnaryOp::Scalar>, Derived> - operator/(const Scalar& scalar) const; - - const CwiseUnaryOp >, Derived> - operator*(const std::complex& scalar) const; - - inline friend const ScalarMultipleReturnType - operator*(const Scalar& scalar, const MatrixBase& matrix) - { return matrix*scalar; } - - inline friend const CwiseUnaryOp >, Derived> - operator*(const std::complex& scalar, const MatrixBase& matrix) - { return matrix*scalar; } - template const typename ProductReturnType::Type operator*(const MatrixBase &other) const; @@ -592,13 +547,6 @@ template class MatrixBase { return (cwise() != other).any(); } - template - typename ei_cast_return_type< - Derived, - const CwiseUnaryOp::Scalar, NewType>, Derived> - >::type - cast() const; - /** \returns the matrix or vector obtained by evaluating this expression. * * Notice that in the case of a plain matrix or vector (not an expression) this function just returns @@ -626,18 +574,6 @@ template class MatrixBase inline const NestByValue nestByValue() const; - ConjugateReturnType conjugate() const; - RealReturnType real() const; - NonConstRealReturnType real(); - const ImagReturnType imag() const; - NonConstImagReturnType imag(); - - template - const CwiseUnaryOp unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const; - - template - const CwiseUnaryView unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const; - template const CwiseBinaryOp binaryExpr(const MatrixBase &other, const CustomBinaryOp& func = CustomBinaryOp()) const; @@ -671,9 +607,6 @@ template class MatrixBase { return *static_cast(const_cast(this)); } #endif // not EIGEN_PARSED_BY_DOXYGEN - const Cwise cwise() const; - Cwise cwise(); - inline const WithFormat format(const IOFormat& fmt) const; /////////// Array module /////////// diff --git a/Eigen/src/Sparse/SparseCwiseUnaryOp.h b/Eigen/src/Sparse/SparseCwiseUnaryOp.h index 9a73374bd..ea9d444ae 100644 --- a/Eigen/src/Sparse/SparseCwiseUnaryOp.h +++ b/Eigen/src/Sparse/SparseCwiseUnaryOp.h @@ -25,55 +25,42 @@ #ifndef EIGEN_SPARSE_CWISE_UNARY_OP_H #define EIGEN_SPARSE_CWISE_UNARY_OP_H -template -struct ei_traits > : ei_traits -{ - typedef typename ei_result_of< - UnaryOp(typename MatrixType::Scalar) - >::type Scalar; - typedef typename MatrixType::Nested MatrixTypeNested; - typedef typename ei_unref::type _MatrixTypeNested; - enum { - CoeffReadCost = _MatrixTypeNested::CoeffReadCost + ei_functor_traits::Cost - }; -}; +// template +// struct ei_traits > : ei_traits +// { +// typedef typename ei_result_of< +// UnaryOp(typename MatrixType::Scalar) +// >::type Scalar; +// typedef typename MatrixType::Nested MatrixTypeNested; +// typedef typename ei_unref::type _MatrixTypeNested; +// enum { +// CoeffReadCost = _MatrixTypeNested::CoeffReadCost + ei_functor_traits::Cost +// }; +// }; template -class SparseCwiseUnaryOp : ei_no_assignment_operator, - public SparseMatrixBase > +class CwiseUnaryOpImp + : public SparseMatrixBase > { public: class InnerIterator; // typedef typename ei_unref::type _LhsNested; - EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseCwiseUnaryOp) - - inline SparseCwiseUnaryOp(const MatrixType& mat, const UnaryOp& func = UnaryOp()) - : m_matrix(mat), m_functor(func) {} - - EIGEN_STRONG_INLINE int rows() const { return m_matrix.rows(); } - EIGEN_STRONG_INLINE int cols() const { return m_matrix.cols(); } - -// EIGEN_STRONG_INLINE const typename MatrixType::Nested& _matrix() const { return m_matrix; } -// EIGEN_STRONG_INLINE const UnaryOp& _functor() const { return m_functor; } - - protected: - const typename MatrixType::Nested m_matrix; - const UnaryOp m_functor; + typedef CwiseUnaryOp Derived; + EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) }; - template -class SparseCwiseUnaryOp::InnerIterator +class CwiseUnaryOpImpl::InnerIterator { - typedef typename SparseCwiseUnaryOp::Scalar Scalar; - typedef typename ei_traits::_MatrixTypeNested _MatrixTypeNested; + typedef typename CwiseUnaryOpImpl::Scalar Scalar; + typedef typename ei_traits::_MatrixTypeNested _MatrixTypeNested; typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator; public: EIGEN_STRONG_INLINE InnerIterator(const SparseCwiseUnaryOp& unaryOp, int outer) - : m_iter(unaryOp.m_matrix,outer), m_functor(unaryOp.m_functor) + : m_iter(unaryOp.nestedExpression(),outer), m_functor(unaryOp._functor()) {} EIGEN_STRONG_INLINE InnerIterator& operator++() @@ -92,6 +79,49 @@ class SparseCwiseUnaryOp::InnerIterator const UnaryOp m_functor; }; +template +class CwiseUnaryOpImp + : public SparseMatrixBase > +{ + public: + + class InnerIterator; +// typedef typename ei_unref::type _LhsNested; + + typedef CwiseUnaryView Derived; + EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) +}; + +template +class CwiseUnaryViewImpl::InnerIterator +{ + typedef typename CwiseUnaryViewImpl::Scalar Scalar; + 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()) + {} + + EIGEN_STRONG_INLINE InnerIterator& operator++() + { ++m_iter; return *this; } + + EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_iter.value()); } + + EIGEN_STRONG_INLINE int index() const { return m_iter.index(); } + EIGEN_STRONG_INLINE int row() const { return m_iter.row(); } + EIGEN_STRONG_INLINE int col() const { return m_iter.col(); } + + EIGEN_STRONG_INLINE operator bool() const { return m_iter; } + + protected: + MatrixTypeIterator m_iter; + const UnaryOp m_functor; +}; + + +/* template template EIGEN_STRONG_INLINE const SparseCwiseUnaryOp @@ -178,6 +208,6 @@ SparseMatrixBase::operator/=(const Scalar& other) for (typename Derived::InnerIterator i(derived(),j); i; ++i) i.valueRef() /= other; return derived(); -} +}*/ #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H diff --git a/Eigen/src/Sparse/SparseMatrixBase.h b/Eigen/src/Sparse/SparseMatrixBase.h index 043fe07b2..cc13c329e 100644 --- a/Eigen/src/Sparse/SparseMatrixBase.h +++ b/Eigen/src/Sparse/SparseMatrixBase.h @@ -97,21 +97,23 @@ template class SparseMatrixBase : public AnyMatrixBase::IsComplex, - const SparseCwiseUnaryOp, Derived>, - const Derived& - >::ret ConjugateReturnType; - /** \internal the return type of MatrixBase::real() */ - typedef SparseCwiseUnaryOp, Derived> RealReturnType; - /** \internal the return type of MatrixBase::imag() */ - typedef SparseCwiseUnaryOp, Derived> ImagReturnType; + /* \internal the return type of MatrixBase::conjugate() */ +// typedef typename ei_meta_if::IsComplex, +// const SparseCwiseUnaryOp, Derived>, +// const Derived& +// >::ret ConjugateReturnType; + /* \internal the return type of MatrixBase::real() */ +// typedef SparseCwiseUnaryOp, Derived> RealReturnType; + /* \internal the return type of MatrixBase::imag() */ +// typedef SparseCwiseUnaryOp, Derived> ImagReturnType; /** \internal the return type of MatrixBase::adjoint() */ typedef typename ei_meta_if::IsComplex, SparseCwiseUnaryOp, SparseNestByValue > >, Transpose >::ret AdjointReturnType; + #include "../Core/CwiseUnaryOps.h" + #ifndef EIGEN_PARSED_BY_DOXYGEN /** This is the "real scalar" type; if the \a Scalar type is already real numbers * (e.g. int, float or double) then \a RealScalar is just the same as \a Scalar. If @@ -284,7 +286,7 @@ template class SparseMatrixBase : public AnyMatrixBase::Scalar>,Derived> operator-() const; +// const SparseCwiseUnaryOp::Scalar>,Derived> operator-() const; template const SparseCwiseBinaryOp::Scalar>, Derived, OtherDerived> @@ -302,17 +304,17 @@ template class SparseMatrixBase : public AnyMatrixBase // Derived& operator+=(const Flagged, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit>& other); - Derived& operator*=(const Scalar& other); - Derived& operator/=(const Scalar& other); +// Derived& operator*=(const Scalar& other); +// Derived& operator/=(const Scalar& other); - const SparseCwiseUnaryOp::Scalar>, Derived> - operator*(const Scalar& scalar) const; - const SparseCwiseUnaryOp::Scalar>, Derived> - operator/(const Scalar& scalar) const; +// const SparseCwiseUnaryOp::Scalar>, Derived> +// operator*(const Scalar& scalar) const; +// const SparseCwiseUnaryOp::Scalar>, Derived> +// operator/(const Scalar& scalar) const; - inline friend const SparseCwiseUnaryOp::Scalar>, Derived> - operator*(const Scalar& scalar, const SparseMatrixBase& matrix) - { return matrix*scalar; } +// inline friend const SparseCwiseUnaryOp::Scalar>, Derived> +// operator*(const Scalar& scalar, const SparseMatrixBase& matrix) +// { return matrix*scalar; } // sparse * sparse @@ -543,12 +545,12 @@ template class SparseMatrixBase : public AnyMatrixBase nestByValue() const; - ConjugateReturnType conjugate() const; - const RealReturnType real() const; - const ImagReturnType imag() const; +// ConjugateReturnType conjugate() const; +// const RealReturnType real() const; +// const ImagReturnType imag() const; - template - const SparseCwiseUnaryOp unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const; +// template +// const SparseCwiseUnaryOp unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const; // template // const CwiseBinaryOp @@ -572,8 +574,8 @@ template class SparseMatrixBase : public AnyMatrixBase cwise() const; - SparseCwise cwise(); +// const SparseCwise cwise() const; +// SparseCwise cwise(); // inline const WithFormat format(const IOFormat& fmt) const;