solverbase.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef TEST_SOLVERBASE_H
  2. #define TEST_SOLVERBASE_H
  3. template<typename DstType, typename RhsType, typename MatrixType, typename SolverType>
  4. void check_solverbase(const MatrixType& matrix, const SolverType& solver, Index rows, Index cols, Index cols2)
  5. {
  6. // solve
  7. DstType m2 = DstType::Random(cols,cols2);
  8. RhsType m3 = matrix*m2;
  9. DstType solver_solution = DstType::Random(cols,cols2);
  10. solver._solve_impl(m3, solver_solution);
  11. VERIFY_IS_APPROX(m3, matrix*solver_solution);
  12. solver_solution = DstType::Random(cols,cols2);
  13. solver_solution = solver.solve(m3);
  14. VERIFY_IS_APPROX(m3, matrix*solver_solution);
  15. // test solve with transposed
  16. m3 = RhsType::Random(rows,cols2);
  17. m2 = matrix.transpose()*m3;
  18. RhsType solver_solution2 = RhsType::Random(rows,cols2);
  19. solver.template _solve_impl_transposed<false>(m2, solver_solution2);
  20. VERIFY_IS_APPROX(m2, matrix.transpose()*solver_solution2);
  21. solver_solution2 = RhsType::Random(rows,cols2);
  22. solver_solution2 = solver.transpose().solve(m2);
  23. VERIFY_IS_APPROX(m2, matrix.transpose()*solver_solution2);
  24. // test solve with conjugate transposed
  25. m3 = RhsType::Random(rows,cols2);
  26. m2 = matrix.adjoint()*m3;
  27. solver_solution2 = RhsType::Random(rows,cols2);
  28. solver.template _solve_impl_transposed<true>(m2, solver_solution2);
  29. VERIFY_IS_APPROX(m2, matrix.adjoint()*solver_solution2);
  30. solver_solution2 = RhsType::Random(rows,cols2);
  31. solver_solution2 = solver.adjoint().solve(m2);
  32. VERIFY_IS_APPROX(m2, matrix.adjoint()*solver_solution2);
  33. }
  34. #endif // TEST_SOLVERBASE_H