Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
scipy
/
linalg
/
__pycache__
/
File Content:
decomp_svd.cpython-35.pyc
�B�W: � @ s� d Z d d l m Z m Z m Z d d l Z d d l m Z m Z m Z d d l m Z m Z d d l m Z m Z d d l m Z d d l m Z d d d d g Z d d d d d d d � Z d d d d � Z d d � Z d d � Z d S)zSVD decomposition functions.� )�division�print_function�absolute_importN)�zeros�r_�diag� )�LinAlgError�_datacopied)�get_lapack_funcs�_compute_lwork)�_asarray_validated)�string_types�svd�svdvals�diagsvd�orthTF�gesddc C se t | d | �} t | j � d k r3 t d � � | j \ } } | pT t | | � } t | t � sr t d � � | d k r� t d | f � � | | d f } t | | f � \ } } t | | j d | j d d | d | �} | | d | d | d | d | �\ } } } } | d k r-t d � � | d k rJt d | � � | r]| | | f S| Sd S)a6 Singular Value Decomposition. Factorizes the matrix a into two unitary matrices U and Vh, and a 1-D array s of singular values (real, non-negative) such that ``a == U*S*Vh``, where S is a suitably shaped matrix of zeros with main diagonal s. Parameters ---------- a : (M, N) array_like Matrix to decompose. full_matrices : bool, optional If True, `U` and `Vh` are of shape ``(M,M)``, ``(N,N)``. If False, the shapes are ``(M,K)`` and ``(K,N)``, where ``K = min(M,N)``. compute_uv : bool, optional Whether to compute also `U` and `Vh` in addition to `s`. Default is True. overwrite_a : bool, optional Whether to overwrite `a`; may improve performance. Default is False. check_finite : bool, optional Whether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs. lapack_driver : {'gesdd', 'gesvd'}, optional Whether to use the more efficient divide-and-conquer approach (``'gesdd'``) or general rectangular approach (``'gesvd'``) to compute the SVD. MATLAB and Octave use the ``'gesvd'`` approach. Default is ``'gesdd'``. .. versionadded:: 0.18 Returns ------- U : ndarray Unitary matrix having left singular vectors as columns. Of shape ``(M,M)`` or ``(M,K)``, depending on `full_matrices`. s : ndarray The singular values, sorted in non-increasing order. Of shape (K,), with ``K = min(M, N)``. Vh : ndarray Unitary matrix having right singular vectors as rows. Of shape ``(N,N)`` or ``(K,N)`` depending on `full_matrices`. For ``compute_uv=False``, only `s` is returned. Raises ------ LinAlgError If SVD computation does not converge. See also -------- svdvals : Compute singular values of a matrix. diagsvd : Construct the Sigma matrix, given the vector s. Examples -------- >>> from scipy import linalg >>> a = np.random.randn(9, 6) + 1.j*np.random.randn(9, 6) >>> U, s, Vh = linalg.svd(a) >>> U.shape, Vh.shape, s.shape ((9, 9), (6, 6), (6,)) >>> U, s, Vh = linalg.svd(a, full_matrices=False) >>> U.shape, Vh.shape, s.shape ((9, 6), (6, 6), (6,)) >>> S = linalg.diagsvd(s, 6, 6) >>> np.allclose(a, np.dot(U, np.dot(S, Vh))) True >>> s2 = linalg.svd(a, compute_uv=False) >>> np.allclose(s, s2) True �check_finite� zexpected matrixzlapack_driver must be a stringr �gesvdz2lapack_driver must be "gesdd" or "gesvd", not "%s"Z_lworkr r � compute_uv� full_matrices�lwork�overwrite_azSVD did not convergez1illegal value in %d-th argument of internal gesddN)r r )r �len�shape� ValueErrorr � isinstancer � TypeErrorr r r )�ar r r r Z lapack_driverZa1�m�nZfuncsZgesXdZgesXd_lworkr �u�s�v�info� r'