numerics 0.1.0
Loading...
Searching...
No Matches
gmres.cpp
Go to the documentation of this file.
3#include "operator/dense.hpp"
4#include <stdexcept>
5
6namespace num {
7
8// Sparse overload
10 const Vector& b,
11 Vector& x,
12 real tol,
13 idx max_iter,
14 idx restart) {
15 if (A.n_rows() != A.n_cols())
16 throw std::invalid_argument("GMRES requires a square matrix");
18 return gmres(op, b, x, tol, max_iter, restart);
19}
20
21// Dense overload -- wraps the matrix-free core with a backend-parameterized
22// matvec
24 const Vector& b,
25 Vector& x,
26 real tol,
27 idx max_iter,
28 idx restart,
29 Backend backend) {
30 if (A.rows() != A.cols())
31 throw std::invalid_argument("GMRES requires a square matrix");
32 operators::DenseOp op(A, backend);
33 return gmres(op, b, x, tol, max_iter, restart);
34}
35
36} // 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:17
idx n_cols() const
Definition sparse.hpp:36
idx n_rows() const
Definition sparse.hpp:35
Restarted GMRES for general linear systems.
double real
Definition types.hpp:10
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 gmres.hpp:25
Backend
Definition policy.hpp:7
std::size_t idx
Definition types.hpp:11
Dense Matrix adapter for the operator protocol.
SparseMatrix adapter for the operator protocol.
Adapt a dense Matrix to the operator protocol.
Definition dense.hpp:12
Adapt a SparseMatrix to the operator protocol.
Definition sparse_op.hpp:15