Skip to main content

Crate tpt_math_linalg_sparse

Crate tpt_math_linalg_sparse 

Source
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 the std support 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§

ArnoldiRitz
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).
LanczosEigenpairs
Approximate eigenpairs of a symmetric operator from a Lanczos run.
MatrixFree
A square operator defined by a closure, with no stored matrix.
ReorderedCholesky
A sparse Cholesky factorisation computed in a reverse Cuthill–McKee order.
ReorderedLu
A sparse LU factorisation computed after a symmetric fill-reducing reordering.
SparseCholesky
Sparse Cholesky factor A = L Lᵀ of a symmetric positive-definite matrix.
SparseLu
Sparse LU factorisation with partial pivoting, P A = L U.

Enums§

FillOrdering
The fill-reducing ordering used to number the unknowns before a factorisation.
SparseError
Errors returned by the sparse solvers and operators.
Which
Which end of the spectrum lanczos should return.

Traits§

LinearOperator
A linear map y = A x on vectors of length ncols, giving vectors of length nrows.

Functions§

arnoldi
Approximate the k eigenvalues of largest modulus of a general operator by the Arnoldi method.
bicgstab
Solve A x = b with the BiCGSTAB method for general (non-symmetric) systems.
bicgstab_op
BiCGSTAB for a general square operator.
bicgstab_with_report
bicgstab with a SolveReport instead of an error for breakdown or non-convergence. Returns the last iterate with its report.
conjugate_gradient
Solve A x = b with the conjugate gradient method for symmetric positive-definite A.
conjugate_gradient_op
Conjugate gradients for a symmetric positive-definite operator.
conjugate_gradient_with_report
conjugate_gradient with a SolveReport instead of an error for breakdown or non-convergence.
gmres
Solve A x = b with restarted GMRES(restart) for a general square A.
gmres_ilu0
GMRES preconditioned by the ILU(0) factors of a itself.
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_preconditioned with a SolveReport instead of an error for breakdown or non-convergence. Returns the last iterate with its report.
ic0_preconditioned_cg
Solve A x = b with conjugate gradients preconditioned by the IC(0) factor of a.
jacobi_preconditioned_cg
Solve A x = b with conjugate gradients preconditioned by the Jacobi (diagonal) preconditioner M = diag(A).
lanczos
Approximate k eigenpairs of a symmetric operator by the Lanczos method.
matrix_free
Wrap a closure apply(x, y), which writes A·x into y, as an n × n LinearOperator.
minimum_degree_ordering
A minimum-degree ordering of the symmetrised pattern of a.
permute_symmetric
The symmetric permutation P A Pᵀ of a, where perm[new] = old.
preconditioned_conjugate_gradient
Solve A x = b with conjugate gradients preconditioned by the Jacobi (diagonal) preconditioner M = diag(A).
reverse_cuthill_mckee
A reverse Cuthill–McKee ordering of the symmetrised pattern of a.