mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
bug #1064: add support for Ref<SparseVector>
This commit is contained in:
@@ -53,10 +53,14 @@ EIGEN_DONT_INLINE void call_ref_3(const Ref<const SparseMatrix<float>, StandardC
|
||||
VERIFY_IS_EQUAL(a.toDense(),b.toDense());
|
||||
}
|
||||
|
||||
template<typename B>
|
||||
EIGEN_DONT_INLINE void call_ref_4(Ref<SparseVector<float> > a, const B &b) { VERIFY_IS_EQUAL(a.toDense(),b.toDense()); }
|
||||
|
||||
template<typename B>
|
||||
EIGEN_DONT_INLINE void call_ref_5(const Ref<const SparseVector<float> >& a, const B &b) { VERIFY_IS_EQUAL(a.toDense(),b.toDense()); }
|
||||
|
||||
void call_ref()
|
||||
{
|
||||
// SparseVector<std::complex<float> > ca = VectorXcf::Random(10).sparseView();
|
||||
// SparseVector<float> a = VectorXf::Random(10).sparseView();
|
||||
SparseMatrix<float> A = MatrixXf::Random(10,10).sparseView(0.5,1);
|
||||
SparseMatrix<float,RowMajor> B = MatrixXf::Random(10,10).sparseView(0.5,1);
|
||||
SparseMatrix<float> C = MatrixXf::Random(10,10).sparseView(0.5,1);
|
||||
@@ -111,6 +115,15 @@ void call_ref()
|
||||
VERIFY_EVALUATION_COUNT( call_ref_2(vr, vr.transpose()), 0);
|
||||
|
||||
VERIFY_EVALUATION_COUNT( call_ref_2(A.block(1,1,3,3), A.block(1,1,3,3)), 1); // should be 0 (allocate starts/nnz only)
|
||||
|
||||
VERIFY_EVALUATION_COUNT( call_ref_4(vc, vc), 0);
|
||||
VERIFY_EVALUATION_COUNT( call_ref_4(vr, vr.transpose()), 0);
|
||||
VERIFY_EVALUATION_COUNT( call_ref_5(vc, vc), 0);
|
||||
VERIFY_EVALUATION_COUNT( call_ref_5(vr, vr.transpose()), 0);
|
||||
VERIFY_EVALUATION_COUNT( call_ref_4(A.col(2), A.col(2)), 0);
|
||||
VERIFY_EVALUATION_COUNT( call_ref_5(A.col(2), A.col(2)), 0);
|
||||
// VERIFY_EVALUATION_COUNT( call_ref_4(A.row(2), A.row(2).transpose()), 1); // does not compile on purpose
|
||||
VERIFY_EVALUATION_COUNT( call_ref_5(A.row(2), A.row(2).transpose()), 1);
|
||||
}
|
||||
|
||||
void test_sparse_ref()
|
||||
@@ -119,5 +132,8 @@ void test_sparse_ref()
|
||||
CALL_SUBTEST_1( check_const_correctness(SparseMatrix<float>()) );
|
||||
CALL_SUBTEST_1( check_const_correctness(SparseMatrix<double,RowMajor>()) );
|
||||
CALL_SUBTEST_2( call_ref() );
|
||||
|
||||
CALL_SUBTEST_3( check_const_correctness(SparseVector<float>()) );
|
||||
CALL_SUBTEST_3( check_const_correctness(SparseVector<double,RowMajor>()) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user