#NEWLINE# def svd( a , full_matrices = True , compute_uv = True , overwrite_a = False , check_finite = True , lapack_driver = 'gesdd' ) : #NEWLINE# #INDENT# "\n    Singular Value Decomposition.\n\n    Factorizes the matrix a into two unitary matrices U and Vh, and\n    a 1-D array s of singular values (real, non-negative) such that\n    ``a == U*S*Vh``, where S is a suitably shaped matrix of zeros with\n    main diagonal s.\n\n    Parameters\n    ----------\n    a : (M, N) array_like\n        Matrix to decompose.\n    full_matrices : bool, optional\n        If True, `U` and `Vh` are of shape ``(M,M)``, ``(N,N)``.\n        If False, the shapes are ``(M,K)`` and ``(K,N)``, where\n        ``K = min(M,N)``.\n    compute_uv : bool, optional\n        Whether to compute also `U` and `Vh` in addition to `s`.\n        Default is True.\n    overwrite_a : bool, optional\n        Whether to overwrite `a`; may improve performance.\n        Default is False.\n    check_finite : bool, optional\n        Whether to check that the input matrix contains only finite numbers.\n        Disabling may give a performance gain, but may result in problems\n        (crashes, non-termination) if the inputs do contain infinities or NaNs.\n    lapack_driver : {'gesdd', 'gesvd'}, optional\n        Whether to use the more efficient divide-and-conquer approach\n        (``'gesdd'``) or general rectangular approach (``'gesvd'``)\n        to compute the SVD. MATLAB and Octave use the ``'gesvd'`` approach.\n        Default is ``'gesdd'``.\n\n        .. versionadded:: 0.18\n\n    Returns\n    -------\n    U : ndarray\n        Unitary matrix having left singular vectors as columns.\n        Of shape ``(M,M)`` or ``(M,K)``, depending on `full_matrices`.\n    s : ndarray\n        The singular values, sorted in non-increasing order.\n        Of shape (K,), with ``K = min(M, N)``.\n    Vh : ndarray\n        Unitary matrix having right singular vectors as rows.\n        Of shape ``(N,N)`` or ``(K,N)`` depending on `full_matrices`.\n\n    For ``compute_uv=False``, only `s` is returned.\n\n    Raises\n    ------\n    LinAlgError\n        If SVD computation does not converge.\n\n    See also\n    --------\n    svdvals : Compute singular values of a matrix.\n    diagsvd : Construct the Sigma matrix, given the vector s.\n\n    Examples\n    --------\n    >>> from scipy import linalg\n    >>> a = np.random.randn(9, 6) + 1.j*np.random.randn(9, 6)\n    >>> U, s, Vh = linalg.svd(a)\n    >>> U.shape, Vh.shape, s.shape\n    ((9, 9), (6, 6), (6,))\n\n    >>> U, s, Vh = linalg.svd(a, full_matrices=False)\n    >>> U.shape, Vh.shape, s.shape\n    ((9, 6), (6, 6), (6,))\n    >>> S = linalg.diagsvd(s, 6, 6)\n    >>> np.allclose(a, np.dot(U, np.dot(S, Vh)))\n    True\n\n    >>> s2 = linalg.svd(a, compute_uv=False)\n    >>> np.allclose(s, s2)\n    True\n\n    " #NEWLINE# a1 = _asarray_validated ( a , check_finite = check_finite ) #NEWLINE# if ( len ( a1 . shape ) != 2 ) : #NEWLINE# #INDENT# raise ValueError ( 'expected matrix' ) #NEWLINE# #UNINDENT# ( m , n ) = a1 . shape #NEWLINE# overwrite_a = ( overwrite_a or _datacopied ( a1 , a ) ) #NEWLINE# if ( not isinstance ( lapack_driver , string_types ) ) : #NEWLINE# #INDENT# raise TypeError ( 'lapack_driver must be a string' ) #NEWLINE# #UNINDENT# if ( lapack_driver not in ( 'gesdd' , 'gesvd' ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'lapack_driver must be "gesdd" or "gesvd", not "%s"' % ( lapack_driver , ) ) ) #NEWLINE# #UNINDENT# funcs = ( lapack_driver , ( lapack_driver + '_lwork' ) ) #NEWLINE# ( gesXd , gesXd_lwork ) = get_lapack_funcs ( funcs , ( a1 , ) ) #NEWLINE# lwork = _compute_lwork ( gesXd_lwork , a1 . shape [ 0 ] , a1 . shape [ 1 ] , compute_uv = compute_uv , full_matrices = full_matrices ) #NEWLINE# ( u , s , v , info ) = gesXd ( a1 , compute_uv = compute_uv , lwork = lwork , full_matrices = full_matrices , overwrite_a = overwrite_a ) #NEWLINE# if ( info > 0 ) : #NEWLINE# #INDENT# raise LinAlgError ( 'SVD did not converge' ) #NEWLINE# #UNINDENT# if ( info < 0 ) : #NEWLINE# #INDENT# raise ValueError ( ( 'illegal value in %d-th argument of internal gesdd' % ( - info ) ) ) #NEWLINE# #UNINDENT# if compute_uv : #NEWLINE# #INDENT# return ( u , s , a ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return s