o 6aG@sLdZddlmZmZmZmZmZmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZddlZddlmZddZGdd d ZGd d d ZGd d d Z GdddZ!GdddZ"GdddZ#ddZ$ddZ%ddZ&ddZ'ddZ(ddZ)Gd d!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_fromvanderN)requires_array_functioncCst|}t||}|SN)rr outer)ndatarB/usr/lib/python3/dist-packages/numpy/lib/tests/test_twodim_base.pyget_mats r c@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)TestEyecCsxttdtgdgdgdgdgttdddtgdgdgdgdgdttdd ktdtddS) Nrrrrr$rrrrr$rrrrr$fdtyper$)rrrboolselfrrr test_basics&   zTestEye.test_basiccCs`ttdddtgdgdgdgdgttdddtgdgd gdgdgdS) Nr"r$kr%r&r'rrrrr#rrrr-rrr test_diag,s  zTestEye.test_diagcCsVttddtgdgdgdgdgttddtgdgdgd gdS) Nr"r+r$rrrr$r)rrr$rrrr#r%r&r4r-rrrtest_2d9s  zTestEye.test_2dcCs^ttddddtgdgdgdgttddddtgd gd gd gd gdS) Nr+r"r0r&r'r2r8r6r7r4r-rrr test_diag2dEszTestEye.test_diag2dcCs0ttdddddgddggttdddddgddggttdddddgddggttdddddgddggttdddddgddgddggttdddddgddgddggttdddddgddgddggttdddddgddgddggttdddddgddgddggdS)Nr:r$rr3r;r+rrr-rrrtest_eye_boundsQs$$$$(zTestEye.test_eye_boundscCs$ttddddddgddggdS)Nr:S3r)1r>r-rrr test_strings\szTestEye.test_stringscCs$ttddtdddgddggdS)Nr:r)TF)rrr,r-rrr test_bool`s$zTestEye.test_boolcCs\tdddd}tddddd}t|||jjsJ|jjr J|jjr&J|jjs,JdS)Nr"r+r3r0F)r1order)rrflags c_contiguous f_contiguous)r.mat_cmat_frrr test_ordercs    zTestEye.test_orderN) __name__ __module__ __qualname__r/r5r9r<r?rCrDrLrrrrr!s     r!c@s6eZdZddZd ddZddZdd Zd d ZdS) TestDiagcCsdtdd}td}tdD] }|||||f<qtt||td}|}tdD]}|||||df<||||d|f<q/tt|dd|tt|dd|dS) Ndl)rRrR)rTr:r0r;)rastyper rangerrcopy)r.valsbr1crrr test_vectorns  zTestDiag.test_vectorNcCs|durdtddd}td}tdD] }|||f||<qtt|||d}tdD] }|||df||<q1tt|d|ddtdD] }||d|f||<qNtt|d |dddS) NrQrRr$rS)rRrr+r:r;)r rUr rVrr)r.rXrYr1rrr test_matrix|s   zTestDiag.test_matrixcCs(tdtddddd}||dS)NrQrRr$rErS)rFr*)rr r\)r.rXrrrtest_fortran_orderszTestDiag.test_fortran_ordercCsddgddgddgg}tt|ddgtt|dddgtt|ddddgtt|d dddgtt|d ddgtt|d dgdS) Nr$r:r+r"rRr0rr3r;r=)rr)r.Arrrtest_diag_boundsszTestDiag.test_diag_boundscCstttdgggdS)Nr$)r ValueErrorrr-rrr test_failureszTestDiag.test_failurer)rMrNrOr[r\r]r`rbrrrrrPms   rPc@eZdZddZdS) TestFliplrcCsnttttdtd}|dddddf}tt||gdgdg}gdgdg}tt||dS)Nr"r3rr$r:r+r"rR)r:r$r)rRr"r+)rrar r r rr.arYrrrr/szTestFliplr.test_basicNrMrNrOr/rrrrrd rdc@rc) TestFlipudcCs^td}|dddddf}tt||gdgdg}gdgdg}tt||dS)Nr"r3rerf)r rr rgrrrr/szTestFlipud.test_basicNrirrrrrkrjrkc@sHeZdZddZddZddZddZd d Zd d Ze d dZ 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 ) rnplinspacerrTlistrVr)r.xyxedgesyedgesHanswerrrr 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)rrrrrprqr.rtrurxxedyedryrrr 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)r{)r$r$?)rr?g"@r+)rrrr~rrr test_densitys   zTestHistogram2d.test_densitycCsDtjddd}t||dddgddgfd\}}}t|ddS)NrQ?g.A)r"rRrr$)rV)rprandomrandrr)r.rrxrrrrrtest_all_outlierss"z!TestHistogram2d.test_all_outlierscCsZtggddgddgfd\}}}t|tdggtggdd\}}}t|tddS)Nrr$binsr|r")r"r")rrrrpr )r.rhedge1edge2rrr 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__s zHTestHistogram2d.test_dispatch..ShouldDispatch.__array_function__N)rMrNrOrrrrrShouldDispatchrjrr$r:rrR)weights)rrdictr Exception)r.rxys_drrrr test_dispatchs    zTestHistogram2d.test_dispatchN) rMrNrOrzrrrrrrrrrrrrls rlc@rc)TestTricCsDtgdgdgdg}ttd|ttdtd|tdS)Nr6r$r$rr$r$r$r+r))rrrr,rU)r.outrrr test_dtype,s zTestTri.test_dtypeN)rMrNrOrrrrrr+rjrcCs~tjdtjdD]2}tjd|d}t|}t|}t|ddgddggt||jt|j|jt|j|jq dS)NAllFloat AllInteger)r:r:r)r$r) rp typecodesr triltriurrrrr*)r*rhrYrZrrrtest_tril_triu_ndim24s   rcCs tjdtjdD]x}tjddgddggddgddggddgddggg|d}tjddgddggddgddggddgddggg|d}tjddgddggddgddggddgddggg|d}t|}t|}t||t||t|j|jt|j|jq dS)Nrrr$rr))rprrrrrrr*)r*rha_tril_desireda_triu_desireda_triu_observeda_tril_observedrrrtest_tril_triu_ndim3@s:    rcCsntddtjggdtjddgg}tgdgdtjddgg}|j}tt||tt||dS)Nr$rr6r)rprinfrrrrr)arrout_trilout_triurrrtest_tril_triu_with_infYs   rcCstjdD]"}|dkr qtjd|d}tt|j|jtt|j|jqtjddgddggd d}tt|j|jtt|j|jtjdd d}tt|j|jtt|j|jdS) NAllV)r+r+r)z2001-01-01T12:00z2002-02-03T13:56z2004-01-01T12:00z2003-01-03T13:45 datetime64zf4,f4)rprr rrr*rr)rZrrrrtest_tril_triu_dtypefs  rcCs\tdtj}tddd}t||tgdtdtjd}t||tgddS)Nr+rn)rr$r:r"rRr$)r$r:rR)rrprrreshaperr)iurhiu1rrrtest_mask_indices|s rcCsLtd}tddd}tddd}tdddd}tgdgdgd gd g}td d dd}t||tgd t||tgdd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgdS)Nr"r:r0rRmr1rr$r:r+r"rRr^rTrrnrmro  r$) r$rRr^rnrmrorrrr) r$r^rTrorrrr3)r3r:r+r")r3r3rTr)r3r3r3rr3r3r3r3)r3r:r+r"rR)r3r3rrnrm)r3r3r3rr)r3r3r3r3)rrrr")rrrr)rrrr"rR)rrrrrm)rrrrr)rrprrrr)il1il2il3il4rhrYrrrtest_tril_indicess`     rc@rc)TestTriuIndicescCsLtd}tddd}tddd}tdddd}tgdgdgd gd g}td d dd}t||tgd t||tgdd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgd||<t|tgdgdgdgdgdS)Nr"r:r0rRrrrrrrr$r) r$r:r+r"r^rTrrorr)r$r:r+r"rRrTrrnrmrrrrrr3r)rRr3r3r3)rnrmr3r3)rrrr3)r3r3r3r3r3)r^r3r3r3r3)rorr3r3r3)rrrr3r3r)r3r3rr)rRr3r3r)r3r3rrr)r^r3r3rr)rorr3r3r)rrprrrr)r.riu2iu3iu4rhrYrrrtest_triu_indicess`     z!TestTriuIndices.test_triu_indicesN)rMrNrOrrrrrrrjrc@rc)TestTrilIndicesFromcC(ttttdttttddSN)r:)r:r:r:)rrarrpr r-rrrtest_exceptionsz#TestTrilIndicesFrom.test_exceptionsNrMrNrOrrrrrrrjrc@rc)TestTriuIndicesFromcCrr)rrarrpr r-rrrrrz#TestTriuIndicesFrom.test_exceptionsNrrrrrrrjrc@seZdZddZddZdS) TestVandercCstgd}t|}tgdgdgdgdg}t||ddddf|jd}tdD]}t||d}t||dd|||fq2dS) N)rr$r;r+r})r$r$r$r$r$)rir"r;r$)Qrnr+r$r$r^N)rprrrshaperV)r.rZvpowersrrrrrr/s     zTestVander.test_basiccCs|tgdtjd}t|}tgdgdgdg}t||tddg}t|dd }tgd gd g}t||dS) N)rorr))yror$)rr$)rr$???r+r)y@rr$)yrr$)rrpint8rr)r.rZrexpectedrrr test_dtypess     zTestVander.test_dtypesN)rMrNrOr/rrrrrrs r).__doc__ numpy.testingrrrrrrnumpyrr r r r r rrrrrrrrrrrrpnumpy.core.tests.test_overridesrr r!rPrdrkrlrrrrrrrrrrrrrrrs, L R/  v    /2