
    (ph+                     J   S r S/rSSKrSSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  \	R                  \
R                  \R                  \R                   S.r\	R$                  \
R&                  \R(                  \R*                  S.rSSS.r " S S5      r    SS jrg)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                   D    \ rS rSrSrS rS r\S 5       r\S 5       r	Sr
g)	_AProd2   z|
Wrapper class for linear operator

The call signature of the __call__ method matches the callback of
the PROPACK routines.
c                      [        U5      U l        g ! [         a'    [        [        R                  " U5      5      U l         g f = fN)r   A	TypeErrornpasarray)selfr   s     L/var/www/html/venv/lib/python3.13/site-packages/scipy/sparse/linalg/_svdp.py__init___AProd.__init__9   s6    	5%a(DF 	5%bjjm4DF	5s    .AAc                     US:X  a  U R                   R                  U5      US S & g U R                   R                  U5      US S & g )Nn)r   matvecrmatvec)r   transamr!   xysparmiparms           r   __call___AProd.__call__?   s5    S=66==#AaD66>>!$AaD    c                 .    U R                   R                  $ r   )r   shaper   s    r   r.   _AProd.shapeE   s    vv||r,   c                      U R                   R                  $ ! [         aS    U R                   R                  [        R
                  " U R                   R                  S   5      5      R                  s $ f = f)Nr   )r   dtypeAttributeErrorr"   r   zerosr.   r/   s    r   r2   _AProd.dtypeI   sU    	B66<< 	B66==$&&,,q/!:;AAA	Bs    AA54A5)r   N)__name__
__module____qualname____firstlineno____doc__r   r*   propertyr.   r2   __static_attributes__ r,   r   r   r   2   s;    5%   B Br,   r   c                 
   Uc  [        S5      eUR                  5       nUS;  a  [        S5      eU(       d  US:X  a  [        S5      e[        U 5      nUR                  R                  n [
        U   n[        U   nUR                  u  nnUS	:  d  U[        UU5      :  a  [        S
5      eUc  SU-  nUc  Sn[        US	-   US	-   U5      nXA:  a  [        SU SU S35      eU(       a  SOSnU(       a  SOSn[        R                  " UUS	-   4SUS9n[        R                  " UU4SUS9nUcf  UR!                  US9USS2S4'   [        R                  " [        R                  " SUS95      (       a!  USS2S4==   SUR!                  US9-  -  ss'   O
 UUSS2S4'   U
c4  [        R"                  " [        R$                  " U5      R&                  5      n
Uc#  [        R$                  " U5      R&                  S-  nU(       a]  [        R(                  " XX4UR+                  5       S9nUc  XA-
  nU[        UU-
  UU5      :  a  [        S5      eUS:  a  [        S5      eO%[        R(                  " XU4UR+                  5       S9n[        R(                  " [-        [/        U5      5      [-        [/        U5      5      4SS9nSnU(       d  U(       aF  UU-   SU-  -   SU-  U-  -   S-   [1        SU-  U-  SU-  -   S-   U[1        UU5      -  5      -   n S U-  n!O5UU-   SU-  -   S!U-  U-  -   S-   [1        UU-   SU-  S-   5      -   n S!U-  S	-   n![        R                  " U UR+                  5       S9n"[        R                  " U![        R2                  S9n#[        R                  " S	UR+                  5       S9n$[        R                  " S	[        R2                  S9n%UR5                  5       (       a$  [        R                  " UU-   S"U-  -   US9n&U"U&U#4n'OU"U#4n'U(       a*  U" [6        U   UUUUUUUUUUU	/U'QUPUPU$PU%P76 u  nn(n)nn*OU" UUUUUUUUU	/	U'QUPUPU$PU%P76 u  nn(n)nn*U*S:  a  [9        S#U* S$35      eU*S:  a  [9        S%U S&U S'35      eUSS2SU24   U(USS2SU24   R;                  5       R<                  U)4$ ! [         a    [        R                  " [        R                  " SUS95      (       a%  [        R                  " [        5      R                  nO$[        R                  " [        5      R                  n[
        U   n[        U   n GNf = f! [          a    [        SU 35      ef = f)(a4  
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   )r2   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   )orderr2   )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   r2   char_lansvd_irl_dict_lansvd_dictKeyErrorr   iscomplexobjemptycomplexfloatr.   minr4   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KKMEL >??>??1IE
++

C
#%c*
c" ;;DAq	A1s1ay=IJJ|!t q1ua!eT"DxgaS+, 	,
 3D3D 	!TAXc5A
!T#S1A
 
z++1+%!Q$??288AS122adGrCKKQK///G	:AadG
 }))*
{hhsm4'((E:#))+N >XFs4&=!Q'' < = =aZ344  ((E.ciikBhhDIDI7sCG I IA$4,q03dF4K!D& 1$c!Qi4! ! 4A$4,q03q1uafqj3II4!88E-DHHV288,E HHQciik*EHHQbhh'E
{{}} QAS1eU"e!+,<U,CT,0!Q7,11a"C?D"CFM"C -4"C 6;"C =B"C5#q$
 "(dAq!UAq# "P)."P07"P9@"PBG"PIN"P5#q$ ax1${CE 	E	 6&' 	' QU8UAa!eHMMO--s22y  #??288AS122((7#((C((5/&&C%c*
c"#V  	:4QC899	:s   *S 	U BUUU4)r   TNTTNFr   NNr   FTgMb`?NNN)r:   __all__numpyr   scipy.sparse.linalgr   scipy.linalgr   _propackr   r   r	   r
   slansvddlansvdclansvdzlansvdrP   slansvd_irldlansvd_irlclansvd_irlzlansvd_irlrO   rb   r   r   r=   r,   r   <module>r      s    )  0 $     
												 
												  
 B B> 15JK8<;?d3r,   