diff options
Diffstat (limited to 'test/sparse_solver.h')
-rw-r--r-- | test/sparse_solver.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/sparse_solver.h b/test/sparse_solver.h index b67653496..fd6199f3e 100644 --- a/test/sparse_solver.h +++ b/test/sparse_solver.h @@ -11,6 +11,33 @@ #include <Eigen/SparseCore> #include <sstream> +template<typename Solver, typename Rhs, typename Guess,typename Result> +void solve_with_guess(IterativeSolverBase<Solver>& solver, const MatrixBase<Rhs>& b, const Guess& g, Result &x) { + if(internal::random<bool>()) + { + // With a temporary through evaluator<SolveWithGuess> + x = solver.derived().solveWithGuess(b,g) + Result::Zero(x.rows(), x.cols()); + } + else + { + // direct evaluation within x through Assignment<Result,SolveWithGuess> + x = solver.derived().solveWithGuess(b.derived(),g); + } +} + +template<typename Solver, typename Rhs, typename Guess,typename Result> +void solve_with_guess(SparseSolverBase<Solver>& solver, const MatrixBase<Rhs>& b, const Guess& , Result& x) { + if(internal::random<bool>()) + x = solver.derived().solve(b) + Result::Zero(x.rows(), x.cols()); + else + x = solver.derived().solve(b); +} + +template<typename Solver, typename Rhs, typename Guess,typename Result> +void solve_with_guess(SparseSolverBase<Solver>& solver, const SparseMatrixBase<Rhs>& b, const Guess& , Result& x) { + x = solver.derived().solve(b); +} + template<typename Solver, typename Rhs, typename DenseMat, typename DenseRhs> void check_sparse_solving(Solver& solver, const typename Solver::MatrixType& A, const Rhs& b, const DenseMat& dA, const DenseRhs& db) { @@ -37,6 +64,12 @@ void check_sparse_solving(Solver& solver, const typename Solver::MatrixType& A, } VERIFY(oldb.isApprox(b) && "sparse solver testing: the rhs should not be modified!"); VERIFY(x.isApprox(refX,test_precision<Scalar>())); + + x.setZero(); + solve_with_guess(solver, b, x, x); + VERIFY(solver.info() == Success && "solving failed when using analyzePattern/factorize API"); + 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 |