+
    LV-jóB  ã                   óD  € R t ^ RIt^ RIHtHtHtHtHtHtH	t	H
t
 ^ RIHt ^RIHtHt ^RIHtHt ^RIHt . ROt]! R4      RR
 l4       t]! R4      RR l4       t]! R4      R 4       t]! R4      RR l4       t]! R4      RRRRRRR	/R ll4       t]! RR4      R 4       tR# )zSVD decomposition functions.N)ÚzerosÚr_ÚdiagÚdotÚarccosÚarcsinÚwhereÚclip)Ú_apply_over_batch)ÚLinAlgErrorÚ_datacopied)Úget_lapack_funcsÚ_compute_lwork)Ú_asarray_validatedTFÚgesddc                ó²  € \        WR7      p\        VP                  4      ^8w  d   \        R4      hVP                  w  rxVP                  ^ 8X  Ed,   \        \        P                  ! ^VP                  R7      4      w  ršp\        P                  ! VRV
P                  R7      pV'       d|   \        P                  ! WgV3V	P                  R7      p\        P                  ! V4      VR&   \        P                  ! WhV3VP                  R7      p\        P                  ! V4      VR&   MI\        P                  ! Wg^ 3V	P                  R7      p\        P                  ! V^ V3VP                  R7      pV'       d   WÜV3# V# T;'       g    \        W`4      p\        V\        4      '       g   \        R4      hVR9  d   RV R	2p\        V4      hV'       dÙ   Wx8”  d   Wx3MW‡3w  ppV'       dN   VV,          \        P                  ! \        P                   4      P"                  8”  d   \        R
V RV R24      hMt\#        VV,          VV,          4      p\#        VV,          VV,          4      \        P                  ! \        P                   4      P"                  8”  d   \        RV R24      hWUR,           3p\%        VV3RR7      w  pp\'        VVP                  ^ ,          VP                  ^,          W!R7      pV! WbVWR7      w  rÜppV^ 8”  d   \)        R4      hV^ 8  d,   VR8X  d   VR8X  d   Rp\        V4      h\        RV)  R24      hV'       d   WÜV3# V# )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'``.

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_finitezexpected matrix©Údtype)Úshaper   .zlapack_driver must be a stringr   z/lapack_driver must be "gesdd" or "gesvd", not "Ú"zIndexing a matrix size z x zL would incur integer overflow in LAPACK. Try using numpy.linalg.svd instead.zIndexing a matrix of z[ elements would incur an in integer overflow in LAPACK. Try using numpy.linalg.svd instead.Ú_lworkÚ	preferred)Úilp64)Ú
compute_uvÚfull_matrices)r   Úlworkr   Úoverwrite_azSVD did not convergezA has a NaN entryzillegal value in zth argument of internal gesdd)é    )r   Úgesvdéüÿÿÿ)r   Úlenr   Ú
ValueErrorÚsizeÚsvdÚnpÚeyer   Ú
empty_likeÚidentityr   Ú
isinstanceÚstrÚ	TypeErrorÚiinfoÚint32Úmaxr   r   r   )Úar   r   r   r   Úlapack_driverÚa1ÚmÚnÚu0Ús0Úv0ÚsÚuÚvÚmessageÚmax_mnÚmin_mnÚszÚfuncsÚgesXdÚgesXd_lworkr   ÚinfoÚmsgs   &&&&&&                   Úi/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/scipy/linalg/_decomp_svd.pyr%   r%      sì  € ô| 
˜AÔ	9€BÜ
ˆ2�8‰8ƒ}˜ÔÜÐ*Ó+Ð+Ø�8‰8�D€Að 
‡w�w�!…|ÜœŸš ¨¯©Ô2Ó3‰
ˆ�ä�MŠM˜" D°·±Ô9ˆßÜ—’˜b¨A¨°b·h±hÔ?ˆAÜ—[’[ “^ˆAˆc‰FÜ—’˜b¨A¨°b·h±hÔ?ˆAÜ—[’[ “^ˆAˆcŠFä—’˜b¨A¨°b·h±hÔ?ˆAÜ—’˜b¨¨A¨°b·h±hÔ?ˆAßØ˜�7ˆNàˆHà×5Ð5¤+¨bÓ"4€Kä�m¤S×)Ò)ÜÐ8Ó9Ð9ØÐ.Ô.ØCÀMÀ?ÐRSÐTˆÜ˜Ó!Ð!çà#$¤5˜!™¨q¨f‰ˆ�ßØ�f�}œrŸxšx¬¯©Ó1×5Ñ5Ô5Ü Ð#:¸6¸(À#ÀfÀXð NHð "Hó Ið Ið 6ô
 �Q˜•Z  V¥Ó,ˆBÜ�1�v•:˜q 6�zÓ*¬R¯XªX´b·h±hÓ-?×-CÑ-CÔCÜ Ð#8¸¸ð =Hð "Hó Ið Ið ¨HÕ4Ð5€Eô *¨%°"°¸kÔJÑ€Eˆ;ô ˜;¨¯©°­°R·X±X¸aµ[Ø&0ôO€Eñ ˜"¸5Ø(5ôP�M€Aˆ!ˆTð ˆa„xÜÐ0Ó1Ð1Øˆa„xØ˜GÔ#¨°¬
