Skip to main content

Module sparse

Module sparse 

Source
Expand description

Sparse matrices and solvers for large systems, following scipy.sparse and scipy.sparse.linalg: COO, CSR and CSC storage; a sparse LU factorisation with a fill-reducing column ordering (minimum degree, COLAMD, nested dissection or reverse Cuthill-McKee; spsolve, SparseLu); Krylov solvers (CG, MINRES, GMRES, LGMRES, BiCGSTAB, LSQR) for any LinearOperator, with Jacobi, incomplete-LU and incomplete-Cholesky preconditioners; a few eigenvalues or singular values by Lanczos methods (eigsh, its shift-invert mode, svds) and of nonsymmetric matrices by Arnoldi’s (eigs, eigs_shift_invert); and expm_multiply. These are real (f64); complex matrices have their own storage, LU and Krylov solvers (ComplexCsrMatrix, ComplexSparseLu, cg_complex, gmres_complex, bicgstab_complex).

See the book entry Sparse matrices and iterative solvers.

Structs§

ComplexCooMatrix
A complex sparse matrix in coordinate form: duplicate entries are summed on conversion.
ComplexCsrMatrix
A complex sparse matrix in compressed sparse row form, with the column indices of each row increasing.
ComplexIterativeOptions
Options of the complex solvers, as the real ones: convergence when ‖b − A x‖ ≤ max(rtol ‖b‖, atol). Options of the complex solvers, as the real ones: convergence when ‖b − A x‖ ≤ max(rtol ‖b‖, atol). Options of the complex solvers, as the real ones: convergence when ‖b − A x‖ ≤ max(rtol ‖b‖, atol). Options for the iterative solvers. Convergence when ‖b − A x‖ ≤ max(rtol ‖b‖, atol) (SciPy’s defaults: rtol = 10⁻⁵, atol = 0).
ComplexIterativeResult
The result of a complex iterative solve.
ComplexJacobi
The preconditioner M = diag(A)⁻¹.
ComplexSparseLu
A sparse LU factorisation P A Q = L U of a complex matrix: Gilbert and Peierls’ left-looking algorithm with partial pivoting by modulus, as SparseLu, with the column order Q from the pattern of A.
CooMatrix
A matrix being assembled from (row, column, value) triplets; duplicates are summed when converting (SciPy’s coo_array).
CscMatrix
Compressed sparse columns: the transpose layout of CsrMatrix (SciPy’s csc_array).
CsrMatrix
Compressed sparse rows: the entries of row i are indices[indptr[i]..indptr[i+1]] (columns, increasing) and the matching data (SciPy’s csr_array).
EigsOptions
Options for eigs (SciPy’s keyword arguments).
EigsResult
The result of eigs.
FnOperator
A linear operator defined by closures.
Ilu
An incomplete factorisation A ≈ L U, with L unit lower triangular (the unit diagonal not stored) and U upper triangular, both by rows.
IncompleteCholesky
An incomplete Cholesky factorisation A + α diag(A) ≈ L Lᵀ, with L lower triangular.
IterativeOptions
Options for the iterative solvers. Convergence when ‖b − A x‖ ≤ max(rtol ‖b‖, atol) (SciPy’s defaults: rtol = 10⁻⁵, atol = 0).
IterativeResult
The result of an iterative solve.
Jacobi
The Jacobi (diagonal) preconditioner M = diag(A)⁻¹.
LgmresSolver
A stateful LGMRES solver: the augmentation vectors it keeps carry over from one call of LgmresSolver::solve to the next, which is how SciPy’s newton_krylov reuses them across Newton iterations.
LsmrOptions
Options for lsmr, with SciPy’s defaults.
LsmrResult
The result of lsmr (SciPy’s x, istop, itn, normr, normar, norma, conda, normx).
SparseLu
A sparse LU factorisation P A Q = L U (SciPy’s splu, with its own algorithm).

Enums§

EigsWhich
Which eigenvalues eigs returns (SciPy’s which).
IcOrdering
The ordering applied before an incomplete factorisation: the factor of P A Pᵀ is a different (and often better) preconditioner than that of A.
Ordering
Column orderings for SparseLu.
Which
Which eigenvalues eigsh returns (SciPy’s which).

