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
fill_spd_matrix(A);
Compile-time contract for y = A*x.
SolverResult cg(const Matrix &A, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
Adapt a dense Matrix to the operator protocol.
Sparse Operator
n, n, rows, cols, values);
Sparse matrix in Compressed Sparse Row (CSR) format.
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.
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.
Adapt a SparseMatrix to the operator protocol.
Callable Operator
apply_stencil(x, y, N);
},
N * N);
CallableOp< F > make_op(F f, idx rows, idx cols)
Lanczos
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.
Exponential Action
Vector expv(real t, const Op &A, const Vector &v, int m_max=30, real tol=1e-8)
Compute for any adapter.
Use operators for algorithms that only require products with \(A\). Use direct factorizations when the assembled matrix and repeated solves justify it.