svd_robust

  • full name: tenpy.linalg.svd_robust

  • parent module: tenpy.linalg

  • type: module

Functions

svd(a[, full_matrices, compute_uv, ...])

Wrapper around scipy.linalg.svd() with gesvd backup plan.

Module description

(More) robust version of singular value decomposition.

We often need to perform an SVD. In general, an SVD is a matrix factorization that is always well defined and should also work for ill-conditioned matrices. But sadly, both numpy.linalg.svd() and scipy.linalg.svd() fail from time to time, raising LinalgError("SVD did not converge"). The reason is that both of them call the LAPACK function #gesdd (where # depends on the data type), which takes an iterative approach that can fail. However, it is usually much faster than the alternative (and robust) #gesvd.

Our workaround is as follows: we provide a function svd() with call signature as scipy’s svd. This function is basically just a wrapper around scipy’s svd, i.e., we keep calling the faster dgesdd. But if that fails, we can still use dgesvd as a backup.

Examples

The idea is that you just import the svd from this module and use it as replacement for np.linalg.svd or scipy.linalg.svd:

>>> from tenpy.linalg.svd_robust import svd
>>> U, S, VT = svd([[1., 1.], [0., 1.]])