quimb.linalg.scipy_linalg

Scipy based linear algebra.

Module Contents

Functions

maybe_sort_and_project(lk, vk, P[, sort])

eigs_scipy(A, k, *[, B, which, return_vecs, sigma, ...])

Returns a few eigenpairs from a possibly sparse hermitian operator

eigs_lobpcg(A, k, *[, B, v0, which, return_vecs, ...])

Interface to scipy's lobpcg eigensolver, which can be good for

svds_scipy(A[, k, return_vecs, backend])

Compute a number of singular value pairs

Attributes

quimb.linalg.scipy_linalg.maybe_sort_and_project(lk, vk, P, sort=True)[source]
quimb.linalg.scipy_linalg.eigs_scipy(A, k, *, B=None, which=None, return_vecs=True, sigma=None, isherm=True, sort=True, P=None, tol=None, backend=None, **eigs_opts)[source]

Returns a few eigenpairs from a possibly sparse hermitian operator

Parameters:
  • A (array_like, sparse_matrix, LinearOperator or quimb.Lazy) – The operator to solve for.

  • k (int) – Number of eigenpairs to return

  • B (array_like, sparse_matrix, LinearOperator or quimb.Lazy, optional) – If given, the RHS operator (which should be positive) defining a generalized eigen problem.

  • which (str, optional) – where in spectrum to take eigenvalues from (see scipy.sparse.linalg.eigsh()).

  • return_vecs (bool, optional) – Whether to return the eigenvectors as well.

  • sigma (float, optional) – Shift, if targeting interior eigenpairs.

  • isherm (bool, optional) – Whether A is hermitian.

  • P (array_like, sparse_matrix, LinearOperator or quimb.Lazy, optional) – Perform the eigensolve in the subspace defined by this projector.

  • sort (bool, optional) – Whether to ensure the eigenvalues are sorted in ascending value.

  • backend (None or 'primme', optional) – Which backend to use.

  • eigs_opts – Supplied to scipy.sparse.linalg.eigsh() or scipy.sparse.linalg.eigs().

Returns:

  • lk ((k,) array) – The eigenvalues.

  • vk ((m, k) array) – Corresponding eigenvectors (if return_vecs=True).

quimb.linalg.scipy_linalg.eigs_lobpcg(A, k, *, B=None, v0=None, which=None, return_vecs=True, sigma=None, isherm=True, P=None, sort=True, **lobpcg_opts)[source]

Interface to scipy’s lobpcg eigensolver, which can be good for generalized eigenproblems with matrix-free operators. Seems to a be a bit innacurate though (e.g. on the order of ~ 1e-6 for eigenvalues). Also only takes real, symmetric problems, targeting smallest eigenvalues (though scipy will soon have complex support, and its easy to add oneself).

Note that the slepc eigensolver also has a lobpcg backend (EPSType='lobpcg') which accepts complex input and is more accurate - though seems slower.

Parameters:
  • A (array_like, sparse_matrix, LinearOperator or callable) – The operator to solve for.

  • k (int) – Number of eigenpairs to return

  • B (array_like, sparse_matrix, LinearOperator or callable, optional) – If given, the RHS operator (which should be positive) defining a generalized eigen problem.

  • v0 (array_like (d, k), optional) – The initial subspace to iterate with.

  • which ({'SA', 'LA'}, optional) – Find the smallest or largest eigenvalues.

  • return_vecs (bool, optional) – Whether to return the eigenvectors found.

  • P (array_like, sparse_matrix, LinearOperator or callable, optional) – Perform the eigensolve in the subspace defined by this projector.

  • sort (bool, optional) – Whether to ensure the eigenvalues are sorted in ascending value.

  • lobpcg_opts – Supplied to scipy.sparse.linagl.lobpcg().

Returns:

  • lk (array_like (k,)) – The eigenvalues.

  • vk (array_like (d, k)) – The eigenvectors, if return_vecs=True.

See also

eigs_scipy, eigs_numpy, eigs_slepc

quimb.linalg.scipy_linalg.svds_scipy(A, k=6, *, return_vecs=True, backend=None, **svds_opts)[source]

Compute a number of singular value pairs

Parameters:
  • A ((m, n) dense, sparse or linear operator.) – The operator to solve.

  • k (int) – Number of requested singular values.

  • return_vecs (bool, optional) – Whether to return the singular vectors.

Returns:

  • U ((m, k) array) – Left singular vectors (if return_vecs=True) as columns.

  • s ((k,) array) – Singular values.

  • VH ((k, n) array) – Right singular vectors (if return_vecs=True) as rows.

quimb.linalg.scipy_linalg.eigs_primme
quimb.linalg.scipy_linalg.svds_primme