mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-20 08:39:37 +08:00
fix += return by value like operations
This commit is contained in:
parent
62eb4dc99b
commit
9bb75937cc
@ -216,7 +216,7 @@ EIGEN_STRONG_INLINE Derived &
|
|||||||
MatrixBase<Derived>::operator-=(const MatrixBase<OtherDerived> &other)
|
MatrixBase<Derived>::operator-=(const MatrixBase<OtherDerived> &other)
|
||||||
{
|
{
|
||||||
SelfCwiseBinaryOp<ei_scalar_difference_op<Scalar>, Derived, OtherDerived> tmp(derived());
|
SelfCwiseBinaryOp<ei_scalar_difference_op<Scalar>, Derived, OtherDerived> tmp(derived());
|
||||||
tmp = other;
|
tmp = other.derived();
|
||||||
return derived();
|
return derived();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,9 @@ class NoAlias
|
|||||||
{
|
{
|
||||||
typedef SelfCwiseBinaryOp<ei_scalar_sum_op<Scalar>, ExpressionType, OtherDerived> SelfAdder;
|
typedef SelfCwiseBinaryOp<ei_scalar_sum_op<Scalar>, ExpressionType, OtherDerived> SelfAdder;
|
||||||
SelfAdder tmp(m_expression);
|
SelfAdder tmp(m_expression);
|
||||||
ei_assign_selector<SelfAdder,OtherDerived,false>::run(tmp,other.derived());
|
typedef typename ei_nested<OtherDerived>::type OtherDerivedNested;
|
||||||
|
typedef typename ei_cleantype<OtherDerivedNested>::type _OtherDerivedNested;
|
||||||
|
ei_assign_selector<SelfAdder,_OtherDerivedNested,false>::run(tmp,OtherDerivedNested(other.derived()));
|
||||||
return m_expression;
|
return m_expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +71,9 @@ class NoAlias
|
|||||||
{
|
{
|
||||||
typedef SelfCwiseBinaryOp<ei_scalar_difference_op<Scalar>, ExpressionType, OtherDerived> SelfAdder;
|
typedef SelfCwiseBinaryOp<ei_scalar_difference_op<Scalar>, ExpressionType, OtherDerived> SelfAdder;
|
||||||
SelfAdder tmp(m_expression);
|
SelfAdder tmp(m_expression);
|
||||||
ei_assign_selector<SelfAdder,OtherDerived,false>::run(tmp,other.derived());
|
typedef typename ei_nested<OtherDerived>::type OtherDerivedNested;
|
||||||
|
typedef typename ei_cleantype<OtherDerivedNested>::type _OtherDerivedNested;
|
||||||
|
ei_assign_selector<SelfAdder,_OtherDerivedNested,false>::run(tmp,OtherDerivedNested(other.derived()));
|
||||||
return m_expression;
|
return m_expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,8 +62,6 @@ template<typename BinaryOp, typename Lhs, typename Rhs> class SelfCwiseBinaryOp
|
|||||||
|
|
||||||
typedef typename ei_packet_traits<Scalar>::type Packet;
|
typedef typename ei_packet_traits<Scalar>::type Packet;
|
||||||
|
|
||||||
using Base::operator=;
|
|
||||||
|
|
||||||
inline SelfCwiseBinaryOp(Lhs& xpr, const BinaryOp& func = BinaryOp()) : m_matrix(xpr), m_functor(func) {}
|
inline SelfCwiseBinaryOp(Lhs& xpr, const BinaryOp& func = BinaryOp()) : m_matrix(xpr), m_functor(func) {}
|
||||||
|
|
||||||
inline Index rows() const { return m_matrix.rows(); }
|
inline Index rows() const { return m_matrix.rows(); }
|
||||||
@ -143,6 +141,15 @@ template<typename BinaryOp, typename Lhs, typename Rhs> class SelfCwiseBinaryOp
|
|||||||
return *this;
|
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<Rhs>::type rhs(_rhs);
|
||||||
|
return Base::operator=(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Lhs& m_matrix;
|
Lhs& m_matrix;
|
||||||
const BinaryOp& m_functor;
|
const BinaryOp& m_functor;
|
||||||
|
@ -168,6 +168,21 @@ template<typename MatrixType> 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<Lower>().llt().solve(matB);
|
||||||
|
VERIFY_IS_APPROX(m2, m1 + symmLo.template selfadjointView<Lower>().llt().solve(matB));
|
||||||
|
m2 = m1;
|
||||||
|
m2 -= symmLo.template selfadjointView<Lower>().llt().solve(matB);
|
||||||
|
VERIFY_IS_APPROX(m2, m1 - symmLo.template selfadjointView<Lower>().llt().solve(matB));
|
||||||
|
m2 = m1;
|
||||||
|
m2.noalias() += symmLo.template selfadjointView<Lower>().llt().solve(matB);
|
||||||
|
VERIFY_IS_APPROX(m2, m1 + symmLo.template selfadjointView<Lower>().llt().solve(matB));
|
||||||
|
m2 = m1;
|
||||||
|
m2.noalias() -= symmLo.template selfadjointView<Lower>().llt().solve(matB);
|
||||||
|
VERIFY_IS_APPROX(m2, m1 - symmLo.template selfadjointView<Lower>().llt().solve(matB));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename MatrixType> void cholesky_cplx(const MatrixType& m)
|
template<typename MatrixType> void cholesky_cplx(const MatrixType& m)
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
template<typename MatrixType> void linearStructure(const MatrixType& m)
|
template<typename MatrixType> void linearStructure(const MatrixType& m)
|
||||||
{
|
{
|
||||||
/* this test covers the following files:
|
/* 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::Index Index;
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user