Ë
    âQ(hÀ+  ã                   óH  — d Z dgZddlZddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ e	j                  e
j                  ej                  ej                   dœZe	j$                  e
j&                  ej(                  ej*                  dœZdddœZ G d„ d«      Z	 	 	 	 dd„Zy)a�  
Python wrapper for PROPACK
--------------------------

PROPACK is a collection of Fortran routines for iterative computation
of partial SVDs of large matrices or linear operators.

Based on BSD licensed pypropack project:
  http://github.com/jakevdp/pypropack
  Author: Jake Vanderplas <vanderplas@astro.washington.edu>

PROPACK source is BSD licensed, and available at
  http://soi.stanford.edu/~rmunk/PROPACK/
Ú_svdpé    N)Úaslinearoperator)ÚLinAlgErroré   )Ú	_spropack)Ú	_dpropack)Ú	_cpropack)Ú	_zpropack)ÚfÚdÚFÚDÚLÚS)ÚLMÚSMc                   ó<   — e Zd ZdZd„ Zd„ Zed„ «       Zed„ «       Zy)Ú_AProdzŒ
    Wrapper class for linear operator

    The call signature of the __call__ method matches the callback of
    the PROPACK routines.
    c                 óŠ   — 	 t        |«      | _        y # t        $ r& t        t        j                  |«      «      | _        Y y w xY w©N)r   ÚAÚ	TypeErrorÚnpÚasarray)Úselfr   s     úW/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/sparse/linalg/_svdp.pyÚ__init__z_AProd.__init__9   s6   € ð	5Ü% aÓ(ˆD�FøÜò 	5Ü%¤b§j¡j°£mÓ4ˆDŽFð	5ús   ‚ “,AÁAc                 óˆ   — |dk(  r| j                   j                  |«      |d d  y | j                   j                  |«      |d d  y )NÚn)r   ÚmatvecÚrmatvec)r   ÚtransaÚmr   ÚxÚyÚsparmÚiparms           r   Ú__call__z_AProd.__call__?   s5   € Ø�SŠ=Ø—6‘6—=‘= Ó#ˆA‰a‰Dà—6‘6—>‘> !Ó$ˆA‰a‰Dó    c                 ó.   — | j                   j                  S r   )r   Úshape©r   s    r   r+   z_AProd.shapeE   s   € à�v‰v�|‰|Ðr)   c                 óì   — 	 | j                   j                  S # t        $ rR | j                   j                  t	        j
                  | j                   j                  d   «      «      j                  cY S w xY w)Nr   )r   ÚdtypeÚAttributeErrorr    r   Úzerosr+   r,   s    r   r.   z_AProd.dtypeI   sU   € ð	BØ—6‘6—<‘<ÐøÜò 	BØ—6‘6—=‘=¤§¡¨$¯&©&¯,©,°q©/Ó!:Ó;×AÑAÒAð	Bús   ‚ ˜AA3Á2A3N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   Úpropertyr+   r.   © r)   r   r   r   2   s;   „ ñò5ò%ð ñó ðð ñBó ñBr)   r   c                 óš
  — |€t        d«      ‚|j                  «       }|dvrt        d«      ‚|s|dk(  rt        d«      ‚t        | «      }|j                  j                  }	 t
        |   }t        |   }|j                  \  }}|d	k  s|t        ||«      kD  rt        d
«      ‚|€d|z  }|€d}t        |d	z   |d	z   |«      }||k  rt        d|› d|› d�«      ‚|rdnd}|rdnd}t        j                  ||d	z   fd|¬«      }t        j                  ||fd|¬«      }|€h|j!                  |¬«      |dd…df<   t        j                  t        j                  d|¬«      «      r/|dd…dfxx   d|j!                  |¬«      z  z  cc<   n
	 ||dd…df<   |
