403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/scipy/linalg/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/scipy/linalg/__pycache__/_decomp_svd.cpython-311.pyc
�

d�c;:���dZddlZddlmZmZmZmZmZmZmZm	Z	ddl
mZmZddl
mZmZddlmZgd�Z		dd�Zdd
�Zd�Zdd�Zdd�Zd�ZdS)zSVD decomposition functions.�N)�zeros�r_�diag�dot�arccos�arcsin�where�clip�)�LinAlgError�_datacopied)�get_lapack_funcs�_compute_lwork)�_asarray_validated)�svd�svdvals�diagsvd�orth�subspace_angles�
null_spaceTF�gesddc�F�t||���}t|j��dkrtd���|j\}}|pt	||��}t|t��std���|dvrtd|�d����||dzf}	t|	|fd	�
��\}
}t||jd|jd||�
��}|
|||||���\}
}}}|dkrtd���|dkrtd|z���|r|
||fS|S)a.
    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 (default), `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
    --------
    >>> import numpy as np
    >>> from scipy import linalg
    >>> rng = np.random.default_rng()
    >>> m, n = 9, 6
    >>> a = rng.standard_normal((m, n)) + 1.j*rng.standard_normal((m, n))
    >>> U, s, Vh = linalg.svd(a)
    >>> U.shape,  s.shape, Vh.shape
    ((9, 9), (6,), (6, 6))

    Reconstruct the original matrix from the decomposition:

    >>> sigma = np.zeros((m, n))
    >>> for i in range(min(m, n)):
    ...     sigma[i, i] = s[i]
    >>> a1 = np.dot(U, np.dot(sigma, Vh))
    >>> np.allclose(a, a1)
    True

    Alternatively, use ``full_matrices=False`` (notice that the shape of
    ``U`` is then ``(m, n)`` instead of ``(m, m)``):

    >>> U, s, Vh = linalg.svd(a, full_matrices=False)
    >>> U.shape, s.shape, Vh.shape
    ((9, 6), (6,), (6, 6))
    >>> S = np.diag(s)
    >>> 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��expected matrixzlapack_driver must be a string)r�gesvdz/lapack_driver must be "gesdd" or "gesvd", not "�"�_lwork�	preferred)�ilp64rr)�
compute_uv�
full_matrices)r"�lworkr#�overwrite_azSVD did not convergez0illegal value in %dth argument of internal gesdd)r�len�shape�
ValueErrorr
�
isinstance�str�	TypeErrorrrr)�ar#r"r%r�
lapack_driver�a1�m�n�funcs�gesXd�gesXd_lworkr$�u�s�v�infos                 �:/usr/lib/python3/dist-packages/scipy/linalg/_decomp_svd.pyrr
s���~
�A�L�	9�	9�	9�B�
�2�8�}�}�����*�+�+�+�
�8�D�A�q��5�+�b�!�"4�"4�K��m�S�)�)�:��8�9�9�9��.�.�.��j�)�M�M�,�-�-�	-�
�M�H�4�5�E�)�%�"��k�J�J�J��E�;�
�;�����R�X�a�[�&0�
�
O�
O�
O�E��E�"��5�(5�;�P�P�P�M�A�q�!�T��a�x�x��0�1�1�1��a�x�x��K� �5�!�"�"�	"����!�Q�w����c���t||���}|jrt|d|d���St|j��dkrtd���t
jd��S)a

    Compute singular values of a matrix.

    Parameters
    ----------
    a : (M, N) array_like
        Matrix to decompose.
    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.

    Returns
    -------
    s : (min(M, N),) ndarray
        The singular values, sorted in decreasing order.

    Raises
    ------
    LinAlgError
        If SVD computation does not converge.

    See Also
    --------
    svd : Compute the full singular value decomposition of a matrix.
    diagsvd : Construct the Sigma matrix, given the vector s.

    Notes
    -----
    ``svdvals(a)`` only differs from ``svd(a, compute_uv=False)`` by its
    handling of the edge case of empty ``a``, where it returns an
    empty sequence:

    >>> import numpy as np
    >>> a = np.empty((0, 2))
    >>> from scipy.linalg import svdvals
    >>> svdvals(a)
    array([], dtype=float64)

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import svdvals
    >>> m = np.array([[1.0, 0.0],
    ...               [2.0, 3.0],
    ...               [1.0, 1.0],
    ...               [0.0, 2.0],
    ...               [1.0, 0.0]])
    >>> svdvals(m)
    array([ 4.28091555,  1.63516424])

    We can verify the maximum singular value of `m` by computing the maximum
    length of `m.dot(u)` over all the unit vectors `u` in the (x,y) plane.
    We approximate "all" the unit vectors with a large sample. Because
    of linearity, we only need the unit vectors with angles in [0, pi].

    >>> t = np.linspace(0, np.pi, 2000)
    >>> u = np.array([np.cos(t), np.sin(t)])
    >>> np.linalg.norm(m.dot(u), axis=0).max()
    4.2809152422538475

    `p` is a projection matrix with rank 1. With exact arithmetic,
    its singular values would be [1, 0, 0, 0].

    >>> v = np.array([0.1, 0.3, 0.9, 0.3])
    >>> p = np.outer(v, v)
    >>> svdvals(p)
    array([  1.00000000e+00,   2.02021698e-17,   1.56692500e-17,
             8.15115104e-34])

    The singular values of an orthogonal matrix are all 1. Here, we
    create a random orthogonal matrix by using the `rvs()` method of
    `scipy.stats.ortho_group`.

    >>> from scipy.stats import ortho_group
    >>> orth = ortho_group.rvs(4)
    >>> svdvals(orth)
    array([ 1.,  1.,  1.,  1.])

    rrF)r"r%rrr)r�sizerr&r'r(�numpy�empty)r,r%rs   r8rr�sq��h	�1�<�8�8�8�A��v���1��� %�'�'�'�	'�	�Q�W����	�	��*�+�+�+��{�1�~�~�r9c��t|��}|jj}t|��}||kr#td|t|||z
f|��fS||kr"t|t||z
|f|��fSt
d���)a�
    Construct the sigma matrix in SVD from singular values and size M, N.

    Parameters
    ----------
    s : (M,) or (N,) array_like
        Singular values
    M : int
        Size of the matrix whose singular values are `s`.
    N : int
        Size of the matrix whose singular values are `s`.

    Returns
    -------
    S : (M, N) ndarray
        The S-matrix in the singular value decomposition

    See Also
    --------
    svd : Singular value decomposition of a matrix
    svdvals : Compute singular values of a matrix.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import diagsvd
    >>> vals = np.array([1, 2, 3])  # The array representing the computed svd
    >>> diagsvd(vals, 3, 4)
    array([[1, 0, 0, 0],
           [0, 2, 0, 0],
           [0, 0, 3, 0]])
    >>> diagsvd(vals, 4, 3)
    array([[1, 0, 0],
           [0, 2, 0],
           [0, 0, 3],
           [0, 0, 0]])

    z-1zLength of s must be M or N.)r�dtype�charr&rrr()r5�M�N�part�typ�MorNs      r8rr�s���N��7�7�D�
�*�/�C��q�6�6�D��q�y�y��$��e�Q��!��H�c�2�2�2�3�3�	
�����$��q��s�A�h��,�,�,�-�-��6�7�7�7r9c�N�t|d���\}}}|jd|jd}}|�/tj|j��jt
||��z}tj|��|z}tj||kt���}|dd�d|�f}	|	S)a�
    Construct an orthonormal basis for the range of A using SVD

    Parameters
    ----------
    A : (M, N) array_like
        Input array
    rcond : float, optional
        Relative condition number. Singular values ``s`` smaller than
        ``rcond * max(s)`` are considered zero.
        Default: floating point eps * max(M,N).

    Returns
    -------
    Q : (M, K) ndarray
        Orthonormal basis for the range of A.
        K = effective rank of A, as determined by rcond

    See Also
    --------
    svd : Singular value decomposition of a matrix
    null_space : Matrix null space

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import orth
    >>> A = np.array([[2, 0, 0], [0, 5, 0]])  # rank 2 array
    >>> orth(A)
    array([[0., 1.],
           [1., 0.]])
    >>> orth(A.T)
    array([[0., 1.],
           [1., 0.],
           [0., 0.]])

    F�r#rrN�r?)
rr'r<�finfor?�eps�max�amax�sum�int�
�A�rcondr4r5�vhrArB�tol�num�Qs
          r8rrs���L�1�E�*�*�*�H�A�q�"��7�1�:�r�x��{�q�A��}���A�G�$�$�(�3�q�!�9�9�4��
�*�Q�-�-�%�
�C�
�)�A��G�3�
'�
'�
'�C�	�!�!�!�T�c�T�'�
�A��Hr9c�|�t|d���\}}}|jd|jd}}|�/tj|j��jt
||��z}tj|��|z}tj||kt���}||d�dd�fj
���}	|	S)a3
    Construct an orthonormal basis for the null space of A using SVD

    Parameters
    ----------
    A : (M, N) array_like
        Input array
    rcond : float, optional
        Relative condition number. Singular values ``s`` smaller than
        ``rcond * max(s)`` are considered zero.
        Default: floating point eps * max(M,N).

    Returns
    -------
    Z : (N, K) ndarray
        Orthonormal basis for the null space of A.
        K = dimension of effective null space, as determined by rcond

    See Also
    --------
    svd : Singular value decomposition of a matrix
    orth : Matrix range

    Examples
    --------
    1-D null space:

    >>> import numpy as np
    >>> from scipy.linalg import null_space
    >>> A = np.array([[1, 1], [1, 1]])
    >>> ns = null_space(A)
    >>> ns * np.sign(ns[0,0])  # Remove the sign ambiguity of the vector
    array([[ 0.70710678],
           [-0.70710678]])

    2-D null space:

    >>> from numpy.random import default_rng
    >>> rng = default_rng()
    >>> B = rng.random((3, 5))
    >>> Z = null_space(B)
    >>> Z.shape
    (5, 2)
    >>> np.allclose(B.dot(Z), 0)
    True

    The basis vectors are orthonormal (up to rounding error):

    >>> Z.T.dot(Z)
    array([[  1.00000000e+00,   6.92087741e-17],
           [  6.92087741e-17,   1.00000000e+00]])

    TrGrrNrH)rr'r<rIr?rJrKrLrMrN�T�conjrOs
          r8rrOs���l�1�D�)�)�)�H�A�q�"��7�1�:�r�x��{�q�A��}���A�G�$�$�(�3�q�!�9�9�4��
�*�Q�-�-�%�
�C�
�)�A��G�3�
'�
'�
'�C�
�3�4�4����6�
������A��Hr9c��t|d���}t|j��dkrtd|j�����t	|��}~t|d���}t|j��dkrtd|j�����t|��t|��kr+td|jd�d|jd�����t	|��}~t|j���|��}t|��}|jd|jdkr|t||��z
}n*|t||j�����z
}~~~|dzd	k}|�	��r.ttt|d�
��dd����}nd
}t||tt|ddd�dd������}|S)a�
    Compute the subspace angles between two matrices.

    Parameters
    ----------
    A : (M, N) array_like
        The first input array.
    B : (M, K) array_like
        The second input array.

    Returns
    -------
    angles : ndarray, shape (min(N, K),)
        The subspace angles between the column spaces of `A` and `B` in
        descending order.

    See Also
    --------
    orth
    svd

    Notes
    -----
    This computes the subspace angles according to the formula
    provided in [1]_. For equivalence with MATLAB and Octave behavior,
    use ``angles[0]``.

    .. versionadded:: 1.0

    References
    ----------
    .. [1] Knyazev A, Argentati M (2002) Principal Angles between Subspaces
           in an A-Based Scalar Product: Algorithms and Perturbation
           Estimates. SIAM J. Sci. Comput. 23:2008-2040.

    Examples
    --------
    An Hadamard matrix, which has orthogonal columns, so we expect that
    the suspace angle to be :math:`\frac{\pi}{2}`:

    >>> import numpy as np
    >>> from scipy.linalg import hadamard, subspace_angles
    >>> rng = np.random.default_rng()
    >>> H = hadamard(4)
    >>> print(H)
    [[ 1  1  1  1]
     [ 1 -1  1 -1]
     [ 1  1 -1 -1]
     [ 1 -1 -1  1]]
    >>> np.rad2deg(subspace_angles(H[:, :2], H[:, 2:]))
    array([ 90.,  90.])

    And the subspace angle of a matrix to itself should be zero:

    >>> subspace_angles(H[:, :2], H[:, :2]) <= 2 * np.finfo(float).eps
    array([ True,  True], dtype=bool)

    The angles between non-orthogonal subspaces are in between these extremes:

    >>> x = rng.standard_normal((4, 3))
    >>> np.rad2deg(subspace_angles(x[:, :2], x[:, [2]]))
    array([ 55.832])  # random
    Trrzexpected 2D array, got shape z/A and B must have the same number of rows, got rz and rg�?)r%g�g�?gN���)rr&r'r(rrrWrXr�anyrr
r	r)	rP�B�QA�QB�QA_H_QB�sigma�mask�	mu_arcsin�thetas	         r8rr�s���F	�1�4�0�0�0�A�
�1�7�|�|�q����j�a�g�g�G�H�H�H�	
�a���B�	��1�4�0�0�0�A�
�1�7�|�|�q����j�a�g�g�G�H�H�H�
�1�v�v��R������j�(*������Q�W�Q�Z�Z�A�B�B�	B�	
�a���B�	��"�$�)�)�+�+�r�"�"�G��G���E�
�x��{�b�h�q�k�!�!���R��!�!�!�����R�����)�)�*�*�*��
�B���A�:���D��x�x�z�z���4���t� <� <� <�c�2�F�F�G�G�	�	��	�

�$�	�6�$�u�T�T�r�T�{�C��*D�*D�#E�#E�F�F�E��Lr9)TTFTr)FT)N)�__doc__r<rrrrrrr	r
�_miscrr
�lapackrr�_decompr�__all__rrrrrr�r9r8�<module>rjs2��"�"�����C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�,�+�+�+�+�+�+�+�4�4�4�4�4�4�4�4�'�'�'�'�'�'�
P�
P�
P��=B�)0�}�}�}�}�@[�[�[�[�|/8�/8�/8�h-
�-
�-
�-
�`=
�=
�=
�=
�@h�h�h�h�hr9

Youez - 2016 - github.com/yon3zu
LinuXploit