a ;jgE@s dZddlZddlZddlZddlZddlZddlZddlZddlZ ddlm Z m Z m Z m Z mZmZmZmZddlmZddlmZddlmZmZmZmZddlmZddlmZmZmZmZm Z dd l!m"Z"dd l#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-z ddl.ZWne/y Yn0d d Z0e(Z1dddZ(ddZ2ddZ3ddZ4hdZ5GdddZ6ddZ7e j89dgZ:e:e7de6de dd gd!d"gge d#e d dge d#e6d$e dd gd!d"gge d#e d dge d#e6d%e dd gd!d"gge d#e gd&gd'ge d#e6d(e d)d*gd+d,gge d#e d-d)ge d#e6d.e d)d*gd+d,gged#e d-d)ged#e6d/e d)d*gd+d,gged#e gd0gd1ged#e6d2e j;d3e d#e j;d4e d#d5hd6e6d7e j8ggde j8de j8d5hd6g7Z:e:e7d`e6dae dd gd dgge d#de6dbe dd gd dgge d#de6dce dd*gddd:gge d#de6dee dd*gddd:gged#de6dfe j;d3e d#dd5hd6e6dgd:ddndoZ?e:e?7Z:GdpdqdqZ@Gdrdsdse@ZAGdtdudue@ZBGdvdwdwe@ZCGdxdydye@ZDGdzd{d{e@ZEGd|d}d}e@ZFd~dZGGdddeAeDZHGdddeHZIGdddeAeDZJGdddeJZKGdddeAeDZLGdddeLZMGdddeAeDZNGdddeNZOGdddZPGdddeAeDZQGdddeQePZRGdddeCeFZSGdddeSePZTGdddeAeDZUGdddeUZVGdddeAeBeDeEZWGdddeWZXGdddeCeFZYGdddeYZZddZ[GdddeAeDZ\Gddde\Z]GdddeAeBZ^Gddde^Z_ej`addddDGdddZbGdddeCeFZcGdddZdGdddeCeFZeGdddZfGdddZgGdddegZhGddÄdegZiGddńdeiehZjGddDŽdǃZkGddɄdegZlGdd˄degZmGdd̈́degZnGddτdejelZoGddфdejemZpGddӄdejenZqGddՄdՃZrddׄZsGddلdكZtGddۄdۃZuGdd݄d݃Zvdd߄Zwej`jxe-ddddZyddZzej`jxe-ddej`j{ddZ|GdddZ}GdddZ~GdddZddZej`jddddZej`je, ddddZddZddZddZddZddZddZddZddZdS(z# Test functions for linalg module N)arraysingledoublecsinglecdoubledotidentitymatmul)swapaxes) AxisError)multiply atleast_2dinfasarray)linalg) matrix_powernorm matrix_rank multi_dot LinAlgError)_multi_dot_matrix_chain_order) assert_ assert_equal assert_raisesassert_array_equalassert_almost_equalassert_allclosesuppress_warningsassert_raises_regex HAS_LAPACK64IS_WASMcCs"t|t|tjrt|ntjuSN)type isinstancenpndarray)outZin_r'H/usr/local/lib/python3.9/site-packages/numpy/linalg/tests/test_linalg.pyconsistent_subclass"sr) cKs8t|jjttfvr|}n|}t||fd|i|dS)Ndecimal)rdtyper"rrold_assert_almost_equal)absingle_decimaldouble_decimalkwr,r'r'r(r,srcCstttttttti|Sr!)rrrrr-r'r'r(get_real_dtype4s r5cCstttttttti|Sr!)rrrrr4r'r'r(get_complex_dtype9s r6cCs|ttfvrdSdSdS)Ngh㈵>gdy=)rrr4r'r'r(get_rtol>s r7>squaresize-0 hermitian nonsquare generalizedstridedc@s*eZdZefddZddZddZdS) LinalgCasecCs.tt|t||_||_||_t||_dS)z A bundle of arguments to be passed to a test case, with an identifying name, the operands a and b, and a set of tags to filter the tests N)rr#strnamer/r0 frozensettags)selfr@r/r0rBr'r'r(__init__Ns zLinalgCase.__init__cCs||j|j|jddS)zN Run the function `do` on this test case, expanding arguments rBN)r/r0rB)rCdor'r'r(checkYszLinalgCase.checkcCsd|jdS)Nz )r@rCr'r'r(__repr___szLinalgCase.__repr__N)__name__ __module__ __qualname__setrDrGrJr'r'r'r(r>Ms r>cCs,|tvsJd|D]}|j|hB|_q|S)z^ Add the given tag (a string) to each of the cases (a list of LinalgCase objects) z Invalid tag)all_tagsrB)tagZcasescaser'r'r( apply_tagcsrRr8r?@@@r4rZdouble_2)rUrTrW)rVrW@r?@y@@y@@y@@@?rZ cdouble_2)rZrYy?@)y?y?y?Z0x0rrrr9rEZ8x8Z1x1Znonarrayr;Z single_nsq_1)rTrUrVZ single_nsq_2g@rX)rUrTrVZ double_nsq_1Z double_nsq_2Z csingle_nsq_1)??@@@)y@y@"@y@@Z csingle_nsq_2rbrcrdy@"y@y@ @)rZrYrdZ cdouble_nsq_1Z cdouble_nsq_2Zcdouble_nsq_1_2y?y@Zcdouble_nsq_2_2Z8x11 Z1x5Z5x1Z0x4Z4x0r:ZhsingleZhdoubleZhcsingley@ZhcdoubleZhemptyZ hnonarrayZ matrix_b_onlyZ hmatrix_1x1cCsrg}tD]b}t|jtjsqt|jd|jd|jg}|jdurLd}n2|jjdkr`|j}nt|jd|jd|jg}t|j d|||j dhBd}| |t|jgdd d |jj }|jdurd}nj|jjdkr t|jgdd|j d  d |jj d d}n$t|jgdd d |jj }t|j d |||j dhBd}| |q|S) Nr_r`r^r*Z_tile3r<rEr`r_Z_tile213)CASESr#r/r$r%rr0ndimr>r@rBappendreshapeshape) new_casesrQr/r0new_caser'r'r(_make_generalized_casess6     $  $  rrccst|tjs|dfVdSdg|j}d|d<|jdkr@d|d<|jdkrRd |d <tjt|D]}d d t|j|D}td d |D}tj ||j d}| tj  d||}||d<| |j}tt||k|dddd |DfV|jdkrF|jddkrFt|j}d|d<tjjj||d}|dfV|jdkr|jddkrt|j}d|d<tjjj||d}|dfV|jdkr`|jdddkr`t|j}d|d<d|d<tjjj||d}|dfVq`dS)z< Generate cartesian product of strides for all axes ZnopNr^)r^r`rir^rjr_)r^rtcSsg|]\}}t||qSr')abs).0r/r0r'r'r( +z%_stride_comb_iter..cSsg|]}tdd|qSr!)slice)rwrepeatr'r'r(rx,ryr4l>[=.Zstride__cSsg|] }d|qS)z%+dr')rwjr'r'r(rx5ryr)stridesZ stride_xxx_0Zstride_xxx_0_xr^r^Zstride_xxx_0_0)r#r$r%rl itertoolsproducttupleziproemptyr-viewZuint32fill __class__ralljoinlistr~libZ stride_tricksZ as_strided)xZ stride_setZrepeatsZ new_shapeZslicesxisr'r'r(_stride_comb_itersF           rc Csng}tD]`}t|jD]P\}}t|jD]<\}}t|jd|d||||jdhBd}||q(qq|S)Nr|r=rE)rkrr/r0r>r@rBrm)rprQr/Za_labelr0Zb_labelrqr'r'r(_make_strided_casesJs rc@s"eZdZeZeefddZdS)LinalgTestCasec Cs|jD]x}|j|@|krq|j|@r&qz||jWqty|}z.d|d}|t7}t||WYd}~qd}~00qdS)zx Run func on each of the cases with all of the tags in require, and none of the tags in exclude zIn test case: z N) TEST_CASESrBrGrF Exception traceback format_excAssertionError)rCrequireexcluderQemsgr'r'r( check_cases^s    zLinalgTestCase.check_casesN)rKrLrMrkrrNrr'r'r'r(r[src@seZdZddZddZdS)LinalgSquareTestCasecCs|jdhddhddS)Nr8r<r9rrrrIr'r'r( test_sq_casestsz"LinalgSquareTestCase.test_sq_casescCs|jddhdhddS)Nr8r9r<rrrIr'r'r(test_empty_sq_casesxs z(LinalgSquareTestCase.test_empty_sq_casesN)rKrLrMrrr'r'r'r(rrsrc@seZdZddZddZdS)LinalgNonsquareTestCasecCs|jdhddhddS)Nr;r<r9rrrIr'r'r(test_nonsq_casessz(LinalgNonsquareTestCase.test_nonsq_casescCs|jddhdhddS)Nr;r9r<rrrIr'r'r(test_empty_nonsq_casess z.LinalgNonsquareTestCase.test_empty_nonsq_casesN)rKrLrMrrr'r'r'r(r}src@seZdZddZddZdS)HermitianTestCasecCs|jdhddhddS)Nr:r<r9rrrIr'r'r(test_herm_casessz!HermitianTestCase.test_herm_casescCs|jddhdhddS)Nr:r9r<rrrIr'r'r(test_empty_herm_casess z'HermitianTestCase.test_empty_herm_casesN)rKrLrMrrr'r'r'r(rsrc@s,eZdZejjddZejjddZdS)LinalgGeneralizedSquareTestCasecCs|jddhdhddS)Nr<r8r9rrrIr'r'r(test_generalized_sq_casess z9LinalgGeneralizedSquareTestCase.test_generalized_sq_casescCs|jhdddS)N>r8r<r9rrrIr'r'r(test_generalized_empty_sq_casessz?LinalgGeneralizedSquareTestCase.test_generalized_empty_sq_casesN)rKrLrMpytestmarkslowrrr'r'r'r(rs rc@s,eZdZejjddZejjddZdS)"LinalgGeneralizedNonsquareTestCasecCs|jddhdhddS)Nr<r;r9rrrIr'r'r(test_generalized_nonsq_casess z?LinalgGeneralizedNonsquareTestCase.test_generalized_nonsq_casescCs|jhdddS)N>r<r9r;rrrIr'r'r("test_generalized_empty_nonsq_casesszELinalgGeneralizedNonsquareTestCase.test_generalized_empty_nonsq_casesN)rKrLrMrrrrrr'r'r'r(rs rc@s,eZdZejjddZejjddZdS)HermitianGeneralizedTestCasecCs|jddhdhddS)Nr<r:r9rrrIr'r'r(test_generalized_herm_casess z8HermitianGeneralizedTestCase.test_generalized_herm_casescCs|jhddhddS)N>r:r<r9nonerrrIr'r'r(!test_generalized_empty_herm_casess z>HermitianGeneralizedTestCase.test_generalized_empty_herm_casesN)rKrLrMrrrrrr'r'r'r(rs rcCsLt|}|jdkr:tj|j|jd}t|jd|d<|St|jdSdS)Nr`r4rj.r)rrlr$rror-r)r/rr'r'r(identity_like_generalizeds  rc@seZdZddZdS) SolveCasescCsjt||}t|jdkrDt||dd}tt||j|nt||}t||t t ||dS)Nr^).N.r) rsolver$rrlr r broadcast_tororr))rCr/r0rBrZadotxr'r'r(rFs   z SolveCases.doNrKrLrMrFr'r'r'r(rsrc@sBeZdZejdeeee gddZ ddZ ddZ dd Z d S) TestSolver-cCs2tjddgddgg|d}tt||j|dSNr^?r4)r$rrrrr-rCr-rr'r'r( test_typesszTestSolve.test_typescCsGdddtj}tdddd}td|}t||}|jdksPJtddd|}t||}|jdksJtddd|}tt tj||dS) Nc@s eZdZdS)z)TestSolve.test_1_d..ArraySubclassNrKrLrMr'r'r'r( ArraySubclasssrr]r_r_r_ra)r_r_r_r^) r$r%arangernrrrror ValueError)rCrr/r0resultr'r'r(test_1_ds  zTestSolve.test_1_dc CsGdddtj}tdddd}tdddd|}t||ddddddf}t|ddddddf|ddddddf}t||tt ||t tj tj|ddddddf|t t tj||ddddddftdddd}t t tj||t t tj|dd|ddtd|}t||ddddf}t|ddddddf|dd}t||tt ||tddd}t t tj||t t tj|dd|ddt t tj|ddddddf|dS) Nc@s eZdZdS)z,TestSolve.test_0_size..ArraySubclassNrr'r'r'r(rsrr]r_r*r^r`r) r$r%rrnrrrrrr#rrrrCrr/r0expectedrr'r'r( test_0_sizes*"8 (& *  zTestSolve.test_0_sizecCsGdddtj}tdddd}tdddd|}t||ddddddf}t||ddddddf}t||tt ||t||ddddddf}t|ddddddf|ddddddf}t||tt ||dS) Nc@s eZdZdS)z.TestSolve.test_0_size_k..ArraySubclassNrr'r'r'r(r srrar^r_r*r`r) r$r%rrnrrrrrr#rr'r'r( test_0_size_k s"" "8 zTestSolve.test_0_size_kN)rKrLrMrr parametrizerrrrrrrrr'r'r'r(rs  !rc@seZdZddZdS)InvCasescCs0t|}tt||t|tt||dSr!)rinvrr rrr))rCr/r0rBZa_invr'r'r(rFs   z InvCases.doNrr'r'r'r(rsrc@s2eZdZejdeeee gddZ ddZ dS)TestInvr-cCs0tjddgddgg|d}tt|j|dSr)r$rrrrr-rr'r'r(r&szTestInv.test_typescCsGdddtj}tjdtjd|}t|}t|jj tj ut |j |j tt ||tjdtjd|}t|}t|jj tjut |j |j tt ||dS)Nc@s eZdZdS)z*TestInv.test_0_size..ArraySubclassNrr'r'r'r(r-srrr^r^r4r[)r$r%zerosint_rrrrr-r"float64rror# complex64rCrr/resr'r'r(r+s  zTestInv.test_0_sizeN rKrLrMrrrrrrrrrr'r'r'r(r%s rc@seZdZddZdS) EigvalsCasescCs&t|}t|\}}t||dSr!)reigvalseigr)rCr/r0rBevevaluesevectorsr'r'r(rF>s zEigvalsCases.doNrr'r'r'r(r<src@s2eZdZejdeeee gddZ ddZ dS) TestEigvalsr-cCs`tjddgddgg|d}tt|j|tjddgddgg|d}tt|jt|dSNr^rr4ri)r$rrrrr-r6rr'r'r(rEszTestEigvals.test_typescCsGdddtj}tjdtjd|}t|}t|jj tj ut d|j tt |tjtjdtjd|}t|}t|jj tjut d|j tt |tjdS)Nc@s eZdZdS)z.TestEigvals.test_0_size..ArraySubclassNrr'r'r'r(rNsrrr4rr^r[r\)r$r%rrrrrrr-r"rrror#rrr'r'r(rLs    zTestEigvals.test_0_sizeNrr'r'r'r(rDs rc@seZdZddZdS)EigCasescCsbt|}|j|j}}tt||t|t|ddddft|j dt t ||dS)N.rtol) rr eigenvalues eigenvectorsrr r$rr7r-rr))rCr/r0rBrrrr'r'r(rFas   z EigCases.doNrr'r'r'r(r_src@s2eZdZejdeeee gddZ ddZ dS)TestEigr-cCstjddgddgg|d}tj|\}}t|j|t|j|tjddgddgg|d}tj|\}}t|jt|t|jt|dSr)r$rrrrr-r6rCr-rwvr'r'r(rks  zTestEig.test_typescCsGdddtj}tjdtjd|}t|\}}t|jj tj ut|jj tj ut |j |j t d|j tt |tjtjdtjd|}t|\}}t|jj tjut|jj tjut |j |j t d|j tt |tjdS)Nc@s eZdZdS)z*TestEig.test_0_size..ArraySubclassNrr'r'r'r(rysrrr4rr[r\)r$r%rrrrrrr-r"rrror#rrCrr/rZres_vr'r'r(rws  zTestEig.test_0_sizeNrr'r'r'r(rjs rc@s.eZdZdZejdeee e gddZ dS) SVDBaseTestsFr-cCstjddgddgg|d}t|}|j|j|j}}}t|j|t|jt |t|j|tj|d|j d}t|jt |dS)Nr^rr4F compute_uvr:) r$rrsvdUSVhrr-r5r:)rCr-rrrrrrr'r'r(rs   zSVDBaseTests.test_typesN) rKrLrMr:rrrrrrrrr'r'r'r(rsrc@seZdZddZdS)SVDCasesc Cspt|d\}}}t|tt|t|ddddft|t|jdtt ||tt ||dS)NF.r) rrrr r$rr7r-rr))rCr/r0rBurvtr'r'r(rFs&z SVDCases.doNrr'r'r'r(rsrc@seZdZddZddZdS)TestSVDcCstd}tj|d|jd\}}}t|jdt|jdt|tdtd}tj|d|jd\}}}t|jdt|jdt|tddS) z6 Empty input should put an identity matrix in u or vh )rarTrrarar[ra)rraN)r$rrrr:rroeye)rCrrrZvhr'r'r(test_empty_identitys      zTestSVD.test_empty_identitycCs@tddgddgg}tj|d|jd}t|}t||dS)Nr^rFr)r$rrrr:Zsvdvalsr)rCrZ s_from_svdZs_from_svdvalsr'r'r( test_svdvalss zTestSVD.test_svdvalsN)rKrLrMrrr'r'r'r(rsrc@seZdZddZdS)SVDHermitianCasesc Cstj|ddd\}}}t|tt|t|ddddft|t|jddd}tt|||t t |j d|j tt|||t t |j d|j t t |ddddf|tt||tt||dS) NFTr:.rcSs<tt|j}|d|d|d<|d<ttj||dS)Nrjriaxes)rrangerlr$conj transpose)matrr'r'r(r:sz'SVDHermitianCases.do..hermitianri)rrrr r$rr7r-rrrrorsortrr))rCr/r0rBrrrr:r'r'r(rFs&,,zSVDHermitianCases.doNrr'r'r'r(rsrc@seZdZdZdS)TestSVDHermitianTN)rKrLrMr:r'r'r'r(rsrc@seZdZddZdS) CondCasescCst|}d|vr"tttj|dStj|dd}tt||d|ddddtt|d |d|ddddtt|d |d|ddddtj|}tt|d t | d  d t | d  d dddtt|d t | d  d t | d  d dddtt|tj t | d  d t | d  d dddtt|tj t | d  d t | d  d dddtt|d tt |d  d  d t |d  d  d ddddS)Nr9F)rr).rirfrer1r2r_rjr^rifro)rrrrcondrrr$rrvsummaxminrsqrt)rCr/r0rBcrZcinvr'r'r(rFsZ  & & && z CondCases.doNrr'r'r'r(rsrc@s>eZdZddZddZejjddddd d Zd d Z d S)TestCondcCstgdgdgdg}tt|tdtt|t dtt|ddtt|ddtt|d td dS) N)rTrr^)rgr)rrrVragUUUUUU?r^rirrgUUUUU6@)rrrrrr$r rCAr'r'r(test_basic_nonsvds zTestCond.test_basic_nonsvdcCsttdtdg}gd}ddg}t||D]\}}tt||dkq0t||D]\}}t||qZdS)NrNr^r_rrirj4&k C)r$ronesrrrrr)rCZAsp_posZp_negrpr'r'r( test_singular szTestCond.test_singularTFz/Platform/LAPACK-dependent failure, see gh-18914)runreasoncCsgd}gd}td}tj|d<|D].}t||}tt|tjtt|q(td}tj|d<|D]t}t||}tt|d||vrt|dd kt|d d kqptt|d tt|d  qpdS) N)Nr^rir_rjrrrr)r`r_r_r^rr^r^rrr_) r$rnanrrrr#risnan)rCZpsrrrr r'r'r(test_nans$      zTestCond.test_nancCstjdtjdddd}d|d<d|d<dD]T}t||}t|dtjt|dtjtt |dtt |dq2dS) NrSr_rr[r)Nr^r_rrirjrr^r) r$randomseedrandrrrrrisfinite)rCrrr r'r'r(test_stacked_singular6s  zTestCond.test_stacked_singularN) rKrLrMrrrrxfailrr"r'r'r'r(r s   r c@seZdZddZdS) PinvCasescCs<t|}t}t||||||dddtt||dS)Nrfrerrpinvr rrr)rCr/r0rBZa_ginvrr'r'r(rFKs z PinvCases.doNrr'r'r'r(r$Fsr$c@s eZdZdS)TestPinvNrr'r'r'r(r(Ssr(c@seZdZddZdS)PinvHermitianCasescCs@tj|dd}t}t||||||dddtt||dS)NTrrfrerr%r'r'r'r(rFYszPinvHermitianCases.doNrr'r'r'r(r)Wsr)c@s eZdZdS)TestPinvHermitianNrr'r'r'r(r*asr*cCstgdgdgdg}ttjj|ddtjj|ddtjtdd"tjj|ddd Wdn1st0YdS) Nr^r_r`)rar^r^)r_r`r^rrcondrz%`rtol` and `rcond` can't be both set.)match)r-r)r$rrrr&rZraisesr)r/r'r'r(test_pinv_rtol_argesr/c@seZdZddZdS)DetCasesc Cst|}t|}|j|j}}t|jjtt fvrFt| t }nt| t }t |} t |tj| ddt |t|tj| ddt|}t|}|dk} t t|| dt|| t dS)Nriaxisrr^)rdetslogdetsignZ logabsdetrr-r"rrastyperrrr reducer$expZ atleast_1drvrr) rCr/r0rBdrrldadrmr'r'r(rFus     z DetCases.doNrr'r'r'r(r0ssr0c@s:eZdZddZejdeee e gddZ ddZ dS) TestDetcCsttdggdtttdggtttdggdtttdggtttdggdt ftttdggdttttdggdtttdggdt ftttdggdttttdggdtdS)Nyrr^)rrr3r"rrr4rrIr'r'r( test_zeroszTestDet.test_zeror-cCs^tjddgddgg|d}ttj|j|tj|\}}t|jt|t|j|dSr)r$rrrr3r-r4r5)rCr-rphrr'r'r(rs zTestDet.test_typescCstjdtjd}t|}t|dt|jjtjut |}t|dt|djjtjut|djjtj utjdtj d}t|}t|dt|jjtj ut |}t|dt|djjtj ut|djjtj udS)Nr[r4rTrrr^) r$rrrr3rrr-r"r4float32r)rCr/rr'r'r(rs         zTestDet.test_0_sizeN) rKrLrMr?rrrrrrrrrr'r'r'r(r=s  r=c@seZdZddZdS) LstsqCasescCsLt|}|j\}}t|d\}}} tj||dd\} } } } |dkrVt| dk||krzt|t || t | |n t | |t| | || |kr||krtt t || |dj dd}t|}t|jdkrd|_t | j|jntgt| }t| |tt| jtjtt| |tt| |dS) NFrir,rr_r1r^rs)r$rrorrlstsqrrrrrZ__array_wrap__rvrrlrrr" issubdtyper-floatingr))rCr/r0rBarrr<nrrrr residualsranksvZ expect_residsr'r'r(rFs2      z LstsqCases.doNrr'r'r'r(rBsrBc@s:eZdZddZejgdgdddZddZd S) TestLstsqcCstgdgdgdgdgj}tgd}tj||dd\}}}}t|dkt||\}}}}t|d ktj||dd\}}}}t|d kdS) N)r>rTr>rTrUr>)r>rUr>r>rTr>)rTr>rTr>r>rW)r>r>r>rUrVr>)r^rrrrrrir,rar`)r$rTrrCr)rCr/r0rrHrIrr'r'r( test_rconds   zTestLstsq.test_rcond)r<rGn_rhs))rar_r_)rrar^)rrar_)rarr^)rarr_)rar_rrrrc Cst||||}t||f}tj||dd\}}}} |dkrTt|dkt|j ||ft|j ||krx|fnd||kr|dkr|t ||} t || | j ddt|t ||t| j t ||fdS)Nr,rr\rjr1)r$rrnrrrCrrrrorrrr ) rCr<rGrNr/r0rrHrIrrr'r'r(test_empty_a_bs zTestLstsq.test_empty_a_bcCsttgd}tgd}t|tt|gj}ttd tj ||ddWdn1sf0YdS)N)rr^r_r`)rig?g?g@gffffff @zIncompatible dimensionsr,) r$rZvstackrlenrLrrrrC)rCryrr'r'r(test_incompatible_dimss  z TestLstsq.test_incompatible_dimsN) rKrLrMrMrrrrPrSr'r'r'r(rKs rKdtcCsg|]}t|qSr')r$r-)rwr r'r'r(rxryrxz?bBhHiIqQefdgFDGOc@seZdZedZegdZegdZegdZeeeegZ e ddgddggZ e egggdZ eeded ed gZd d Zd dZddZddZddZddZddZejjeddddZdS)TestMatrixPowerra)r`rr^r_)r_r`rr^)r^r_r`rr^rr_rgGcCs|j|}tt|ddddd|jtt|ddddd|jtt|ddddd|jtt|ddddd|jdS)Nr_di rr^r`)rshft_1r6rrrshft_0rshft_2rshft_3)rCrTZrshftr'r'r(test_large_powers z TestMatrixPower.test_large_powercCs>dd}|jD]*}||||tkr||j|qdS)NcSs*t|d}t|t|t|j|jdS)Nr)rrrr-)Mmzr'r'r(tzs z.TestMatrixPower.test_power_is_zero..tz rshft_allr6objectstackedrCrTrarr'r'r(test_power_is_zeros  z"TestMatrixPower.test_power_is_zerocCs>dd}|jD]*}||||tkr||j|qdS)NcSs&t|d}t||t|j|jdS)Nr^)rrr-)rr`r'r'r(ra%s  z-TestMatrixPower.test_power_is_one..tzrbrfr'r'r(test_power_is_one$s  z!TestMatrixPower.test_power_is_onecCs>dd}|jD]*}||||tkr||j|qdS)NcSs>t|d}|jtkrtnt}t||||t|j|jdS)Nr_)rr-rdr rr)rr`mmulr'r'r(ra0s z-TestMatrixPower.test_power_is_two..tzrbrfr'r'r(test_power_is_two/s  z!TestMatrixPower.test_power_is_twocCs0dd}|jD]}||jvr|||qdS)NcSs4t|d}|jtkrtnt}t|||t|dSNri)rr-rdr rrr)rZinvmatrir'r'r(ra<s  z3TestMatrixPower.test_power_is_minus_one..tz)rcdtnoinvr6rfr'r'r(test_power_is_minus_one;s  z'TestMatrixPower.test_power_is_minus_onecCs.|j|}ttt|dttt|dgdS)Ng?r^)r[r6r TypeErrorrrCrTrr'r'r(test_exceptions_bad_powerFs z)TestMatrixPower.test_exceptions_bad_powercCsPttttdg|dttttdgdgg|dttttd|ddS)Nr^r_)rar`r_)rrrr$rr)rCrTr'r'r(test_exceptions_non_squareKsz*TestMatrixPower.test_exceptions_non_squarefp errors don't work in wasmrcCs,||jvrdS|j|}ttt|ddSrk)rlnoninvr6rrrror'r'r(test_exceptions_not_invertiblePs  z.TestMatrixPower.test_exceptions_not_invertibleN)rKrLrMr$rr[rZr\r]rcrrtblockrerdr-rlr^rgrhrjrmrprqrrskipifr rur'r'r'r(rUs"          rUc@seZdZddZdS)TestEigvalshCasescCs^t|d}t|\}}|jddt||t|jdt|d}t||t|jddS)NLrir1rr)reigvalshrrrr7r-)rCr/r0rBrrrev2r'r'r(rFZs    zTestEigvalshCases.doNrr'r'r'r(rxXsrxc@sBeZdZejdeeee gddZ ddZ ddZ dd Z d S) TestEigvalshr-cCs:tjddgddgg|d}tj|}t|jt|dSr)r$rrrzrr-r5)rCr-rrr'r'r(rgs zTestEigvalsh.test_typescCsXtjddgddggtjd}tttjj|ddtttjj|dtttjj|ddSNr^rr4ZlrongZUPLOlowerupper)r$rrArrrrzrCrr'r'r( test_invalidmszTestEigvalsh.test_invalidcCstjddgddggtjd}tjddgddggtjd}tjddgtjd}ttj}tj|}t|||dtjj|dd}t|||dtjj|dd}t|||dtjj|d d}t|||dtjj|d d}t|||ddS Nrr^r4rirryr~lrr)r$rrr7rrzr)rCKloKuptgtrrr'r'r( test_UPLOss  zTestEigvalsh.test_UPLOcCsGdddtj}tjdtjd|}t|}t|jj tj ut d|j tt |tjtjdtjd|}t|}t|jj tjut d|j tt |tjdS)Nc@s eZdZdS)z/TestEigvalsh.test_0_size..ArraySubclassNrr'r'r'r(rsrrr4rr[r\)r$r%rrrrrzrr-r"rrror#rrArr'r'r(rs    zTestEigvalsh.test_0_sizeNrKrLrMrrrrrrrrrrrr'r'r'r(r|fs  r|c@seZdZddZdS) TestEighCasesc Cst|}|j|j}}t|\}}|jddt||tt||t |ddddft |t |j dt|d\} } t| |tt|| t | ddddft | t |j t |ddS)Nrir1.rr)rerr_msg)reighrrrrrrr r$rr7r-repr) rCr/r0rBrrZevcrrr{Zevc2r'r'r(rFs        zTestEighCases.doNrr'r'r'r(rsrc@sBeZdZejdeeee gddZ ddZ ddZ dd Z d S) TestEighr-cCsJtjddgddgg|d}tj|\}}t|jt|t|j|dSr)r$rrrrr-r5rr'r'r(rszTestEigh.test_typescCsXtjddgddggtjd}tttjj|ddtttjj|dtttjj|ddSr})r$rrArrrrrr'r'r(rszTestEigh.test_invalidcCstjddgddggtjd}tjddgddggtjd}tjddgtjd}ttj}tj|\}}t|||dtjj|dd\}}t|||dtjj|dd\}}t|||dtjj|d d\}}t|||dtjj|d d\}}t|||ddSr)r$rrr7rrr)rCrrrrrrr'r'r(rs zTestEigh.test_UPLOcCsGdddtj}tjdtjd|}t|\}}t|jj tj ut|jj tj ut |j |j t d|j tt |tjtjdtjd|}t|\}}t|jj tjut|jj tjut |j |j t d|j tt |tjdS)Nc@s eZdZdS)z+TestEigh.test_0_size..ArraySubclassNrr'r'r'r(rsrrr4rr[r\)r$r%rrrrrrr-r"rrror#rrArr'r'r(rs  zTestEigh.test_0_sizeNrr'r'r'r(rs  rc@s eZdZdZdZeddZdS) _TestNormBaseNcCs:t|jjtjr"t|j|jjntt|jjtjdSr!) issubclassr-r"r$ZinexactrrealrrE)rrr'r'r( check_dtypesz_TestNormBase.check_dtype)rKrLrMrTdec staticmethodrr'r'r'r(rsrc@s4eZdZddZddZddZddZd d Zd S) _TestNormGeneralcCsFttgdtttg|jddttttg|jdddS)Nr>r4)rrrrTr rIr'r'r( test_emptysz_TestNormGeneral.test_emptyc Cstgd}tjd}tjd}||}|D]N}||}t|tj }|||t|dt<}| t dt|d}|||t|dWdn1s0Yt|d}|||t|dt|d }|||t|d t|d}|||t||j d |j d t|d }|||t||j d |j d t|tj}|||t|dq.dS)Nr AllIntegerZAllFloatr>divide by zero encounteredrirr_r^rUrrag?rT) r$r typecodesr6rrrrrfilterRuntimeWarningr-r" rCr/Z exact_typesZ inexact_typesZ all_typesZ each_typeatZansupr'r'r(test_vector_return_types:         (            z(_TestNormGeneral.test_vector_return_typecsvgd}gd}gd}fdd}|||fD] }||q.t|jdt|jdt|jdfD] }||qddS)N)r^r_r`ra)rirjrurt)rir_ruracstjjt|djdtjjt|tdjdtjjt|t djdtjjt|ddjdtjjt|ddjdtjjt|d djdtjjt|d d jdtjjt|d d jddS)Ng6ҭ@r,rWrTr^$@rigQ?r_rjgsc?rra)r$testingrrrr)rrIr'r(_test0s0z+_TestNormGeneral.test_vector.._testr4)rrT)rCr/r0r rrr'rIr( test_vector+s   z_TestNormGeneral.test_vectorc stgdgdg|jdddddddtjtj fD]hfd d tjdD}ttdd |fd d tjdD}ttdd |q4tjdd |jd dddj }dddddtjtj dfD]؉t t| |dD]}|\}}|dkr||7}|dkr"||7}||kr@t tt|d qt|d }|||||krfdd tjD}n fdd tjD}t||qqdS)Nr+rarfr*r4rirr^r_r`cs$g|]}tdd|fdqSNordrrwkrorderr'r(rxOryz._TestNormGeneral.test_axis..rr2cs$g|]}t|ddfdqSrrrrr'r(rxQryrarjrcs*g|]"}tddj|ddqSNr1r)rtakerBk_indexrr'r(rxgscs,g|]$}tddj|djdqSr)rrrLrrr'r(rxjs)rrTr$rrrorrrrnrlr combinationsrr) rCZ expected0Z expected1ndr2Zrow_axisZcol_axisrGrr')rrrrr( test_axisIs6       z_TestNormGeneral.test_axisc Cstjdd|jdddd}d}d}t|ddd }t|ddd d }tt|||ddd d }t|j |k||j |ddddddddtj tj fD]}t |j D]v}t|||d }t|||d d }tt|||||d t |j }d||<t|}t|j |k||j |||qqdddddtj tj ddf D]}tt |j dD]}t|||d }t|||d d }tt|||||d t |j }d||d<d||d<t|}t|j |k||j |||qTq>dS)Nr^rr4r_r`razorder {0}, axis = {1}z;Shape mismatch found {0}, expected {1}, order={2}, axis={3}rT)rr2keepdims)r)r^r^r^rirrjrnuc)r$rrTrnrrZsqueezeformatrrorrrlrrr permutations) rCrZ allclose_errZ shape_errrfoundZexpected_shaperrr'r'r( test_keepdimsnsN              z_TestNormGeneral.test_keepdimsN)rKrLrMrrrrrr'r'r'r(rs )%rc@s:eZdZejZddZddZddZddZd d Z d S) _TestNorm2DcCs tt|jgg|jdddS)Nr4r>)rrrrTrIr'r'r(test_matrix_emptysz_TestNorm2D.test_matrix_emptyc Cs|gdgdg}tjd}d}||}|D]N}||}t|tj }|||t|dt<}| t dt|d}|||t|dWdn1s0Yt|d }|||t|dt|d }|||t|d t|d }|||t|dt|tj}|||t|dt|d }|||t|dt|d}|||tj j|dddq0dS)NrrrZfdFDrUrrirTr^r_gLXz?rjrrgU&,t=@r*r) rr$rr6rrrrrrrrrr'r'r(test_matrix_return_types@        (                 z#_TestNorm2D.test_matrix_return_typecCs|jddgddgg|jd}tt|dtt|ddtt|dd tt|td tt|t d tt|dd tt|d d tt|ddtt|ddttt|dttt|dttt|ddS)Nr^r`rfrgr4gT"@rrrg(@rWrirXr_gW?"@rjgїʄ?Znofrorur)rrTrrrrrrr'r'r(test_matrix_2x2sz_TestNorm2D.test_matrix_2x2cCsd|jgdgdgdg|jd}tt|dtt|ddtt|dd tt|td tt|t d tt|d d tt|ddtt|ddtt|dddS)Ng?r+)r*rrf)r`r_r^r4grj=Q0?rrgB+pc?g?g333333?r^rTrig?r_g&.d?rjgܸՠ?)rrTrrrrr'r'r(test_matrix_3x3s z_TestNorm2D.test_matrix_3x3cCs|jgdgdg|jd}tjdd|jdddd}ttt|d d ttt|d d tttddgd dtttddgd dtttddgd dd D]4}ttt||dttt||dttt||dqttt|ddttt|ddttt|dddS)Nr+rr4r^rr_r`rarrrtestrr`r)r^r_r_r`rr^r_) rrTr$rrnrrrr )rCrrrr'r'r( test_bad_argssz_TestNorm2D.test_bad_argsN) rKrLrMr$rrrrrrr'r'r'r(rs 3rc@s eZdZdS) _TestNormNrr'r'r'r(rsrc@s$eZdZddZddZddZdS)TestNorm_NonSystematiccCs*tjdtjd}tt|ddddddS)N r4r`rgL)@r_r)r$rZ longdoubler.rrr'r'r(test_longdouble_normsz+TestNorm_NonSystematic.test_longdouble_normcCs,tjdgtjd}tt|ddddddS)Nir4r`rlrfr)r$rZint32r.rrr'r'r( test_intminsz"TestNorm_NonSystematic.test_intmincCstjdtjd}d|d<d|d<d}ttjj|dd |d d |tj}ttjj|dd |d d |tj}ttjj|dd |d d dS)Nr_r4y@@ry@r^gV;'@r`rrr rf) r$rZ clongdoubler.rrr6 complex128r)rCr9rr'r'r(test_complex_high_ord#s  z,TestNorm_NonSystematic.test_complex_high_ordN)rKrLrMrrrr'r'r'r(rsrc@seZdZejZdZdS)_TestNormDoubleBaser+N)rKrLrMr$rrTrr'r'r'r(r1src@seZdZejZdZdS)_TestNormSingleBaser*N)rKrLrMr$rArTrr'r'r'r(r6src@seZdZejZdZdS)_TestNormInt64Baser+N)rKrLrMr$Zint64rTrr'r'r'r(r;src@s eZdZdS)TestNormDoubleNrr'r'r'r(r@src@s eZdZdS)TestNormSingleNrr'r'r'r(rDsrc@s eZdZdS) TestNormInt64Nrr'r'r'r(rHsrc@seZdZddZddZdS)TestMatrixRankcCstdttdtd}d|d<tt|dtttddttgddtttd dttdgdt|tdtdg}tt|tgd ttddttd t|d d d Wdn1s0YdS)Nrar>ririr`rr)r^rrrr^)ra)r`rarz#`tol` and `rtol` can't be both set.g{Gz?)tolr)rrr$rrrrr)rCImsr'r'r(test_matrix_rankNs zTestMatrixRank.test_matrix_rankcCstdttdddtdttdddtdttdddtd}d|d<td t|ddd |d<tdt|dd d td t|dd d dS)NraTrr^rrr>rr`g:0yE>g|"BE>)r:rg;䡈E>)rrr$rrr)rCrr'r'r(test_symmetric_rankgs z"TestMatrixRank.test_symmetric_rankN)rKrLrMrrr'r'r'r(rLsrcCstjd}tdD]}|jdd}|dddf|dddf|dddf<tt|d|ddd f|ddd f|ddd f<tt|d qdS) Ni3rX)(rsizer^r_rrrarfr`r])r$rZ RandomStaternormalrr)rngiXr'r'r(test_reduced_rankus   ,,rc @seZdZejZddZejddggdddZ dd Z d d Z d d Z ejdgdejdgdejdej ejejejgddZdS)TestQRc Cst|}|j}|j\}}t||}tj|dd}|j|j}} t|j|kt| j|ktt ||tt | |t|j||fkt| j||fkt t || |t t |j |t|t t| | tj|dd\} } t| j|kt| j|ktt | |tt | |t| j||fkt| j||fkt t | | |t t | j | t|t t| | tj|dd} t| j|ktt | |t | | dS)Ncompletemodereducedr)r"r-ror rqrQRrr#rrrLrr$rtriu) rCr/a_typea_dtyper<rGrrrrq1r1r2r'r'r(check_qrs:  zTestQR.check_qrr<rG)r`rrr[cCstt||}t||f}||tjj|dd\}}t|jtjt|jtjt|j ||ft|j |fdS)Nrawr) r r$rrrrrr-rro)rCr<rGrr/htaur'r'r( test_qr_emptys  zTestQR.test_qr_emptycCs|jddgddgddggtjd}tj|dd \}}t|jtjkt|jtjkt|jd kt|jd ktj|jdd \}}t|jtjkt|jtjkt|jd kt|jd kdS) Nr^r_r`rarfr*r4rrrrrh) rr$rrrrr-rorL)rCr/rrr'r'r( test_mode_raws"zTestQR.test_mode_rawcCs|ddgddgg}|ddgddgddgg}dD]8}||}||}||||||jq6dD]H}dd||}dd||}||||||jqtdS) Nr^r_r`rarfr*fd?)rr6rrL)rCr/r0rTm1m2r'r'r(test_mode_all_but_economics      z!TestQR.test_mode_all_but_economiccCsft|}|j}|jdd\}}t||}tj|dd\}}t|j|kt|j|ktt||tt||t|jdd||fkt|jdd||fktt |||t |jd} t | |jdd|jdfd} tt t |dd|| tt |dddddf|tj|dd\} } t| j|kt| j|ktt| |tt| |t| jdd||fkt| jdd||fktt | | |t | jd} t | | jdd| jdfd} tt t | dd| | tt | dddddf| tj|dd} t| j|ktt| |t| | dS) Nrjrrrir_.rr)r"r-ror rrrr#rr r$rrr rr)rCr/rrr<rGrqrZI_matZ stack_I_matrrrr'r'r(check_qr_stackedsL ""zTestQR.check_qr_stackedr))r`ra)rar`rrr outer_size)rr)r_r`rarTcCsXtjd}|j||d|}|j||d|}||||d|dS)N{rr)r$rZ default_rngrr6r)rCrrrTrrrr'r'r(test_stacked_inputss  zTestQR.test_stacked_inputsN)rKrLrMr$rrrrrrrrrrrrrrr'r'r'r(rs( -rc@sfeZdZejdgdejdejejej ej fejdddgddZ d d Z d d Z d S) TestCholeskyro)rrr`r`)2r)r`rrr-rFTc Cs^tjdtjj|}t|tjr:|dtjj|}ttt|}d|dd<t | | |}tj ||d}tj j||d}|rt | | |}nt || | }t*d|jdt|j}Wdn1s0Yt||||d |d |d |d tj|dd d } ttt| tt| dkdS)Nr^r)rirjrjr4rir  )atolrri)Zaxis1Zaxis2)r$rrrandnrDZcomplexfloatingrrrQr rrrrcholeskyZ_no_nep50_warningroZfinfoepsrdiagonalrrZisreal) rCror-rr/tr r0r r9r'r'r(test_basic_property&s$    8&z TestCholesky.test_basic_propertycCsGdddtj}tjdtjd|}t|}t|j|jt |j j tj ut t |tjtjdtjd|}t|}t|j|jt |j j tjut t |tjdS)Nc@s eZdZdS)z/TestCholesky.test_0_size..ArraySubclassNrr'r'r'r(rKsrrr4)r^rr)r$r%rrrrr rrorr-r"rr#rrr'r'r(rJs  zTestCholesky.test_0_sizecCsTtddgddgg}tt|tj|ddttj|ddt|jdS)Ny?yy@y@FrT)r$rrrr rLr)rCr/r'r'r(test_upper_lower_argZs  z!TestCholesky.test_upper_lower_argN)rKrLrMrrrr$rArrrrrrr'r'r'r(r$src@seZdZedZedZegdgdgdgZe ej eeee e d,ej eddejfeWdn1s0YdS) TestOuterr`rOr)rr_raz$Input arrays must be one-dimensionalN)rKrLrMr$rZarr1Zarr2rrrrouterrrZnewaxisr'r'r'r(rfs  rcCstjdkrd}nd}tjtjfD]}tjd|d}||j|}||jd }t |jjdt j t j t jfD](}||}t|||t|||qxq dS)Nlittle)rCrrr'r'r(&test_basic_function_with_two_argumentss  z3TestMultiDot.test_basic_function_with_two_argumentscCs\tjd}tjd}tjd}tjd}tt||||g||||dS)Nr<r=r_r^r>)rCrrr?Dr'r'r(9test_basic_function_with_dynamic_programming_optimizations     zFTestMultiDot.test_basic_function_with_dynamic_programming_optimizationcCsLtjd}tjd}tjd}tjd}tt||||gjddS)Nr_r=r<rrr$rrrro)rCA1drr?rCr'r'r(test_vector_as_first_argument s     z*TestMultiDot.test_vector_as_first_argumentcCsLtjd}tjd}tjd}tjd}tt||||gjddS)Nr<r=r_)r*rE)rCrrr?D1dr'r'r(test_vector_as_last_arguments     z)TestMultiDot.test_vector_as_last_argumentcCsLtjd}tjd}tjd}tjd}tt||||gjddS)Nr_r=r<r'rE)rCrFrr?rHr'r'r(&test_vector_as_first_and_last_argument!s     z3TestMultiDot.test_vector_as_first_and_last_argumentc Cstjd}tjd}tjd}td}t|||g|d}||usLJt||||t|t|t||dS)Nr<r=r&r$rrrrr)rCrrr?r&retr'r'r(test_three_arguments_and_out+s     z)TestMultiDot.test_three_arguments_and_outcCsdtjd}tjd}td}t||g|d}||us>Jt|||t|t||dS)Nr<r=)r*r*rKrL)rCrrr&rMr'r'r(test_two_arguments_and_out8s    z'TestMultiDot.test_two_arguments_and_outcCsztjd}tjd}tjd}tjd}td}t||||g|d}||usZJt|||||dS)Nr<r=rB)r*r^rKrL)rCrrr?rCr&rMr'r'r(-test_dynamic_programming_optimization_and_outBs      z:TestMultiDot.test_dynamic_programming_optimization_and_outc Cstjdtjdtjdtjdtjdtjdg}tgdgdgd gd gd gd g}tjgd gdgdgdgdgdgtd}|d8}t|dd\}}tt|ddddft|ddddftt|t|dS)N)#)rR)rSrf)rfr)r)rTr)r>g@gþ@gO@g1@g@)r>r>g@g@gջ@g@)r>r>r>gp@g@g@)r>r>r>r>g@@gX@)r>r>r>r>r>g@)r>r>r>r>r>r>)rr^r^r`r`r`)rrr_r`r`r`)rrrr`r`r`)rrrrrarf)rrrrrrf)rrrrrrr4r^T)Z return_costsri)r$rrintrrr)rCZarraysZ m_expectedZ s_expectedrr<r'r'r(test_dynamic_programming_logicNs:        z+TestMultiDot.test_dynamic_programming_logiccCs&tttgttttjdgdS)Nr)rrrr$rrIr'r'r(test_too_few_input_arraysls z&TestMultiDot.test_too_few_input_arraysN)rKrLrMr@rArDrGrIrJrNrOrPrVrWr'r'r'r(r:s        r:c@sveZdZejdeddfeddfgddZejdd d gd d Z ejd ddgddZ ddZ dS) TestTensorinvzarr, indrar*r]r_r_r`r`r_r^cCs:tttj||dWdn1s,0YdS)Nind)rrr tensorinv)rCrFr\r'r'r(test_non_square_handlingss z&TestTensorinv.test_non_square_handlingz shape, ind)rar*r]r`r_)r]r`r^cCsNtd}||_tj||d}|j|d|jd|}|j}t||dS)Nrar/r\)r$rrorr]r)rCror\r/ainvractualr'r'r(test_tensorinv_shape{s  z"TestTensorinv.test_tensorinv_shaper\rrjcCsJtd}d|_tttj||dWdn1s<0YdS)Nrar_rb)r$rrorrrr])rCr\r/r'r'r(test_tensorinv_ind_limits  z&TestTensorinv.test_tensorinv_ind_limitcCsJtd}d|_tj|dd}td}tt||dtj||dS)Nrar`r^r[) r$rrorr]rr tensordot tensorsolve)rCr/rcr0r'r'r(test_tensorinv_results   z#TestTensorinv.test_tensorinv_resultN) rKrLrMrrrr$rr^rerfrir'r'r'r(rXqs     rXc@sTeZdZejdeddfeddfgddZejdgd d d Z dS) TestTensorsolveza, axesrYNrZ)rr_cCsPtt4t|jdd}tj|||dWdn1sB0YdSNr_r)rrr$rrorrh)rCr/rr0r'r'r(r^s z(TestTensorsolve.test_non_square_handlingro))r_r`r*)r`rarar`)rr`r`rcCsNtjj|}t|jdd}tj||}ttj||t |jd|dSrk) r$rr rrorrhrrgrQ)rCror/r0rr'r'r(test_tensorsolve_results z'TestTensorsolve.test_tensorsolve_result) rKrLrMrrrr$rr^rlr'r'r'r(rjs   rjcCsRtjddgddggdd}ttdt|Wdn1sD0YdS)Nr^rjr_rfZfloat16r4zunsupported in linalg)r$rrrnrr )rFr'r'r(test_unsupported_commontypes rmz,Bad memory reports lead to OOM in ci testingcCsRd}tjd|gtjd}tjddgtjd}d|d<t||}t|dddS)Nr^r4)rri)r$rrArrr)rGr/r0r r'r'r(test_blas64_dots  roz*Numpy not compiled with 64-bit BLAS/LAPACKc Cstj}tjjj}d}d}|}tjddg|d}tjdg|d}tjdg|d}|||||||dd}t|ddt|d|t|d|t|} t d | kod kndS) Nlr^r4ririnfor<rGrnl) r$rrr&ZdgeqrfrrrUitemr) r-Zlapack_routiner<rGZldar/ZworkrresultsZlworkr'r'r(!test_blas64_geqrf_lwork_smoketests  rscCsFtdd}tj|}tgdgdgdg}t||dS)N<r`rarf)rr*r+)rTrY&)r.4:)r$rrnrrrrrrdrr'r'r( test_diagonals r}cCs8tdd}tj|}tgd}t||dS)Nrtru)$t)r$rrnrtracerrr|r'r'r( test_traces rcCstdd}tj||d}tgdgdgdg}t||gd}gd}tj||}tgd}t||ttd2|ddddf}tj||Wdn1s0YdS) Nrrr^)rir_rir+r)rur*ruz8input arrays must be \(arrays of\) 3-dimensional vectors) r$rrnrcrossrrrr)rrdrrrZx_2dimr'r'r( test_crosss&   rcCsHtdd}tj||dks&Jtjj||ddgddksDJdS)Nr*r7rr)r$rrnrrg)rr'r'r(test_tensordot srcCsDtdd}tj||j}tddgddgg}t||dS)Nr*rrfr)r$rrnrr rLrrr|r'r'r( test_matmul srcCsrtdd}tj|}|j}t||ttd(tj|dddfWdn1sd0YdS)Nr*rz$array must be at least 2-dimensionalr) r$rrnrZmatrix_transposerLrrrr|r'r'r(test_matrix_transpose( s  rcCs\tdd}tj|}t|tdddtjj|dd}t|tdggdddS)Nrr^)ː,@r`r2Tr)r$rrnrZ matrix_normrrr)rrdr'r'r(test_matrix_norm5 s  rcCstdd}tj|}t|tdddtjj|dd}t|tgdddtjj|d d }tjd dd d }t |j |j t||dddS)Nrrrr`rrr1)g|a2@gsh|? @gDioI#@Trrrr4) r$rrnrZ vector_normrrrfullrror|r'r'r(test_vector_norm@ s r)r*r+)__doc__rrrrr2r4rnumpyr$rrrrrrrr Z numpy._corer Znumpy.exceptionsr r r rrrZ numpy.linalgrrrrrZnumpy.linalg._linalgrZ numpy.testingrrrrrrrrrr Znumpy.linalg.lapack_lite ImportErrorr)r.r5r6r7rOr>rRrrrkrr rrrrrrrrrrrrrrrrrrrrrrrrrrr r$r(r)r*r/r0r=rBrKrrrUrxr|rrrrrrrrrrrrrrrrrrrrwrr-rr9r:rXrjrmr#ror#rsr}rrrrrrrr'r'r'r(s((    0          #          9   ! 0        K  $ .C   *1V6; x) #B 1 ")