Skip to main content

Module qr

Module qr 

Source
Expand description

Householder QR factorisation + least-squares solve (caller-owned, zero-heap). Householder QR decomposition A = Q·R and least-squares solve.

Functionality parity with nalgebra’s linalg::qr, in the qualia idiom: zero allocation, operating on caller-owned row-major slices, fail-closed. No DMatrix, no heap, no dependency.

QR is the stable workhorse the engine was missing entirely (the prior LA had only fixed-size Matrix4x4 LU and the silo’s heap routines). It gives:

  • orthogonal factorisation A(m×n) = Q(m×m)·R(m×n), m ≥ n;
  • least-squares min‖A·x − b‖ for overdetermined full-rank systems (the normal-equations route proved in [super::gemm], but numerically stable — no AᵀA conditioning blow-up);
  • a square linear solve as the m == n case (alternative to LU).

Storage convention (LAPACK geqrf style): [qr_factor] overwrites a in place — the upper triangle (incl. diagonal) becomes R; below the diagonal holds the essential Householder vectors v (with implicit v[j] = 1); the per-column scalings go in tau.

Functions§

qr_factor
Compute the Householder QR factorisation of the m×n row-major matrix a (m ≥ n) in place. On return:
qr_form_q
Materialise the thin orthogonal factor Q (m×n, row-major) from a factored a/tau (from qr_factor). q must be length m*n. The thin Q satisfies Q·R_n = A (with R_n the n×n upper triangle of a) and has orthonormal columns (Qᵀ·Q = I_n).
qr_solve_least_squares
Least-squares solve min‖A·x − b‖ for an m×n (m ≥ n) full-rank system, given the factored a/tau (from qr_factor).