€2t        j"                  t        j$                  |«      j&                  «      }
|€"t        j$                  |«      j&                  dz  }|r^t        j(                  |
|||f|j+                  «       ¬«      }|€||z
  }|t        ||z
  ||«      kD  rt        d«      ‚|dk  r3t        d«      ‚t        j(                  |
||f|j+                  «       ¬«      }t        j(                  t-        t/        |«      «      t-        t/        |«      «      fd¬«      }d}|s|rF||z   d|z  z   d|z  |z  z   dz   t1        d|z  |z  d|z  z   dz   |t1        ||«      z  «      z   } d |z  }!n5||z   d|z  z   d!|z  |z  z   dz   t1        ||z   d|z  dz   «      z   } d!|z  d	z   }!t        j                  | |j+                  «       ¬«      }"t        j                  |!t        j2                  ¬«      }#t        j                  d	|j+                  «       ¬«      }$t        j                  d	t        j2                  ¬«      }%|j5                  «       r&t        j                  ||z   d"|z  z   |¬«      }&|"|&|#f}'n|"|#f}'|r* |t6        |   |||||||||||	g|'¢|‘|‘|$‘|%‘­Ž \  }}(})}}*n ||||||||||	g	|'¢|‘|‘|$‘|%‘­Ž \  }}(})}}*|*dkD  rt9        d#|*› d$�«      ‚|*dk  rt9        d%|› d&|› d'�«      ‚|dd…d|…f   |(|dd…d|…f   j;                  «       j<                  |)fS # t        $ r‡ t        j                  t        j                  d|¬«      «      r$t        j                  t        «      j                  }n#t        j                  t        «      j                  }t
        |   }t        |   }Y �Œ»w xY w# t         $ r t        d|› �«      ‚w xY w)(ax  
    Compute the singular value decomposition of a linear operator using PROPACK

    Parameters
    ----------
    A : array_like, sparse matrix, or LinearOperator
        Operator for which SVD will be computed.  If `A` is a LinearOperator
        object, it must define both ``matvec`` and ``rmatvec`` methods.
    k : int
        Number of singular values/vectors to compute
    which : {"LM", "SM"}
        Which singular triplets to compute:
        - 'LM': compute triplets corresponding to the `k` largest singular
                values
        - 'SM': compute triplets corresponding to the `k` smallest singular
                values
        `which='SM'` requires `irl_mode=True`.  Computes largest singular
        values by default.
    irl_mode : bool, optional
        If `True`, then compute SVD using IRL (implicitly restarted Lanczos)
        mode.  Default is `True`.
    kmax : int, optional
        Maximal number of iterations / maximal dimension of the Krylov
        subspace. Default is ``10 * k``.
    compute_u : bool, optional
        If `True` (default) then compute left singular vectors, `u`.
    compute_v : bool, optional
        If `True` (default) then compute right singular vectors, `v`.
    tol : float, optional
        The desired relative accuracy for computed singular values.
        If not specified, it will be set based on machine precision.
    v0 : array_like, optional
        Starting vector for iterations: must be of length ``A.shape[0]``.
        If not specified, PROPACK will generate a starting vector.
    full_output : bool, optional
        If `True`, then return sigma_bound.  Default is `False`.
    delta : float, optional
        Level of orthogonality to maintain between Lanczos vectors.
        Default is set based on machine precision.
    eta : float, optional
        Orthogonality cutoff.  During reorthogonalization, vectors with
        component larger than `eta` along the Lanczos vector will be purged.
        Default is set based on machine precision.
    anorm : float, optional
        Estimate of ``||A||``.  Default is ``0``.
    cgs : bool, optional
        If `True`, reorthogonalization is done using classical Gram-Schmidt.
        If `False` (default), it is done using modified Gram-Schmidt.
    elr : bool, optional
        If `True` (default), then extended local orthogonality is enforced
        when obtaining singular vectors.
    min_relgap : float, optional
        The smallest relative gap allowed between any shift in IRL mode.
        Default is ``0.001``.  Accessed only if ``irl_mode=True``.
    shifts : int, optional
        Number of shifts per restart in IRL mode.  Default is determined
        to satisfy ``k <= min(kmax-shifts, m, n)``.  Must be
        >= 0, but choosing 0 might lead to performance degradation.
        Accessed only if ``irl_mode=True``.
    maxiter : int, optional
        Maximum number of restarts in IRL mode.  Default is ``1000``.
        Accessed only if ``irl_mode=True``.
    rng : `numpy.random.Generator`, optional
        Pseudorandom number generator state. When `rng` is None, a new
        `numpy.random.Generator` is created using entropy from the
        operating system. Types other than `numpy.random.Generator` are
        passed to `numpy.random.default_rng` to instantiate a ``Generator``.

    Returns
    -------
    u : ndarray
        The `k` largest (``which="LM"``) or smallest (``which="SM"``) left
        singular vectors, ``shape == (A.shape[0], 3)``, returned only if
        ``compute_u=True``.
    sigma : ndarray
        The top `k` singular values, ``shape == (k,)``
    vt : ndarray
        The `k` largest (``which="LM"``) or smallest (``which="SM"``) right
        singular vectors, ``shape == (3, A.shape[1])``, returned only if
        ``compute_v=True``.
    sigma_bound : ndarray
        the error bounds on the singular values sigma, returned only if
        ``full_output=True``.

    Nz:`rng` must be a normalized numpy.random.Generator instance>   r   r   z#`which` must be either 'LM' or 'SM'r   z#`which`='SM' requires irl_mode=Truer   )r.   r   z.k must be positive and not greater than m or né
   iè  z3kmax must be greater than or equal to k, but kmax (z) < k (ú)r%   r   r   )Úorderr.   )Úsizey              ð?zv0 must be of length g      è?z0shifts must satisfy k <= min(kmax-shifts, m, n)!zshifts must be >= 0!Úié   é	   é   é   é   é   é   é    z#An invariant subspace of dimension z was found.zk=z0 singular triplets did not converge within kmax=z iterations)Ú
