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. Structural concepts describe the callable interface; property wrappers declare numerical contracts such as symmetry or positive definiteness.

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) };
};

Declared mathematical-property concepts:

  • num::operators::SymmetricLinearOperator
  • num::operators::SPDLinearOperator

These concepts are satisfied by wrappers such as assume_symmetric(Aop) and assume_spd(Aop). They do not prove the property; they make the numerical contract explicit at the call site.

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);
SPDOp< Op > assume_spd(Op op)
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:17
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 gmres.hpp:25
Adapt a SparseMatrix to the operator protocol.
Definition sparse_op.hpp:15

Callable Operator

[N](const num::Vector& x, num::Vector& y) {
apply_stencil(x, y, N);
},
N * N);
num::cg(num::operators::assume_spd(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(num::operators::assume_symmetric(Aop), 20, 1e-10, 100);
SymmetricOp< Op > assume_symmetric(Op op)
LanczosResult lanczos(const Op &A, idx k, real tol=1e-10, idx max_steps=0, Backend backend=Backend::seq)
Operator Lanczos for a declared symmetric adapter.
Definition lanczos.hpp:156

Exponential Action

num::Vector y = num::expv(t, Aop, v, 30, 1e-8);
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:29

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