Expand description
Sparse linear algebra implemented entirely in-house (no external backend).
This crate provides general-purpose sparse matrix storage — coordinate
(triplet, CooMatrix), compressed-sparse-row (CsrMatrix) and
compressed-sparse-column (CscMatrix) — plus iterative solvers, preconditioners
and direct LU / Cholesky factorisations:
conjugate_gradient for symmetric positive-definite systems and
bicgstab for general (non-symmetric) systems.
Everything is hand-rolled on top of tpt_math_linalg_dense::DVector (the
dense RHS/solution type) and tpt_math_numeric::Scalar, so there is no
nalgebra/faer/sprs dependency and no license exposure. The design
deliberately mirrors the storage portion of a sparse format only; it does
not try to replace tpt-fem-sparse,
which is a separate FEM-assembly adapter (element scatter + duplicate-summing
triplet accumulation) living in the tpt-fem repo.
§Features
std(default) — enable the allocator and thestdsupport of deps.alloc— signal allocator availability (sparse containers need it).
§Examples
use tpt_math_linalg_dense::DVector;
use tpt_math_linalg_sparse::{CooMatrix, conjugate_gradient, SparseError};
// Build the 2x2 SPD system A x = b with A = [[4,1],[1,3]], b = [1,2].
let mut coo = CooMatrix::<f64>::new(2, 2);
coo.push(0, 0, 4.0);
coo.push(0, 1, 1.0);
coo.push(1, 0, 1.0);
coo.push(1, 1, 3.0);
let a = coo.to_csr();
let b = DVector::from_vec(vec![1.0, 2.0]);
let x = conjugate_gradient(&a, &b, None, 1e-12, 100).unwrap();
let expected = DVector::from_vec(vec![1.0 / 11.0, 7.0 / 11.0]);
assert!((x[0] - expected[0]).abs() < 1e-10);
assert!((x[1] - expected[1]).abs() < 1e-10);Structs§
- Arnoldi
Ritz - Approximate eigenvalues of a general operator from an Arnoldi run.
- CooMatrix
- A sparse matrix in coordinate (COO / triplet) form.
- CscMatrix
- A sparse matrix in compressed-sparse-column (CSC) form.
- CsrMatrix
- A sparse matrix in compressed-sparse-row (CSR) form.
- Ic0
- Incomplete Cholesky factorisation with zero fill-in, IC(0).
- Ilu0
- Incomplete LU factorisation with zero fill-in, ILU(0).
- Lanczos
Eigenpairs - Approximate eigenpairs of a symmetric operator from a Lanczos run.
- Matrix
Free - A square operator defined by a closure, with no stored matrix.
- Reordered
Cholesky - A sparse Cholesky factorisation computed in a reverse Cuthill–McKee order.
- Reordered
Lu - A sparse LU factorisation computed after a symmetric fill-reducing reordering.
- Sparse
Cholesky - Sparse Cholesky factor
A = L Lᵀof a symmetric positive-definite matrix. - Sparse
Lu - Sparse LU factorisation with partial pivoting,
P A = L U.
Enums§
- Fill
Ordering - The fill-reducing ordering used to number the unknowns before a factorisation.
- Sparse
Error - Errors returned by the sparse solvers and operators.
- Which
- Which end of the spectrum
lanczosshould return.
Traits§
- Linear
Operator - A linear map
y = A xon vectors of lengthncols, giving vectors of lengthnrows.
Functions§
- arnoldi
- Approximate the
keigenvalues of largest modulus of a general operator by the Arnoldi method. - bicgstab
- Solve
A x = bwith the BiCGSTAB method for general (non-symmetric) systems. - bicgstab_
op - BiCGSTAB for a general square operator.
- bicgstab_
with_ report bicgstabwith aSolveReportinstead of an error for breakdown or non-convergence. Returns the last iterate with its report.- conjugate_
gradient - Solve
A x = bwith the conjugate gradient method for symmetric positive-definiteA. - conjugate_
gradient_ op - Conjugate gradients for a symmetric positive-definite operator.
- conjugate_
gradient_ with_ report conjugate_gradientwith aSolveReportinstead of an error for breakdown or non-convergence.- gmres
- Solve
A x = bwith restarted GMRES(restart) for a general squareA. - gmres_
ilu0 - GMRES preconditioned by the ILU(0) factors of
aitself. - gmres_
op - Restarted, right-preconditioned GMRES for a general square operator.
- gmres_
right_ preconditioned - Right-preconditioned restarted GMRES.
- gmres_
right_ preconditioned_ with_ report gmres_right_preconditionedwith aSolveReportinstead of an error for breakdown or non-convergence. Returns the last iterate with its report.- ic0_
preconditioned_ cg - Solve
A x = bwith conjugate gradients preconditioned by the IC(0) factor ofa. - jacobi_
preconditioned_ cg - Solve
A x = bwith conjugate gradients preconditioned by the Jacobi (diagonal) preconditionerM = diag(A). - lanczos
- Approximate
keigenpairs of a symmetric operator by the Lanczos method. - matrix_
free - Wrap a closure
apply(x, y), which writesA·xintoy, as ann × nLinearOperator. - minimum_
degree_ ordering - A minimum-degree ordering of the symmetrised pattern of
a. - permute_
symmetric - The symmetric permutation
P A Pᵀofa, whereperm[new] = old. - preconditioned_
conjugate_ gradient - Solve
A x = bwith conjugate gradients preconditioned by the Jacobi (diagonal) preconditionerM = diag(A). - reverse_
cuthill_ mckee - A reverse Cuthill–McKee ordering of the symmetrised pattern of
a.