§
    µ³ÙgÀ+  ã                   ó   — 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dS )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                   óJ   — e Zd ZdZd„ Zd„ Zed„ ¦   «         Zed„ ¦   «         ZdS )Ú_AProdzŒ
    Wrapper class for linear operator

    The call signature of the __call__ method matches the callback of
    the PROPACK routines.
    c                 óž   — 	 t          |¦  «        | _        d S # t          $ r* t          t          j        |¦  «        ¦  «        | _        Y d S w xY w©N)r   ÚAÚ	TypeErrorÚnpÚasarray)Úselfr   s     úO/granary/edev/quantum/lib/python3.11/site-packages/scipy/sparse/linalg/_svdp.pyÚ__init__z_AProd.__init__9   sR   € ð	5Ý% aÑ(Ô(ˆDŒFˆFˆFøÝð 	5ð 	5ð 	5Ý%¥b¤j°¡m¤mÑ4Ô4ˆDŒFˆFˆFˆFð	5øøøs   ‚ ˜0AÁAc                 ó’   — |dk    r!| j                              |¦  «        |d d …<   d S | j                              |¦  «        |d d …<   d S )NÚn)r   ÚmatvecÚrmatvec)r   ÚtransaÚmr   ÚxÚyÚsparmÚiparms           r   Ú__call__z_AProd.__call__?   sI   € Ø�SŠ=ˆ=Ø”6—=’= Ñ#Ô#ˆAˆaˆaˆa‰DˆDˆDà”6—>’> !Ñ$Ô$ˆAˆaˆaˆa‰DˆDˆDó    c                 ó   — | j         j        S r   )r   Úshape©r   s    r   r+   z_AProd.shapeE   s   € àŒvŒ|Ðr)   c                 ó¾   — 	 | j         j        S # t          $ rD | 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   s`   € ð	BØ”6”<ÐøÝð 	Bð 	Bð 	BØ”6—=’=¥¤¨$¬&¬,°q¬/Ñ!:Ô!:Ñ;Ô;ÔAÐAÐAÐAð	Bøøøs   ‚ ŽAAÁAN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   Úpropertyr+   r.   © r)   r   r   r   2   sw   € € € € € ðð ð5ð 5ð 5ð%ð %ð %ð ðð ñ „Xðð ðBð Bñ „XðBð Bð Br)   r   r   TFçü©ñÒMb`?c                 óZ  — |€t          d¦  «        ‚|                     ¦   «         }|dvrt          d¦  «        ‚|s|dk    rt          d¦  «        ‚t          | ¦  «        }|j        j        }	 t
          |         }t          |         }n�# t          $ r‚ t          j	        t          j
        d|¬¦  «        ¦  «        rt          j        t          ¦  «        j        }nt          j        t          ¦  «        j        }t
          |         }t          |         }Y nw xY w|j        \  }}|d	k     s|t          ||¦  «        k    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|¬¦  «        }|€q|                     |¬¦  «        |dd…df<   t          j	        t          j
        d|¬¦  «        ¦  «        r+|dd…dfxx         d|                     |¬¦  «        z  z  cc<   n+	 ||dd…df<   n # t           $ r t          d|› �¦  «        ‚w xY w|
€+t          j        t          j        |¦  «        j        ¦  «        }
|€t          j        |¦  «        j        dz  }|rpt          j        |
|||f|                     ¦   «         ¬¦  «        }|€||z
  }|t          ||z
  ||¦  «        k    rt          d¦  «        ‚|dk     rt          d¦  «        ‚n+t          j        |
||f|                     ¦   «         ¬¦  «        }t          j        t-          t/          |¦  «        ¦  «        t-          t/          |¦  «        ¦  «        fd¬¦  «        }d}|s|rN||z   d|z  z   d|z  |z  z   dz   t1          d|z  |z  d|z  z   dz   |t1          ||¦  «        z  ¦  «        z   } d |z  }!n9||z   d|z  z   d!|z  |z  z   dz   t1          ||z   d|z  dz   ¦  «        z   } d!|z  d	z   }!t          j
        | |                     ¦   «         ¬¦  «        }"t          j
        |!t          j        ¬¦  «        }#t          j
        d	|                     ¦   «         ¬¦  «        }$t          j
        d	t          j        ¬¦  «        }%|                     ¦   «         r%t          j
        ||z   d"|z  z   |¬¦  «        }&|"|&|#f}'n|"|#f}'|r. |t6          |         |||||||||||	g|'¢|‘|‘|$‘|%‘R Ž \  }}(})}}*n ||||||||||	g	|'¢|‘|‘|$‘|%‘R Ž \  }}(})}}*|*dk    rt9          d#|*› d$�¦  «        ‚|*dk     rt9          d%|› d&|› d'�¦  «        ‚|dd…d|…f         |(|dd…d|…f                              ¦   «         j        |)fS )(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ÐVà�KŠK‰MŒM€EØ�LÐ Ð ÝÐ>Ñ?Ô?Ð?Øð @˜ š˜ÝÐ>Ñ?Ô?Ð?å�1‰IŒI€EØ
