numerics 0.1.0
Loading...
Searching...
No Matches
Operator Examples and Concepts

Linear operators supply the operation

\[ y \leftarrow A x . \]

They are used by CG, GMRES, Lanczos, and exponential-action routines.

Storage Concepts

Storage concepts are defined in include/core/concepts.hpp:

Operator concepts are defined in include/operator/concepts.hpp:

template<class Op, class X = Vector, class Y = Vector>
concept LinearOperator =
VectorLike<X> && MutableVectorLike<Y> &&
requires(const Op& A, const X& x, Y& y) {
{ A.rows() } -> std::convertible_to<idx>;
{ A.cols() } -> std::convertible_to<idx>;
{ A.apply(x, y) };
};

Dense Operator

num::Matrix A(3, 3, 0.0);
fill_spd_matrix(A);
static_assert(num::operators::LinearOperator<decltype(Aop)>);
num::Vector x(3, 0.0);
num::SolverResult info = num::cg(Aop, b, x);
Compile-time contract for y = A*x.
Definition concepts.hpp:19
SolverResult cg(const Matrix &A, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
Definition cg.cpp:8
Adapt a dense Matrix to the operator protocol.
Definition dense.hpp:12

Sparse Operator

n, n, rows, cols, values);
num::SolverResult info = num::gmres(Aop, b, x, 1e-10, 200);
Sparse matrix in Compressed Sparse Row (CSR) format.
Definition sparse.hpp:15
static SparseMatrix from_triplets(idx n_rows, idx n_cols, const std::vector< idx > &rows, const std::vector< idx > &cols, const std::vector< real > &vals)
Build from coordinate (COO / triplet) lists.
Definition sparse.cpp:25
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
Adapt a SparseMatrix to the operator protocol.
Definition sparse.hpp:11

Callable Operator

[N](const num::Vector& x, num::Vector& y) {
apply_stencil(x, y, N);
},
N * N);
num::SolverResult info = num::cg(Aop, b, x, 1e-8, 1000);
CallableOp< F > make_op(F f, idx rows, idx cols)
Definition callable.hpp:39

Lanczos

auto eig = num::lanczos(Aop, 20, 1e-10, 100);
LanczosResult lanczos(const Op &A, idx k, real tol=1e-10, idx max_steps=0, Backend backend=Backend::seq)
Operator Lanczos for any symmetric adapter.
Definition lanczos.hpp:31

Exponential Action

num::expv(Aop, v, t, y);
Vector expv(real t, const Op &A, const Vector &v, int m_max=30, real tol=1e-8)
Compute for any adapter.
Definition expv.hpp:27

Use operators for algorithms that only require products with \(A\). Use direct factorizations when the assembled matrix and repeated solves justify it.