numerics 0.1.0
Loading...
Searching...
No Matches
num Namespace Reference

Namespaces

namespace  backends
 
namespace  cuda
 
namespace  detail
 
namespace  kernel
 
namespace  markov
 
namespace  mpi
 
namespace  ode
 
namespace  operators
 
namespace  pde
 
namespace  plt
 
namespace  spectral
 
namespace  viz
 

Classes

struct  BackwardEuler
 
class  BandedMatrix
 LAPACK-style band storage. More...
 
struct  BandedSolverResult
 
class  BasicMatrix
 Dense row-major owning matrix. More...
 
class  BasicVector
 Dense owning vector. More...
 
class  CellList2D
 
class  CellList3D
 
struct  ClusterResult
 
struct  ComplexTriDiag
 
struct  CrankNicolsonADI
 
struct  EigenResult
 Symmetric eigendecomposition \(A=V\Lambda V^T\). More...
 
struct  Euler
 
class  EulerSteps
 
class  FieldSolver
 
struct  GivensRotation
 
class  Gnuplot
 
struct  Grid2D
 
class  Grid3D
 
struct  Histogram
 Fixed-bin histogram over \([\ell,h)\). More...
 
struct  IntRange
 
struct  LanczosResult
 
struct  LUResult
 Packed factorization \(PA=LU\). More...
 
class  MagneticSolver
 
struct  MCMCProblem
 
struct  Metropolis
 
struct  ODEParams
 
struct  ODEProblem
 
struct  ODEResult
 
struct  PBCLattice2D
 4-neighbor periodic-boundary index arrays for an NxN lattice. More...
 
struct  PowerResult
 Result of a single-eigenvalue iteration. More...
 
struct  QRResult
 QR factorization \(A=QR\). More...
 
struct  RK4
 
struct  RK45
 
class  RK45Steps
 
class  RK4_2ndSteps
 
class  RK4Steps
 
struct  Rng
 Seeded pseudo-random number generator (Mersenne Twister). Pass a pointer to rng_* functions to draw samples. More...
 
struct  RootResult
 
struct  RunningStats
 Welford updates for mean and variance. More...
 
class  ScalarField2D
 
class  ScalarField3D
 
struct  Series
 
struct  SmallMatrix
 
struct  SmallVec
 
struct  SolverResult
 
class  SparseMatrix
 Sparse matrix in Compressed Sparse Row (CSR) format. More...
 
struct  SPHKernel
 
struct  Step
 
struct  StepEnd
 
struct  SVDResult
 
struct  SymplecticResult
 
struct  SymplecticStep
 
struct  Vec2ConstView
 
struct  Vec2View
 Non-owning view of a flat vector as \((x_i,y_i)\) pairs. More...
 
struct  VectorField3D
 
class  VerletList2D
 
class  VerletSteps
 
class  Yoshida4Steps
 

Concepts

concept  VectorLike
 Indexed real-valued vector interface.
 
concept  MutableVectorLike
 Mutable indexed real-valued vector interface.
 
concept  ContiguousVectorLike
 Contiguous real-valued vector storage.
 
concept  DenseMatrixLike
 Dense row-major real matrix interface.
 
concept  MutableDenseMatrixLike
 Mutable dense row-major real matrix interface.
 
concept  ContiguousDenseMatrixLike
 Contiguous dense row-major real matrix storage.
 
concept  VecField
 
concept  IsODEProblem
 
concept  IsExplicitODEAlg
 
concept  IsImplicitODEAlg
 
concept  IsMCMCAlg
 

Typedefs

using ScalarFn = std::function< real(real)>
 Real-valued scalar function f(x)
 
using VectorFn = std::function< void(real, real *, real *)>
 Real-valued multivariate function f(x) where x is a scalar parameter and the function returns a vector of residuals – used in nonlinear systems.
 
using Matrix = BasicMatrix< real >
 Double-precision dense matrix with full backend dispatch (CPU + GPU).
 
using real = double
 
using idx = std::size_t
 
using cplx = std::complex< real >
 
using Vector = BasicVector< real >
 Real-valued dense vector with full backend dispatch (CPU + GPU)
 
using CVector = BasicVector< cplx >
 Complex-valued dense vector (sequential; no GPU)
 
using LinearSolver = std::function< SolverResult(const Vector &rhs, Vector &x)>
 Callable that solves \(Ax=\mathrm{rhs}\).
 
using ODERhsFn = std::function< void(real t, const Vector &y, Vector &dydt)>
 
using AccelFn = std::function< void(const Vector &q, Vector &acc)>
 
using ObserverFn = std::function< void(real t, const Vector &y)>
 
using SympObserverFn = std::function< void(real t, const Vector &q, const Vector &v)>
 
using Point = std::pair< double, double >
 

Enumerations

enum class  Backend {
  seq , blocked , simd , blas ,
  omp , gpu , lapack
}
 

Functions

real trapz (ScalarFn f, real a, real b, idx n=100, Backend backend=Backend::seq)
 Trapezoidal rule with n panels.
 
real simpson (ScalarFn f, real a, real b, idx n=100, Backend backend=Backend::seq)
 Simpson's 1/3 rule with n panels (n must be even)
 
real gauss_legendre (ScalarFn f, real a, real b, idx p=5)
 Gauss-Legendre quadrature (exact for polynomials up to degree 2p-1)
 
real adaptive_simpson (ScalarFn f, real a, real b, real tol=1e-8, idx max_depth=50)
 Adaptive Simpson quadrature.
 
real romberg (ScalarFn f, real a, real b, real tol=1e-10, idx max_levels=12)
 Romberg integration (Richardson extrapolation on trapezoidal rule)
 
RootResult bisection (ScalarFn f, real a, real b, real tol=1e-10, idx max_iter=1000)
 Bisection method.
 
RootResult newton (ScalarFn f, ScalarFn df, real x0, real tol=1e-10, idx max_iter=1000)
 Newton-Raphson method.
 
RootResult secant (ScalarFn f, real x0, real x1, real tol=1e-10, idx max_iter=1000)
 Secant method (Newton without derivative)
 
RootResult brent (ScalarFn f, real a, real b, real tol=1e-10, idx max_iter=1000)
 Brent's method (bisection + secant + inverse quadratic interpolation)
 
void matvec (const Matrix &A, const Vector &x, Vector &y, Backend b=default_backend)
 y = A * x
 
void matmul (const Matrix &A, const Matrix &B, Matrix &C, Backend b=default_backend)
 C = A * B.
 
void matadd (real alpha, const Matrix &A, real beta, const Matrix &B, Matrix &C, Backend b=default_backend)
 C = alpha*A + beta*B.
 
void matmul_blocked (const Matrix &A, const Matrix &B, Matrix &C, idx block_size=64)
 C = A * B (cache-blocked)
 
void matmul_register_blocked (const Matrix &A, const Matrix &B, Matrix &C, idx block_size=64, idx reg_size=4)
 C = A * B (register-blocked)
 
void matmul_simd (const Matrix &A, const Matrix &B, Matrix &C, idx block_size=64)
 C = A * B (SIMD-accelerated)
 
void matvec_simd (const Matrix &A, const Vector &x, Vector &y)
 y = A * x (SIMD-accelerated)
 
template<idx N>
constexpr SmallVec< N > operator+ (SmallVec< N > a, const SmallVec< N > &b) noexcept
 
template<idx N>
constexpr SmallVec< N > operator* (real s, SmallVec< N > v) noexcept
 
template<class T >
constexpr idx to_idx (T x) noexcept
 Cast any integer to idx without a verbose static_cast.
 
template<int N, typename T >
constexpr T ipow (T x) noexcept
 Compute x^N at compile time via repeated squaring.
 
real bessel_j (real nu, real x)
 J_nu(x) – Bessel function of the first kind.
 
real bessel_y (real nu, real x)
 Y_nu(x) – Bessel function of the second kind (Neumann function)
 
real bessel_i (real nu, real x)
 I_nu(x) – modified Bessel function of the first kind.
 
real bessel_k (real nu, real x)
 K_nu(x) – modified Bessel function of the second kind.
 
real sph_bessel_j (unsigned int n, real x)
 j_n(x) – spherical Bessel function of the first kind
 
real sph_bessel_y (unsigned int n, real x)
 y_n(x) – spherical Neumann function (spherical Bessel of the second kind)
 
real legendre (unsigned int n, real x)
 P_n(x) – Legendre polynomial of degree n.
 
real assoc_legendre (unsigned int n, unsigned int m, real x)
 P_n^m(x) – associated Legendre polynomial.
 
