la-stack
Fast, stack-allocated linear algebra for fixed dimensions in Rust.
This crate grew from the need to support delaunay with fast, stack-allocated linear algebra primitives and algorithms
while keeping the API intentionally small and explicit.
📐 Introduction
la-stack provides a handful of const-generic, stack-backed building blocks:
Vector<const D: usize>for fixed-length vectors ([f64; D]today)Matrix<const D: usize>for fixed-size square matrices ([[f64; D]; D]today)Lu<const D: usize>for LU factorization with partial pivoting (solve + det)
✨ Design goals
- ✅ Const-generic dimensions (no dynamic sizes)
- ✅ Stack storage only (no heap allocation in core types)
- ✅
Copytypes where possible - ✅ Explicit algorithms (LU, solve, determinant)
- ✅
unsafeforbidden - ✅ No runtime dependencies (dev-dependencies are for contributors only)
🔢 Scalar types
Today, the core types are implemented for f64. The intent is to support f32 and f64
(and f128 if/when Rust gains a stable primitive for it). Longer term, we may add optional
arbitrary-precision support (e.g. via rug) depending on performance.
🚀 Quickstart
Add this to your Cargo.toml:
[]
= "0.1"
Solve a 5×5 system via LU:
use *;
// This system requires pivoting (a[0][0] = 0), so it's a good LU demo.
// A = J - I: zeros on diagonal, ones elsewhere.
let a = from_rows;
let b = new;
let lu = a.lu.unwrap;
let x = lu.solve_vec.unwrap.into_array;
// Floating-point rounding is expected; compare with a tolerance.
let expected = ;
for in x.iter.zip
🧩 API at a glance
| Type | Storage | Purpose | Key methods |
|---|---|---|---|
Vector<D> |
[f64; D] |
Fixed-length vector | new, zero, dot, norm2_sq |
Matrix<D> |
[[f64; D]; D] |
Fixed-size square matrix | from_rows, zero, identity, lu, det |
Lu<D> |
Matrix<D> + pivot array |
Factorization for solves/det | solve_vec, det |
Storage shown above reflects the current f64 implementation.
📋 Examples
The examples/ directory contains small, runnable programs:
# or:
🤝 Contributing
A short contributor workflow:
For the full set of developer commands, see just --list and WARP.md.
📄 License
BSD 3-Clause License. See LICENSE.