a :jgI@sHdZddlmZmZmZmZmZmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZddlZddlZddZGdddZGd d d ZGd d d ZGd ddZ GdddZ!GdddZ"ddZ#ddZ$ddZ%ddZ&ddZ'ddZ(Gdd d Z)Gd!d"d"Z*Gd#d$d$Z+Gd%d&d&Z,dS)'z"Test functions for matrix module ) assert_equalassert_array_equalassert_array_max_ulpassert_array_almost_equal assert_raisesassert_)arangeaddfliplrflipudzerosoneseyearraydiag histogram2dtri mask_indices triu_indicestriu_indices_from tril_indicestril_indices_fromvanderNcCst|}t||}|SN)rr outer)ndatarJ/usr/local/lib/python3.9/site-packages/numpy/lib/tests/test_twodim_base.pyget_mats rc@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)TestEyecCsxttdtgdgdgdgdgttdddtgdgdgdgdgdttdd ktdtddS) Nrrrrr#rrrrr#rrrrr#fdtyper#)rrrboolselfrrr test_basics&   zTestEye.test_basiccCsbtttdtdtddgddggtttdtdtddtgdgdgdS) Nr(r#rr!)Mkr$r%)rrnpZuint64intrr,rrr test_uint64)s( zTestEye.test_uint64cCs`ttdddtgdgdgdgdgttdddtgdgd gdgdgdS) Nr!r#r1r$r%r&rrrrr"rrrr,rrr test_diag/s  zTestEye.test_diagcCsVttddtgdgdgdgdgttddtgdgdgd gdS) Nr!r*r#rrrr#r)rrr#rrrr"r$r%r8r,rrrtest_2d<s  zTestEye.test_2dcCs^ttddddtgdgdgdgttddddtgd gd gd gd gdS) Nr*r!r/r5r%r&r6r<r:r;r8r,rrr test_diag2dHszTestEye.test_diag2dcCs0ttdddddgddggttdddddgddggttdddddgddggttdddddgddggttdddddgddgddggttdddddgddgddggttdddddgddgddggttdddddgddgddggttdddddgddgddggdS)Nr/r#rr7r>r*rrr,rrrtest_eye_boundsTs$$$$zTestEye.test_eye_boundscCs$ttddddddgddggdS)Nr/ZS3r(1rAr,rrr test_strings_szTestEye.test_stringscCs$ttddtdddgddggdS)Nr/r(TF)rrr+r,rrr test_boolcszTestEye.test_boolcCs\tdddd}tddddd}t|||jjs4J|jjr@J|jjrLJ|jjsXJdS)Nr!r*r7r5F)r1order)rrflags c_contiguous f_contiguous)r-Zmat_cZmat_frrr test_orderfs    zTestEye.test_orderN) __name__ __module__ __qualname__r.r4r9r=r?rBrErFrLrrrrr s    r c@s6eZdZddZd ddZddZdd Zd d ZdS) TestDiagcCsdtdd}td}tdD]}|||||f<q"tt||td}|}tdD],}|||||df<||||d|f<q^tt|dd|tt|dd|dS) Ndl)rRrR)rTr/r5r>)rastyper rangerrcopy)r-valsbr1crrr test_vectorqs  zTestDiag.test_vectorNcCs|durdtddd}td}tdD]}|||f||<q.tt|||d}tdD]}|||df||<qbtt|d|ddtdD]}||d|f||<qtt|d |dddS) NrQrRr#rS)rRrr*r/r>)rrUr rVrr)r-rXrYr1rrr test_matrixs   zTestDiag.test_matrixcCs(tdtddddd}||dS)NrQrRr#rGrS)rHr))rrr\)r-rXrrrtest_fortran_orderszTestDiag.test_fortran_ordercCsddgddgddgg}tt|ddgtt|dddgtt|ddddgtt|d dddgtt|d ddgtt|d dgdS) Nr#r/r*r!rRr5rr7r>r@)rr)r-Arrrtest_diag_boundsszTestDiag.test_diag_boundscCstttdgggdS)Nr#)r ValueErrorrr,rrr test_failureszTestDiag.test_failure)N)rMrNrOr[r\r]r`rbrrrrrPps   rPc@seZdZddZdS) TestFliplrcCsnttttdtd}|dddddf}tt||gdgdg}gdgdg}tt||dS)Nr!r7rr#r/r*r!rR)r/r#r)rRr!r*)rrar r rrr-arYrrrr.szTestFliplr.test_basicNrMrNrOr.rrrrrcsrcc@seZdZddZdS) TestFlipudcCs^td}|dddddf}tt||gdgdg}gdgdg}tt||dS)Nr!r7rdre)rrr rfrrrr.szTestFlipud.test_basicNrhrrrrrisric@s^eZdZddZddZddZddZd d Zd d Zd dZ e j dddgddZ dS)TestHistogram2dc Cs tgd}tgd}tddd}tddd}t||||fd}tgdgdgdgd gd gdgdgdgdg }t|j|t|||d}t|j|tttdttd\}}}t|tddt|tdd d t|tdd d dS) N)g̙ }?g% ?g$F?g;cjY?gI+?)gp5x?g?_?gp?gbd?gg<=?rr# ) rrrr#rrrrr) rrrrrrr#rr) rrrrrrrrr) r#rr#rrrrrr) rr#rrrrrrr ) rr2linspacerrTlistrVr)r-xyZxedgesZyedgesHanswerrrr test_simples8   zTestHistogram2d.test_simplecCstgd}tgd}t||dddgddggdd\}}}tgd gd gd gd gd gdg}t||ddt|tdddt|tddddS)N)r#r#r/r*r!r!r!rR)r#r*r/rr#r/r*r!)r^rRrr^rRT)rVdensity)rrrr)rr#rr#r)rrr#rr)r#rrrr)rr#r#r#rrrrrr#g @r*rT)rrrrr2rnr-rqrrrsxedyedrtrrr test_asyms"   zTestHistogram2d.test_asymcCshtgd}tgd}t||gdgdgdd\}}}tgdgdgdgd}t||d dS) N) r#r/r*r#r/r*r#r/r*) r#r#r#r/r/r/r*r*r*)r#r/r*rRT)rv)r#r#?)r}r}?g"@r*)rrrryrrr test_densitys   zTestHistogram2d.test_densitycCsDtjddd}t||dddgddgfd\}}}t|ddS)NrQ?g.A)r!rRrr#)rV)r2randomZrandrr)r-rrsrzr{rrrtest_all_outlierss"z!TestHistogram2d.test_all_outlierscCsZtggddgddgfd\}}}t|tdggtggdd\}}}t|tddS)Nrr#Zbinsrwr!)r!r!)rrrr2r )r-rgZedge1Zedge2rrr test_emptys zTestHistogram2d.test_emptyc Cstgd}tgd}d}t|||df\}}}tgdgdgdgdgdgdgdgdgdgd g }t||t|tgd t||d|f\}}}tgd gd gd gdg}t||t|tgd dS)N)rg.ShouldDispatchcSs |||fSrr)r-functiontypesargskwargsrrr__array_function__szHTestHistogram2d.test_dispatch..ShouldDispatch.__array_function__N)rMrNrOrrrrrShouldDispatchsrr#r/rrR)weights)rrdictr Exception)r-rZxyZs_drrrr test_dispatchs   zTestHistogram2d.test_dispatch)x_leny_len)rkrm)cCsRt|t|}}tjtddt||Wdn1sD0YdS)Nz"x and y must have the same length.)match)r2r pytestZraisesrar)r-rrrqrrrrrtest_bad_length,s zTestHistogram2d.test_bad_lengthN)rMrNrOrur|rrrrrrmarkZ parametrizerrrrrrjs rjc@seZdZddZdS)TestTricCsDtgdgdgdg}ttd|ttdtd|tdS)Nr:r#r#rr#r#r#r*r()rrrr+rU)r-outrrr test_dtype5s zTestTri.test_dtypeN)rMrNrOrrrrrr4srcCs~tjdtjdD]d}tjd|d}t|}t|}t|ddgddggt||jt|j|jt|j|jqdS)NAllFloat AllInteger)r/r/r(r#r) r2 typecodesr triltriurrorr))r)rgrYrZrrrtest_tril_triu_ndim2=s   rcCs tjdtjdD]}tjddgddggddgddggddgddggg|d}tjddgddggddgddggddgddggg|d}tjddgddggddgddggddgddggg|d}t|}t|}t||t||t|j|jt|j|jqdS)Nrrr#rr()r2rrrrrrr))r)rgZa_tril_desiredZa_triu_desiredZa_triu_observedZa_tril_observedrrrtest_tril_triu_ndim3Is8    rcCsntddtjggdtjddgg}tgdgdtjddgg}|j}tt||tt||dS)Nr#rr:r)r2rinfrorrr)arrZout_trilZout_triurrrtest_tril_triu_with_infbs   rcCstjdD]D}|dkrq tjd|d}tt|j|jtt|j|jq tjddgddggd d}tt|j|jtt|j|jtjdd d}tt|j|jtt|j|jdS) NZAllV)r*r*r(z2001-01-01T12:00z2002-02-03T13:56z2004-01-01T12:00z2003-01-03T13:45Z datetime64zf4,f4)r2rr rrr)rr)rZrrrrtest_tril_triu_dtypeos  rcCs\tdtj}tddd}t||tgdtdtjd}t||tgddS)Nr*rl)rr#r/r!rRr#)r#r/rR)rr2rrreshaperr)iurgiu1rrrtest_mask_indicess  rcCsLtd}tddd}tddd}tdddd}tgdgdgd gd g}td d dd}t||tgd t||tgdd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgdS)Nr!r/r5rRmr1rr#r/r*r!rRr^rTrrlrkrm  r#) r#rRr^rlrkrmrrrr) r#r^rTrmrrrrr7)r7r/r*r!)r7r7rTr)r7r7r7rr7r7r7r7)r7r/r*r!rR)r7r7rrlrk)r7r7r7rr)r7r7r7r7r)rrrr!)rrrr)rrrr!rR)rrrrrk)rrrrr)rr2rrrr)Zil1Zil2Zil3Zil4rgrYrrrtest_tril_indicess`     rc@seZdZddZdS)TestTriuIndicescCsLtd}tddd}tddd}tdddd}tgdgdgd gd g}td d dd}t||tgd t||tgdd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgdS)Nr!r/r5rRrrrrrrr#r) r#r/r*r!r^rTrrmrr)r#r/r*r!rRrTrrlrkrrrrrr7r)rRr7r7r7)rlrkr7r7)rrrr7)r7r7r7r7r7)r^r7r7r7r7)rmrr7r7r7)rrrr7r7r)r7r7rr)rRr7r7r)r7r7rrr)r^r7r7rr)rmrr7r7r)rr2rrrr)r-rZiu2Ziu3Ziu4rgrYrrrtest_triu_indicess`     z!TestTriuIndices.test_triu_indicesN)rMrNrOrrrrrrsrc@seZdZddZdS)TestTrilIndicesFromcCs(ttttdttttddSN)r/)r/r/r/)rrarr2r r,rrrtest_exceptionssz#TestTrilIndicesFrom.test_exceptionsNrMrNrOrrrrrrsrc@seZdZddZdS)TestTriuIndicesFromcCs(ttttdttttddSr)rrarr2r r,rrrrsz#TestTriuIndicesFrom.test_exceptionsNrrrrrrsrc@seZdZddZddZdS) TestVandercCstgd}t|}tgdgdgdgdg}t||ddddf|jd}tdD].}t||d}t||dd|||fqddS) N)rr#r>r*rx)r#r#r#r#r#)rir!r>r#)Qrlr*r#r#r^N)r2rrrshaperV)r-rZvZpowersrrrrrr.s    zTestVander.test_basiccCs|tgdtjd}t|}tgdgdgdg}t||tddg}t|dd }tgd gd g}t||dS) N)rmrr()yrmr#)rr#)rr#???r*r)y@rr#)yrr#)rr2Zint8rr)r-rZrexpectedrrr test_dtypess     zTestVander.test_dtypesN)rMrNrOr.rrrrrrsr)-__doc__Z numpy.testingrrrrrrnumpyrr r r r r rrrrrrrrrrrr2rrr rPrcrirjrrrrrrrrrrrrrrrs* LX/  |    /2