real sph_legendre (unsigned int l, unsigned int m, real theta)
 Y_l^m(theta) – spherical harmonic (real part, theta in radians)
 
real hermite (unsigned int n, real x)
 H_n(x) – (physicists') Hermite polynomial.
 
real laguerre (unsigned int n, real x)
 L_n(x) – Laguerre polynomial.
 
real assoc_laguerre (unsigned int n, unsigned int m, real x)
 L_n^m(x) – associated Laguerre polynomial.
 
real ellint_K (real k)
 K(k) – complete elliptic integral of the first kind.
 
real ellint_E (real k)
 E(k) – complete elliptic integral of the second kind.
 
real ellint_Pi (real n, real k)
 Pi(n, k) – complete elliptic integral of the third kind.
 
real ellint_F (real k, real phi)
 F(k, phi) – incomplete elliptic integral of the first kind.
 
real ellint_Ei (real k, real phi)
 E(k, phi) – incomplete elliptic integral of the second kind.
 
real ellint_Pi_inc (real n, real k, real phi)
 Pi(n, k, phi) – incomplete elliptic integral of the third kind.
 
real expint (real x)
 Ei(x) – exponential integral.
 
real zeta (real x)
 zeta(x) – Riemann zeta function
 
real beta (real a, real b)
 B(a, b) – beta function.
 
std::vector< reallinspace (real start, real stop, idx n)
 Evenly spaced values from start to stop, inclusive. MATLAB/NumPy linspace.
 
std::vector< int > int_range (int start, int n)
 Integer sequence [start, start+1, ..., start+n-1]. Wraps std::iota.
 
real rng_uniform (Rng *r, real lo, real hi)
 Uniform real in [lo, hi).
 
real rng_normal (Rng *r, real mean, real stddev)
 Normal (Gaussian) sample with given mean and standard deviation.
 
int rng_int (Rng *r, int lo, int hi)
 Uniform integer in [lo, hi] (inclusive on both ends).
 
real gaussian2d (real x, real y, real cx, real cy, real sigma)
 2D isotropic Gaussian centred at \((c_x, c_y)\) with width \(\sigma\): \(\exp\!\bigl(-\tfrac{(x-c_x)^2+(y-c_y)^2}{2\sigma^2}\bigr)\)
 
void scale (Vector &v, real alpha, Backend b=default_backend)
 Compute \(v \leftarrow \alpha v\).
 
void add (const Vector &x, const Vector &y, Vector &z, Backend b=default_backend)
 Compute \(z=x+y\).
 
void axpy (real alpha, const Vector &x, Vector &y, Backend b=default_backend)
 Compute \(y \leftarrow y+\alpha x\).
 
real dot (const Vector &x, const Vector &y, Backend b=default_backend)
 Compute \(x^T y\).
 
real norm (const Vector &x, Backend b=default_backend)
 Compute \(\|x\|_2\).
 
void scale (CVector &v, cplx alpha)
 v *= alpha
 
void axpy (cplx alpha, const CVector &x, CVector &y)
 y += alpha * x
 
cplx dot (const CVector &x, const CVector &y)
 Conjugate inner product <x, y> = Sigma conj(x_i) * y_i.
 
real norm (const CVector &x)
 Euclidean norm sqrt(Sigma |v_i|^2)
 
BandedSolverResult banded_lu (BandedMatrix &A, idx *ipiv)
 In-place banded \(PA=LU\) factorization.
 
void banded_lu_solve (const BandedMatrix &A, const idx *ipiv, Vector &b)
 Solve \(Ax=b\) using a precomputed banded LU factorization.
 
void banded_lu_solve_multi (const BandedMatrix &A, const idx *ipiv, real *B, idx nrhs)
 Solve \(AX=B\) using a precomputed banded LU factorization.
 
BandedSolverResult banded_solve (const BandedMatrix &A, const Vector &b, Vector &x)
 Factor and solve \(Ax=b\).
 
void banded_matvec (const BandedMatrix &A, const Vector &x, Vector &y, Backend backend=default_backend)
 Compute \(y=Ax\).
 
void banded_gemv (real alpha, const BandedMatrix &A, const Vector &x, real beta, Vector &y, Backend backend=default_backend)
 Compute \(y=\alpha Ax+\beta y\).
 
real banded_rcond (const BandedMatrix &A, const idx *ipiv, real anorm)
 Estimate \(1/\kappa_1(A)\).
 
real banded_norm1 (const BandedMatrix &A)
 Compute \(\|A\|_1\).
 
EigenResult eig_sym (const Matrix &A, real tol=1e-12, idx max_sweeps=100, Backend backend=lapack_backend)
 
template<class Op >
requires operators::LinearOperator<Op, Vector, Vector>
LanczosResult lanczos (const Op &A, idx k, real tol=1e-10, idx max_steps=0, Backend backend=Backend::seq)
 Operator Lanczos for any symmetric \(y=A x\) adapter.
 
LanczosResult lanczos (const Matrix &A, idx k, real tol=1e-10, idx max_steps=0, Backend backend=Backend::seq)
 
LanczosResult lanczos (const SparseMatrix &A, idx k, real tol=1e-10, idx max_steps=0, Backend backend=Backend::seq)
 
PowerResult power_iteration (const Matrix &A, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
 Power iteration – finds the eigenvalue largest in absolute value.
 
PowerResult inverse_iteration (const Matrix &A, real sigma, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
 Inverse iteration – finds the eigenvalue closest to a shift sigma.
 
PowerResult rayleigh_iteration (const Matrix &A, const Vector &x0, real tol=1e-10, idx max_iter=50, Backend backend=default_backend)
 Rayleigh quotient iteration – cubically convergent.
 
template<class Op >
requires operators::LinearOperator<Op, Vector, Vector>
Vector expv (real t, const Op &A, const Vector &v, int m_max=30, real tol=1e-8)
 Compute \(\exp(tA)v\) for any \(y=A x\) adapter.
 
Vector expv (real t, const SparseMatrix &A, const Vector &v, int m_max=30, real tol=1e-8)
 
LUResult lu (const Matrix &A, Backend backend=lapack_backend)
 
void lu_solve (const LUResult &f, const Vector &b, Vector &x)
 Solve \(Ax=b\) from a precomputed \(PA=LU\) factorization.
 
void lu_solve (const LUResult &f, const Matrix &B, Matrix &X)
 Solve \(AX=B\) from a precomputed \(PA=LU\) factorization.
 
real lu_det (const LUResult &f)
 Compute \(\det(A)=\det(P)^{-1}\prod_i U_{ii}\).
 
Matrix lu_inv (const LUResult &f)
 Compute \(A^{-1}\) by solving \(AX=I\).
 
QRResult qr (const Matrix &A, Backend backend=lapack_backend)
 Factor \(A\in\mathbb{R}^{m\times n}\) as \(A=QR\).
 
void qr_solve (const QRResult &f, const Vector &b, Vector &x)
 Solve \(\min_x \|Ax-b\|_2\).
 
void thomas (const Vector &a, const Vector &b, const Vector &c, const Vector &d, Vector &x, Backend backend=lapack_backend)
 
SolverResult cg (const Matrix &A, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
 
template<class Op >
requires operators::LinearOperator<Op, Vector, Vector>
SolverResult cg (const Op &A, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
 Operator CG for any \(y=A x\) adapter.
 
SolverResult gauss_seidel (const Matrix &A, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
 Gauss-Seidel iterative solver for Ax = b.
 
SolverResult jacobi (const Matrix &A, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
 Jacobi iterative solver for Ax = b.
 
template<class Op >
requires operators::LinearOperator<Op, Vector, Vector>
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 \(y=A x\) adapter.
 
SolverResult gmres (const SparseMatrix &A, const Vector &b, Vector &x, real tol=1e-6, idx max_iter=1000, idx restart=30)
 
SolverResult gmres (const Matrix &A, const Vector &b, Vector &x, real tol=1e-6, idx max_iter=1000, idx restart=30, Backend backend=default_backend)
 
void sparse_matvec (const SparseMatrix &A, const Vector &x, Vector &y)
 y = A * x
 
SVDResult svd (const Matrix &A, Backend backend=lapack_backend, real tol=1e-12, idx max_sweeps=100)
 
SVDResult svd_truncated (const Matrix &A, idx k, Backend backend=default_backend, idx oversampling=10, Rng *rng=nullptr)
 
EulerSteps euler (ODERhsFn f, Vector y0, ODEParams p={})
 
RK4Steps rk4 (ODERhsFn f, Vector y0, ODEParams p={})
 
RK45Steps rk45 (ODERhsFn f, Vector y0, ODEParams p={})
 
VerletSteps verlet (AccelFn accel, Vector q0, Vector v0, ODEParams p={})
 
Yoshida4Steps yoshida4 (AccelFn accel, Vector q0, Vector v0, ODEParams p={})
 
RK4_2ndSteps rk4_2nd (AccelFn accel, Vector q0, Vector v0, ODEParams p={})
 
ODEResult ode_euler (ODERhsFn f, Vector y0, ODEParams p={}, ObserverFn obs=nullptr)
 Forward Euler, 1st-order, fixed step.
 
ODEResult ode_rk4 (ODERhsFn f, Vector y0, ODEParams p={}, ObserverFn obs=nullptr)
 Classic 4th-order Runge-Kutta, fixed step.
 
ODEResult ode_rk45 (ODERhsFn f, Vector y0, ODEParams p={}, ObserverFn obs=nullptr)
 Adaptive Dormand-Prince RK45 with FSAL and PI step-size control.
 
SymplecticResult ode_verlet (AccelFn accel, Vector q0, Vector v0, ODEParams p={}, SympObserverFn obs=nullptr)
 Velocity Verlet, 2nd-order symplectic, 1 force evaluation per step.
 
SymplecticResult ode_yoshida4 (AccelFn accel, Vector q0, Vector v0, ODEParams p={}, SympObserverFn obs=nullptr)
 Yoshida 4th-order symplectic, 3 force evaluations per step.
 
SymplecticResult ode_rk4_2nd (AccelFn accel, Vector q0, Vector v0, ODEParams p={}, SympObserverFn obs=nullptr)
 RK4 for second-order systems q'' = accel(q), Nystrom form.
 
template<typename T >
void laplacian_stencil_2d (const BasicVector< T > &x, BasicVector< T > &y, int N)
 
template<typename T >
void laplacian_stencil_2d_periodic (const BasicVector< T > &x, BasicVector< T > &y, int N)
 Periodic second-order 2D Laplacian stencil.
 
template<typename T >
void laplacian_stencil_2d_4th (const BasicVector< T > &x, BasicVector< T > &y, int N)
 Fourth-order 2D Laplacian cross stencil.
 
real sample_2d_periodic (const Vector &field, idx N, real h, real px, real py, real ox, real oy)
 
template<typename T , typename F >
void col_fiber_sweep (BasicVector< T > &data, int N, F &&f)
 Apply a mutable 1D operation to each column fiber.
 
template<typename T , typename F >
void row_fiber_sweep (BasicVector< T > &data, int N, F &&f)
 Apply a mutable 1D operation to each row fiber.
 
template<typename F >
void fill_grid (Vector &u, int N, double h, F &&f)
 Fill grid values at \(x_i=(i+1)h,\ y_j=(j+1)h\).
 
Series row_slice (const Vector &u, int N, double h, int row)
 Extract one row as \((x_j,u_j)\) plot data.
 
Series col_slice (const Vector &u, int N, double h, int col)
 Extract one column as \((y_i,u_i)\) plot data.
 
template<typename F >
void fill_grid (ScalarField2D &g, F &&f)
 
Series row_slice (const ScalarField2D &g, int row)
 
Series col_slice (const ScalarField2D &g, int col)
 
void laplacian_stencil_2d_periodic (const ScalarField2D &x, ScalarField2D &y)
 
void laplacian_stencil_2d_4th (const ScalarField2D &x, ScalarField2D &y)
 
real sample_2d_periodic (const ScalarField2D &g, real px, real py, real ox=0.0, real oy=0.0)
 
void neg_laplacian_3d (const Vector &x, Vector &y, int nx, int ny, int nz, double inv_dx2)
 Compute \(-\Delta_h x\) on a 3D grid.
 
void gradient_3d (const Grid3D &phi, Grid3D &gx, Grid3D &gy, Grid3D &gz)
 Compute \(\nabla\phi\) with central differences.
 
void divergence_3d (const Grid3D &fx, const Grid3D &fy, const Grid3D &fz, Grid3D &out)
 Compute \(\nabla\cdot f\) with central differences.
 
void curl_3d (const Grid3D &ax, const Grid3D &ay, const Grid3D &az, Grid3D &bx, Grid3D &by, Grid3D &bz)
 Compute \(\nabla\times A\) with central differences.
 
void apply_siam_style (Gnuplot &gp)
 Apply SIAM-style theme to a raw Gnuplot pipe.
 
void set_loglog (Gnuplot &gp)
 
void set_logx (Gnuplot &gp)
 
void save_png (Gnuplot &gp, const std::string &filename, int w=900, int h=600)
 
template<IsODEProblem P>
ODEResult solve (const P &prob, const RK45 &alg, ObserverFn obs=nullptr)
 
template<IsODEProblem P>
ODEResult solve (const P &prob, const RK4 &alg, ObserverFn obs=nullptr)
 
template<IsODEProblem P>
ODEResult solve (const P &prob, const Euler &alg, ObserverFn obs=nullptr)
 
template<VecField F>
void solve (F &u, const BackwardEuler &alg)
 
template<VecField F, typename Observer >
void solve (F &u, const BackwardEuler &alg, Observer &&obs)
 
template<IsMCMCAlg A, typename MeasureFn , typename RNG >
double solve (const MCMCProblem &prob, const A &alg, MeasureFn &&measure, RNG &rng)
 Run equilibration and measurement sweeps, then return the mean.
 
template<typename InCluster , typename Neighbors >
ClusterResult connected_components (int n_sites, InCluster &&in_cluster, Neighbors &&neighbors)
 
real autocorr_time (const real *data, idx n, real c=6.0)
 

Variables

constexpr Backend seq = Backend::seq
 
constexpr Backend blocked = Backend::blocked
 
constexpr Backend simd = Backend::simd
 
constexpr Backend blas = Backend::blas
 
constexpr Backend omp = Backend::omp
 
constexpr Backend gpu = Backend::gpu
 
constexpr Backend lapack = Backend::lapack
 
constexpr bool has_blas
 
constexpr bool has_lapack
 
constexpr bool has_omp
 
constexpr bool has_simd
 
constexpr Backend default_backend
 
constexpr Backend best_backend = default_backend
 
constexpr Backend lapack_backend
 
constexpr real pi = 3.14159265358979323846
 
constexpr real e = 2.71828182845904523536
 
constexpr real phi = 1.61803398874989484820
 Golden ratio.
 
constexpr real sqrt2 = 1.41421356237309504880
 
constexpr real sqrt3 = 1.73205080756887729353
 
constexpr real ln2 = 0.69314718055994530942
 
constexpr real inv_pi = 0.31830988618379067154
 1/pi
 
constexpr real two_pi = 6.28318530717958647692
 2pi
 
constexpr real half_pi = 1.57079632679489661923
 pi/2
 

Typedef Documentation

◆ AccelFn

using num::AccelFn = typedef std::function<void(const Vector& q, Vector& acc)>

Definition at line 13 of file ode.hpp.

◆ cplx

using num::cplx = typedef std::complex<real>

Definition at line 12 of file types.hpp.

◆ CVector

using num::CVector = typedef BasicVector<cplx>

Complex-valued dense vector (sequential; no GPU)

Definition at line 132 of file vector.hpp.

◆ idx

using num::idx = typedef std::size_t

Definition at line 11 of file types.hpp.

◆ LinearSolver

using num::LinearSolver = typedef std::function<SolverResult(const Vector& rhs, Vector& x)>

Callable that solves \(Ax=\mathrm{rhs}\).

Definition at line 12 of file linear_solver.hpp.

◆ Matrix

using num::Matrix = typedef BasicMatrix<real>

Double-precision dense matrix with full backend dispatch (CPU + GPU).

Definition at line 127 of file matrix.hpp.

◆ ObserverFn

using num::ObserverFn = typedef std::function<void(real t, const Vector& y)>

Definition at line 14 of file ode.hpp.

◆ ODERhsFn

using num::ODERhsFn = typedef std::function<void(real t, const Vector& y, Vector& dydt)>

Definition at line 12 of file ode.hpp.

◆ Point

using num::Point = typedef std::pair<double, double>

Definition at line 13 of file plot.hpp.

◆ real

using num::real = typedef double

Definition at line 10 of file types.hpp.

◆ ScalarFn

using num::ScalarFn = typedef std::function<real(real)>

Real-valued scalar function f(x)

Definition at line 11 of file types.hpp.

◆ SympObserverFn

using num::SympObserverFn = typedef std::function<void(real t, const Vector& q, const Vector& v)>

Definition at line 15 of file ode.hpp.

◆ Vector

using num::Vector = typedef BasicVector<real>

Real-valued dense vector with full backend dispatch (CPU + GPU)

Definition at line 129 of file vector.hpp.

◆ VectorFn

using num::VectorFn = typedef std::function<void(real, real*, real*)>

Real-valued multivariate function f(x) where x is a scalar parameter and the function returns a vector of residuals – used in nonlinear systems.

Definition at line 15 of file types.hpp.

Enumeration Type Documentation

◆ Backend

enum class num::Backend
strong
Enumerator
seq 
blocked 
simd 
blas 
omp 
gpu 
lapack 

Definition at line 7 of file policy.hpp.

Function Documentation

◆ adaptive_simpson()

real num::adaptive_simpson ( ScalarFn  f,
real  a,
real  b,
real  tol = 1e-8,
idx  max_depth = 50 
)

Adaptive Simpson quadrature.

Parameters
fIntegrand
aLower bound
bUpper bound
tolAbsolute error tolerance
max_depthMaximum recursion depth

Definition at line 103 of file quadrature.cpp.

◆ add()

void num::add ( const Vector x,
const Vector y,
Vector z,
Backend  b = default_backend 
)

◆ apply_siam_style()

void num::apply_siam_style ( Gnuplot gp)
inline

Apply SIAM-style theme to a raw Gnuplot pipe.

Definition at line 52 of file plot.hpp.

◆ assoc_laguerre()

real num::assoc_laguerre ( unsigned int  n,
unsigned int  m,
real  x 
)
inline

L_n^m(x) – associated Laguerre polynomial.

Definition at line 160 of file math.hpp.

◆ assoc_legendre()

real num::assoc_legendre ( unsigned int  n,
unsigned int  m,
real  x 
)
inline

P_n^m(x) – associated Legendre polynomial.

Definition at line 124 of file math.hpp.

◆ autocorr_time()

real num::autocorr_time ( const real data,
idx  n,
real  c = 6.0 
)

Integrated autocorrelation time tau_int from a stored time series.

Uses the automatic windowing criterion (Madras & Sokal 1988): accumulate C(t)/C(0) until W > c*tau_int (c = 6 default). Returns tau_int >= 0.5; returns 0.5 on failure.

Parameters
dataPointer to time series of length n
nLength of the series
cWindow parameter (default 6)

Definition at line 6 of file stats.cpp.

References e.

◆ axpy() [1/2]

void num::axpy ( cplx  alpha,
const CVector x,
CVector y 
)

y += alpha * x

Definition at line 106 of file vector.cpp.

References num::BasicVector< T >::size().

◆ axpy() [2/2]

◆ banded_gemv()

void num::banded_gemv ( real  alpha,
const BandedMatrix A,
const Vector x,
real  beta,
Vector y,
Backend  backend = default_backend 
)

◆ banded_lu()

BandedSolverResult num::banded_lu ( BandedMatrix A,
idx ipiv 
)

In-place banded \(PA=LU\) factorization.

Definition at line 135 of file banded.cpp.

References num::BandedMatrix::data(), num::BandedMatrix::kl(), num::BandedMatrix::ku(), num::BandedMatrix::ldab(), and num::BandedMatrix::size().

Referenced by banded_solve().

◆ banded_lu_solve()

void num::banded_lu_solve ( const BandedMatrix A,
const idx ipiv,
Vector b 
)

◆ banded_lu_solve_multi()

void num::banded_lu_solve_multi ( const BandedMatrix A,
const idx ipiv,
real B,
idx  nrhs 
)

Solve \(AX=B\) using a precomputed banded LU factorization.

Definition at line 247 of file banded.cpp.

References num::BandedMatrix::data(), num::BandedMatrix::kl(), num::BandedMatrix::ku(), num::BandedMatrix::ldab(), and num::BandedMatrix::size().

◆ banded_matvec()

void num::banded_matvec ( const BandedMatrix A,
const Vector x,
Vector y,
Backend  backend = default_backend 
)

Compute \(y=Ax\).

Definition at line 300 of file banded.cpp.

References banded_gemv().

◆ banded_norm1()

real num::banded_norm1 ( const BandedMatrix A)

◆ banded_rcond()

real num::banded_rcond ( const BandedMatrix A,
const idx ipiv,
real  anorm 
)

Estimate \(1/\kappa_1(A)\).

Definition at line 364 of file banded.cpp.

References banded_lu_solve(), and num::BandedMatrix::size().

◆ banded_solve()

BandedSolverResult num::banded_solve ( const BandedMatrix A,
const Vector b,
Vector x 
)

◆ bessel_i()

real num::bessel_i ( real  nu,
real  x 
)
inline

I_nu(x) – modified Bessel function of the first kind.

Definition at line 74 of file math.hpp.

◆ bessel_j()

real num::bessel_j ( real  nu,
real  x 
)
inline

J_nu(x) – Bessel function of the first kind.

Definition at line 56 of file math.hpp.

◆ bessel_k()

real num::bessel_k ( real  nu,
real  x 
)
inline

K_nu(x) – modified Bessel function of the second kind.

Definition at line 83 of file math.hpp.

◆ bessel_y()

real num::bessel_y ( real  nu,
real  x 
)
inline

Y_nu(x) – Bessel function of the second kind (Neumann function)

Definition at line 65 of file math.hpp.

◆ beta()

◆ bisection()

RootResult num::bisection ( ScalarFn  f,
real  a,
real  b,
real  tol = 1e-10,
idx  max_iter = 1000 
)

Bisection method.

Parameters
fContinuous function
a,bBracket: f(a) and f(b) must have opposite signs
tolConvergence tolerance on |f(root)| and interval width
max_iterMaximum iterations

Definition at line 8 of file roots.cpp.

◆ brent()

RootResult num::brent ( ScalarFn  f,
real  a,
real  b,
real  tol = 1e-10,
idx  max_iter = 1000 
)

Brent's method (bisection + secant + inverse quadratic interpolation)

Guaranteed to converge if f(a) and f(b) have opposite signs. Superlinear convergence near smooth roots. Preferred method when a reliable bracket is available.

Parameters
fFunction
a,bBracket: f(a) and f(b) must have opposite signs
tolConvergence tolerance
max_iterMaximum iterations

Definition at line 61 of file roots.cpp.

References e.

◆ cg() [1/2]

◆ cg() [2/2]

template<class Op >
requires operators::LinearOperator<Op, Vector, Vector>
SolverResult num::cg ( const Op &  A,
const Vector b,
Vector x,
real  tol = 1e-10,
idx  max_iter = 1000,
Backend  backend = default_backend 
)

Operator CG for any \(y=A x\) adapter.

Definition at line 27 of file cg.hpp.

References axpy(), beta(), dot(), e, num::SolverResult::iterations, scale(), and num::BasicVector< T >::size().

◆ col_fiber_sweep()

template<typename T , typename F >
void num::col_fiber_sweep ( BasicVector< T > &  data,
int  N,
F &&  f 
)

Apply a mutable 1D operation to each column fiber.

Definition at line 141 of file stencil.hpp.

Referenced by num::CrankNicolsonADI::sweep().

◆ col_slice() [1/2]

Series num::col_slice ( const ScalarField2D g,
int  col 
)
inline

◆ col_slice() [2/2]

Series num::col_slice ( const Vector u,
int  N,
double  h,
int  col 
)
inline

Extract one column as \((y_i,u_i)\) plot data.

Definition at line 187 of file stencil.hpp.

References num::Series::store().

Referenced by col_slice().

◆ connected_components()

template<typename InCluster , typename Neighbors >
ClusterResult num::connected_components ( int  n_sites,
InCluster &&  in_cluster,
Neighbors &&  neighbors 
)

BFS connected-component labelling with pre-allocated flat queue (no heap per call).

Parameters
n_sitesTotal number of sites
in_clusterbool(int i) – include site i?
neighborsvoid(int i, auto&& visit) – call visit(nb) per neighbor of i

Definition at line 38 of file connected_components.hpp.

References num::ClusterResult::id, num::ClusterResult::largest_id, num::ClusterResult::largest_size, and num::ClusterResult::sizes.

◆ curl_3d()

void num::curl_3d ( const Grid3D ax,
const Grid3D ay,
const Grid3D az,
Grid3D bx,
Grid3D by,
Grid3D bz 
)
inline

Compute \(\nabla\times A\) with central differences.

Definition at line 294 of file stencil.hpp.

References num::Grid3D::dx(), num::Grid3D::nx(), num::Grid3D::ny(), and num::Grid3D::nz().

Referenced by num::FieldSolver::curl().

◆ divergence_3d()

void num::divergence_3d ( const Grid3D fx,
const Grid3D fy,
const Grid3D fz,
Grid3D out 
)
inline

Compute \(\nabla\cdot f\) with central differences.

Definition at line 274 of file stencil.hpp.

References num::Grid3D::dx(), num::Grid3D::nx(), num::Grid3D::ny(), and num::Grid3D::nz().

Referenced by num::FieldSolver::divergence().

◆ dot() [1/2]

cplx num::dot ( const CVector x,
const CVector y 
)

Conjugate inner product <x, y> = Sigma conj(x_i) * y_i.

Definition at line 111 of file vector.cpp.

References num::BasicVector< T >::size().

◆ dot() [2/2]

◆ eig_sym()

EigenResult num::eig_sym ( const Matrix A,
real  tol = 1e-12,
idx  max_sweeps = 100,
Backend  backend = lapack_backend 
)

◆ ellint_E()

real num::ellint_E ( real  k)
inline

E(k) – complete elliptic integral of the second kind.

Definition at line 182 of file math.hpp.

◆ ellint_Ei()

real num::ellint_Ei ( real  k,
real  phi 
)
inline

E(k, phi) – incomplete elliptic integral of the second kind.

Definition at line 209 of file math.hpp.

References phi.

◆ ellint_F()

real num::ellint_F ( real  k,
real  phi 
)
inline

F(k, phi) – incomplete elliptic integral of the first kind.

Definition at line 200 of file math.hpp.

References phi.

◆ ellint_K()

real num::ellint_K ( real  k)
inline

K(k) – complete elliptic integral of the first kind.

Definition at line 173 of file math.hpp.

◆ ellint_Pi()

real num::ellint_Pi ( real  n,
real  k 
)
inline

Pi(n, k) – complete elliptic integral of the third kind.

Definition at line 191 of file math.hpp.

◆ ellint_Pi_inc()

real num::ellint_Pi_inc ( real  n,
real  k,
real  phi 
)
inline

Pi(n, k, phi) – incomplete elliptic integral of the third kind.

Definition at line 218 of file math.hpp.

References phi.

◆ euler()

EulerSteps num::euler ( ODERhsFn  f,
Vector  y0,
ODEParams  p = {} 
)

Definition at line 372 of file ode.cpp.

Referenced by ode_euler().

◆ expint()

real num::expint ( real  x)
inline

Ei(x) – exponential integral.

Definition at line 230 of file math.hpp.

◆ expv() [1/2]

template<class Op >
requires operators::LinearOperator<Op, Vector, Vector>
Vector num::expv ( real  t,
const Op &  A,
const Vector v,
int  m_max = 30,
real  tol = 1e-8 
)

Compute \(\exp(tA)v\) for any \(y=A x\) adapter.

Definition at line 27 of file expv.hpp.

References axpy(), beta(), num::detail::dense_expm_pade6(), e, num::kernel::subspace::mgs_orthogonalize(), norm(), scale(), and num::BasicVector< T >::size().

Referenced by expv().

◆ expv() [2/2]

Vector num::expv ( real  t,
const SparseMatrix A,
const Vector v,
int  m_max = 30,
real  tol = 1e-8 
)

Definition at line 95 of file expv.cpp.

References expv().

◆ fill_grid() [1/2]

template<typename F >
void num::fill_grid ( ScalarField2D g,
F &&  f 
)

◆ fill_grid() [2/2]

template<typename F >
void num::fill_grid ( Vector u,
int  N,
double  h,
F &&  f 
)

Fill grid values at \(x_i=(i+1)h,\ y_j=(j+1)h\).

Definition at line 167 of file stencil.hpp.

Referenced by fill_grid().

◆ gauss_legendre()

real num::gauss_legendre ( ScalarFn  f,
real  a,
real  b,
idx  p = 5 
)

Gauss-Legendre quadrature (exact for polynomials up to degree 2p-1)

Parameters
fIntegrand
aLower bound
bUpper bound
pNumber of quadrature points (1 to 5 supported)

Definition at line 63 of file quadrature.cpp.

◆ gauss_seidel()

SolverResult num::gauss_seidel ( const Matrix A,
const Vector b,
Vector x,
real  tol = 1e-10,
idx  max_iter = 1000,
Backend  backend = default_backend 
)

Gauss-Seidel iterative solver for Ax = b.

Updates each component x[i] in-place using the latest values of all other components. Converges for strictly diagonally dominant or symmetric positive definite A.

With Backend::omp the residual computation is parallelised; the update sweep remains sequential to preserve convergence properties.

Parameters
ASquare matrix
bRight-hand side vector
xSolution vector (initial guess on input, solution on output)
tolConvergence tolerance on residual norm (default 1e-10)
max_iterMaximum iterations (default 1000)
backendExecution backend (default: default_backend)
Returns
SolverResult with convergence info

Definition at line 13 of file gauss_seidel.cpp.

References num::BasicMatrix< T >::cols(), e, num::BasicMatrix< T >::rows(), and num::BasicVector< T >::size().

◆ gaussian2d()

real num::gaussian2d ( real  x,
real  y,
real  cx,
real  cy,
real  sigma 
)
inline

2D isotropic Gaussian centred at \((c_x, c_y)\) with width \(\sigma\): \(\exp\!\bigl(-\tfrac{(x-c_x)^2+(y-c_y)^2}{2\sigma^2}\bigr)\)

Definition at line 312 of file math.hpp.

◆ gmres() [1/3]

SolverResult num::gmres ( const Matrix A,
const Vector b,
Vector x,
real  tol = 1e-6,
idx  max_iter = 1000,
idx  restart = 30,
Backend  backend = default_backend 
)

Definition at line 22 of file krylov.cpp.

References num::BasicMatrix< T >::cols(), gmres(), and num::BasicMatrix< T >::rows().

◆ gmres() [2/3]

template<class Op >
requires operators::LinearOperator<Op, Vector, Vector>
SolverResult num::gmres ( const Op &  A,
const Vector b,
Vector x,
real  tol = 1e-6,
idx  max_iter = 1000,
idx  restart = 30 
)

Operator GMRES for any \(y=A x\) adapter.

Definition at line 24 of file krylov.hpp.

References beta(), e, num::kernel::subspace::mgs_orthogonalize(), norm(), scale(), and num::BasicVector< T >::size().

Referenced by gmres(), and gmres().

◆ gmres() [3/3]

SolverResult num::gmres ( const SparseMatrix A,
const Vector b,
Vector x,
real  tol = 1e-6,
idx  max_iter = 1000,
idx  restart = 30 
)

Definition at line 8 of file krylov.cpp.

References gmres(), num::SparseMatrix::n_cols(), and num::SparseMatrix::n_rows().

◆ gradient_3d()

void num::gradient_3d ( const Grid3D phi,
Grid3D gx,
Grid3D gy,
Grid3D gz 
)
inline

Compute \(\nabla\phi\) with central differences.

Definition at line 258 of file stencil.hpp.

References phi.

Referenced by num::FieldSolver::gradient().

◆ hermite()

real num::hermite ( unsigned int  n,
real  x 
)
inline

H_n(x) – (physicists') Hermite polynomial.

Definition at line 142 of file math.hpp.

◆ int_range()

std::vector< int > num::int_range ( int  start,
int  n 
)
inline

Integer sequence [start, start+1, ..., start+n-1]. Wraps std::iota.

Definition at line 270 of file math.hpp.

◆ inverse_iteration()

PowerResult num::inverse_iteration ( const Matrix A,
real  sigma,
real  tol = 1e-10,
idx  max_iter = 1000,
Backend  backend = default_backend 
)

Inverse iteration – finds the eigenvalue closest to a shift sigma.

Factorizes (A - sigmaI) once then solves repeatedly.

Parameters
ASquare matrix (symmetric recommended)
sigmaShift – should be near the target eigenvalue
tolTolerance on eigenvalue change between iterations
max_iterMaximum iterations
backendBackend forwarded to matvec and dot

Definition at line 46 of file power.cpp.

References num::BasicMatrix< T >::cols(), dot(), e, lu(), lu_solve(), matvec(), num::detail::normalise(), and num::BasicMatrix< T >::rows().

◆ ipow()

template<int N, typename T >
constexpr T num::ipow ( x)
constexprnoexcept

Compute x^N at compile time via repeated squaring.

Definition at line 9 of file integer_pow.hpp.

References ipow().

Referenced by ipow().

◆ jacobi()

SolverResult num::jacobi ( const Matrix A,
const Vector b,
Vector x,
real  tol = 1e-10,
idx  max_iter = 1000,
Backend  backend = default_backend 
)

Jacobi iterative solver for Ax = b.

Updates all components simultaneously using only values from the previous iteration. Converges for strictly diagonally dominant A. Trivially parallelisable with Backend::omp.

Parameters
ASquare matrix
bRight-hand side vector
xSolution vector (initial guess on input, solution on output)
tolConvergence tolerance on residual norm (default 1e-10)
max_iterMaximum iterations (default 1000)
backendExecution backend (default: default_backend)
Returns
SolverResult with convergence info

Definition at line 7 of file jacobi.cpp.

References num::BasicMatrix< T >::cols(), e, num::BasicMatrix< T >::rows(), and num::BasicVector< T >::size().

◆ laguerre()

real num::laguerre ( unsigned int  n,
real  x 
)
inline

L_n(x) – Laguerre polynomial.

Definition at line 151 of file math.hpp.

◆ lanczos() [1/3]

LanczosResult num::lanczos ( const Matrix A,
idx  k,
real  tol = 1e-10,
idx  max_steps = 0,
Backend  backend = Backend::seq 
)

◆ lanczos() [2/3]

template<class Op >
requires operators::LinearOperator<Op, Vector, Vector>
LanczosResult num::lanczos ( const Op &  A,
idx  k,
real  tol = 1e-10,
idx  max_steps = 0,
Backend  backend = Backend::seq 
)

Operator Lanczos for any symmetric \(y=A x\) adapter.

Definition at line 31 of file lanczos.hpp.

References axpy(), beta(), dot(), e, eig_sym(), num::kernel::subspace::mgs_orthogonalize(), num::EigenResult::values, and num::EigenResult::vectors.

Referenced by lanczos(), and lanczos().

◆ lanczos() [3/3]

LanczosResult num::lanczos ( const SparseMatrix A,
idx  k,
real  tol = 1e-10,
idx  max_steps = 0,
Backend  backend = Backend::seq 
)

Definition at line 18 of file lanczos.cpp.

References lanczos(), num::SparseMatrix::n_cols(), and num::SparseMatrix::n_rows().

◆ laplacian_stencil_2d()

template<typename T >
void num::laplacian_stencil_2d ( const BasicVector< T > &  x,
BasicVector< T > &  y,
int  N 
)

Definition at line 22 of file stencil.hpp.

Referenced by num::pde::diffusion_step_2d_dirichlet().

◆ laplacian_stencil_2d_4th() [1/2]

template<typename T >
void num::laplacian_stencil_2d_4th ( const BasicVector< T > &  x,
BasicVector< T > &  y,
int  N 
)

Fourth-order 2D Laplacian cross stencil.

\[ y_{ij} = \frac{1}{12}\bigl( -x_{i-2,j} + 16x_{i-1,j} - 30x_{i,j} + 16x_{i+1,j} - x_{i+2,j} -x_{i,j-2} + 16x_{i,j-1} + 16x_{i,j+1} - x_{i,j+2} \bigr) \]

Definition at line 66 of file stencil.hpp.

Referenced by num::pde::diffusion_step_2d_4th_dirichlet(), and laplacian_stencil_2d_4th().

◆ laplacian_stencil_2d_4th() [2/2]

void num::laplacian_stencil_2d_4th ( const ScalarField2D x,
ScalarField2D y 
)
inline

◆ laplacian_stencil_2d_periodic() [1/2]

template<typename T >
void num::laplacian_stencil_2d_periodic ( const BasicVector< T > &  x,
BasicVector< T > &  y,
int  N 
)

Periodic second-order 2D Laplacian stencil.

Definition at line 42 of file stencil.hpp.

References num::BasicVector< T >::data().

Referenced by num::pde::diffusion_step_2d(), and laplacian_stencil_2d_periodic().

◆ laplacian_stencil_2d_periodic() [2/2]

void num::laplacian_stencil_2d_periodic ( const ScalarField2D x,
ScalarField2D y 
)
inline

◆ legendre()

real num::legendre ( unsigned int  n,
real  x 
)
inline

P_n(x) – Legendre polynomial of degree n.

Definition at line 115 of file math.hpp.

◆ linspace()

std::vector< real > num::linspace ( real  start,
real  stop,
idx  n 
)
inline

Evenly spaced values from start to stop, inclusive. MATLAB/NumPy linspace.

Definition at line 260 of file math.hpp.

◆ lu()

LUResult num::lu ( const Matrix A,
Backend  backend = lapack_backend 
)

◆ lu_det()

real num::lu_det ( const LUResult f)

Compute \(\det(A)=\det(P)^{-1}\prod_i U_{ii}\).

Definition at line 57 of file lu.cpp.

References num::LUResult::LU, num::LUResult::piv, and num::BasicMatrix< T >::rows().

◆ lu_inv()

Matrix num::lu_inv ( const LUResult f)

Compute \(A^{-1}\) by solving \(AX=I\).

Definition at line 71 of file lu.cpp.

References e, num::LUResult::LU, lu_solve(), and num::BasicMatrix< T >::rows().

◆ lu_solve() [1/2]

void num::lu_solve ( const LUResult f,
const Matrix B,
Matrix X 
)

Solve \(AX=B\) from a precomputed \(PA=LU\) factorization.

Definition at line 42 of file lu.cpp.

References num::BasicMatrix< T >::cols(), lu_solve(), and num::BasicMatrix< T >::rows().

◆ lu_solve() [2/2]

void num::lu_solve ( const LUResult f,
const Vector b,
Vector x 
)

Solve \(Ax=b\) from a precomputed \(PA=LU\) factorization.

Definition at line 19 of file lu.cpp.

References num::LUResult::LU, num::LUResult::piv, and num::BasicMatrix< T >::rows().

Referenced by num::detail::dense_expm_pade6(), inverse_iteration(), lu_inv(), lu_solve(), and rayleigh_iteration().

◆ matadd()

void num::matadd ( real  alpha,
const Matrix A,
real  beta,
const Matrix B,
Matrix C,
Backend  b = default_backend 
)

C = alpha*A + beta*B.

Definition at line 68 of file matrix.cpp.

References beta(), blas, blocked, gpu, lapack, num::backends::blas::matadd(), num::backends::omp::matadd(), num::backends::seq::matadd(), omp, seq, and simd.

◆ matmul()

◆ matmul_blocked()

void num::matmul_blocked ( const Matrix A,
const Matrix B,
Matrix C,
idx  block_size = 64 
)

C = A * B (cache-blocked)

Divides A, B, C into BLOCKxBLOCK tiles so the working set fits in L2 cache.

Parameters
block_sizeTile edge length (default 64).

Definition at line 94 of file matrix.cpp.

References num::backends::seq::matmul_blocked().

◆ matmul_register_blocked()

void num::matmul_register_blocked ( const Matrix A,
const Matrix B,
Matrix C,
idx  block_size = 64,
idx  reg_size = 4 
)

C = A * B (register-blocked)

Extends cache blocking with a REGxREG register tile inside each cache tile.

Parameters
block_sizeCache tile edge (default 64).
reg_sizeRegister tile edge (default 4).

Definition at line 98 of file matrix.cpp.

References num::backends::seq::matmul_register_blocked().

◆ matmul_simd()

void num::matmul_simd ( const Matrix A,
const Matrix B,
Matrix C,
idx  block_size = 64 
)

C = A * B (SIMD-accelerated)

Dispatches at compile time: AVX-256 + FMA on x86, NEON on AArch64, falls back to matmul_blocked if neither is available.

Definition at line 106 of file matrix.cpp.

References num::backends::simd::matmul().

◆ matvec()

◆ matvec_simd()

void num::matvec_simd ( const Matrix A,
const Vector x,
Vector y 
)

y = A * x (SIMD-accelerated)

Definition at line 110 of file matrix.cpp.

References num::backends::simd::matvec().

◆ neg_laplacian_3d()

void num::neg_laplacian_3d ( const Vector x,
Vector y,
int  nx,
int  ny,
int  nz,
double  inv_dx2 
)
inline

Compute \(-\Delta_h x\) on a 3D grid.

Definition at line 232 of file stencil.hpp.

Referenced by num::FieldSolver::solve_poisson().

◆ newton()

RootResult num::newton ( ScalarFn  f,
ScalarFn  df,
real  x0,
real  tol = 1e-10,
idx  max_iter = 1000 
)

Newton-Raphson method.

Parameters
fFunction
dfDerivative of f
x0Initial guess
tolConvergence tolerance
max_iterMaximum iterations

Definition at line 30 of file roots.cpp.

References e.

◆ norm() [1/2]

real num::norm ( const CVector x)

Euclidean norm sqrt(Sigma |v_i|^2)

Definition at line 118 of file vector.cpp.

References num::BasicVector< T >::size().

◆ norm() [2/2]

◆ ode_euler()

ODEResult num::ode_euler ( ODERhsFn  f,
Vector  y0,
ODEParams  p = {},
ObserverFn  obs = nullptr 
)

Forward Euler, 1st-order, fixed step.

Definition at line 392 of file ode.cpp.

References euler().

Referenced by solve().

◆ ode_rk4()

ODEResult num::ode_rk4 ( ODERhsFn  f,
Vector  y0,
ODEParams  p = {},
ObserverFn  obs = nullptr 
)

Classic 4th-order Runge-Kutta, fixed step.

Definition at line 399 of file ode.cpp.

References rk4().

Referenced by solve().

◆ ode_rk45()

ODEResult num::ode_rk45 ( ODERhsFn  f,
Vector  y0,
ODEParams  p = {},
ObserverFn  obs = nullptr 
)

Adaptive Dormand-Prince RK45 with FSAL and PI step-size control.

Definition at line 406 of file ode.cpp.

References rk45().

Referenced by solve().

◆ ode_rk4_2nd()

SymplecticResult num::ode_rk4_2nd ( AccelFn  accel,
Vector  q0,
Vector  v0,
ODEParams  p = {},
SympObserverFn  obs = nullptr 
)

RK4 for second-order systems q'' = accel(q), Nystrom form.

Note
Not symplectic. Prefer ode_verlet or ode_yoshida4 for long Hamiltonian runs.

Definition at line 435 of file ode.cpp.

References rk4_2nd().

◆ ode_verlet()

SymplecticResult num::ode_verlet ( AccelFn  accel,
Vector  q0,
Vector  v0,
ODEParams  p = {},
SympObserverFn  obs = nullptr 
)

Velocity Verlet, 2nd-order symplectic, 1 force evaluation per step.

Definition at line 413 of file ode.cpp.

References verlet().

◆ ode_yoshida4()

SymplecticResult num::ode_yoshida4 ( AccelFn  accel,
Vector  q0,
Vector  v0,
ODEParams  p = {},
SympObserverFn  obs = nullptr 
)

Yoshida 4th-order symplectic, 3 force evaluations per step.

Definition at line 424 of file ode.cpp.

References yoshida4().

◆ operator*()

template<idx N>
constexpr SmallVec< N > num::operator* ( real  s,
SmallVec< N >  v 
)
constexprnoexcept

Definition at line 57 of file small_matrix.hpp.

◆ operator+()

template<idx N>
constexpr SmallVec< N > num::operator+ ( SmallVec< N >  a,
const SmallVec< N > &  b 
)
constexprnoexcept

Definition at line 52 of file small_matrix.hpp.

◆ power_iteration()

PowerResult num::power_iteration ( const Matrix A,
real  tol = 1e-10,
idx  max_iter = 1000,
Backend  backend = default_backend 
)

Power iteration – finds the eigenvalue largest in absolute value.

Parameters
ASquare matrix (need not be symmetric)
tolTolerance on eigenvalue change between iterations
max_iterMaximum iterations
backendBackend forwarded to matvec and dot

Definition at line 10 of file power.cpp.

References num::BasicMatrix< T >::cols(), dot(), e, matvec(), num::detail::normalise(), and num::BasicMatrix< T >::rows().

◆ qr()

QRResult num::qr ( const Matrix A,
Backend  backend = lapack_backend 
)

Factor \(A\in\mathbb{R}^{m\times n}\) as \(A=QR\).

Definition at line 10 of file qr.cpp.

References lapack, num::backends::lapack::qr(), and num::backends::seq::qr().

Referenced by svd_truncated().

◆ qr_solve()

void num::qr_solve ( const QRResult f,
const Vector b,
Vector x 
)

Solve \(\min_x \|Ax-b\|_2\).

Definition at line 19 of file qr.cpp.

References num::BasicMatrix< T >::cols(), num::QRResult::Q, num::QRResult::R, and num::BasicMatrix< T >::rows().

◆ rayleigh_iteration()

PowerResult num::rayleigh_iteration ( const Matrix A,
const Vector x0,
real  tol = 1e-10,
idx  max_iter = 50,
Backend  backend = default_backend 
)

Rayleigh quotient iteration – cubically convergent.

Updates the shift sigma = v^T*A*v at every step -> fresh LU each iteration.

Parameters
ASymmetric matrix
x0Starting vector (determines which eigenvalue is found)
tolTolerance on residual ||A*v - lambda*v||
max_iterMaximum iterations
backendBackend forwarded to matvec, dot, axpy, norm

Definition at line 95 of file power.cpp.

References num::BasicMatrix< T >::cols(), dot(), lu(), lu_solve(), matvec(), num::detail::normalise(), num::BasicMatrix< T >::rows(), num::LUResult::singular, and num::BasicVector< T >::size().

◆ rk4()

RK4Steps num::rk4 ( ODERhsFn  f,
Vector  y0,
ODEParams  p = {} 
)

Definition at line 375 of file ode.cpp.

Referenced by ode_rk4().

◆ rk45()

RK45Steps num::rk45 ( ODERhsFn  f,
Vector  y0,
ODEParams  p = {} 
)

Definition at line 378 of file ode.cpp.

Referenced by ode_rk45().

◆ rk4_2nd()

RK4_2ndSteps num::rk4_2nd ( AccelFn  accel,
Vector  q0,
Vector  v0,
ODEParams  p = {} 
)

Definition at line 388 of file ode.cpp.

Referenced by ode_rk4_2nd().

◆ rng_int()

int num::rng_int ( Rng r,
int  lo,
int  hi 
)
inline

Uniform integer in [lo, hi] (inclusive on both ends).

Definition at line 303 of file math.hpp.

References num::Rng::engine.

◆ rng_normal()

real num::rng_normal ( Rng r,
real  mean,
real  stddev 
)
inline

Normal (Gaussian) sample with given mean and standard deviation.

Definition at line 298 of file math.hpp.

References num::Rng::engine.

Referenced by svd_truncated().

◆ rng_uniform()

real num::rng_uniform ( Rng r,
real  lo,
real  hi 
)
inline

Uniform real in [lo, hi).

Definition at line 293 of file math.hpp.

References num::Rng::engine.

◆ romberg()

real num::romberg ( ScalarFn  f,
real  a,
real  b,
real  tol = 1e-10,
idx  max_levels = 12 
)

Romberg integration (Richardson extrapolation on trapezoidal rule)

Parameters
fIntegrand
aLower bound
bUpper bound
tolConvergence tolerance
max_levelsMaximum refinement levels

Definition at line 109 of file quadrature.cpp.

◆ row_fiber_sweep()

template<typename T , typename F >
void num::row_fiber_sweep ( BasicVector< T > &  data,
int  N,
F &&  f 
)

Apply a mutable 1D operation to each row fiber.

Definition at line 154 of file stencil.hpp.

Referenced by num::CrankNicolsonADI::sweep().

◆ row_slice() [1/2]

Series num::row_slice ( const ScalarField2D g,
int  row 
)
inline

◆ row_slice() [2/2]

Series num::row_slice ( const Vector u,
int  N,
double  h,
int  row 
)
inline

Extract one row as \((x_j,u_j)\) plot data.

Definition at line 177 of file stencil.hpp.

References num::Series::store().

Referenced by row_slice().

◆ sample_2d_periodic() [1/2]

real num::sample_2d_periodic ( const ScalarField2D g,
real  px,
real  py,
real  ox = 0.0,
real  oy = 0.0 
)
inline

◆ sample_2d_periodic() [2/2]

real num::sample_2d_periodic ( const Vector field,
idx  N,
real  h,
real  px,
real  py,
real  ox,
real  oy 
)
inline

Bilinear interpolation on a periodic NxN grid with configurable stagger offset.

field[i,j] is defined at physical position ((i + ox/h)*h, (j + oy/h)*h). Returns the interpolated field value at physical point (px, py).

Parameters
oxx-axis origin offset in physical units (0 for unstaggered, h/2 for v-face)
oyy-axis origin offset in physical units (0 for unstaggered, h/2 for u-face)

MAC grid usage:

\[ \text{interp\_u}(px,py) = \texttt{sample\_2d\_periodic}(u, N, h,\; px, py,\; 0,\; h/2) \]

\[ \text{interp\_v}(px,py) = \texttt{sample\_2d\_periodic}(v, N, h,\; px, py,\; h/2,\; 0) \]

Definition at line 116 of file stencil.hpp.

Referenced by sample_2d_periodic().

◆ save_png()

void num::save_png ( Gnuplot gp,
const std::string &  filename,
int  w = 900,
int  h = 600 
)
inline

Definition at line 73 of file plot.hpp.

◆ scale() [1/2]

void num::scale ( CVector v,
cplx  alpha 
)

v *= alpha

Definition at line 101 of file vector.cpp.

References num::BasicVector< T >::size().

◆ scale() [2/2]

◆ secant()

RootResult num::secant ( ScalarFn  f,
real  x0,
real  x1,
real  tol = 1e-10,
idx  max_iter = 1000 
)

Secant method (Newton without derivative)

Parameters
fFunction
x0,x1Two distinct initial guesses
tolConvergence tolerance
max_iterMaximum iterations

Definition at line 44 of file roots.cpp.

References e.

◆ set_loglog()

void num::set_loglog ( Gnuplot gp)
inline

Definition at line 67 of file plot.hpp.

◆ set_logx()

void num::set_logx ( Gnuplot gp)
inline

Definition at line 70 of file plot.hpp.

◆ simpson()

real num::simpson ( ScalarFn  f,
real  a,
real  b,
idx  n = 100,
Backend  backend = Backend::seq 
)

Simpson's 1/3 rule with n panels (n must be even)

Parameters
backendBackend::omp parallelises the panel sum

Definition at line 26 of file quadrature.cpp.

◆ solve() [1/6]

template<IsMCMCAlg A, typename MeasureFn , typename RNG >
double num::solve ( const MCMCProblem prob,
const A &  alg,
MeasureFn &&  measure,
RNG &  rng 
)

Run equilibration and measurement sweeps, then return the mean.

Definition at line 71 of file solve.hpp.

References num::MCMCProblem::accept_prob, num::markov::metropolis_sweep_prob(), num::MCMCProblem::n_sites, and num::MCMCProblem::propose.

◆ solve() [2/6]

template<IsODEProblem P>
ODEResult num::solve ( const P &  prob,
const Euler alg,
ObserverFn  obs = nullptr 
)

Definition at line 55 of file solve.hpp.

References ode_euler().

◆ solve() [3/6]

template<IsODEProblem P>
ODEResult num::solve ( const P &  prob,
const RK4 alg,
ObserverFn  obs = nullptr 
)

Definition at line 50 of file solve.hpp.

References ode_rk4().

◆ solve() [4/6]

template<IsODEProblem P>
ODEResult num::solve ( const P &  prob,
const RK45 alg,
ObserverFn  obs = nullptr 
)

◆ solve() [5/6]

template<VecField F>
void num::solve ( F &  u,
const BackwardEuler alg 
)

Definition at line 60 of file solve.hpp.

References num::ode::advance(), and num::BackwardEuler::solver.

◆ solve() [6/6]

template<VecField F, typename Observer >
void num::solve ( F &  u,
const BackwardEuler alg,
Observer &&  obs 
)

Definition at line 65 of file solve.hpp.

References num::ode::advance(), and num::BackwardEuler::solver.

◆ sparse_matvec()

◆ sph_bessel_j()

real num::sph_bessel_j ( unsigned int  n,
real  x 
)
inline

j_n(x) – spherical Bessel function of the first kind

Definition at line 94 of file math.hpp.

◆ sph_bessel_y()

real num::sph_bessel_y ( unsigned int  n,
real  x 
)
inline

y_n(x) – spherical Neumann function (spherical Bessel of the second kind)

Definition at line 104 of file math.hpp.

◆ sph_legendre()

real num::sph_legendre ( unsigned int  l,
unsigned int  m,
real  theta 
)
inline

Y_l^m(theta) – spherical harmonic (real part, theta in radians)

Definition at line 133 of file math.hpp.

◆ svd()

SVDResult num::svd ( const Matrix A,
Backend  backend = lapack_backend,
real  tol = 1e-12,
idx  max_sweeps = 100 
)

Definition at line 11 of file svd.cpp.

References lapack, num::backends::lapack::svd(), and num::backends::seq::svd().

Referenced by svd_truncated().

◆ svd_truncated()

SVDResult num::svd_truncated ( const Matrix A,
idx  k,
Backend  backend = default_backend,
idx  oversampling = 10,
Rng rng = nullptr 
)

◆ thomas()

◆ to_idx()

template<class T >
constexpr idx num::to_idx ( x)
constexprnoexcept

Cast any integer to idx without a verbose static_cast.

Definition at line 16 of file types.hpp.

◆ trapz()

real num::trapz ( ScalarFn  f,
real  a,
real  b,
idx  n = 100,
Backend  backend = Backend::seq 
)

Trapezoidal rule with n panels.

Parameters
backendBackend::omp parallelises the panel sum

Definition at line 14 of file quadrature.cpp.

◆ verlet()

VerletSteps num::verlet ( AccelFn  accel,
Vector  q0,
Vector  v0,
ODEParams  p = {} 
)

Definition at line 382 of file ode.cpp.

Referenced by ode_verlet().

◆ yoshida4()

Yoshida4Steps num::yoshida4 ( AccelFn  accel,
Vector  q0,
Vector  v0,
ODEParams  p = {} 
)

Definition at line 385 of file ode.cpp.

Referenced by ode_yoshida4().

◆ zeta()

real num::zeta ( real  x)
inline

zeta(x) – Riemann zeta function

Definition at line 239 of file math.hpp.

Referenced by num::backends::seq::svd().

Variable Documentation

◆ best_backend

constexpr Backend num::best_backend = default_backend
inlineconstexpr

Definition at line 64 of file policy.hpp.

◆ blas

constexpr Backend num::blas = Backend::blas
inlineconstexpr

Definition at line 20 of file policy.hpp.

◆ blocked

constexpr Backend num::blocked = Backend::blocked
inlineconstexpr

Definition at line 18 of file policy.hpp.

◆ default_backend

constexpr Backend num::default_backend
inlineconstexpr
Initial value:
=
Backend::blocked

Definition at line 53 of file policy.hpp.

◆ e

◆ gpu

constexpr Backend num::gpu = Backend::gpu
inlineconstexpr

Definition at line 22 of file policy.hpp.

◆ half_pi

constexpr real num::half_pi = 1.57079632679489661923
constexpr

pi/2

Definition at line 51 of file math.hpp.

◆ has_blas

constexpr bool num::has_blas
inlineconstexpr
Initial value:
=
false

Definition at line 25 of file policy.hpp.

◆ has_lapack

constexpr bool num::has_lapack
inlineconstexpr
Initial value:
=
false

Definition at line 32 of file policy.hpp.

◆ has_omp

constexpr bool num::has_omp
inlineconstexpr
Initial value:
=
false

Definition at line 39 of file policy.hpp.

◆ has_simd

constexpr bool num::has_simd
inlineconstexpr
Initial value:
=
false

Definition at line 46 of file policy.hpp.

◆ inv_pi

constexpr real num::inv_pi = 0.31830988618379067154
constexpr

1/pi

Definition at line 49 of file math.hpp.

◆ lapack

constexpr Backend num::lapack = Backend::lapack
inlineconstexpr

Definition at line 23 of file policy.hpp.

◆ lapack_backend

constexpr Backend num::lapack_backend
inlineconstexpr
Initial value:
=
Backend::seq

Definition at line 66 of file policy.hpp.

◆ ln2

constexpr real num::ln2 = 0.69314718055994530942
constexpr

Definition at line 48 of file math.hpp.

◆ omp

constexpr Backend num::omp = Backend::omp
inlineconstexpr

Definition at line 21 of file policy.hpp.

◆ phi

constexpr real num::phi = 1.61803398874989484820
constexpr

◆ pi

constexpr real num::pi = 3.14159265358979323846
constexpr

Definition at line 43 of file math.hpp.

Referenced by num::pde::poisson2d(), and num::pde::poisson2d_fd().

◆ seq

constexpr Backend num::seq = Backend::seq
inlineconstexpr

Definition at line 17 of file policy.hpp.

◆ simd

constexpr Backend num::simd = Backend::simd
inlineconstexpr

Definition at line 19 of file policy.hpp.

◆ sqrt2

constexpr real num::sqrt2 = 1.41421356237309504880
constexpr

Definition at line 46 of file math.hpp.

◆ sqrt3

constexpr real num::sqrt3 = 1.73205080756887729353
constexpr

Definition at line 47 of file math.hpp.

◆ two_pi

constexpr real num::two_pi = 6.28318530717958647692
constexpr

2pi

Definition at line 50 of file math.hpp.