|
| 1 | +# la-stack |
| 2 | + |
| 3 | +[](https://crates.io/crates/la-stack) |
| 4 | +[](https://crates.io/crates/la-stack) |
| 5 | +[](LICENSE) |
| 6 | +[](https://docs.rs/la-stack) |
| 7 | +[](https://github.com/acgetchell/la-stack/actions/workflows/ci.yml) |
| 8 | +[](https://github.com/acgetchell/la-stack/actions/workflows/rust-clippy.yml) |
| 9 | +[](https://github.com/acgetchell/la-stack/actions/workflows/audit.yml) |
| 10 | + |
| 11 | +Fast, stack-allocated linear algebra for fixed dimensions in Rust. |
| 12 | + |
| 13 | +This crate exists primarily to support the [`delaunay`](https://crates.io/crates/delaunay) crate’s needs while keeping the API intentionally small and explicit. |
| 14 | + |
| 15 | +## 📐 Introduction |
| 16 | + |
| 17 | +`la-stack` provides a handful of const-generic, stack-backed building blocks: |
| 18 | + |
| 19 | +- `Vector<const D: usize>` for fixed-length vectors (`[f64; D]` today) |
| 20 | +- `Matrix<const D: usize>` for fixed-size square matrices (`[[f64; D]; D]` today) |
| 21 | +- `Lu<const D: usize>` for LU factorization with partial pivoting (solve + det) |
| 22 | + |
| 23 | +## ✨ Design goals |
| 24 | + |
| 25 | +- ✅ Const-generic dimensions (no dynamic sizes) |
| 26 | +- ✅ Stack storage only (no heap allocation in core types) |
| 27 | +- ✅ `Copy` types where possible |
| 28 | +- ✅ Explicit algorithms (LU, solve, determinant) |
| 29 | +- ✅ `unsafe` forbidden |
| 30 | +- ✅ No runtime dependencies (dev-dependencies are for contributors only) |
| 31 | + |
| 32 | +## 🔢 Scalar types |
| 33 | + |
| 34 | +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. |
| 35 | + |
| 36 | +## 🚀 Quickstart |
| 37 | + |
| 38 | +Add this to your `Cargo.toml`: |
| 39 | + |
| 40 | +```toml |
| 41 | +[dependencies] |
| 42 | +la-stack = "0.1" |
| 43 | +``` |
| 44 | + |
| 45 | +Solve a 3×3 system via LU: |
| 46 | + |
| 47 | +```rust |
| 48 | +use la_stack::{LaError, Matrix, Vector, DEFAULT_PIVOT_TOL}; |
| 49 | + |
| 50 | +fn main() -> Result<(), LaError> { |
| 51 | + // Requires pivoting (a[0][0] = 0), so it's a good LU demo. |
| 52 | + let a = Matrix::<3>::from_rows([[0.0, 1.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 0.0]]); |
| 53 | + let b = Vector::<3>::new([5.0, 4.0, 3.0]); |
| 54 | + |
| 55 | + let lu = a.lu(DEFAULT_PIVOT_TOL)?; |
| 56 | + let x = lu.solve_vec(b)?.into_array(); |
| 57 | + |
| 58 | + println!("x = {x:?}"); |
| 59 | + Ok(()) |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +## 🧩 API at a glance |
| 64 | + |
| 65 | +| Type | Storage | Purpose | Key methods | |
| 66 | +|---|---|---|---| |
| 67 | +| `Vector<D>` | `[f64; D]` | Fixed-length vector | `new`, `zero`, `dot`, `norm2_sq` | |
| 68 | +| `Matrix<D>` | `[[f64; D]; D]` | Fixed-size square matrix | `from_rows`, `zero`, `identity`, `lu`, `det` | |
| 69 | +| `Lu<D>` | `Matrix<D>` + pivot array | Factorization for solves/det | `solve_vec`, `det` | |
| 70 | + |
| 71 | +Storage shown above reflects the current `f64` implementation. |
| 72 | + |
| 73 | +## 📋 Examples |
| 74 | + |
| 75 | +The `examples/` directory contains small, runnable programs: |
| 76 | + |
| 77 | +```bash |
| 78 | +just examples |
| 79 | +# or: |
| 80 | +cargo run --example solve_3x3 |
| 81 | +cargo run --example det_3x3 |
| 82 | +``` |
| 83 | + |
| 84 | +## 🤝 Contributing |
| 85 | + |
| 86 | +A short contributor workflow: |
| 87 | + |
| 88 | +```bash |
| 89 | +cargo install just |
| 90 | +just ci # lint + fast tests + bench compile |
| 91 | +just commit-check # lint + all tests + examples |
| 92 | +``` |
| 93 | + |
| 94 | +For the full set of developer commands, see `just --list` and `WARP.md`. |
| 95 | + |
| 96 | +## 📄 License |
| 97 | + |
| 98 | +BSD 3-Clause License. See [LICENSE](LICENSE). |
0 commit comments