Traits§

ComplexLinearOperator
A complex linear operator x ↦ A x, for the complex Krylov solvers and as a preconditioner.
LinearOperator
A matrix seen only through its products with vectors (SciPy’s LinearOperator).

Functions§

bandwidth
The bandwidth max |i − j| over the stored entries of A with rows and columns permuted by perm (perm[k] is the original index placed at position k).
bicgstab
BiCGSTAB for general square A (SciPy’s bicgstab): biconjugate gradients stabilised by a one-step minimal-residual smoothing, two products with A per iteration.
bicgstab_complex
BiCGSTAB (SciPy’s bicgstab on complex data), left-preconditioned as SciPy’s.
cg
Conjugate gradients for symmetric positive definite A (SciPy’s cg): each step minimises the A-norm of the error over a growing Krylov subspace, with search directions that are A-conjugate. With M, the preconditioned residual z = M r replaces r in the recurrences.
cg_complex
Conjugate gradients for Hermitian positive definite A (SciPy’s cg on complex data), with the inner product ⟨x, y⟩ = xᴴ y.
colamd
A column ordering of A that approximately minimises the fill of the Cholesky factor of AᵀA, and so bounds the fill of the LU factors of A Q under any row pivoting (SciPy’s COLAMD).
eigs
k eigenvalues and eigenvectors of a square operator (SciPy’s eigs), by the Krylov-Schur method. The Arnoldi process builds an orthonormal basis V of a Krylov subspace with A V = V H + f eₘᵀ; the eigenvalues of the small H (Ritz values) approximate those of A, with residuals ‖f‖ |eₘᵀ y| known without forming the vectors. When the subspace reaches ncv vectors, the Schur form of H is reordered to put the wanted Ritz values first, and the factorisation is cut back to their invariant subspace: a real orthonormal basis of it, so that the work stays in real arithmetic. The Arnoldi process then extends it again.
eigs_shift_invert
The k eigenvalues of a sparse matrix nearest the real shift σ, with eigenvectors (SciPy’s eigs(A, k, sigma=σ)). The eigenvalues λ near σ are the largest in magnitude of (A − σI)⁻¹, θ = 1/(λ − σ), which Arnoldi finds quickly; each product with the inverse is one solve with a sparse LU factorisation of A − σI. The values are returned nearest first.
eigsh
k eigenvalues and eigenvectors of a symmetric operator (SciPy’s eigsh). The Lanczos process builds an orthonormal basis Q of the Krylov subspace in which A is tridiagonal, QᵀAQ = T; the eigenvalues of T (Ritz values) approximate the extreme eigenvalues of A, with residual norms |β_m s_{m,i}| known without forming the vectors. Full reorthogonalisation keeps Q orthonormal in floating point; if the wanted Ritz values have not converged to tol relative accuracy, the subspace is doubled.
eigsh_shift_invert
The k eigenvalues of a symmetric sparse matrix nearest σ, with eigenvectors (SciPy’s eigsh(A, k, sigma=σ), shift-invert mode). The eigenvalues λ of A near σ are the largest in magnitude of (A − σI)⁻¹, θ = 1/(λ − σ), which Lanczos finds quickly; each product with the inverse is one solve with a sparse LU factorisation of A − σI.
expm_multiply
e^{tA} b (SciPy’s expm_multiply at one time point). With μ = trace(A)/n and B = A − μI, e^{tA} b = e^{tμ} (e^{tB/s})^s b, and each factor is applied by the Taylor series Σ_{j≤m} (tB/s)^j b / j!, stopping early once two consecutive terms are negligible.
gmres
Restarted GMRES(restart) for general square A (SciPy’s gmres, default restart 20): the Arnoldi process builds an orthonormal Krylov basis, and Givens rotations keep the small least- squares problem for the residual-minimising combination triangular, which gives the residual norm at every step without forming x. Right preconditioning, A M y = b, x = M y.
gmres_complex
Restarted GMRES (SciPy’s gmres on complex data): Arnoldi with modified Gram-Schmidt, complex Givens rotations on the Hessenberg matrix, and right preconditioning.
lgmres
LGMRES with SciPy’s defaults (inner_m = 30, outer_k = 3), from a fresh state. options.max_iterations counts cycles (default 1000).
lsmr
LSMR for min ‖A x − b‖² + λ² ‖x‖² (Fong and Saunders; SciPy’s lsmr). Like LSQR it builds the Golub-Kahan bidiagonalisation of A, but it minimises ‖Aᵀr‖ over the Krylov subspace rather than ‖r‖, so ‖Aᵀr‖ decreases monotonically and the iteration can be stopped safely early: the property that makes it the inner solver of large least-squares trust-region methods.
lsqr
LSQR for min ‖A x − b‖ with any rectangular A (Paige and Saunders; SciPy’s lsqr): Golub-Kahan bidiagonalisation of A, mathematically CG on the normal equations but stable. It stops when ‖r‖ ≤ btol ‖b‖ + atol ‖A‖ ‖x‖ (a consistent system) or ‖Aᵀr‖ ≤ atol ‖A‖ ‖r‖ (a least-squares solution), with SciPy’s atol = btol = 10⁻⁶ by default (options.rtol is used for both).
minimum_degree
A minimum-degree ordering of the symmetric pattern of A + Aᵀ (SciPy’s MMD_AT_PLUS_A is the same idea): repeatedly eliminate a vertex of least degree in the elimination graph.
minimum_degree_exact
The textbook minimum-degree ordering of the symmetric pattern of A + Aᵀ: repeatedly eliminate a vertex of least degree in the elimination graph, where eliminating a vertex joins all its neighbours into a clique (the fill it would create). Ties go to the lowest index. This is the textbook algorithm on an explicit graph with a lazily updated priority queue; AMD and MMD reach similar orderings faster with quotient graphs, supervariables and approximate degrees.
minres
MINRES for symmetric (possibly indefinite) A (Paige and Saunders; SciPy’s minres): the Lanczos process with Givens rotations, minimising ‖b − A x‖ over the Krylov subspace with short recurrences.
nested_dissection
A nested dissection ordering of the symmetric pattern of A + Aᵀ: a small vertex separator splits the graph into two parts that no longer touch, each part is ordered recursively, and the separator is numbered last. Eliminating the parts independently confines the fill to each part and to the separator; on an n × n grid the fill is O(N log N) for N = n² unknowns, against O(N^1.5) for banded and minimum-degree orderings. Pieces of at most 800 vertices, and the separators, are ordered by approximate minimum degree, with the vertices still to come as a frozen halo.
reverse_cuthill_mckee
The reverse Cuthill-McKee ordering of the symmetric pattern of A + Aᵀ (SciPy’s reverse_cuthill_mckee): a breadth-first search from a vertex of low degree in each connected component, visiting neighbours by increasing degree, then reversed. It concentrates the entries near the diagonal (reduces the bandwidth), which limits fill-in during elimination.
spsolve
Solves the sparse system A x = b (SciPy’s spsolve) by a sparse LU factorisation with the minimum-degree column ordering.
spsolve_complex
Solves the complex sparse system A x = b (SciPy’s spsolve) by a sparse LU factorisation with the minimum-degree column ordering.
spsolve_complex_colamd
A complex sparse LU factorisation with the COLAMD column ordering, which does not assume a symmetric pattern.
svds
The k largest singular values with their left and right singular vectors (columns), descending (SciPy’s svds, which returns them ascending). Golub-Kahan bidiagonalisation A V = U B with full reorthogonalisation, the SVD of the small bidiagonal B, a doubled subspace until the residuals are below tol, and deflation for repeated singular values.
symamd
A column ordering for a symmetric matrix (SYMAMD): colamd applied to a matrix with one row, holding the two columns i and j, for each off-diagonal pair a_ij ≠ 0, whose AᵀA has the pattern of A + Aᵀ. It is a minimum-degree ordering of the symmetric graph, found by the COLAMD machinery, with its handling of dense vertices.

Type Aliases§

EigenPairs
Eigenvalues (ascending) and eigenvectors (columns).