
    -iip(                         d gZ ddl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 )_svdp    N)aslinearoperator)LinAlgError   )_propack)fdFD)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     _/var/www/html/bet.cuttalo.com/ml/venv/lib/python3.11/site-packages/scipy/sparse/linalg/_svdp.py__init__z_AProd.__init__(   sR    	5%a((DFFF 	5 	5 	5%bjmm44DFFFF	5s    0AAc                     |dk    r!| j                             |          |d d <   d S | j                             |          |d d <   d S )Nr   )r   matvecrmatvec)r   transamnxys         r   __call__z_AProd.__call__.   sI    Q;;6==##AaaaDDD6>>!$$AaaaDDD    c                     | j         j        S r   )r   shaper   s    r   r$   z_AProd.shape4   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.dtype8   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   !   sw         5 5 5% % %   X B B XB B Br"   r   r   TFMb`?c                    |t          d          |                                }|dvrt          d          |s|dk    rt          d          t          |           }|j        j        }	 t
          |         }t          |         }nW# t          $ rJ t          j	        t          j
        d|                    rd	}nd
}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|          }t          j        |d|                                          }t          j        |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|rP||z   d|dz  z  z   d|z  z   dz   }"|"t-          d |dz  z  d|z  z   dz   |!t-          ||          z            z  }"d!|z  }#n9||z   d|z  z   d|dz  z  z   dz   t-          ||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   |z   |          }(|$|(|%f})n|$|%f})|                    dt          j        t          j                  j        dt          j        "          }*|r, |t:          |         ||||||||	|||||g|)|| |&|'|*R  }+n ||||||||	|||||g|)|| |&|'|*R  }+|+dk    rt=          d#|+ d$          |+dk     rt=          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   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!i          	            )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arrayintboolmaxint32isupperintegersiinfoint64uint64_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ioptionNBlworkliworkworkiworkdparmiparmzworkworks	rng_stateinfos,                                               r   r   r   @   sA   r {UVVVKKMMEL  >??? @>???1IIE
+
C
#%c*
c" # # #?28AS11122 	CCC%c*
c"# ;DAq	A1s1ayy==IJJJ|!t q1ua!eT""Daxx++ +&'+ + +, , 	,
  11qD 11qD 	!TAXc555A
!T#S111AHQc555E
(1Csyy{{
3
3
3C
 
z++1+%%!!!Q$?28AS11122 	0aaadGGGrCKKQK////GGG	:AaaadGG 	: 	: 	:8Q88999	: })**
{hsmm4' C(E3z:#))++NNN >AXFs4&=!Q'''' < = = =aZZ3444  (E3.ciikkBBBhDIIDII7sCCCG 
B  I A$'	!AdF*Q.QtQwY4'!+RAq		\:::4A$47*Q.QUAdFQJ1G1GG4!8E---DHV28,,,E HQciikk***EHQbh'''E
{{}} QS111eU"e "(););)?"#29  6 6I  Iz*5141fa#E3<49<;B< "< $)< +0< 2;< < <
 vdD!Q4eQsA II%I'.I05I7<I>GI I I axxC$CCCE E 	E	& & && & &' ' 	' QQQU8UAaaa!eHMMOO-s22s   ,B ACC	I   I=)r   TNTTNFr   NNr   FTr0   NNN)__all__numpyr   scipy.sparse.linalgr   scipy.linalgr    r   slansvddlansvdclansvdzlansvdrD   slansvd_irldlansvd_irlclansvd_irlzlansvd_irlrC   rX   r   r   r/   r"   r   <module>r      s  )     0 0 0 0 0 0 $ $ $ $ $ $       
								  
								   
  B B B B B B B B> 15JK8<;?c3 c3 c3 c3 c3 c3r"   