Œ+Ô
€Cð
#Ý% cÔ*ˆ
Ý˜cÔ"ˆˆøÝð #ð #ð #åŒ?�2œ8 A¨SÐ1Ñ1Ô1Ñ2Ô2ð 	'Ý”(�7Ñ#Ô#Ô(ˆCˆCå”(�5‘/”/Ô&ˆCÝ% cÔ*ˆ
Ý˜cÔ"ˆˆˆð#øøøð Œ;�D€A€qØ	ˆAŠˆ�1•s˜1˜a‘y”y’=�=ÝÐIÑJÔJÐJà€|Ø�!‰tˆØ€Øˆõ ˆq�1‰u�a˜!‘e˜TÑ"Ô"€DØˆa‚x€xÝð+Øð+ð +Ø&'ð+ð +ð +ñ,ô ,ð 	,ð
 Ð$ˆ3ˆ3 €DØÐ$ˆ3ˆ3 €Dõ 	Œ�!�T˜A‘X� c°Ð5Ñ5Ô5€AÝ
Œ�!�T� #¨SÐ1Ñ1Ô1€Að
 
€zØ—+’+ 1�+Ñ%Ô%ˆˆ!ˆ!ˆ!ˆQˆ$‰ÝŒ?�2œ8 A¨SÐ1Ñ1Ô1Ñ2Ô2ð 	0Øˆaˆaˆa�ˆdˆGˆGŒG�r˜CŸKšK¨Q˜KÑ/Ô/Ñ/Ñ/ˆGˆG‰Gøð	:ØˆAˆaˆaˆa�ˆd‰GˆGøÝð 	:ð 	:ð 	:ÝÐ8°QÐ8Ð8Ñ9Ô9Ð9ð	:øøøð €}Ý”�œ ™œÔ)Ñ*Ô*ˆØ
€{ÝŒh�s‰mŒmÔ 4Ñ'ˆàð CÝ”(˜E 3¨¨zÐ:À#Ç)Â)Á+Ä+ÐNÑNÔNˆð ˆ>Ø˜A‘XˆFØ�s�4˜&‘= ! QÑ'Ô'Ò'Ð'Ýð <ñ =ô =ð =à�aŠZˆZÝÐ3Ñ4Ô4Ð4ð õ ”(˜E 3¨Ð.°c·i²i±k´kÐBÑBÔBˆåŒh��D ™IœI™œ­­D°©I¬I©¬Ð7¸sÐCÑCÔC€Gð €Ið ð �Ið Ø�A‘˜˜$™‘  4¡¨¡Ñ,¨qÑ0µ3Øˆd‰F�4‰K˜!˜D™&Ñ  1Ñ$Ø•c˜!˜Q‘i”iÑñ4!ô 4!ñ !ˆð �4‘ˆˆà�A‘˜˜$™‘  4¡¨¡Ñ,¨qÑ0µ3°q¸1±u¸aÀ¹fÀq¹jÑ3IÔ3IÑIˆØ�4‘˜!‘ˆÝŒ8�E §¢¡¤Ð-Ñ-Ô-€DÝŒH�V¥2¤8Ð,Ñ,Ô,€Eõ ŒH�Q˜cŸiši™kœkÐ*Ñ*Ô*€EÝŒH�Q�bœhÐ'Ñ'Ô'€Eà
‡{‚{�}„}ð õ ”˜˜Q™  A¡™¨SÐ1Ñ1Ô1ˆØ�e˜UÐ"ˆˆà�e�ˆàð PØ!+ Õ,<¸UÔ,CÀTØ,0°!°Q¸ÀÀ7Ø,1°1°a¸ð"Cà?Dð"CàFMð"Cð -4ð"Cð 6;ð"Cð =Bð"Cð "Cð "CÑˆˆ5�#�q˜$˜$ð
 "( ¨¨d°A°q¸!¸UÀAÀqÈ#ð "PØ).ð"PØ07ð"PØ9@ð"PØBGð"PØINð"Pð "Pð "PÑˆˆ5�#�q˜$ð ˆa‚x€xÝØC°$ÐCÐCÐCñEô Eð 	Eà	�ŠˆÝð&�ð &ð &Øð&ð &ð &ñ'ô 'ð 	'ð ˆQˆQˆQ���ˆUŒ8�U˜A˜a˜a˜a  ! ˜eœHŸMšM™OœOÔ-¨sÐ2Ð2s   Á,B ÂB	DÄDÈ<	I ÉI#)r   TNTTNFr   NNr   FTr7   NNN)r4   Ú__all__Únumpyr   Úscipy.sparse.linalgr   Úscipy.linalgr   Ú_propackr   r   r	   r
   ÚslansvdÚdlansvdÚclansvdÚzlansvdrJ   Úslansvd_irlÚdlansvd_irlÚclansvd_irlÚzlansvd_irlrI   r\   r   r   r6   r)   r   ú<module>r“      sT  ððð ð ˆ)€à Ð Ð Ð à 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø $Ð $Ð $Ð $Ð $Ð $à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ð 
Ô	Ø	Ô	Ø	Ô	Ø	Ô	ð	ð €ð 
Ô	Ø	Ô	Ø	Ô	Ø	Ô	ð	ð Ð ð Ø
ðð Ð ðBð Bð Bð Bð Bñ Bô Bð Bð> 15ØJKØ8<Ø;?ðd3ð d3ð d3ð d3ð d3ð d3r)   