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§
- Complex
CooMatrix - A complex sparse matrix in coordinate form: duplicate entries are summed on conversion.
- Complex
CsrMatrix - A complex sparse matrix in compressed sparse row form, with the column indices of each row increasing.
- Complex
Iterative Options - 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). - Complex
Iterative Result - The result of a complex iterative solve.
- Complex
Jacobi - The preconditioner
M = diag(A)⁻¹. - Complex
Sparse Lu - A sparse LU factorisation
P A Q = L Uof a complex matrix: Gilbert and Peierls’ left-looking algorithm with partial pivoting by modulus, asSparseLu, with the column orderQfrom the pattern ofA. - CooMatrix
- A matrix being assembled from
(row, column, value)triplets; duplicates are summed when converting (SciPy’scoo_array). - CscMatrix
- Compressed sparse columns: the transpose layout of
CsrMatrix(SciPy’scsc_array). - CsrMatrix
- Compressed sparse rows: the entries of row
iareindices[indptr[i]..indptr[i+1]](columns, increasing) and the matchingdata(SciPy’scsr_array). - Eigs
Options - Options for
eigs(SciPy’s keyword arguments). - Eigs
Result - The result of
eigs. - FnOperator
- A linear operator defined by closures.
- Ilu
- An incomplete factorisation
A ≈ L U, withLunit lower triangular (the unit diagonal not stored) andUupper triangular, both by rows. - Incomplete
Cholesky - An incomplete Cholesky factorisation
A + α diag(A) ≈ L Lᵀ, withLlower triangular. - Iterative
Options - Options for the iterative solvers. Convergence when
‖b − A x‖ ≤ max(rtol ‖b‖, atol)(SciPy’s defaults:rtol = 10⁻⁵,atol = 0). - Iterative
Result - The result of an iterative solve.
- Jacobi
- The Jacobi (diagonal) preconditioner
M = diag(A)⁻¹. - Lgmres
Solver - A stateful LGMRES solver: the augmentation vectors it keeps carry over from one call of
LgmresSolver::solveto the next, which is how SciPy’snewton_krylovreuses them across Newton iterations. - Lsmr
Options - Options for
lsmr, with SciPy’s defaults. - Lsmr
Result - The result of
lsmr(SciPy’sx, istop, itn, normr, normar, norma, conda, normx). - Sparse
Lu - A sparse LU factorisation
P A Q = L U(SciPy’ssplu, with its own algorithm).
Enums§
- Eigs
Which - Which eigenvalues
eigsreturns (SciPy’swhich). - IcOrdering
- The ordering applied before an incomplete factorisation: the factor of
P A Pᵀis a different (and often better) preconditioner than that ofA. - Ordering
- Column orderings for
SparseLu. - Which
- Which eigenvalues
eigshreturns (SciPy’swhich).
Traits§
- Complex
Linear Operator - A complex linear operator
x ↦ A x, for the complex Krylov solvers and as a preconditioner. - Linear
Operator - A matrix seen only through its products with vectors (SciPy’s
LinearOperator).
Functions§
- bandwidth
- The bandwidth
max |i − j|over the stored entries ofAwith rows and columns permuted byperm(perm[k]is the original index placed at positionk). - bicgstab
- BiCGSTAB for general square
A(SciPy’sbicgstab): biconjugate gradients stabilised by a one-step minimal-residual smoothing, two products withAper iteration. - bicgstab_
complex - BiCGSTAB (SciPy’s
bicgstabon complex data), left-preconditioned as SciPy’s. - cg
- Conjugate gradients for symmetric positive definite
A(SciPy’scg): each step minimises theA-norm of the error over a growing Krylov subspace, with search directions that areA-conjugate. WithM, the preconditioned residualz = M rreplacesrin the recurrences. - cg_
complex - Conjugate gradients for Hermitian positive definite
A(SciPy’scgon complex data), with the inner product⟨x, y⟩ = xᴴ y. - colamd
- A column ordering of
Athat approximately minimises the fill of the Cholesky factor ofAᵀA, and so bounds the fill of the LU factors ofA Qunder any row pivoting (SciPy’sCOLAMD). - eigs
keigenvalues and eigenvectors of a square operator (SciPy’seigs), by the Krylov-Schur method. The Arnoldi process builds an orthonormal basisVof a Krylov subspace withA V = V H + f eₘᵀ; the eigenvalues of the smallH(Ritz values) approximate those ofA, with residuals‖f‖ |eₘᵀ y|known without forming the vectors. When the subspace reachesncvvectors, the Schur form ofHis 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
keigenvalues of a sparse matrix nearest the real shiftσ, with eigenvectors (SciPy’seigs(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 ofA − σI. The values are returned nearest first. - eigsh
keigenvalues and eigenvectors of a symmetric operator (SciPy’seigsh). The Lanczos process builds an orthonormal basisQof the Krylov subspace in whichAis tridiagonal,QᵀAQ = T; the eigenvalues ofT(Ritz values) approximate the extreme eigenvalues ofA, with residual norms|β_m s_{m,i}|known without forming the vectors. Full reorthogonalisation keepsQorthonormal in floating point; if the wanted Ritz values have not converged totolrelative accuracy, the subspace is doubled.- eigsh_
shift_ invert - The
keigenvalues of a symmetric sparse matrix nearestσ, with eigenvectors (SciPy’seigsh(A, k, sigma=σ), shift-invert mode). The eigenvaluesλofAnearσ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 ofA − σI. - expm_
multiply e^{tA} b(SciPy’sexpm_multiplyat one time point). Withμ = trace(A)/nandB = 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 squareA(SciPy’sgmres, 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 formingx. Right preconditioning,A M y = b,x = M y. - gmres_
complex - Restarted GMRES (SciPy’s
gmreson 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_iterationscounts cycles (default 1000). - lsmr
- LSMR for
min ‖A x − b‖² + λ² ‖x‖²(Fong and Saunders; SciPy’slsmr). Like LSQR it builds the Golub-Kahan bidiagonalisation ofA, 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 rectangularA(Paige and Saunders; SciPy’slsqr): Golub-Kahan bidiagonalisation ofA, 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’satol = btol = 10⁻⁶by default (options.rtolis used for both). - minimum_
degree - A minimum-degree ordering of the symmetric pattern of
A + Aᵀ(SciPy’sMMD_AT_PLUS_Ais 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’sminres): 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 ann × ngrid the fill isO(N log N)forN = n²unknowns, againstO(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’sreverse_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’sspsolve) by a sparse LU factorisation with the minimum-degree column ordering. - spsolve_
complex - Solves the complex sparse system
A x = b(SciPy’sspsolve) 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
klargest singular values with their left and right singular vectors (columns), descending (SciPy’ssvds, which returns them ascending). Golub-Kahan bidiagonalisationA V = U Bwith full reorthogonalisation, the SVD of the small bidiagonalB, a doubled subspace until the residuals are belowtol, and deflation for repeated singular values. - symamd
- A column ordering for a symmetric matrix (SYMAMD):
colamdapplied to a matrix with one row, holding the two columnsiandj, for each off-diagonal paira_ij ≠ 0, whoseAᵀAhas the pattern ofA + Aᵀ. It is a minimum-degree ordering of the symmetric graph, found by the COLAMD machinery, with its handling of dense vertices.
Type Aliases§
- Eigen
Pairs - Eigenvalues (ascending) and eigenvectors (columns).