L i!ddlmcmZddlZddlmZmZm Z ddl m Z ddlm Z ddl mZmZmZmZddlZddlmZej*dZej*dZej*ej0ej2g d Zej*d Zej*d ZGd dZy)N)hilbertsvdvalsnormaslinearoperator) interp_decomp)assert_assert_allclose assert_equalassert_array_equal)raisesc#Kdyw)N-q=rk/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/linalg/tests/test_interpolative.pyepsr)s Ksc#RKtjjd}|yw)Nl,b30k0)nprandom default_rngrngs rrr.s ))   0 1C Is%')paramsc#\Kd}t|j|jyw)Ni,)rastypeparam)requestns rAr 4s& A !*  GMM **s*,c#&Kt|yw)Nr)r s rLr"<s 1 sctjj|d} tj||kdd}|S#t$r|j d}Y|SwxYw)NF) compute_uvr)rlinalgsvdnonzero IndexErrorshape)r rSranks rr+r+Asc aE *Azz!c'"1%a( K wwqz KsAAAceZdZejj dgddZejj dgddZejj ddgdZejj dgddZ ejj dgddZ d Z d Z d Z d Zd ZdZdZdZejj dej(ej*gejj dddgejj dddgdZdZy)TestInterpolativeDecompositionz rand,lin_op)FF)TF)TTc|s|n|}tj||||\}} } tj|dd| d|f| | } t|| |dyN)randr:0yE>rtolatol pymatrixidrreconstruct_matrix_from_idr ) selfr r"rr1lin_oprA_or_LkidxprojBs rtest_real_id_fixed_precisionz;TestInterpolativeDecomposition.test_real_id_fixed_precisionMsY !a!//$CP 3  1 1!As2AwJ-d K13U3rc|}|s|n|} tj| |||\} } tj|dd| d|f| | } t|| |dyr0r6) r9r r"rr+r1r:rr<r;r=r>r?s rtest_real_id_fixed_rankz6TestInterpolativeDecomposition.test_real_id_fixed_rankXs\  a,,VQTsK T  1 1!As2AwJ-d K13U3rr.c|}|s|n|} tj| |||\} } tj| | } tj||| } t | |dd| d|f|dt | | z||dyr0)r7rreconstruct_interp_matrixreconstruct_skel_matrixr )r9r r"rr+r1r:rr<r;r=r>Pr?s r%test_real_id_skel_and_interp_matriceszDTestInterpolativeDecomposition.test_real_id_skel_and_interp_matricescs  a,,VQTsK T  0 0d ;  . .q!S 91QBQZ=s?Aqs7rc|s|n|}tj||||\}} } || z| jjz} t || |dyr0r7r&Tconjr ) r9r r"rr1r:rr;Ur*Vr?s rtest_svd_fixed_precisionz7TestInterpolativeDecomposition.test_svd_fixed_precisionosM!a..4SA1a EACCHHJ 13U3rc|}|s|n|} tj| |||\} } } | | z| jjz} t || |dyr0rI)r9r r"rr+r1r:rr<r;rLr*rMr?s rtest_svd_fixed_rankz2TestInterpolativeDecomposition.test_svd_fixed_rankysR  a..3?1a EACCHHJ 13U3rc|}tj||d\}}tj|dd|d|f||\}}} ||z| jj z} t || |dy)NFr1r2r3)r7r id_to_svdrJrKr ) r9r rr+r<r=r>rLr*rMr?s rtest_id_to_svdz-TestInterpolativeDecomposition.test_id_to_svdsm ,,Q> T&&qCG}c4@1a EACCHHJ 13U3rclt|}tj||}t||dddy)Nrrư>r2r3)rr7estimate_spectral_normr )r9r rs norm_2_ests rtest_estimate_spectral_normz:TestInterpolativeDecomposition.test_estimate_spectral_norms/ AJ66qcB  AaDt$?rc|j}|dddfxxdzcc<t||z }tj|||}t ||dddy)Nrg333333?rrVr2r3)copyrr7estimate_spectral_norm_diffr )r9r rr?rXrYs r test_estimate_spectral_norm_diffz?TestInterpolativeDecomposition.test_estimate_spectral_norm_diffsQ FFH !Q$3 AEN;;AqcJ  AaDt$?rc6tjgdgdgdg|j}||fD]h}d}tjj |t |d|z}t j|||}t||k\t||dzkjy)Nrarrrradtype& .>r ) rarrayrdr% matrix_rankrr7 estimate_rankr )r9r rr?Mrank_tolrank_nprank_ests rtest_rank_estimates_arrayz8TestInterpolativeDecomposition.test_rank_estimates_arrays HHiI6agg FQ .AHii++AtAqzH/DEG!//8EH H' ( H" , -  .rcRtjgdgdgdg|j}||fD]v}t|}d}tjj |t |d|z}tj|||}t||dz k\t||dzkxy)Nr`rbrcrerfr) rrhrdrr%rirr7rjr ) r9r rr?rkMLrlrmrns rtest_rank_estimates_lin_opz9TestInterpolativeDecomposition.test_rank_estimates_lin_ops HHiI6agg FQ -A!!$BHii++AtAqzH/DEG!//H#FH H! + , H! + ,  -rctdjtj}t t 5t j|dddddy#1swYyxYw)NrVFrR)rrrfloat32 assert_raises ValueErrorr7r)r9r s r test_badcallz+TestInterpolativeDecomposition.test_badcallsI AJ  bjj ) : & :  $ $Q5 9 : : :s AA#ctjd}tt5t j |ddddy#1swYyxYw)N)rqrq)ronesrwrxr7r&)r9as rtest_rank_too_largez2TestInterpolativeDecomposition.test_rank_too_larges: GGFO : & ! NN1a  ! ! !s AAcd}tjjdd}tj||\}}}t ||j dtj||}tj|||}t|||ztj||\}}tj||}tj|||}t|||zy)Nrra) rrr1r7rr r)rDrEr )r9rr r<r=r>rFr?s rtest_full_rankz-TestInterpolativeDecomposition.test_full_ranks IINN2q !!//37 3Q #  0 0d ;  . .q!S 91q5!,,Q2 T  0 0d ;  . .q!S 91q5!rrdr1TFrrag?ctjgdgdgdgdgdg|d}|j}t|j||t ||y) N)rrrrr)rrrrarara)rarrrarr)rrarrrar)rrrarrraC)rdorderrR)rrhr\rrJr )r9rdr1rr r?s r test_bug_9793z,TestInterpolativeDecomposition.test_bug_9793sT HH+(((( * !  - FFHacc3T*1a rc.tjjd}|jddg}t |}t j |d\}}}t|jdt|jdt|jd|jd d g}t |}t j |d \}}}t|jd t|jd t|jdy)NlCaNJ1ru)sizer{)rr{)r{)rur{rq rf)rqrf)rf)rrf) rrruniformrr7r&r r))r9rxxlurXvs r%test_svd_aslinearoperator_shape_checkzDTestInterpolativeDecomposition.test_svd_aslinearoperator_shape_checksii##$45 KKaVK $ a ..Q'1aQWWf%QWWd#QWWf% KKaVK $ a ..Q'1aQWWf%QWWd#QWWf%rN)__name__ __module__ __qualname__pytestmark parametrizer@rBrGrNrPrTrZr^rorsryr~rrfloat64 complex128rrrrrr-r-Ksh [[57474 [[57474 [[]^,<= 8> 8 [[57474 [[574744@ @. -: ! "& [[Wrzz2==&AB [[VdE]3 [[UQH- !.4C !&rr-)scipy.linalg.interpolativer% interpolativer7numpyr scipy.linalgrrrscipy.sparse.linalgrr numpy.testingr r r r rr rwfixturerrrrr r"r+r-rrrrs:0///04// *  BMM23+4+]&]&r