oxiblas-lapack
LAPACK (Linear Algebra PACKage) decompositions and solvers for OxiBLAS
Overview
oxiblas-lapack implements matrix decompositions and linear system solvers in pure Rust. Includes LU, QR, Cholesky, SVD, EVD, Schur decomposition and more, with optimizations that deliver 6-23× speedup over naive implementations.
Features
Decompositions
LU Factorization
Lu- LU with partial pivoting (PA = LU)LuFullPiv- LU with full pivoting (PAQ = LU)BandLu- Banded LU factorization for tridiagonal/pentadiagonal systems
Cholesky Factorization
Cholesky- LL^T for symmetric positive definite matricesLdlt- LDL^T decomposition (no square roots)BandCholesky- Banded Cholesky for sparse symmetric systems
QR Factorization
Qr- Standard QR decompositionQrPivot- QR with column pivotingLq- LQ decomposition (QR variant)Rq- RQ decompositionCod- Complete orthogonal decomposition
SVD (Singular Value Decomposition)
Svd- Standard SVD using Jacobi methodSvdDc- SVD with divide-and-conquer (faster for large matrices)
Eigenvalue Decomposition
SymmetricEvd- Symmetric eigenvalue decomposition (Jacobi)SymmetricEvdDc- Symmetric EVD with divide-and-conquerGeneralEvd- General eigenvalue decomposition (QR algorithm)
Other Decompositions
Schur- Schur decomposition (A = QTQ^T)Hessenberg- Hessenberg reduction
Solvers
solve- General linear system Ax = bsolve_multiple- Multiple right-hand sidessolve_triangular- Triangular system solvelstsq- Least squares solutiontridiag_solve- Tridiagonal system (Thomas algorithm)
Utilities
det- Determinantinv- Matrix inversepinv- Pseudoinverse (via SVD)cond- Condition numberrcond- Reciprocal condition numberrank- Matrix ranknullity- Nullity (dimension of null space)null_space- Null space basiscol_space- Column space basis- Norms:
norm_1,norm_2,norm_inf,norm_frobenius
Installation
[]
= "0.1"
Usage Examples
LU Decomposition
use Lu;
use Mat;
let a = from_rows;
// Compute LU factorization
let lu = compute?;
// Get L and U factors
let l = lu.l;
let u = lu.u;
// Solve Ax = b
let b = vec!;
let x = lu.solve?;
// Determinant
let det = lu.determinant;
// Inverse
let inv = lu.inverse?;
QR Decomposition
use Qr;
use Mat;
let a = from_rows;
// Compute QR
let qr = compute?;
// Get Q and R factors
let q = qr.q;
let r = qr.r;
// Solve least squares problem
let b = vec!;
let x = qr.solve?;
Cholesky Decomposition
use Cholesky;
use Mat;
// Symmetric positive definite matrix
let a = from_rows;
// Compute Cholesky (LL^T)
let chol = compute?;
// Get L factor
let l = chol.l;
// Solve Ax = b (faster than LU for SPD matrices)
let b = vec!;
let x = chol.solve?;
// Determinant
let det = chol.determinant;
SVD (Singular Value Decomposition)
use Svd;
use Mat;
let a = from_rows;
// Compute SVD: A = U Σ V^T
let svd = compute?;
// Get singular values
let singular_values = svd.singular_values; // [4.24, 2.00]
// Get U and V^T matrices
let u = svd.u;
let vt = svd.vt;
// Pseudoinverse
let pinv = svd.pseudoinverse?;
// Rank and nullity
let rank = svd.rank;
let nullity = svd.nullity;
// Condition number
let cond = svd.condition_number;
Eigenvalue Decomposition
use SymmetricEvd;
use Mat;
// Symmetric matrix
let a = from_rows;
// Compute eigenvalues and eigenvectors
let evd = compute?;
// Get eigenvalues (sorted)
let eigenvalues = evd.eigenvalues;
// Get eigenvectors
let eigenvectors = evd.eigenvectors;
// Reconstruct: A = V Λ V^T
let reconstructed = evd.reconstruct;
Linear System Solvers
use solve;
use Mat;
let a = from_rows;
let b = vec!;
// Solve Ax = b
let x = solve?;
// x = [1.0, 2.0]
// Multiple right-hand sides
let b_multi = from_rows;
let x_multi = solve_multiple?;
Matrix Utilities
use ;
use Mat;
let a = from_rows;
// Determinant
let d = det?; // -2.0
// Inverse
let a_inv = inv?;
// Matrix rank
let r = rank?; // 2
// 2-norm (spectral norm)
let n = norm_2?; // ≈ 5.465
Performance
Optimization Achievements
| Operation | Size | Speedup vs Naive | Status |
|---|---|---|---|
| LU (blocked) | 1024×1024 | 14-23× | 🟢 |
| Cholesky (blocked) | 1024×1024 | 6-10× | 🟢 |
| QR | 500×500 | ~3-4× | 🟢 |
| SVD (D&C) | 500×500 | ~2-3× | 🟢 |
| SymmetricEVD (D&C) | 500×500 | ~2-3× | 🟢 |
Benchmarks vs OpenBLAS
| Algorithm | Target Performance | Status |
|---|---|---|
| QR Factorization | ~75% OpenBLAS | 🟢 Achieved |
| SVD | ~70% OpenBLAS | 🟢 Achieved |
| EVD | ~70% OpenBLAS | 🟢 Achieved |
Algorithms
LU Decomposition
- Partial pivoting for numerical stability
- Blocked algorithm for Level 3 BLAS performance
- Cache-aware tiling (14-23× speedup)
Cholesky Factorization
- Blocked algorithm using SYRK/TRSM
- Right-looking variant for better cache locality
- 6-10× speedup over naive implementation
QR Decomposition
- Householder reflections for orthogonality
- Blocked algorithm for efficiency
- Column pivoting for rank-revealing
SVD
- Jacobi method - stable for small to medium matrices
- Divide-and-conquer - faster for large matrices (SvdDc)
- Two-stage approach - Bidiagonalization + Golub-Kahan
Eigenvalue Decomposition
- Jacobi method - symmetric EVD (robust)
- Divide-and-conquer - faster symmetric EVD
- QR algorithm - general eigenvalues (with shifts)
- Schur decomposition - intermediate step for general EVD
Architecture
oxiblas-lapack/
├── lu/
│ ├── lu.rs # LU with partial pivoting
│ ├── lu_full_piv.rs # LU with full pivoting
│ └── band_lu.rs # Banded LU
├── cholesky/
│ ├── cholesky.rs # Cholesky decomposition
│ ├── ldlt.rs # LDL^T decomposition
│ └── band_chol.rs # Banded Cholesky
├── qr/
│ ├── qr.rs # Standard QR
│ ├── qr_pivot.rs # QR with pivoting
│ ├── lq.rs # LQ decomposition
│ ├── rq.rs # RQ decomposition
│ └── cod.rs # Complete orthogonal
├── svd/
│ ├── svd.rs # Jacobi SVD
│ └── svd_dc.rs # Divide-and-conquer SVD
├── evd/
│ ├── symmetric.rs # Symmetric EVD (Jacobi)
│ ├── symmetric_dc.rs # Symmetric EVD (D&C)
│ └── general.rs # General EVD (QR algorithm)
├── schur/
│ ├── schur.rs # Schur decomposition
│ └── hessenberg.rs # Hessenberg reduction
├── solve.rs # Linear system solvers
└── utils.rs # Determinant, inverse, norms, etc.
Examples
Benchmarks
# QR benchmarks
# SVD benchmarks
# Factorization benchmarks
Numerical Stability
- Pivoting used where necessary (LU, QR)
- Householder reflections (QR) - numerically stable
- Givens rotations (Jacobi) - stable for symmetric problems
- Divide-and-conquer algorithms for large-scale problems
Related Crates
oxiblas-core- Core traits and SIMDoxiblas-matrix- Matrix typesoxiblas-blas- BLAS operationsoxiblas-sparse- Sparse decompositionsoxiblas- Meta-crate
License
Licensed under MIT or Apache-2.0 at your option.