# Python Interface¶

Primme.svds(A, k=6, ncv=None, tol=0, which='LM', v0=None, maxiter=None, return_singular_vectors=True, precAHA=None, precAAH=None, precAug=None, u0=None, orthou0=None, orthov0=None, return_stats=False, maxBlockSize=0, method=None, methodStage1=None, methodStage2=None, return_history=False, **kargs)

Compute k singular values and vectors of the matrix A.

Parameters: A ({sparse matrix, LinearOperator}) – Array to compute the SVD on, of shape (M, N) k (int, optional) – Number of singular values and vectors to compute. Must be 1 <= k < min(A.shape). ncv (int, optional) – The maximum size of the basis tol (float, optional) – Tolerance for singular values. Zero (default) means 10**4 times the machine precision. A triplet (u,sigma,v) is marked as converged when (||A*v - sigma*u||**2 + ||A.H*u - sigma*v||**2)**.5 is less than “tol” * ||A||, or close to the minimum tolerance that the method can achieve. See the note. which (str ['LM' | 'SM'] or number, optional) – Which k singular values to find: ‘LM’ : largest singular values ‘SM’ : smallest singular values number : closest singular values to (referred as sigma later) u0 (ndarray, optional) – Initial guesses for the left singular vectors. If only u0 or v0 is provided, the other is computed. If both are provided, u0 and v0 should have the same number of columns. v0 (ndarray, optional) – Initial guesses for the right singular vectors. maxiter (int, optional) – Maximum number of matvecs with A and A.H. precAHA ({N x N matrix, array, sparse matrix, LinearOperator}, optional) – Approximate inverse of (A.H*A - sigma**2*I). If provided and M>=N, it usually accelerates the convergence. precAAH ({M x M matrix, array, sparse matrix, LinearOperator}, optional) – Approximate inverse of (A*A.H - sigma**2*I). If provided and M

Notes

The default method used is the hybrid method, which first solves the equivalent eigenvalue problem A.H*A or A*A.H (normal equations) and then refines the solution solving the augmented problem. The minimum tolerance that this method can achieve is ||A||*epsilon, where epsilon is the machine precision. However it may not return triplets with singular values smaller than ||A||*epsilon if “tol” is smaller than ||A||*epsilon/sigma.

This function is a wrapper to PRIMME functions to find singular values and vectors [1].

References

 [1] PRIMME Software, https://github.com/primme/primme
 [2] L. Wu, E. Romero and A. Stathopoulos, PRIMME_SVDS: A High- Performance Preconditioned SVD Solver for Accurate Large-Scale Computations. https://arxiv.org/abs/1607.01404

Primme.eigsh()
eigenvalue decomposition for a sparse symmetrix/complex Hermitian matrix A
scipy.sparse.linalg.eigs()
eigenvalues and eigenvectors for a general (nonsymmetric) matrix A

Examples

>>> import Primme, scipy.sparse
>>> A = scipy.sparse.spdiags(range(1, 11), [0], 100, 10) # sparse diag. rect. matrix
>>> svecs_left, svals, svecs_right = Primme.svds(A, 3, tol=1e-6, which='SM')
>>> svals # the three smallest singular values of A
array([ 1.,  2.,  3.])

>>> import Primme, scipy.sparse
>>> A = scipy.sparse.rand(10000, 100, random_state=10)
>>> prec = scipy.sparse.spdiags(np.reciprocal(A.multiply(A).sum(axis=0)),
...           [0], 100, 100) # square diag. preconditioner
>>> svecs_left, svals, svecs_right = Primme.svds(A, 3, which=6.0, tol=1e-6, precAHA=prec)
>>> ["%.5f" % x for x in svals.flat] # the three closest singular values of A to 0.5
['5.99871', '5.99057', '6.01065']