Skip to main content

Crate tpt_math_linalg_dense

Crate tpt_math_linalg_dense 

Source
Expand description

Dense linear algebra implemented entirely in-house (no external backend).

This crate owns the dynamically-sized DVector and DMatrix types used as the storage backend for tpt-math-linalg and tpt-math-optimize. The matrices are stored column-major in a plain Vec<T>, so there is no faer/nalgebra dependency and no license exposure. The arithmetic, norms, and the partial-pivot-LU solve/inverse are all hand-rolled.

Unlike the old nalgebra-backed path, this crate is the single storage backend for tpt-math-linalg and tpt-math-optimize, so it owns its own DVector/DMatrix types (which also resolves an orphan-rule problem for any external solver trait impls).

§Features

  • std (default) — enable the allocator and the std support of deps.
  • alloc — signal allocator availability (dynamic vectors need it).

§Examples

use tpt_math_linalg_dense::{DMatrix, DVector};

let a = DVector::from_vec(vec![1.0_f64, 2.0, 3.0]);
let b = DVector::from_vec(vec![4.0_f64, 5.0, 6.0]);
assert_eq!(a.dot(&b), 32.0);

let m = DMatrix::from_row_slice(2, 2, &[1.0_f64, 2.0, 3.0, 4.0]);
let v = DVector::from_vec(vec![1.0_f64, 1.0]);
let mv = m * v;
assert_eq!(mv[0], 3.0);
assert_eq!(mv[1], 7.0);

Structs§

Cholesky
A Cholesky factorisation A = L Lᵀ of a symmetric positive-definite matrix, kept for repeated solves.
DMatrix
A dynamically-sized matrix of T, stored column-major in a contiguous Vec ((i, j) lives at i + j * nrows).
DVector
A dynamically-sized column vector of T, stored as a contiguous Vec.
Eigenvalue
An eigenvalue re + i·im of a real matrix.
Lu
A reusable LU factorisation P A = L U of a square matrix.
Qr
A Householder QR factorisation A = Q R of a tall (m ≥ n) matrix, used for least-squares solves. Q is kept implicitly as its reflectors.
SolveDiagnostics
Quality measures for a dense linear solve, from DMatrix::solve_with_report.

Enums§

DenseError
Errors returned by the fallible dense linear-algebra routines.

Constants§

ILL_CONDITIONED_THRESHOLD
The threshold on cond · ε above which a solve is flagged.

Functions§

solve_banded
Solve A x = b for a banded A with kl sub-diagonals and ku super-diagonals, by Gaussian elimination with partial pivoting.
solve_tridiagonal
Solve a tridiagonal system T x = rhs with the Thomas algorithm in O(n).

Type Aliases§

SvdFactors
The factors (U, σ, V) of a thin singular value decomposition.