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 leasteps). - 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
misrowsxcols, zeroed. -
static auto vm_householder_norm(const vm_
mat* A, const int r0, const int c) -> vm_ float_ t - Euclidean norm of column
cfrom rowr0downward. -
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_. |
| tau | Householder scales from vm_. |
| 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_. |
| tau | Householder scales from vm_. |
| 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.