src/solvers/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 least eps).
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 = b from 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_lu_factor.
pivot Row permutation from vm_lu_factor.
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.