aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sparse_ref.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2015-10-21 09:47:43 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2015-10-21 09:47:43 +0200
commit896126588997f89d647ec857a4dd832e462a013b (patch)
treefe93f7da5bca5c1d41d0f0fff6208df530f27c25 /test/sparse_ref.cpp
parentfe630c98739186c1dd3faf7a06b52a64baa5ea23 (diff)
bug #1064: add support for Ref<SparseVector>
Diffstat (limited to 'test/sparse_ref.cpp')
-rw-r--r--test/sparse_ref.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/test/sparse_ref.cpp b/test/sparse_ref.cpp
index d2d475616..f4aefbb48 100644
--- a/test/sparse_ref.cpp
+++ b/test/sparse_ref.cpp
@@ -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>()) );
}
}