ValueErrorÚupperr   r.   ÚcharÚ_lansvd_irl_dictÚ_lansvd_dictÚKeyErrorr   ÚiscomplexobjÚemptyÚcomplexÚfloatr+   Úminr0   ÚuniformÚsqrtÚfinfoÚepsÚarrayÚlowerÚintÚboolÚmaxÚint32ÚisupperÚ_which_converterr   ÚconjÚT)+r   ÚkÚwhichÚirl_modeÚkmaxÚ	compute_uÚ	compute_vÚv0Úfull_outputÚtolÚdeltaÚetaÚanormÚcgsÚelrÚ
min_relgapÚshiftsÚmaxiterÚrngÚaprodÚtypÚ
lansvd_irlÚlansvdr#   r   ÚjobuÚjobvÚuÚvÚdoptionÚioptionÚ	blocksizeÚlworkÚliworkÚworkÚiworkÚdparmr'   ÚzworkÚworksÚsigmaÚbndÚinfos+                                              r   r   r   Q   s¾  € ðr €{ÜÐUÓVÐVà�K‰K‹M€EØ�LÑ ÜÐ>Ó?Ð?Ù˜ šÜÐ>Ó?Ð?ä�1‹I€EØ
�+‰+×
Ñ
€Cð
#Ü% cÑ*ˆ
Ü˜cÑ"ˆð �;‰;�D€A€qØ	ˆAŠ�1”s˜1˜a“y’=ÜÐIÓJÐJà€|Ø�!‰tˆØ€Øˆô ˆq�1‰u�a˜!‘e˜TÓ"€DØˆa‚xÜðØ˜˜g a S¨ð+ó,ð 	,ñ
 ‰3 €DÙ‰3 €Dô 	�‰�!�T˜A‘X� c°Ô5€AÜ
�‰�!�T� #¨SÔ1€Að
 
