numerics 0.1.0
Loading...
Searching...
No Matches
numerics

C++23 numerical routines for dense and structured linear algebra, ODE/PDE integration, Fourier transforms, quadrature, statistics, Monte Carlo sampling, and particle geometry.

The package is a solver suite. Operators provide a common argument form for Krylov and action routines, but the library also includes direct solvers, eigenvalue routines, SVD, FFTs, finite-difference routines, stochastic kernels, and optional BLAS/LAPACK/LAPACKE, FFTW3, OpenMP, CUDA, and MPI backends.

Examples

Implementation Notes

Dense Linear Algebra

#include <numerics.hpp>
num::Matrix A(2, 2, 0.0);
A(0, 0) = 4.0; A(0, 1) = 1.0;
A(1, 0) = 1.0; A(1, 1) = 3.0;
num::Vector b{1.0, 2.0};
auto F = num::lu(A);
num::lu_solve(F, b, x);
void lu_solve(const LUResult &f, const Vector &b, Vector &x)
Solve from a precomputed factorization.
Definition lu.cpp:19
LUResult lu(const Matrix &A, Backend backend=lapack_backend)
Definition lu.cpp:10
Umbrella include for the numerics library.

Iterative Solvers

num::Vector x(2, 0.0);
num::SolverResult info = num::cg(Aop, b, x, 1e-10, 100);
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

Matrix-Free Operators

[N](const num::Vector& u, num::Vector& Lu) {
apply_negative_laplacian(u, Lu, N);
},
N * N);
num::SolverResult info = num::gmres(Lop, rhs, sol);
CallableOp< F > make_op(F f, idx rows, idx cols)
Definition callable.hpp:39
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

ODE Integration

auto rhs = [](double, const num::Vector& y, num::Vector& dy) {
dy[0] = y[1];
dy[1] = -y[0];
};
auto result = num::solve(
num::ODEProblem{rhs, {1.0, 0.0}, 0.0, 20.0},
num::RK45{.rtol = 1e-8, .atol = 1e-10});
ODEResult solve(const P &prob, const RK45 &alg, ObserverFn obs=nullptr)
Definition solve.hpp:39
constexpr real e
Definition math.hpp:44
double rtol

Build

cmake -B build -DNUMERICS_BUILD_TESTS=ON
cmake --build build -j$(nproc)
ctest --test-dir build --output-on-failure

CMake Use

find_package(numerics REQUIRED)
target_link_libraries(my_program PRIVATE numerics::numerics)