lu.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). -
auto vm_lu_factor(vm_
mat* A, int* pivot, int* sign) -> bool - In-place LU factorization with partial pivoting.
-
auto vm_lu_solve(const vm_
mat* LU, const int* pivot, const vm_ float_ t* b, vm_ float_ t* x) -> bool - Solves
A x = bfrom a factored LU. -
auto vm_mat_det(const vm_
mat* A) -> vm_ float_ t - Determinant of a square matrix via LU.
-
auto vm_mat_inverse(vm_
mat* out, const vm_ mat* A) -> bool - Inverse of a square matrix via LU.
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. |
bool vm_lu_factor(vm_ mat* A,
int* pivot,
int* sign)
In-place LU factorization with partial pivoting.
| Parameters | |
|---|---|
| A | Square matrix, overwritten with L and U. |
| pivot | Row permutation; length A->rows. |
| sign | Optional; set to +1 or -1 for the permutation sign. |
| Returns | True on success. |
On success A holds L (unit diagonal, strictly below) and U (on and above the diagonal). pivot[i] is the original row now at position i.
bool vm_lu_solve(const vm_ mat* LU,
const int* pivot,
const vm_ float_ t* b,
vm_ float_ t* x)
Solves A x = b from a factored LU.
| Parameters | |
|---|---|
| LU | Factored matrix from vm_. |
| pivot | Row permutation from vm_. |
| b | Right-hand side, length n. |
| x | Solution, length n. |
| Returns | True on success. |
vm_ float_ t vm_mat_det(const vm_ mat* A)
Determinant of a square matrix via LU.
| Parameters | |
|---|---|
| A | Square matrix (not modified). |
| Returns | det(A), or 0 on failure. |
bool vm_mat_inverse(vm_ mat* out,
const vm_ mat* A)
Inverse of a square matrix via LU.
| Parameters | |
|---|---|
| out | Inverse on success. |
| A | Square matrix (not modified). |
| Returns | True on success. |
Allocates or resizes out when it is not already n x n.