skcuda.linalg.svd

skcuda.linalg.svd(a_gpu, jobu='A', jobvt='A', lib='cusolver')[source]

Singular Value Decomposition.

Factors the matrix a into two unitary matrices, u and vh, and a 1-dimensional array of real, non-negative singular values, s, such that a == dot(u.T, dot(diag(s), vh.T)).

Parameters:
  • a (pycuda.gpuarray.GPUArray) – Input matrix of shape (m, n) to decompose.
  • jobu ({'A', 'S', 'O', 'N'}) – If ‘A’, return the full u matrix with shape (m, m). If ‘S’, return the u matrix with shape (m, k). If ‘O’, return the u matrix with shape (m, k) without allocating a new matrix. If ‘N’, don’t return `u.
  • jobvt ({'A', 'S', 'O', 'N'}) – If ‘A’, return the full vh matrix with shape (n, n). If ‘S’, return the vh matrix with shape (k, n). If ‘O’, return the vh matrix with shape (k, n) without allocating a new matrix. If ‘N’, don’t return `vh.
  • lib (str) – Library to use. May be either ‘cula’ or ‘cusolver’.
Returns:

  • u (pycuda.gpuarray.GPUArray) – Unitary matrix of shape (m, m) or (m, k) depending on value of jobu.
  • s (pycuda.gpuarray.GPUArray) – Array containing the singular values, sorted such that s[i] >= s[i+1]. s is of length min(m, n).
  • vh (pycuda.gpuarray.GPUArray) – Unitary matrix of shape (n, n) or (k, n), depending on jobvt.

Notes

If using CULA, double precision is only supported if the standard version of the CULA Dense toolkit is installed.

This function destroys the contents of the input matrix regardless of the values of jobu and jobvt.

Only one of jobu or jobvt may be set to O, and then only for a square matrix.

The CUSOLVER library in CUDA 7.0 only supports jobu == jobvt == ‘A’.

Examples

>>> import pycuda.autoinit
>>> import pycuda.gpuarray as gpuarray
>>> import numpy as np
>>> import skcuda.linalg as linalg
>>> linalg.init()
>>> a = np.random.randn(9, 6) + 1j*np.random.randn(9, 6)
>>> a = np.asarray(a, np.complex64)
>>> a_gpu = gpuarray.to_gpu(a)
>>> u_gpu, s_gpu, vh_gpu = linalg.svd(a_gpu, 'S', 'S')
>>> np.allclose(a, np.dot(u_gpu.get(), np.dot(np.diag(s_gpu.get()), vh_gpu.get())), 1e-4)
True