src/solvers/qr.c file

Functions

static auto vm_mat_at(const vm_mat* m, const int r, const int c) -> vm_float_t*
Column-major element pointer data[r + c * rows].
static auto vm_mat_max_abs(const vm_mat* m) -> vm_float_t
Largest absolute entry of m.
static auto vm_factor_tol(const vm_float_t scale, const int n) -> vm_float_t
Scale-aware cutoff n * eps * scale (at least eps).
static auto vm_min_int(const int a, const int b) -> int
Integer minimum.
static auto vm_mat_resize(vm_mat* m, const int rows, const int cols) -> bool
Ensure m is rows x cols, zeroed.
static auto vm_householder_norm(const vm_mat* A, const int r0, const int c) -> vm_float_t
Euclidean norm of column c from row r0 downward.
static void vm_apply_householder(const vm_mat* M, const vm_mat* QR, const vm_float_t tau, const int k, const int c0, const int n_cols)
Apply the k-th stored Householder reflector to rows k:m of a panel.
auto vm_qr_factor(vm_mat* A, vm_float_t* tau) -> bool
In-place Householder QR.
auto vm_qr_unpack(vm_mat* Q, vm_mat* R, const vm_mat* QR, const vm_float_t* tau) -> bool
Thin factors: Q is m x k, R is k x n, k = min(m, n).
auto vm_qr_solve(const vm_mat* QR, const vm_float_t* tau, const vm_float_t* b, vm_float_t* x) -> bool
Least-squares solve min ||A x - b|| from a factored QR.

Function documentation

static vm_float_t* vm_mat_at(const vm_mat* m, const int r, const int c)

Column-major element pointer data[r + c * rows].

Parameters
m Matrix.
r Row index.
c Column index.
Returns Pointer to element (r, c).

static vm_float_t vm_mat_max_abs(const vm_mat* m)

Largest absolute entry of m.

Parameters
m Matrix.
Returns Max |m_ij|, or 0 if empty.

static vm_float_t vm_factor_tol(const vm_float_t scale, const int n)

Scale-aware cutoff n * eps * scale (at least eps).

Parameters
scale Typical magnitude of the matrix.
n Matrix order (clamped to at least 1).
Returns Factorization / rank tolerance.

static int vm_min_int(const int a, const int b)

Integer minimum.

Parameters
a First value.
b Second value.
Returns The smaller of a and b.

static bool vm_mat_resize(vm_mat* m, const int rows, const int cols)

Ensure m is rows x cols, zeroed.

Parameters
m Matrix to resize.
rows Desired rows.
cols Desired columns.
Returns True if m->data is valid.

Reuses the buffer when the size already matches.

static vm_float_t vm_householder_norm(const vm_mat* A, const int r0, const int c)

Euclidean norm of column c from row r0 downward.

Parameters
A Matrix.
r0 First row of the slice.
c Column index.
Returns 2-norm of the slice.

static void vm_apply_householder(const vm_mat* M, const vm_mat* QR, const vm_float_t tau, const int k, const int c0, const int n_cols)

Apply the k-th stored Householder reflector to rows k:m of a panel.

Parameters
M Panel being updated (may alias QR).
QR Factored matrix holding Householder vectors below the diagonal.
tau Householder scale for column k.
k Reflector index.
c0 First column of the panel.
n_cols Number of columns to update.

n_cols consecutive columns starting at c0 are updated in place.

bool vm_qr_factor(vm_mat* A, vm_float_t* tau)

In-place Householder QR.

Parameters
A Matrix overwritten with R and Householder vectors.
tau Householder scales, length min(m, n).
Returns True on success.

A is m x n.

On success the upper triangle of A is R and the strict lower part stores Householder vectors. tau must hold min(m, n) scalars.

bool vm_qr_unpack(vm_mat* Q, vm_mat* R, const vm_mat* QR, const vm_float_t* tau)

Thin factors: Q is m x k, R is k x n, k = min(m, n).

Parameters
Q Orthonormal factor on success.
R Upper-triangular factor on success.
QR Factored matrix from vm_qr_factor.
tau Householder scales from vm_qr_factor.
Returns True on success.

Allocates or resizes Q and R when they do not already match.

bool vm_qr_solve(const vm_mat* QR, const vm_float_t* tau, const vm_float_t* b, vm_float_t* x)

Least-squares solve min ||A x - b|| from a factored QR.

Parameters
QR Factored matrix from vm_qr_factor.
tau Householder scales from vm_qr_factor.
b Right-hand side, length m.
x Solution, length n.
Returns True on success.

Requires m >= n. b has length m, x has length n.