€zØ—+‘+ 1�+Ó%ˆŠ!ˆQˆ$‰Ü�?‰?œ2Ÿ8™8 A¨SÔ1Ô2ØŠa�ˆd‹G�r˜CŸK™K¨Q˜KÓ/Ñ/Ñ/ŒGð	:ØˆAŠa�ˆd‰Gð
 €}Ü—‘œŸ™ ›×)Ñ)Ó*ˆØ
€{Ü�h‰h�s‹m×Ñ 4Ñ'ˆáÜ—(‘(˜E 3¨¨zÐ:À#Ç)Á)Ã+ÔNˆð ˆ>Ø˜A‘XˆFØŒs�4˜&‘= ! QÓ'Ò'Üð <ó =ð =à�aŠZÜÐ3Ó4Ð4ô —(‘(˜E 3¨Ð.°c·i±i³kÔBˆä�h‰hœœD ›I›¬¬D°«I«Ð7¸sÔC€Gð €Iñ ‘IØ�A‘˜˜$™‘  4¡¨¡Ñ,¨qÑ0´3Øˆd‰F�4‰K˜!˜D™&Ñ  1Ñ$Ø”c˜!˜Q“iÑó4!ñ !ˆð �4‘‰à�A‘˜˜$™‘  4¡¨¡Ñ,¨qÑ0´3°q¸1±u¸aÀ¹fÀq¹jÓ3IÑIˆØ�4‘˜!‘ˆÜ�8‰8�E §¡£Ô-€DÜ�H‰H�V¤2§8¡8Ô,€Eô �H‰H�Q˜cŸi™i›kÔ*€EÜ�H‰H�QœbŸh™hÔ'€Eà
‡{�{„}ô —‘˜˜Q™  A¡™¨SÔ1ˆØ�e˜UÐ"‰à�e�ˆáÙ!+Ô,<¸UÑ,CÀTØ,0°!°Q¸ÀÀ7Ø,1°1°a¸ð"Cà?Dð"CàFMð"Cð -4ð"Cð 6;ð"Cð =Bò"CÑˆˆ5�#�q™$ñ
 "(¨¨d°A°q¸!¸UÀAÀqÈ#ð "PØ).ð"PØ07ð"PØ9@ð"PØBGð"PØINò"PÑˆˆ5�#�q˜$ð ˆa‚xÜØ1°$°°{ÐCóEð 	Eà	�ŠÜØ��ð Ø�6˜ð&ó'ð 	'ð ŠQ���ˆU‰8�U˜Aša  ! ˜e™HŸM™M›O×-Ñ-¨sÐ2Ð2øôy ò #ä�?‰?œ2Ÿ8™8 A¨SÔ1Ô2Ü—(‘(œ7Ó#×(Ñ(‰Cä—(‘(œ5“/×&Ñ&ˆCÜ% cÑ*ˆ
Ü˜cÑ"‹ð#ûôV ò 	:ÜÐ4°Q°CÐ8Ó9Ð9ð	:ús   Á!R Æ	T2 ÒBT/Ô.T/Ô2U
)r   TNTTNFr   NNr   FTgü©ñÒMb`?NNN)r4   Ú__all__Únumpyr   Úscipy.sparse.linalgr   Úscipy.linalgr   Ú_propackr   r   r	   r
   ÚslansvdÚdlansvdÚclansvdÚzlansvdrI   Úslansvd_irlÚdlansvd_irlÚclansvd_irlÚzlansvd_irlrH   r[   r   r   r6   r)   r   ú<module>r’      s³   ðñð ˆ)€ã å 0Ý $å Ý Ý Ý ð 
×	Ñ	Ø	×	Ñ	Ø	×	Ñ	Ø	×	Ñ	ñ	€ð 
×	Ñ	Ø	×	Ñ	Ø	×	Ñ	Ø	×	Ñ	ñ	Ð ð Ø
ñÐ ÷Bñ Bð> 15ØJKØ8<Ø;?ôd3r)   