diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index 171140c27..5def0db2a 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -216,7 +216,7 @@ EIGEN_STRONG_INLINE Derived & MatrixBase::operator-=(const MatrixBase &other) { SelfCwiseBinaryOp, Derived, OtherDerived> tmp(derived()); - tmp = other; + tmp = other.derived(); return derived(); } diff --git a/Eigen/src/Core/NoAlias.h b/Eigen/src/Core/NoAlias.h index 03198879f..53ad3bfee 100644 --- a/Eigen/src/Core/NoAlias.h +++ b/Eigen/src/Core/NoAlias.h @@ -59,7 +59,9 @@ class NoAlias { typedef SelfCwiseBinaryOp, ExpressionType, OtherDerived> SelfAdder; SelfAdder tmp(m_expression); - ei_assign_selector::run(tmp,other.derived()); + typedef typename ei_nested::type OtherDerivedNested; + typedef typename ei_cleantype::type _OtherDerivedNested; + ei_assign_selector::run(tmp,OtherDerivedNested(other.derived())); return m_expression; } @@ -69,7 +71,9 @@ class NoAlias { typedef SelfCwiseBinaryOp, ExpressionType, OtherDerived> SelfAdder; SelfAdder tmp(m_expression); - ei_assign_selector::run(tmp,other.derived()); + typedef typename ei_nested::type OtherDerivedNested; + typedef typename ei_cleantype::type _OtherDerivedNested; + ei_assign_selector::run(tmp,OtherDerivedNested(other.derived())); return m_expression; } diff --git a/Eigen/src/Core/SelfCwiseBinaryOp.h b/Eigen/src/Core/SelfCwiseBinaryOp.h index 5100f6b25..f77589747 100644 --- a/Eigen/src/Core/SelfCwiseBinaryOp.h +++ b/Eigen/src/Core/SelfCwiseBinaryOp.h @@ -62,8 +62,6 @@ template class SelfCwiseBinaryOp typedef typename ei_packet_traits::type Packet; - using Base::operator=; - inline SelfCwiseBinaryOp(Lhs& xpr, const BinaryOp& func = BinaryOp()) : m_matrix(xpr), m_functor(func) {} inline Index rows() const { return m_matrix.rows(); } @@ -142,6 +140,15 @@ template class SelfCwiseBinaryOp #endif return *this; } + + // overloaded to honor evaluation of special matrices + // maybe another solution would be to not use SelfCwiseBinaryOp + // at first... + SelfCwiseBinaryOp& operator=(const Rhs& _rhs) + { + typename ei_nested::type rhs(_rhs); + return Base::operator=(rhs); + } protected: Lhs& m_matrix; diff --git a/test/cholesky.cpp b/test/cholesky.cpp index 0edf9a793..46140bb11 100644 --- a/test/cholesky.cpp +++ b/test/cholesky.cpp @@ -168,6 +168,21 @@ template void cholesky(const MatrixType& m) } } + // test some special use cases of SelfCwiseBinaryOp: + MatrixType m1 = MatrixType::Random(rows,cols), m2(rows,cols); + m2 = m1; + m2 += symmLo.template selfadjointView().llt().solve(matB); + VERIFY_IS_APPROX(m2, m1 + symmLo.template selfadjointView().llt().solve(matB)); + m2 = m1; + m2 -= symmLo.template selfadjointView().llt().solve(matB); + VERIFY_IS_APPROX(m2, m1 - symmLo.template selfadjointView().llt().solve(matB)); + m2 = m1; + m2.noalias() += symmLo.template selfadjointView().llt().solve(matB); + VERIFY_IS_APPROX(m2, m1 + symmLo.template selfadjointView().llt().solve(matB)); + m2 = m1; + m2.noalias() -= symmLo.template selfadjointView().llt().solve(matB); + VERIFY_IS_APPROX(m2, m1 - symmLo.template selfadjointView().llt().solve(matB)); + } template void cholesky_cplx(const MatrixType& m) diff --git a/test/linearstructure.cpp b/test/linearstructure.cpp index a0b8982dd..b5c58bdaa 100644 --- a/test/linearstructure.cpp +++ b/test/linearstructure.cpp @@ -27,7 +27,7 @@ template void linearStructure(const MatrixType& m) { /* this test covers the following files: - Sum.h Difference.h Opposite.h ScalarMultiple.h + CwiseUnaryOp.h, CwiseBinaryOp.h, SelfCwiseBinaryOp.h */ typedef typename MatrixType::Index Index; typedef typename MatrixType::Scalar Scalar;