libqe 0.2.6-dev.9001
QE C++ library
Loading...
Searching...
No Matches
linalg_fallback.hpp File Reference

Thin LAPACK-free implementations of SVD, QR, and symmetric eigendecomposition for use in WASM / no-LAPACK builds. More...

#include <armadillo>
#include <cmath>
#include <limits>

Go to the source code of this file.

Namespaces

namespace  qe
 
namespace  qe::linalg
 

Functions

Eigendecomposition
void qe::linalg::eig_sym (arma::vec &eigval, arma::mat &eigvec, const arma::mat &S)
 Eigendecomposition of a real symmetric matrix.
 
QR Factorization
void qe::linalg::qr_full (arma::mat &Q, arma::mat &R, const arma::mat &A)
 Full (square) QR factorization of an n×p matrix.
 
Singular Value Decomposition
void qe::linalg::svd (arma::mat &U, arma::vec &s, arma::mat &V, const arma::mat &A)
 Full SVD: A ≈ U * diag(s) * V', singular values descending.
 
void qe::linalg::svd_right (arma::vec &s, arma::mat &V, const arma::mat &A)
 Singular values and right singular vectors only (left vectors skipped).
 
Linear System Solve
arma::mat qe::linalg::solve_spd (const arma::mat &A, const arma::mat &b, double tol=1e-12)
 Solve A*x = b for symmetric positive (semi-)definite A.
 
arma::mat qe::linalg::inv_sym (const arma::mat &A, double tol=1e-12)
 Inverse of a symmetric positive (semi-)definite matrix, falling back to the pseudo-inverse when it is singular.
 

Detailed Description

Thin LAPACK-free implementations of SVD, QR, and symmetric eigendecomposition for use in WASM / no-LAPACK builds.

When ARMA_USE_LAPACK is defined these wrappers delegate directly to the standard Armadillo routines (arma::svd, arma::qr, arma::eig_sym), so there is zero overhead in normal builds. When LAPACK is not available (e.g. Emscripten WASM builds) the wrappers fall back to pure C++ implementations that work for the small matrices typical in ENA (p ≤ ~100 connection dimensions).

All routines live in namespace qe::linalg and operate on arma::mat (double precision).

Fallback algorithms:

  • SVD — one-sided Jacobi iterations on $A^T$ (Demmel & Veselić 1992)
  • QR — modified Gram-Schmidt
  • eig_sym — cyclic Jacobi (classical Jacobi sweep)