Ë
    ÏÍ:j¨*  ã                   ó,  — 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
 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)Ú_svdpé    N)Ú	HAS_ILP64)Úaslinearoperator)ÚLinAlgErroré   )Ú_propack)ÚfÚdÚFÚD)Ú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     ún/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/scipy/sparse/linalg/_svdp.pyÚ__init__z_AProd.__init__)   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 )Nr   )r   ÚmatvecÚrmatvec)r   ÚtransaÚmÚnÚxÚys         r   Ú__call__z_AProd.__call__/   s5   € Ø�QŠ;Ø—6‘6—=‘= Ó#ˆA‰a‰Dà—6‘6—>‘> !Ó$ˆA‰a‰Dó    c                 ó.   — | j                   j                  S r   )r   Úshape©r   s    r   r%   z_AProd.shape5   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.dtype9   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   "   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|¬«      }t        j                  |d|j                  «       ¬«      }t        j                  |d|j                  «       ¬«      }|€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(        rt        j*                  nt        j,                  } t        j&                  t/        t1        |«      «      t/        t1        |«      «      f| ¬«      }!d}"|s|rH||z   d|dz  z  z   d|z  z   dz   }#|#t3        d|dz  z  d|z  z   dz   |"t3        ||«      z  «      z  }#d |z  }$n5||z   d|z  z   d|dz  z  z   dz   t3        ||z   d|z  dz   «      z   }#d|z  dz   }$t        j                  |#|j                  «       ¬«      }%t        j                  |$| ¬«      }&t        j                  d|j                  «       ¬«      }'t        j                  d| ¬«      }(|j5                  «       r#t        j                  ||z   |z   |¬«      })|%|)|&f}*n|%|&f}*t7        |d!«      rO|j9                  dt        j:                  t        j*                  «      j2                  dt        j<                  ¬"«      }+nN|j?                  dt        j:                  t        j*                  «      j2                  dt        j<                  ¬"«      }+|r( |t@        |   ||||||||	|||||g|*¢|‘|!‘|'‘|(‘|+‘­Ž },n ||||||||	|||||g|*¢|‘|!‘|'‘|(‘|+‘­Ž },|,dkD  rtC        d#|,› d$�«      ‚|,dk  rtC        d%|› d&|› d'�«      ‚|dd…d|…f   ||dd…d|…f   jE                  «       jF                  |fS # t        $ rE t        j                  t        j                  d|¬«      «      rd	}nd
}t
        |   }t        |   }Y �Œtw 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   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   )Úorderr(   )Úsizey              ð?zv0 must be of length g      è?z0shifts must satisfy k <= min(kmax-shifts, m, n)!zshifts must be >= 0!é    é   é   é	   é   é   é   Úintegers)ÚlowÚhighr5   r(   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Úemptyr%   Úminr*   ÚlowerÚuniformÚsqrtÚfinfoÚepsÚarrayr   Úint64Úint32ÚintÚboolÚmaxÚisupperÚhasattrr=   ÚiinfoÚuint64ÚrandintÚ_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ÚsigmaÚbndÚdoptionÚ	int_dtypeÚioptionÚNBÚlworkÚliworkÚworkÚiworkÚdparmÚiparmÚzworkÚworksÚ	rng_stateÚinfos-                                                r   r   r   A   sG  € ð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¨ð+ó,ð 	,ñ
 ‰1˜q€DÙ‰1˜q€Dô 	�‰�!�T˜A‘X� c°Ô5€AÜ
�‰�!�T� #¨SÔ1€AÜ�H‰H�Q˜c¨¯©«Ô5€EÜ
�(‰(�1˜C s§y¡y£{Ô
3€Cð
 
€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ˆå%”—’¬2¯8©8€IÜ�h‰hœœD ›I›¬¬D°«I«Ð7¸yÔI€Gð 
€Bñ ‘IØ�A‘˜˜$ ™'™	Ñ! A d¡FÑ*¨QÑ.ˆØ”�Q�t˜Q‘w‘Y  4¡Ñ'¨!Ñ+¨R´°A°q³	©\Ó:Ñ:ˆØ�4‘‰à�A‘˜˜$™‘  4¨¡7¡Ñ*¨QÑ.´°Q¸±U¸A¸d¹FÀQ¹JÓ1GÑGˆØ�4‘˜!‘ˆÜ�8‰8�E §¡£Ô-€DÜ�H‰H�V 9Ô-€Eô �H‰H�Q˜cŸi™i›kÔ*€EÜ�H‰H�Q˜iÔ(€Eà
‡{�{„}Ü—‘˜˜Q™ ™¨SÔ1ˆØ�e˜UÐ"‰à�e�ˆô ˆs�JÔØ—L‘LØœŸ™¤§¡Ó*×.Ñ.°Q¼b¿i¹ið !ó 
‰	ð —K‘KØœŸ™¤§¡Ó*×.Ñ.°Q¼b¿i¹ið  ó 
ˆ	ñ ÙÔ*¨5Ñ1°4Ø  1 f¨a°¸#Ø  E¨3°ð<à49ð<à;Bð<ð "ð<ð $)ð<ð +0ð<ð 2;ò<‰ñ
 �d˜D ! Q¨¨4°°e¸QÀÀsÈAð IØðIØ%ðIØ'.ðIØ05ðIØ7<ðIØ>GòIˆð ˆa‚xÜØ1°$°°{ÐCóEð 	Eà	�ŠÜØ��ð Ø�6˜ð&ó'ð 	'ð ŠQ���ˆU‰8�U˜Aša  ! ˜e™HŸM™M›O×-Ñ-¨sÐ2Ð2øôO ò #ä�?‰?œ2Ÿ8™8 A¨SÔ1Ô2Ø‰CàˆCÜ% cÑ*ˆ
Ü˜cÑ"‹ð#ûôZ ò 	:ÜÐ4°Q°CÐ8Ó9Ð9ð	:ús   Á!V Ç	W+ ÖA
W(×'W(×+X)r   TNTTNFr   NNr   FTgü©ñÒMb`?NNN)Ú__all__Únumpyr   Úscipy.linalg.lapackr   Úscipy.sparse.linalgr   Úscipy.linalgr   Ú r   ÚslansvdÚdlansvdÚclansvdÚzlansvdrD   Úslansvd_irlÚdlansvd_irlÚclansvd_irlÚzlansvd_irlrC   rY   r   r   r0   r#   r   ú<module>r”      s¦   ðØˆ)€ã Ý )å 0Ý $å ð 
×	Ñ	Ø	×	Ñ	Ø	×	Ñ	Ø	×	Ñ	ñ	€ð 
×	Ñ	Ø	×	Ñ	Ø	×	Ñ	Ø	×	Ñ	ñ	Ð ð Ø
ñÐ ÷Bñ Bð> 15ØJKØ8<Ø;?ôo3r#   