Ø%ˆCÜ˜S“/Ð!ÜÐ,¨d¨U¨GÐ3PÐQÓRÐRßØ�Qˆwˆàˆó    c                ó    € \        V ^ VVR7      # )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.

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.])

)r   r   r   )r%   )r0   r   r   s   &&&rD   ÚsvdvalsrG   ¶   s   € ôR ˆq˜Q¨KØ(ô*ð *rE   c                ó"  € \        V 4      pVP                  P                  p\        V 4      pWQ8X  d,   \        P
                  ! V\        WV,
          3VR7      34      # WR8X  d#   \        V\        W,
          V3VR7      3,          # \        R4      h)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]])

r   zLength of s must be M or N.)	r   r   Úcharr"   r&   Úhstackr   r   r#   )r8   ÚMÚNÚpartÚtypÚMorNs   &&&   rD   ÚdiagsvdrP     sx   € ôP �‹7€DØ
�*‰*�/‰/€CÜˆq‹6€DØ„yÜ�yŠy˜$¤ q¨a­% j¸Ô <Ð=Ó>Ð>Ø	ŒÜ�$œ˜q�u a˜j°Ô4Ð4Õ5Ð5äÐ6Ó7Ð7rE   c                ó€  € \        V RR7      w  r#pVP                  ^ ,          VP                  ^,          reVf;   \        P                  ! VP                  4      P
                  \        WV4      ,          p\        P                  ! VRR7      V,          p\        P                  ! W78„  \        R7      pVRRV13,          p	V	# )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   Nç        ©Úinitialr   ºNNN)
r%   r   r&   Úfinfor   Úepsr/   ÚamaxÚsumÚint)
ÚAÚrcondr9   r8   ÚvhrK   rL   ÚtolÚnumÚQs
   &&        rD   Úorthra   8  s�   € ôN �1 EÔ*�H€Aˆ"Ø�7‰7�1�:�r—x‘x •{€qØ‚}Ü—’˜Ÿ™Ó!×%Ñ%¬¨A«	Õ1ˆÜ
�'Š'�!˜RÔ
  5Õ
(€CÜ
�&Š&�‘¤Ô
$€CØ	ˆ!ˆTˆcˆTˆ'�
€AØ€HrE   r   r   r1   c               ó²  € \        V RVW4R7      w  rVpVP                  ^ ,          VP                  ^,          r˜Vf;   \        P                  ! VP                  4      P
                  \        W‰4      ,          p\        P                  ! VRR7      V,          p
\        P                  ! Wj8„  \        R7      pW{R1R3,          P                  P                  4       pV# )a  
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).
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'``.

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.copysign(1, 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]])

