Add unit test for solveWithGuess, and fix template resolution.

This commit is contained in:
Gael Guennebaud 2016-07-04 17:19:38 +02:00
parent 7f7839c12f
commit fbcfc2f862
2 changed files with 24 additions and 2 deletions

View File

@ -81,7 +81,8 @@ struct evaluator<SolveWithGuess<Decomposition,RhsType, GuessType> >
: m_result(solve.rows(), solve.cols()) : m_result(solve.rows(), solve.cols())
{ {
::new (static_cast<Base*>(this)) Base(m_result); ::new (static_cast<Base*>(this)) Base(m_result);
solve.dec()._solve_with_guess_impl(solve.rhs(), m_result, solve().guess()); m_result = solve.guess();
solve.dec()._solve_with_guess_impl(solve.rhs(), m_result);
} }
protected: protected:
@ -91,7 +92,7 @@ protected:
// Specialization for "dst = dec.solveWithGuess(rhs)" // Specialization for "dst = dec.solveWithGuess(rhs)"
// NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere // NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere
template<typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar> template<typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar>
struct Assignment<DstXprType, SolveWithGuess<DecType,RhsType,GuessType>, internal::assign_op<Scalar,Scalar>, Dense2Dense, Scalar> struct Assignment<DstXprType, SolveWithGuess<DecType,RhsType,GuessType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
{ {
typedef SolveWithGuess<DecType,RhsType,GuessType> SrcXprType; typedef SolveWithGuess<DecType,RhsType,GuessType> SrcXprType;
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &) static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)

View File

@ -11,6 +11,21 @@
#include <Eigen/SparseCore> #include <Eigen/SparseCore>
#include <sstream> #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) {
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) {
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> 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) void check_sparse_solving(Solver& solver, const typename Solver::MatrixType& A, const Rhs& b, const DenseMat& dA, const DenseRhs& db)
{ {
@ -37,6 +52,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(oldb.isApprox(b) && "sparse solver testing: the rhs should not be modified!");
VERIFY(x.isApprox(refX,test_precision<Scalar>())); 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(); x.setZero();
// test the analyze/factorize API // test the analyze/factorize API