o 6aJ@sddlZddlZddlmZmZmZmZmZm Z m Z m Z ddl m Z mZmZmZmZmZmZmZmZmZmZGdddZGdddZGdd d ZGd d d ZGd d d ZGdddZddZGdddZddZ GdddZ!ddZ"dS)N)assert_ assert_equalassert_array_equalassert_almost_equalassert_array_almost_equal assert_raisesassert_raises_regex assert_warns) mgridogrid ndenumerate fill_diagonal diag_indicesdiag_indices_from index_expndindexr_s_ix_c@sfeZdZddZddZddZddZd d Zd d Zd dZ e j dgdddZ ddZdS)TestRavelUnravelIndexcCsttdddttjddddtttjdddWdn1s)wYtttjdddWdn1sDwYtttjddd Wdn1s_wYtttjddd Wdn1szwYttdddttddd ttd ddtttjd dtttjd dtttjddtttjddtttjddtttjddtttjddtttjddttddgdttgdddtgdgdg}tt|dgdttj|dddgdttj|ddd gd!ttj|d"d#d gd$ttd%d&d'tttgddgdgdgttjtgddddgdgdgttd'd&gd%dS)(N)rrr)indicesshape)rhape)r)^)ims)dims)rBg?)r)rr)rr$)rr)皙?g.)r#)rrr#)r'r(r()r#r)r())%Forder)r, )r#r(clipmode)r+r#r#)r3wrap) r2r2)r'rr#r)r(r* iU)rnp unravel_indexr TypeErrorravel_multi_index ValueErrorarray)selfarrrEC/usr/lib/python3/dist-packages/numpy/lib/tests/test_index_tricks.py test_basicsj    z TestRavelUnravelIndex.test_basiccCsd}d}tt|tjgdtt|tjddtt|tjtgdtttjgtddggggtt|tjggfdtt|tjgdgfdtt|tjtgtgfdtttjgtdtjgtdfdgtttjgggtddgdS) Nz9indices must be integral: the provided empty sequence waszonly int indices permitted) r'r)rEdtyperHr'abc)r)r')rr?r=r>rBrintr@)rCmsg1msg2rErErFtest_empty_indicesGs: z(TestRavelUnravelIndex.test_empty_indicescCstjtjkr(ddgddgddgddgdd gddgd dgf}tt|d d d gtttjddd gd gf}ttjj d}tt||dfd gtttj||ddfttj||dfddd gtttj||ddfdddS)Nrr'r)ur7riK ir)r,r*x$i r;r(lzl nm)llr.r/) r=intpint64rr@rrAr>iinfomax)rCrD dummy_arrhalf_maxrErErFtest_big_indices[s.    z&TestRavelUnravelIndex.test_big_indicescCsptjtjtjtjtjtjfD]}tjgdgdg|d}d}d|d|d}tt |||t|t |||dd|d}ttj ||d d |t|tj ||d d tjgdgdgd g|d}d }d d|d|d|d}tt |||t|t |||dd|dd|d}ttj ||d d |t|tj ||d d qdS)N)rrrrr'r#)rr(rr'rrrI)r)r;r;rrr)r.r/)rr'rrr<r))r)r;rHrHr) r=int16uint16int32uint32rVuint64rBrr@r>)rCrJcoordsruncoordsrErErF test_dtypesss:    z!TestRavelUnravelIndex.test_dtypescCsdttjgddddtgddttjgddddtgddtttjgdddS)N)r)rr"r)r#r'r*r:r9r4)rrr(r)r9raiser3rd)rrrr)rr=r@rrArCrErErFtest_clipmodessz$TestRavelUnravelIndex.test_clipmodescCs0tgdd\}}t|jjt|jjdS)Nrrr')r#r))r=r>rflags writeable)rCxyrErErFtest_writeabilitys z'TestRavelUnravelIndex.test_writeabilitycCsBtdd}t|dttdtjdgdttdtjdgddS)NrrEz0d arrayz out of boundsr)r=r>rrrArCrjrErErFtest_0ds  zTestRavelUnravelIndex.test_0dr5)r3r9rdcCsttjtjdtjdd|d}|jdksJtttjtjdtjdd|dWddS1s3wYdS)N)r'rrIrrrr4r)r'r)r=r@zerosrUrrrA)rCr5resrErErFtest_empty_array_ravels "z,TestRavelUnravelIndex.test_empty_array_ravelcCszttjdtjdd}t|dksJtdd|DsJtttdgdWddS1s6wYdS)NrrIror'css|]}|jdkVqdS)rpN)r).0arErErF szATestRavelUnravelIndex.test_empty_array_unravel..r)r=r>rqrUlenallrrA)rCrrrErErFtest_empty_array_unravels  "z.TestRavelUnravelIndex.test_empty_array_unravelN)__name__ __module__ __qualname__rGrPr[rcrfrlrnpytestmark parametrizersryrErErErFrs7   rc@sVeZdZddZddZddZddZej d d d gd d Z ddZ ddZ dS)TestGridcCstddd}tddd}t|jdkt|jdkt|ddkt|ddt|ddkt|d|dddt|d|dd dt|d|dd ddS) Nr"r$@r%)rH)r ggfffff?gqq?)r rrr)rCrubrErErFrGszTestGrid.test_basiccCs8tjdddd\}}t|dt|tdddddS)NrrHT)retstepg9/?yI@r2)r=linspacerrr )rCrkstrErErFtest_linspace_equivalences z"TestGrid.test_linspace_equivalencecCsVtddddddf}tddddddf}t|jdkt|jd kt|d d ddftd d  t|dddd fdtd d t|d dddftd d d t|ddddfdtd d d t|d dddf|d d ddfdtdd d t|ddddf|dddd fdtdd d dS)Nr"rrrr%g?)rrHrH)rrrrrHdrr)r rrrr=onesr)rCcrrErErFtest_nds$&$($$zTestGrid.test_ndcCs\tddddddf}tddddddf}tj|}t||D] \}}t||q"dS)Nr"rrrr)r r r=broadcast_arrayszipr)rC grid_full grid_sparsegrid_broadcastfrrErErF test_sparses   zTestGrid.test_sparsezstart, stop, step, expected)NrHr)rH)irN)icCsJt||||||f}t|||}t|j|dt|j|ddS)Nrr)r rsize)rCstartstopstepexpectedgrid grid_smallrErErFtest_mgrid_size_none_handlings z&TestGrid.test_mgrid_size_none_handlingcCstdddf}ttdtdtdf}t|jtjkt||tddd}ttdtdtd}t|jtjkt||dS)Nr%gQ?)r r=float32rrJfloat64r)rCgrid64grid32rErErFtest_accepts_npfloatings"  z TestGrid.test_accepts_npfloatingcCsPttdddftddtdfttdddtddtddS)Nr%g333333?y@)rr r= complex64rerErErFtest_accepts_npcomplexfloatings "z'TestGrid.test_accepts_npcomplexfloatingN) rzr{r|rGrrrr}r~rrrrrErErErFrs    rc@s<eZdZddZddZddZddZd d Zd d Zd S)TestConcatenatorcCsDttdtgdtd}t|dd|f}t|gddS)N)rrr'r#r)r(r)r) rrrrrrrrrrrr)rrr=rBr)rCrrrErErFtest_1ds zTestConcatenator.test_1dcCs"tdddf}t|jdkdS)Ng333333$@rrHf8)rrrJrCgrErErFtest_mixed_typez TestConcatenator.test_mixed_typecCs4tdtdgtgddf}t|jdkdS)Ng333333$r)rr'r#g$@r)rr=rBrrJrrErErFtest_more_mixed_types"z%TestConcatenator.test_more_mixed_typecCsBtddd}t|jdktddtd}t|jdkdS)NrrTyY@)d)rrrr=rrrErErFtest_complex_stepsz"TestConcatenator.test_complex_stepcCstjdd}tjdd}td||f}t|jdkt|ddddf|t|ddddf|t||f}t|jdkt|ddddf|t|ddddf|dS)Nr)1)r)rH)rHr))r=randomrandrrrr)rCrrrrErErFtest_2d%s zTestConcatenator.test_2dcCsbttdtddfgdttgdtdfgdtttdgdfgddS)Nrrrrrrr')rrrr'rg)rrr=rBrerErErFrn1s $zTestConcatenator.test_0dN) rzr{r|rrrrrrnrErErErFr s rc@seZdZddZdS)TestNdenumeratecCs0tddgddgg}ttt|gddS)Nrrr'r#)))rrr))rrr)rr'))rrr#)r=rBrlistr rCrurErErFrG8s zTestNdenumerate.test_basicN)rzr{r|rGrErErErFr7s rc@seZdZddZddZdS)TestIndexExpressioncCsJtd}t|dd|tddt|dd|tdddS)Nrr")r=arangerrrrrErErFtest_regression_1?s "z%TestIndexExpression.test_regression_1cCstjddd}t|ddddddgf|tddddddgft|ddddddgf|tddddddgfdS)Nr#r)r(r'rr)r=rrrrrrrErErF test_simple_1Es:>z!TestIndexExpression.test_simple_1N)rzr{r|rrrErErErFr>s rc@s4eZdZddZddZddZddZd d Zd S) TestIx_cCsbttd\}t|jtjtg\}t|jtjttjgtjd\}t|jtjdS)NrrI)r=rrangerrJrUrBrrrErErFrMs  zTestIx_.test_regression_1csd}ttjfD]>tjfdd|D}tt||D](\\}}t|j|tt fddt|jDtt |j tj qqdS)N)r#r)r'rcsg|]}|qSrErE)rtsz)funcrErF ]z0TestIx_.test_shape_and_dtype..c3s$|] \}}|kr|dkVqdS)rNrE)rtjsh)krErFrv`s"z/TestIx_.test_shape_and_dtype..) rr=rr enumeraterrrrrx issubdtyperJinteger)rCsizesarraysrurrE)rrrFtest_shape_and_dtypeYs zTestIx_.test_shape_and_dtypecCs,gd}t|\}tt|d|dS)N)TFTTr)r=nonzerorr)rCbool_aint_arErErF test_boolcs zTestIx_.test_boolcCs"gdgdg}tttj|dS)Nrgr#r)r()rrAr=r)rCidx2drErErF test_1d_onlyhrzTestIx_.test_1d_onlycCsRd}t|}t||}t|dj|dft|djd|ft|j|fdS)Nr)rr)r=rrrr)rClength_of_vectorrjoutrErErFtest_repeated_inputls   zTestIx_.test_repeated_inputN)rzr{r|rrrrrrErErErFrLs    rcCs>tjtgdgddtgdgf}t|gdgdS)Nrgrr)rrr'rrr#r)r()r=c_rBr)rurErErFtest_c_vs*rc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)TestFillDiagonalcC<tdt}t|dt|tgdgdgdgdS)N)r'r'r)r)rrrr)rrrr)r=rqrMr rrBrrErErFrG|   zTestFillDiagonal.test_basiccCsftdt}t|dt|tgdgdgdgdgdgdgdgdgdgdg dS)NrKr)rrrrrrrrrErErFtest_tall_matrixs   z!TestFillDiagonal.test_tall_matrixcCshtdt}t|ddt|tgdgdgdgdgdgdgdgdgdgdg dS)NrKr)TrrrrrrrErErFtest_tall_matrix_wraps   z&TestFillDiagonal.test_tall_matrix_wrapcCr)N)r'rHr)) r)rrrrrrrrr) rr)rrrrrrrr) rrr)rrrrrrrrrrErErFtest_wide_matrixrz!TestFillDiagonal.test_wide_matrixcCsDtdt}t|dtgd}tt|dk||||fdS)N)r'r'r'r'r#rr)r=rqrMr rBrwhere)rCruirErErFtest_operate_4d_arrays   z&TestFillDiagonal.test_operate_4d_arraycCFtdt}ttdt|dWddS1swYdS)Nr' at least 2-dr)r=rqrMrrAr rrErErFtest_low_dim_handlings   "z&TestFillDiagonal.test_low_dim_handlingcCr)N)r'r'r*r' equal lengthrrrrErErFtest_hetero_shape_handlings   "z+TestFillDiagonal.test_hetero_shape_handlingN) rzr{r|rGrrrrrrrErErErFr{s   rc Cstd}tgdgdgdgdg}d||<t|tgdgdgd gd gtd d }td t}d||<t|tddgddggddgddgggdS)Nr#)rrr'r#)r)r(r*r;)r<rHrr:)r2r)rrr'r#)r)rr*r;)r<rHrr:)r2rrrrr')rrrrr)rr=rBrrqrM)dirud3rErErFtest_diag_indicess4     rc@s$eZdZddZddZddZdS)TestDiagIndicesFromcCs<tjd}t|\}}t|tdt|tddS)Nr8r#)r=rrrr)rCrjrrrErErFtest_diag_indices_froms  z*TestDiagIndicesFrom.test_diag_indices_fromcCsBtd}ttd t|WddS1swYdS)Nr*r)r=rrrArrmrErErFtest_error_small_inputs   "z*TestDiagIndicesFrom.test_error_small_inputcCsDtdt}ttd t|WddS1swYdS)N)r'r'rr'r)r=rqrMrrArrmrErErFtest_error_shape_mismatchs   "z-TestDiagIndicesFrom.test_error_shape_mismatchN)rzr{r|rrrrErErErFrs rcCsttddd}ddttdD}t||ttd}t||ttd}t|ttdtt}t|dgttd}t|dgttd g}t|gdS) Nrrr'cSsg|]\}}|qSrErE)rtixerErErFrrz test_ndindex..rg)r'rEr)rrr r=rqrr)rjrrErErF test_ndindexs        r)#r}numpyr= numpy.testingrrrrrrrr numpy.lib.index_tricksr r r r rrrrrrrrrrrrrrrrrrrErErErFs (4.Q**G