T)r   r   r   r1   NrR   rS   r   rU   )r%   r   r&   rV   r   rW   r/   rX   rY   rZ   ÚTÚconj)r[   r\   r   r   r1   r9   r8   r]   rK   rL   r^   r_   r`   s   &&$$$        rD   Ú
null_spacere   i  s    € ôH �1 D°kØ ,ôK�H€Aˆ"à�7‰7�1�:�r—x‘x •{€qØ‚}Ü—’˜Ÿ™Ó!×%Ñ%¬¨A«	Õ1ˆÜ
�'Š'�!˜RÔ
  5Õ
(€CÜ
�&Š&�‘¤Ô
$€CØ
‰4�ˆ6�
�‰×ÑÓ€AØ€HrE   c                óÚ  € \        V RR7      p \        V P                  4      ^8w  d   \        RV P                   24      h\	        V 4      p? \        VRR7      p\        VP                  4      ^8w  d   \        RVP                   24      h\        V4      \        V4      8w  d4   \        RVP                  ^ ,           RVP                  ^ ,           24      h\	        V4      p?\        VP                  P                  4       V4      p\        V4      pVP                  ^,          VP                  ^,          8¼  d   V\        W$4      ,
          pM*V\        W4P                  P                  4       4      ,
          p???V^,          R8¬  pVP                  4       '       d#   \        \        \        VRR7      RR4      4      pMR	p\        Wg\        \        VR
R
R1,          RR4      4      4      pV# )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
Tr   zexpected 2D array, got shape z/A and B must have the same number of rows, got z and g      à?)r   g      ð?rR   Ng      ð¿éÿÿÿÿ)r   r"   r   r#   ra   r   rc   rd   rG   Úanyr   r	   r   r   )	r[   ÚBÚQAÚQBÚQA_H_QBÚsigmaÚmaskÚ	mu_arcsinÚthetas	   &&       rD   Úsubspace_anglesrq   ¸  s’  € ôH 	˜1¨4Ô0€AÜ
ˆ1�7‰7ƒ|�qÔÜÐ8¸¿¹¸	ÐBÓCÐCÜ	ˆa‹€BØ	ä˜1¨4Ô0€AÜ
ˆ1�7‰7ƒ|�qÔÜÐ8¸¿¹¸	ÐBÓCÐCÜ
ˆ1ƒv”�R“ÔÜÐJØŸH™H Q�K˜=¨¨a¯g©g°a­j¨\ð;ó <ð 	<ä	ˆa‹€BØ	ô �"—$‘$—)‘)“+˜rÓ"€GÜ�GÓ€Eð 
‡x�x�…{�b—h‘h˜q•kÔ!Ø”�RÓ!Õ!‰à”�RŸ™Ÿ™Ó)Ó*Õ*ˆØ
ˆB�ð �A�:˜Ñ€DØ‡x�x‡z‚zÜœ4¤¨°tÔ <¸cÀ2ÓFÓG‰	àˆ	ô
 �$¤6¬$¨u±T°r°T­{¸CÀÓ*DÓ#EÓF€EØ€LrE   )r%   rG   rP   ra   rq   re   )r0   é   )TTFTr   )FT)r8   é   )r[   rr   )N)ri   rr   )Ú__doc__Únumpyr&   r   r   r   r   r   r   r   r	   Úscipy._lib._utilr
   Ú_miscr   r   Úlapackr   r   Ú_decompr   Ú__all__r%   rG   rP   ra   re   rq   © rE   rD   Ú<module>r|      sè   ðÙ "Û ß C× CÓ Cå .÷ ,ß 4Ý 'ò Q€ñ �8Óóbó ðbñJ �8ÓóI*ó ðI*ñX �8Óñ/8ó ð/8ñh �8Óó-ó ð-ñ` �8ÓñK¨Uð KÀð KØ$ôKó ðKñ\ �8˜XÓ&ñhó 'òhrE   