L i+HdZdgZddlZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z e je je je j d Ze j$e j&e j(e j*d Zd d dZGddZ ddZy)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 PROPACK source is BSD licensed, and available at http://soi.stanford.edu/~rmunk/PROPACK/ _svdpN)aslinearoperator) LinAlgError) _spropack) _dpropack) _cpropack) _zpropack)fdFDLS)LMSMc<eZdZdZdZdZedZedZy)_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&ttj||_YywxYwN)rA TypeErrornpasarray)selfrs _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/sparse/linalg/_svdp.py__init__z_AProd.__init__9s6 5%a(DF 5%bjjm4DF 5s,AAc|dk(r|jj||ddy|jj||ddy)Nn)rmatvecrmatvec)rtransamrxysparmiparms r__call__z_AProd.__call__?s5 S=66==#AaD66>>!$AaDc.|jjSr)rshapers rr+z _AProd.shapeEsvv||r)c |jjS#t$rR|jjt j |jj djcYSwxYw)Nr)rdtypeAttributeErrorr rzerosr+r,s rr.z _AProd.dtypeIsU B66<<  B66==$&&,,q/!:;AA A BsAA32A3N) __name__ __module__ __qualname____doc__rr(propertyr+r.r)rrr2s; 5 % BBr)rc | td|j}|dvr td|s|dk(r tdt|}|jj} t |}t |}|j\}}|d ks|t||kDr td |d |z}|d }t|d z|d z|}||krtd |d|d|rdnd}|rdnd}tj||d zfd|}tj||fd|}|h|j!||dddf<tjtjd|r/|dddfxxd|j!|zz cc<n ||dddf<| 2tj"tj$|j&} | "tj$|j&dz} |r^tj(| | | |f|j+}|||z }|t||z ||kDr td|dkr3tdtj(| | | f|j+}tj(t-t/| t-t/|fd}d}|s|rF||zd|zzd|z|zzdzt1d|z|zd|zzdz|t1||zz} d |z}!n5||zd|zzd!|z|zzdzt1||zd|zdzz} d!|zd z}!tj| |j+}"tj|!tj2}#tjd |j+}$tjd tj2}%|j5r&tj||zd"|zz|}&|"|&|#f}'n|"|#f}'|r*|t6|||||||||||| g |'|||$|%\}}(})}}*n|||||||||| g |'|||$|%\}}(})}}*|*dkDrt9d#|*d$|*dkrt9d%|d&|d'|ddd|f|(|ddd|fj;j<|)fS#t$rtjtjd|r$tjtj}n#tjtj}t |}t |}YwxYw#t$rtd|wxYw)(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>rrz#`which` must be either 'LM' or 'SM'rz#`which`='SM' requires irl_mode=Truer)r.rz.k must be positive and not greater than m or n iz3kmax must be greater than or equal to k, but kmax (z) < k ()r%rr )orderr.)sizey?zv0 must be of length g?z0shifts must satisfy k <= min(kmax-shifts, m, n)!zshifts must be >= 0!i  z#An invariant subspace of dimension z was found.zk=z0 singular triplets did not converge within kmax=z iterations) ValueErrorupperrr.char_lansvd_irl_dict _lansvd_dictKeyErrorr iscomplexobjemptycomplexfloatr+minr0uniformsqrtfinfoepsarraylowerintboolmaxint32isupper_which_converterrconjT)+rkwhichirl_modekmax compute_u compute_vv0 full_outputtoldeltaetaanormcgselr min_relgapshiftsmaxiterrngaprodtyp lansvd_irllansvdr#rjobujobvuvdoptionioption blocksizelworkliworkworkiworkdparmr'zworkworkssigmabndinfos+ rrrQsr {UVV KKME L >??  >?? 1IE ++  C #%c* c" ;;DAq A1s1ay=IJJ |!t q1ua!eT "D ax gaS +, , 3D3D !TAXc5A !T#S1A  z++1+%!Q$ ??288AS1 2 adGrCKKQK// /G :AadG  } ))* {hhsm4'((E3z:#))+N >AXF s4&=!Q' '<= = aZ34 4((E3.ciikBhhDIDI7sCGIIA$4,q03 dF4K!D& 1 $ c!Qi 4!!4A$4,q03q1uafqj3II4! 88E -D HHV288 ,E HHQciik *E HHQbhh 'E {{}QAS1eU"e !+,rs  )0$                              BB>15JK8<;?d3r)