mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-19 08:09:36 +08:00
bug #1384: fix evaluation of "sparse/scalar" that used the wrong evaluation path.
This commit is contained in:
parent
d024e9942d
commit
c86911ac73
@ -357,6 +357,16 @@ struct binary_evaluator<CwiseBinaryOp<scalar_product_op<T1,T2>, Lhs, Rhs>, Itera
|
||||
explicit binary_evaluator(const XprType& xpr) : Base(xpr) {}
|
||||
};
|
||||
|
||||
// "sparse ./ dense"
|
||||
template<typename T1, typename T2, typename Lhs, typename Rhs>
|
||||
struct binary_evaluator<CwiseBinaryOp<scalar_quotient_op<T1,T2>, Lhs, Rhs>, IteratorBased, IndexBased>
|
||||
: sparse_conjunction_evaluator<CwiseBinaryOp<scalar_quotient_op<T1,T2>, Lhs, Rhs> >
|
||||
{
|
||||
typedef CwiseBinaryOp<scalar_quotient_op<T1,T2>, Lhs, Rhs> XprType;
|
||||
typedef sparse_conjunction_evaluator<XprType> Base;
|
||||
explicit binary_evaluator(const XprType& xpr) : Base(xpr) {}
|
||||
};
|
||||
|
||||
// "sparse && sparse"
|
||||
template<typename Lhs, typename Rhs>
|
||||
struct binary_evaluator<CwiseBinaryOp<scalar_boolean_and_op, Lhs, Rhs>, IteratorBased, IteratorBased>
|
||||
|
@ -161,11 +161,15 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
if(internal::random<bool>())
|
||||
m1.makeCompressed();
|
||||
|
||||
Index m1_nnz = m1.nonZeros();
|
||||
|
||||
VERIFY_IS_APPROX(m1*s1, refM1*s1);
|
||||
VERIFY_IS_APPROX(m1+m2, refM1+refM2);
|
||||
VERIFY_IS_APPROX(m1+m2+m3, refM1+refM2+refM3);
|
||||
VERIFY_IS_APPROX(m3.cwiseProduct(m1+m2), refM3.cwiseProduct(refM1+refM2));
|
||||
VERIFY_IS_APPROX(m1*s1-m2, refM1*s1-refM2);
|
||||
VERIFY_IS_APPROX(m4=m1/s1, refM1/s1);
|
||||
VERIFY_IS_EQUAL(m4.nonZeros(), m1_nnz);
|
||||
|
||||
if(SparseMatrixType::IsRowMajor)
|
||||
VERIFY_IS_APPROX(m1.innerVector(0).dot(refM2.row(0)), refM1.row(0).dot(refM2.row(0)));
|
||||
@ -208,8 +212,12 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
|
||||
VERIFY_IS_APPROX(m1.sum(), refM1.sum());
|
||||
|
||||
m4 = m1; refM4 = m4;
|
||||
|
||||
VERIFY_IS_APPROX(m1*=s1, refM1*=s1);
|
||||
VERIFY_IS_EQUAL(m1.nonZeros(), m1_nnz);
|
||||
VERIFY_IS_APPROX(m1/=s1, refM1/=s1);
|
||||
VERIFY_IS_EQUAL(m1.nonZeros(), m1_nnz);
|
||||
|
||||
VERIFY_IS_APPROX(m1+=m2, refM1+=refM2);
|
||||
VERIFY_IS_APPROX(m1-=m2, refM1-=refM2);
|
||||
@ -220,13 +228,22 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
VERIFY_RAISES_ASSERT( m1 -= m1.innerVector(0) );
|
||||
VERIFY_RAISES_ASSERT( refM1 -= m1.innerVector(0) );
|
||||
VERIFY_RAISES_ASSERT( refM1 += m1.innerVector(0) );
|
||||
m1 = m4; refM1 = refM4;
|
||||
}
|
||||
|
||||
// test aliasing
|
||||
VERIFY_IS_APPROX((m1 = -m1), (refM1 = -refM1));
|
||||
VERIFY_IS_EQUAL(m1.nonZeros(), m1_nnz);
|
||||
m1 = m4; refM1 = refM4;
|
||||
VERIFY_IS_APPROX((m1 = m1.transpose()), (refM1 = refM1.transpose().eval()));
|
||||
VERIFY_IS_EQUAL(m1.nonZeros(), m1_nnz);
|
||||
m1 = m4; refM1 = refM4;
|
||||
VERIFY_IS_APPROX((m1 = -m1.transpose()), (refM1 = -refM1.transpose().eval()));
|
||||
VERIFY_IS_EQUAL(m1.nonZeros(), m1_nnz);
|
||||
m1 = m4; refM1 = refM4;
|
||||
VERIFY_IS_APPROX((m1 += -m1), (refM1 += -refM1));
|
||||
VERIFY_IS_EQUAL(m1.nonZeros(), m1_nnz);
|
||||
m1 = m4; refM1 = refM4;
|
||||
|
||||
if(m1.isCompressed())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user