From 1c137496c62e7ca2d6c1aab0befc7617e4f82a13 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sun, 24 Feb 2013 20:36:54 +0100 Subject: Extend sparseqr unit test to check linearly dependent columns --- test/sparseqr.cpp | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'test/sparseqr.cpp') diff --git a/test/sparseqr.cpp b/test/sparseqr.cpp index d34f7c48d..0a5cd5369 100644 --- a/test/sparseqr.cpp +++ b/test/sparseqr.cpp @@ -22,15 +22,25 @@ int generate_sparse_rectangular_problem(MatrixType& A, DenseMat& dA, int maxRows dA.resize(rows,rows); initSparse(density, dA, A,ForceNonZeroDiag); A.makeCompressed(); + int nop = internal::random(0, internal::random(0,1) > 0.5 ? cols/2 : 0); + for(int k=0; k(0,cols-1); + int j1 = internal::random(0,cols-1); + Scalar s = internal::random(); + A.col(j0) = s * A.col(j1); + dA.col(j0) = s * dA.col(j1); + } return rows; } template void test_sparseqr_scalar() { typedef SparseMatrix MatrixType; - MatrixType A; - Matrix dA; + typedef Matrix DenseMat; typedef Matrix DenseVector; + MatrixType A; + DenseMat dA; DenseVector refX,x,b; SparseQR > solver; generate_sparse_rectangular_problem(A,dA); @@ -50,13 +60,23 @@ template void test_sparseqr_scalar() std::cerr << "sparse QR factorization failed\n"; exit(0); return; - } + } //Compare with a dense QR solver - refX = dA.colPivHouseholderQr().solve(b); - VERIFY(x.isApprox(refX,test_precision())); + ColPivHouseholderQR dqr(dA); + refX = dqr.solve(b); + + VERIFY_IS_EQUAL(dqr.rank(), solver.rank()); + + if(solver.rank() (A * x - b).norm() ); + else + VERIFY_IS_APPROX(x, refX); } void test_sparseqr() { - CALL_SUBTEST_1(test_sparseqr_scalar()); - CALL_SUBTEST_2(test_sparseqr_scalar >()); + for(int i=0; i()); + CALL_SUBTEST_2(test_sparseqr_scalar >()); + } } \ No newline at end of file -- cgit v1.2.3