numerics 0.1.0
Loading...
Searching...
No Matches
krylov.cpp
Go to the documentation of this file.
3#include <stdexcept>
4
5namespace num {
6
7// Sparse overload
9 const Vector& b,
10 Vector& x,
11 real tol,
12 idx max_iter,
13 idx restart) {
14 if (A.n_rows() != A.n_cols())
15 throw std::invalid_argument("GMRES requires a square matrix");
17 return gmres(op, b, x, tol, max_iter, restart);
18}
19
20// Dense overload -- wraps the matrix-free core with a backend-parameterized
21// matvec
23 const Vector& b,
24 Vector& x,
25 real tol,
26 idx max_iter,
27 idx restart,
28 Backend backend) {
29 if (A.rows() != A.cols())
30 throw std::invalid_argument("GMRES requires a square matrix");
31 operators::DenseOp op(A, backend);
32 return gmres(op, b, x, tol, max_iter, restart);
33}
34
35} // namespace num
constexpr idx rows() const noexcept
Definition matrix.hpp:87
constexpr idx cols() const noexcept
Definition matrix.hpp:88
Sparse matrix in Compressed Sparse Row (CSR) format.
Definition sparse.hpp:15
idx n_cols() const
Definition sparse.hpp:34
idx n_rows() const
Definition sparse.hpp:33
Restarted GMRES for general linear systems.
double real
Definition types.hpp:10
Backend
Definition policy.hpp:7
SolverResult gmres(const Op &A, const Vector &b, Vector &x, real tol=1e-6, idx max_iter=1000, idx restart=30)
Operator GMRES for any adapter.
Definition krylov.hpp:24
std::size_t idx
Definition types.hpp:11
Umbrella include for operator concepts and adapters.
Adapt a dense Matrix to the operator protocol.
Definition dense.hpp:12
Adapt a SparseMatrix to the operator protocol.
Definition sparse.hpp:11