Skip to main content

Crate tpt_math_linalg

Crate tpt_math_linalg 

Source
Expand description

Linear algebra with compile-time dimensional safety.

tpt_math_linalg_dense (a hand-rolled, in-house dense linear-algebra crate with no external backend) provides the storage, but it is dimensionless: a DVector<f64> is just numbers. uom (via tpt_math_units) gives compile-time unit checking, but has no vector or matrix types. This crate is the bridge: it wraps the dense storage and tags it with a phantom unit type U (typically a uom quantity), so that adding a length-vector to a mass-vector is a compile error, and matrix multiplication propagates units correctly:

Mat<U, V> * Mat<V, W> = Mat<U, W>

§Examples

use tpt_math_linalg::Vec;
use tpt_math_units::prelude::{Length, Time, Velocity};
use tpt_math_linalg_dense::DVector;

// A position vector in metres. `Length`/`Time`/`Velocity` are the concrete
// `f64` SI quantity types re-exported by `tpt_math_units::prelude`.
let pos = Vec::<Length>::from_raw(DVector::from_row_slice(&[3.0_f64, 4.0]));
let dur = Vec::<Time>::from_raw(DVector::from_row_slice(&[2.0_f64, 1.0]));
// Cannot add `pos + dur`: different units (a compile error).
let _ = pos.raw().clone() + dur.raw().clone(); // raw dense ops remain available

§Backend decision

This crate wraps tpt-math-linalg-dense only — never nalgebra, which is Apache-2.0-only and disqualified as a wrap target by the workspace license policy (ADR-0007). tpt-math-linalg-dense is implemented in-house (no faer/nalgebra dependency), so there is no license exposure. The dense storage lives in tpt-math-linalg-dense so the ArgminMath orphan-rule problem is solved there once, and this crate only adds the unit-tagging layer on top. A dual facade was never considered, since tpt-math-linalg-dense is the single storage backend.

Re-exports§

pub use tpt_math_linalg_dense;
pub use tpt_math_units;

Structs§

Mat
A matrix whose rows have unit U and columns have unit V.
Vec
A vector of elements with unit U (typically a uom quantity type).