num::cg¶
Defined in header <linear/solvers/cg.hpp>
template <std::floating_point T, class MatVec>
krylov_result<T> cg(MatVec &&A, T *x, const T *b, idx n, T *work, T tol = T(1e-10),
idx max_iter = 1000); // (1)
template <class Op, class V>
requires math::inner_product_space<V> && math::spd_operator<Op, V> &&
std::floating_point<math::scalar_t<V>>
solver_result cg(const Op &A, const V &b, V &x, cg_options options = {}); // (2)
(1) Solve a symmetric positive definite system by conjugate gradients, on raw pointers: \(A x = b\). A(x, y) writes \(y = A x\); work holds \(3n\). Stops if \(p^T A p \le 0\).
(2) Solve a symmetric positive definite system by conjugate gradients: \(A x = b\). x is the initial guess.
Exceptions¶
std::invalid_argument: If dimensions mismatch.