diff options
author | Gael Guennebaud <g.gael@free.fr> | 2014-10-20 16:46:47 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2014-10-20 16:46:47 +0200 |
commit | a303b6a733509db8c533e94e7a903ad7d28fef8d (patch) | |
tree | a916f101c06e4d4c999e274e5a3d322c90480bcc /test/sparse_solver.h | |
parent | fe57b2f963da832d14f4d7b6d4a9554ceef26e36 (diff) |
bug #670: add unit test for mapped input in sparse solver.
Diffstat (limited to 'test/sparse_solver.h')
-rw-r--r-- | test/sparse_solver.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/test/sparse_solver.h b/test/sparse_solver.h index b10eaebcc..ee350d561 100644 --- a/test/sparse_solver.h +++ b/test/sparse_solver.h @@ -15,6 +15,7 @@ void check_sparse_solving(Solver& solver, const typename Solver::MatrixType& A, { typedef typename Solver::MatrixType Mat; typedef typename Mat::Scalar Scalar; + typedef typename Mat::Index Index; DenseRhs refX = dA.lu().solve(db); { @@ -35,8 +36,8 @@ void check_sparse_solving(Solver& solver, const typename Solver::MatrixType& A, return; } VERIFY(oldb.isApprox(b) && "sparse solver testing: the rhs should not be modified!"); - VERIFY(x.isApprox(refX,test_precision<Scalar>())); + x.setZero(); // test the analyze/factorize API solver.analyzePattern(A); @@ -54,8 +55,31 @@ void check_sparse_solving(Solver& solver, const typename Solver::MatrixType& A, return; } VERIFY(oldb.isApprox(b) && "sparse solver testing: the rhs should not be modified!"); - VERIFY(x.isApprox(refX,test_precision<Scalar>())); + + + x.setZero(); + // test with Map + MappedSparseMatrix<Scalar,Mat::Options,Index> Am(A.rows(), A.cols(), A.nonZeros(), const_cast<Index*>(A.outerIndexPtr()), const_cast<Index*>(A.innerIndexPtr()), const_cast<Scalar*>(A.valuePtr())); + solver.compute(Am); + if (solver.info() != Success) + { + std::cerr << "sparse solver testing: factorization failed (check_sparse_solving)\n"; + exit(0); + return; + } + DenseRhs dx(refX); + dx.setZero(); + Map<DenseRhs> xm(dx.data(), dx.rows(), dx.cols()); + Map<const DenseRhs> bm(db.data(), db.rows(), db.cols()); + xm = solver.solve(bm); + if (solver.info() != Success) + { + std::cerr << "sparse solver testing: solving failed\n"; + return; + } + VERIFY(oldb.isApprox(bm) && "sparse solver testing: the rhs should not be modified!"); + VERIFY(xm.isApprox(refX,test_precision<Scalar>())); } // test dense Block as the result and rhs: |