o 6apj@sddlZddlZddlmZmZmZmZmZm Z m Z m Z m Z m Z mZddlmZmZmZmZddlmZmZmZmZmZmZmZGdddZGdddZGd d d ZGd d d ZGd ddZ GdddZ!ddZ"GdddZ#ddZ$dS)N) arrayarange atleast_1d atleast_2d atleast_3dblockvstackhstacknewaxis concatenatestack)_block_dispatcher _block_setup_block_concatenate_block_slicing)assert_ assert_raisesassert_array_equal assert_equalassert_raises_regex assert_warnsIS_PYPYc@4eZdZddZddZddZddZd d Zd S) TestAtleast1dcCsBtd}td}t|t|g}tdgtdgg}t||dSNrrrselfabresdesiredr$B/usr/lib/python3/dist-packages/numpy/core/tests/test_shape_base.py test_0D_arrays zTestAtleast1d.test_0D_arraycCsNtddg}tddg}t|t|g}tddgtddgg}t||dSNrrrrr$r$r% test_1D_arrays  zTestAtleast1d.test_1D_arraycCNtddgddgg}tddgddgg}t|t|g}||g}t||dSr'rrr$r$r% test_2D_array zTestAtleast1d.test_2D_arraycCftddgddgg}tddgddgg}t||g}t||g}t|t|g}||g}t||dSr'rrr$r$r% test_3D_array%  zTestAtleast1d.test_3D_arraycCsXttdjdkttdjdkttdjdkttddgddggjdkd S) zB Test to make sure equivalent Travis O's r1array function r(r@@rrrN)rrshaperr$r$r% test_r1array.s"zTestAtleast1d.test_r1arrayN)__name__ __module__ __qualname__r&r)r+r.r8r$r$r$r%r  rc@r) TestAtleast2dcCsFtd}td}t|t|g}tdggtdggg}t||dSrrrrrr$r$r%r&8s zTestAtleast2d.test_0D_arraycCsRtddg}tddg}t|t|g}tddggtddggg}t||dSr'r>rr$r$r%r)?s  zTestAtleast2d.test_1D_arraycCr*r'r>rr$r$r%r+Fr,zTestAtleast2d.test_2D_arraycCr-r'r>rr$r$r%r.Mr/zTestAtleast2d.test_3D_arraycCsZttdjdkttddgjdkttddgddggddgddgggjd kd S) zB Test to make sure equivalent Travis O's r2array function r(rrr1rrrr3r4rrrrN)rrr6r7r$r$r% test_r2arrayVs2zTestAtleast2d.test_r2arrayN)r9r:r;r&r)r+r.rBr$r$r$r%r=7r<r=c@s,eZdZddZddZddZddZd S) TestAtleast3dcCsJtd}td}t|t|g}tdgggtdgggg}t||dSrrrrrr$r$r%r&_s zTestAtleast3d.test_0D_arraycCsZtddg}tddg}t|t|g}tdgdgggtdgdgggg}t||dSr'rDrr$r$r%r)fs  $zTestAtleast3d.test_1D_arraycCsrtddgddgg}tddgddgg}t|t|g}|ddddtf|ddddtfg}t||dSr')rrr rrr$r$r%r+ms ,zTestAtleast3d.test_2D_arraycCr-r'rDrr$r$r%r.tr/zTestAtleast3d.test_3D_arrayN)r9r:r;r&r)r+r.r$r$r$r%rC^s  rCc@s<eZdZddZddZddZddZd d Zd d Zd S) TestHstackcCtttddSNr)r TypeErrorr r7r$r$r%test_non_iterablezTestHstack.test_non_iterablecCrFNr$)r ValueErrorr r7r$r$r%test_empty_inputrJzTestHstack.test_empty_inputcCs6td}td}t||g}tddg}t||dSrrr rrr$r$r%r&s   zTestHstack.test_0D_arraycCs:tdg}tdg}t||g}tddg}t||dSrrNrr$r$r%r)s    zTestHstack.test_1D_arraycCsNtdgdgg}tdgdgg}t||g}tddgddgg}t||dSrrNrr$r$r%r+s  zTestHstack.test_2D_arraycCstttddtdDWdn1swYttttddtdWddS1s;wYdS)Ncs|]}tdVqdSr(Nnpr.0_r$r$r% z,TestHstack.test_generator..rcSs|SNr$)xr$r$r%sz+TestHstack.test_generator..)r(r)r FutureWarningr rangemaprRonesr7r$r$r%test_generators  "zTestHstack.test_generatorN) r9r:r;rIrMr&r)r+r_r$r$r$r%rE~s rEc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS) TestVstackcCrFrG)rrHrr7r$r$r%rIrJzTestVstack.test_non_iterablecCrFrK)rrLrr7r$r$r%rMrJzTestVstack.test_empty_inputcCs:td}td}t||g}tdgdgg}t||dSrrrrrr$r$r%r&s  zTestVstack.test_0D_arraycCs>tdg}tdg}t||g}tdgdgg}t||dSrrarr$r$r%r)s   zTestVstack.test_1D_arraycCsRtdgdgg}tdgdgg}t||g}tdgdgdgdgg}t||dSrrarr$r$r%r+s  zTestVstack.test_2D_arraycCsFtddg}tddg}t||g}tddgddgg}t||dSrrarr$r$r%test_2D_array2s   zTestVstack.test_2D_array2cCsDtttddtdDWddS1swYdS)NcsrOrPrQrSr$r$r%rVrWz,TestVstack.test_generator..r)rr[rr\r7r$r$r%r_s "zTestVstack.test_generatorN) r9r:r;rIrMr&r)r+rbr_r$r$r$r%r`s r`c @seZdZddZddZddZddZd d Zej j e d d d dZ ddZ ej dddgej dgdej dgdddZej dddgej dgdej ddgfdgdgfdgdgd gfgd!d"Zej dddgd#d$Zej dddgd%d&ZdS)'TestConcatenatecCs6td}t|g}d|d<|d|dksJdSNr(r)rr)rReyer rr r!r$r$r%test_returns_copys  z!TestConcatenate.test_returns_copycCs\dD]-}td|}tj||fddttjtj||f|dttjtj||f|d dqtttdttttdfttdtjtdtdftd}td }t t d }t d D]A}tj||f|ddttd |tj||f|ddtttj||f|d dt |d d}t |d d}| |dqdtttddS)Nrrr(r0raxisr)rzall the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension\(s\) and the array at index 1 has 2 dimension\(s\)r?rrr(r(zall the input array dimensions for the concatenation axis must match exactly, but along dimension {}, the array at index 0 has size 1 and the array at index 1 has size 2rr$)rRr^r r AxisErrorrLrrzeroslistr\formatmoveaxisappendpop)rndimr r!rjir$r$r%test_exceptionss8      zTestConcatenate.test_exceptionscCs tjdtjdd}ttd}dg}tj||fdd}t|j|jt|j dtj||fdd}t|j |j t |t|j|jtj|||fddd }t gd }t ||t|j t |}tj||fdd}tj||fd|d }t||ut||dS) Nr3dtyper5r(rYrirU)rjrx)z0.0z1.0z2.0z3.0012rY)rjout)rRrfloat64reshaperor\r rrxrtsizelenrrrnr)rr r!crdr}routr$r$r%test_concatenate_axis_Nones"     z*TestConcatenate.test_concatenate_axis_NonecCs<tdd}t|d}t||t|d}t||dS)Nrd)rRrr r)rrYrr$r$r% test_large_concatenate_axis_Nones    z0TestConcatenate.test_large_concatenate_axis_Nonec Cs4ttd}tt|f|ttt|f|ttt|f|ttd}tt||f||ttt||f||ttt||f||tt||fd||tt||fd||tgdgdg}tgdg}tgdgdgdg}tt||f|tt||fd|tt|j|jfd|jtt|j|jfd|jttt|j|jfdt d  d }|d ddf}|d dd f}|d d df}tt|||fd |tt|||fd|tt|j|j|jfd|j| } t|||fd | d} t | | ut || dS)Nr3r(rrl) ) rrrr*)rr(.rr})ror\rr tuplerTrrLrrcopyrr) rr4r3a23a13r"a0a1a2r}rr$r$r%test_concatenates:   z TestConcatenate.test_concatenatez7PYPY handles sq_concat, nb_add differently than cpython)reasoncCsddl}tddg}tddg}ddg}tgd}tt|j||tt|j||tt|j||tt|j|dtt|jd|dS)Nrrrr(r3)rrr(r3)operatorrrrHconcat)rrr r!nr"r$r$r%test_operator_concatCs   z$TestConcatenate.test_operator_concatcCstddg}tddg}ttt||ftddttt||ftddttt||ftddt||ftdddS) Nrrr(r3r4r)r3r)rr3)rrrLr rRemptyrfr$r$r%test_bad_out_shapePs  z"TestConcatenate.test_bad_out_shaperjNr out_dtype)c8f4f8z>f8i8S4casting)noequivsafe same_kindunsafecCs2tjd|d}tddgtddgf}tj|d||dsWttt||||d Wdn1s4wYttt||j||d Wdn1sQwYn#t||||d }t||j||d }||usnJt|||j|kszJttt||||d WddS1swYdS) Nr3rwg?g@gffffff @g@r)r)r}rjr)rxrjr)r}rxrj) rRrrcan_castrrHr rxr)rrjrrr} to_concatres_out res_dtyper$r$r%test_out_and_dtypeYs0     "z"TestConcatenate.test_out_and_dtype string_dt)SryS0U0arrsgrstring?cCs2tj|||dd}|jtd|jksJdS)Nr)rjrxrr)rRr rxrastype)rrrrjr"r$r$r%test_dtype_with_promotionts z)TestConcatenate.test_dtype_with_promotioncCstttjdgdgfd|dWdn1swYtttjdgdgfd|dWddS1s>wYdS)NrrrxrjrypytestraisesrHrRr rrjr$r$r%"test_string_dtype_does_not_inspects  "z2TestConcatenate.test_string_dtype_does_not_inspectcCsLtjtddtjdgdgfd|dWddS1swYdS)Nz.*subarray dtype)matchrz(2,)irrrr$r$r%test_subarray_errors"z#TestConcatenate.test_subarray_error)r9r:r;rgrvrrrrmarkskipifrrr parametrizerrrrr$r$r$r%rcs2) *     rcc CstttddtdtdtdgtdtdtdgfD] }tt|gdq#tgd}tgd}tgdgdg}tt||f|ttj||fdd|jttt||g|ttt||g|ddt d D}gd }gd }t ||D]\}}t t||j |qt tjd t|ddt tjd t|d dddt d D}gd}gd}t ||D]\}}t t||j |qttggggj dkttggggddj dkt|} tj||f| dt| |t tdtgt tdtdtdgt tdttddgt tdttddgddt tdttdtdgddt tdttdtdgtttddt dD} Wdn 1siwYt| tgddS)Nrrhrr()r3r4rricSsg|]}tjdqS)r(rRrandomrandnrSr$r$r% sztest_stack..r)rrrl)rr(r(rrrz out of boundscSsg|] }tjddqSr(r3rrSr$r$r%rs)rrrrlrr)rr(r3r(rr3r(r3rrrr)r(r)rr(rzneed at least one arrayzmust have the same shaper(r(css|]}|VqdSrXr$)rTrYr$r$r%rVsztest_stack..r)rrHr rRint32rrrror\ziprr6rrmr zeros_likerLrrnrr[) input_r r!r1arraysaxesexpected_shapesrjexpected_shaper}resultr$r$r% test_stacksd    rc@seZdZejgddddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+S), TestBlock)rforce_concatenate force_slicing)paramscCsBdd}dd}|jdkr|S|jdkr|S|jdkrtStd) NcSt|\}}}}t|||SrX)rrr list_ndim result_ndimrUr$r$r%_block_force_concatenate z1TestBlock.block.._block_force_concatenatecSrrX)rrrr$r$r%_block_force_slicingrz-TestBlock.block.._block_force_slicingrrrz7Unknown blocking request. There is a typo in the tests.)paramrrL)rrequestrrr$r$r%rs    zTestBlock.blockcCs2td}||}d|d<|d|dksJdSrd)rRre)rrr r!r$r$r%rgs zTestBlock.test_returns_copycCstdg\}}}}|dksJtdgg\}}}}|dksJtddgg\}}}}|dks0Jtdgdgg\}}}}|dksBJtddgddgg\}}}}|dksVJdS)Nrrr(r3)r)rrrU total_sizer$r$r%test_block_total_size_estimates    z(TestBlock.test_block_total_size_estimatecCsBtd}d|}tgdgdg}|||g}t||dS)Nr5r)rrrrrRr^rr)rra_2db_2dr#rr$r$r%test_block_simple_row_wises   z$TestBlock.test_block_simple_row_wisecCsRtd}d|}tddgddgddgddgg}||g|gg}t||dSNr5rrr)rrrrexpectedrr$r$r%test_block_simple_column_wises  z'TestBlock.test_block_simple_column_wisecCsDtgd}tgd}tgd}|||g}t||dSNrhrr(r3)rrr(rr(r3rRrrrrr r!rrr$r$r%"test_block_with_1d_arrays_row_wise s  z,TestBlock.test_block_with_1d_arrays_row_wisecCsTtgd}tgd}tgdgdg}|||g||gg}t||dSrrrr$r$r%'test_block_with_1d_arrays_multiple_rowss z1TestBlock.test_block_with_1d_arrays_multiple_rowscCsPtgd}tgd}tgdgdg}||g|gg}t||dS)Nrhrr)rra_1db_1drrr$r$r%%test_block_with_1d_arrays_column_wises z/TestBlock.test_block_with_1d_arrays_column_wisecCsRtd}tddg}||g|gg}tddgddgddgg}t||dSrr)rrrrrrr$r$r%test_block_mixed_1d_and_2d"s  z$TestBlock.test_block_mixed_1d_and_2dc Cstgdg}tgdg}tgdg}tgd}td}tgd}td}tgdgdgdgd gd gd g} |||g|g|g||g|gg} t| | dS) NrrrrA)r(r(r(r(r(r()r3r3r3r3r3r3r4rrrrrrrrrrrrrr4rrrrrrrrrrrrRrrnr) rrone_2dtwo_2dthree_2dfour_1dfive_0dsix_1dzero_2drrr$r$r%test_block_complicated+s*   z TestBlock.test_block_complicatedc Cstgd}tgdgdgdg}tgd}tgd}td}tgd}td}|||g|g|gg|g||g|gg} tgdgd gd gd gd gd g} t| | dS) NrrAr(r(r()r3r3r3r4rrr)r(r(r(rrr)r3r3r3rrrrrr ) rronetwothreefourfivesixzerorrr$r$r% test_nestedCs4   zTestBlock.test_nestedc CsZtdtd}tdtd}tdtd}tdtd}td td }td td }td td}tdtd} |||g||gg||g|| ggg} tgdgdgdgdgdggdgdgdgdgdggdgdgdgdgdggdgdgdgdgdggdgdgdgdgdgg} t| | dS)NrAr)r(rrr)rr(rr(rkr3)rr(r(r4)r(rr(r)r(r(rrr)rrr3r3r3)r(r(r4r4r4)rrrrr)rrrrr)rRr^intrr) rra000a100a010a001a011a101a110a111rrr$r$r%test_3das` zTestBlock.test_3dcCsptddg}td}tt|||gtt|||gtdtdgtdtdgg}tt||dS)Nrr)rr(r5)rRrrerrLr^)rrr r!to_blockr$r$r% test_block_with_mismatched_shapes z*TestBlock.test_block_with_mismatched_shapecCs2t|dtdt|tdtddS)Nrr()rrRrrerrr$r$r% test_no_listsszTestBlock.test_no_listscCsxd}tt||ddggtt||dggtt||dgdgtt||gdgtt||dgdggddggdggdS)Nzdepths are mismatchedrrr(r3r4rrL)rrmsgr$r$r%test_invalid_nestings  zTestBlock.test_invalid_nestingcCs6ttd|gttd|ggttd|dgggdS)Nrrr*r(r$r$r%test_empty_listsszTestBlock.test_empty_listscCs0ttd|ddgddgfttd|ddgdS)Nrrrr(r3r@r)rrHr(r$r$r% test_tupleszTestBlock.test_tuplecCsNd}dtd}dtd}||||g}tgdgg}t||dS)Nrrr@r()rrr()r@r/r2r2r2rrrr r!rrrr$r$r%test_different_ndimss zTestBlock.test_different_ndimscCs^d}dtd}dtd}|||g|gg}tgdgdgdgg}t||dS)Nrrr@r(rh)rr/r/)r2r2r2rr0r$r$r%test_different_ndims_depthss z%TestBlock.test_different_ndims_depthscCstjddd}tjddd}||g||gg||g||ggg}||g||gg||g||ggg}||jds7J||jds@Jtjddd}tjddd}||g||gg}||g||gg}||jdsgJ||jdspJdS)NrC)orderF C_CONTIGUOUS F_CONTIGUOUSr)rRrnflags)rrarr_carr_fb_cb_fr$r$r%test_block_memory_orders8z!TestBlock.test_block_memory_orderN)r9r:r;rfixturerrgrrrrrrrrrr%r'r)r,r-r.r1r2r=r$r$r$r%rs,    7   rcCsGddd}|}|}|}ttt||gttt|g|gttt||g||gttt|g||ggg|||gttt||f||fgdS)Nc@s eZdZdS)z(test_block_dispatcher..ArrayLikeN)r9r:r;r$r$r$r% ArrayLikesr?)rror )r?r r!rr$r$r%test_block_dispatchers$ r@)%rnumpyrR numpy.corerrrrrrrr r r r numpy.core.shape_baser rrr numpy.testingrrrrrrrrr=rCrEr`rcrrr@r$r$r$r%s"4$(' #(D: +