a :jg @s:ddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z ddlmZmZmZmZmZmZmZmZGdddZGdd d ZGd d d ZGd d d ZGdddZGdddZGdddZGdddZGdddZGdddZ GdddZ!GdddZ"GdddZ#dS) N)array_indexing)product)ComplexWarningVisibleDeprecationWarning)assert_ assert_equal assert_raisesassert_raises_regexassert_array_equal assert_warns HAS_REFCOUNTIS_WASMc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&dIdJZ'dKdLZ(dMdNZ)dOdPZ*dQdRZ+e,j-.dSdTdUe/0dVgge,j-.dWdXdYge,j-.dZd[dXgd\d]Z1e,j-j2e3d^d_d`daZ4dbdcZ5ddS)e TestIndexingcstdgggttfddttfddttfddttfddttfddttfddttfd dttfd dttfd dttfd dttfd dttfddttfddttfddttfddttfddttfddttfddttfddttfddttfddttfdddS)NcsdSNrarI/usr/local/lib/python3.9/site-packages/numpy/_core/tests/test_indexing.pyz3TestIndexing.test_index_no_floats..csdS)N)rrrrrrrrrcsdS)N)rrrrrrrrrcsdddfSrrrrrrrrcsdddfSrrrrrrrrcsdddddfSrrrrrrrrcsdddddfSrrrrrrrrcsdS)N)rrrrrrrrrrcsdS)N)rrrrrrrrrrcsdS)N)rrrrrrrrrrcsdSNffffffrrrrrr rcsdS)N)rrrrrrrr!rcsdS)N)rrrrrrrr"rcsdddfSrrrrrrr#rcsdddfSrrrrrrr$rcsdddddfSrrrrrrr%rcsdddddfSrrrrrrr&rcsdS)N)rrrrrrrrr'rcsdS)N)rrrrrrrrr(rcsdS)N)rrrrrrrrr)rcsdddfSrrrrrrr*rcsdddddfSrrrrrrr+r)nparrayr IndexErrorselfrrrtest_index_no_floatss.z!TestIndexing.test_index_no_floatscstdggttfddttfddttfddttfddttfddttfddttfd dttfd dttfd dttfd dttfd dttfddttfddttfddttfddttfddttfddttfddttfddttfddttfddttfdddS)Nrcs ddSrrrrrrr1rz5TestIndexing.test_slicing_no_floats..csddddfS)Nrrrrrrrr2rcsdddddfSNrr rrrrrrr3rcsdddddfS)Nrr rrrrrr4rcsddddfSrrrrrrr5rcs ddSrrrrrrr7rcsddddfS)Nrr"@rrrrrr8rcsdddddfSr!rrrrrr9rcsddddfSrrrrrrr:rcsdddddfS)Nr@r rrrrrr;rcsdddS)N?rrrrrr=rcsdddddfS)Nrr r#rrrrrr>rcsdddddfS)Nr"r$rrrrrrr?rcsdddddfS)N@rrrrrr@rcsdddddfS)Nrr#rrrrrrArcsdddS)Nr%r r#rrrrrrCrcsdddS)Nr%r#rrrrrrDrcsdddddfS)Nrr#rrrrrrErcsdddddfS)Nr%r"r$rrrrrrrFrcsdddddfS)Nr%r&rrrrrrGrcsdddddfS)Ng?r$r#rrrrrrHrcsdddSrrrrrrrJrrrr TypeErrorrrrrtest_slicing_no_floats-s.z#TestIndexing.test_slicing_no_floatscs&tdgggttfdddS)Nr"csSNrrrrrrPrz;TestIndexing.test_index_no_array_to_index..r(rrrrtest_index_no_array_to_indexLsz)TestIndexing.test_index_no_array_to_indexcCs<tgd}t|d|tjt|dj|jddS)Nr"r r")rrrZnewaxisndimrrrrrtest_none_indexRszTestIndexing.test_none_indexcCsPtgd}t|d|t|dj|utd}tt|dtjdS)Nr-rr)rrrrbase isinstanceint_r0rrrtest_empty_tuple_indexXs  z#TestIndexing.test_empty_tuple_indexcCsFtjddd}t|dj|jt|d|tt|dtjdS)NrZV4dtype.)rzerosrr7typendarray)rsrrrtest_void_scalar_empty_tuple`sz)TestIndexing.test_void_scalar_empty_tuplecCstd}|tj}td}t||||td||<t|tdtddd}t||||tddddf||<t|tddddfjdddtddd}t|||f|||fdS)Nr r r"Zaxis)rarangeastypeZuintpr reshaperepeat)rindexZu_indexarrrrrtest_same_kind_index_castingfs   &z)TestIndexing.test_same_kind_index_castingcCsztgd}t|ggt|gj|jtjgtjd}t|ggt|gj|jtg}tt|j|dS)Nr-r6)rrrr7intprr __getitem__rrbrrrtest_empty_fancy_indexzs z#TestIndexing.test_empty_fancy_indexcCs@tgd}tgd}|||<tgd}t||dS)Nrr"r r r"rrrr)rridxexpectedrrr test_gh_26542s zTestIndexing.test_gh_26542cCsVtgdg}tjdtd}tgd}||||f<tgdg}t||dS)NrLr.r6rM)rrr8intr)rrZidx_rowZidx_colrPrrrtest_gh_26542_2ds  zTestIndexing.test_gh_26542_2dcCsJtd}t|dd}|dd|dd<|dd}t||dS)Ndir=)rr@copyr)rrEZ expected_valsZ actual_valsrrrtest_gh_26542_index_overlaps   z(TestIndexing.test_gh_26542_index_overlapcCstgdgdgdg}t|d|ut|d|t|dj|ut|d|dt|d|dddft|d|dddft|dtd td }d |tf<t|d dS) Nr-r'r .)r.r.r)r.r"r r")rrrrr2EllipsisrIrrrtest_ellipsis_indexs   z TestIndexing.test_ellipsis_indexcCs`tgdgdgdg}t|dgdt|dgdtt|jdtt|jddS)Nr-rWrYri@l)rrrrrrHr0rrrtest_single_int_indexs z"TestIndexing.test_single_int_indexcCsXtgdgdgdg}t|td|dt|td|ddddS)Nr-rWrYTFrrNr0rrrtest_single_bool_indexs  z#TestIndexing.test_single_bool_indexcCsxtd}tdg}tt|j|tdgd}tt|j|tjdtd}tt|j|tt|jtd|fdS)N)rr'r.TFrXr'r'r6) ronesrrrrHr8boolslice)rrErDrrrtest_boolean_shape_mismatchs  z(TestIndexing.test_boolean_shape_mismatchcCsJtgdg}tjdgtd}t|||d||<t|gdgdS)N)rrrTr6r%)r%r%r%)rrrerrIrrrtest_boolean_indexing_onedims z)TestIndexing.test_boolean_indexing_onedimcCsPtd}dd}tt||gtt||gdtt||ddgddS)Nr'cSs|||dk<dS)Nr`r)rvrrrfsz>TestIndexing.test_boolean_assignment_value_mismatch..fr-r")rr@r ValueError)rrrjrrr&test_boolean_assignment_value_mismatchs  z3TestIndexing.test_boolean_assignment_value_mismatchcCsZtd}tjdtd}d|dd<tjdtd||<td}d|dd<t||dS)Nr6TrTr")rr8rerdobjectr )rrEindxrPrrr!test_boolean_assignment_needs_apis    z.TestIndexing.test_boolean_assignment_needs_apicCstgdgdgdg}tgdgdgdg}t||gdt||dgdgt||d||d d||<t|gd gd gd gdS) Nr-rWrYTFT)FTF)r"r.rrZr\r"rr )rr r)r'rrX)rr[rrNrIrrrtest_boolean_indexing_twodims    z)TestIndexing.test_boolean_indexing_twodimcCsDtgd}gd}t||ddgt|d|fddggdS)Nr-rqr"r.rNrIrrrtest_boolean_indexing_listsz'TestIndexing.test_boolean_indexing_listcCstd}tjdtjdddd}tdddd}|||<t|ddtd}tdddddd}|||ddf<t|dddgdS) Nrr6r`rrr r=r r")rrdr8rGr@rrB)rrrJcrrr,test_reverse_strides_and_subspace_bufferinits  z9TestIndexing.test_reverse_strides_and_subspace_bufferinitcCsXtddddf}tdddd}t||||dtddd}dS)Nr=r`Cr )rr@r rUrB)rrirrr'test_reversed_strides_result_allocation,sz4TestIndexing.test_reversed_strides_result_allocationcCsftdd}tdd}tddddj|ddg<tddddj|ddg<t||dS)N)r.r'r r`r r'rr")rfullr@rBTrUrrIrrr%test_uncontiguous_subspace_assignment5s   "z2TestIndexing.test_uncontiguous_subspace_assignmentcCs*td}tt|jtdgfddS)N)@r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r"r@)rrdrrrHrr0rrr(test_too_many_fancy_indices_special_case@s z5TestIndexing.test_too_many_fancy_indices_special_casecCsJtd}t|td|tdt|td|tddS)Nr"TF)rrrrer0rrrtest_scalar_array_boolEs z#TestIndexing.test_scalar_array_boolcCsBtd}t||dut||dut||ddudS)Nrr.)rr@rr0rrrtest_everything_returns_viewsRs z*TestIndexing.test_everything_returns_viewscCsDtd}tt|jddggdftt|jddggdfddS)Nrrrr"rL)rr8rrrH __setitem__r0rrrtest_broaderrors_indexingZs z&TestIndexing.test_broaderrors_indexingcCsztd}tjdtjd}d|d<tt|j|tt|j|dtjdtjd}d|d<tt|j|tt|j|ddS)Nrrxr6r=r`r )rr8rdrGrrrHr)rrindrrr test_trivial_fancy_out_of_bounds_s z-TestIndexing.test_trivial_fancy_out_of_boundscCsttd}tjdtjdddddddddf}t|||d||<td}d|d<d|d<t||dS)NrXr6r r"r.rr`)rr@rGrBr )rrrOresrrrtest_trivial_fancy_not_possiblejs , z,TestIndexing.test_trivial_fancy_not_possiblecCsGdddtj}td}|j|d}|d||gdddf<t|dk||ddgdf<t|dk|d||d<t|dkdS) Nc@seZdZddZdS)z7TestIndexing.test_nonbaseclass_values..SubClasscSs|ddS)Nc)fillroldrrr__array_finalize__{szJTestIndexing.test_nonbaseclass_values..SubClass.__array_finalize__N__name__ __module__ __qualname__rrrrrSubClasszsrr)r9r"rr"r r.r'r.)rr:r8rUviewrrall)rrrr;rrrtest_nonbaseclass_valuesys   z%TestIndexing.test_nonbaseclass_valuescCstd}tjdtjddd}t||gdddf<t||t||ddgdf<t||t||d<t||dS)Nrr?r6rr.)rr8r@float64rB memoryviewr )rrr;rrrtest_array_like_valuess    z#TestIndexing.test_array_like_valuescCs|tjjgdddgd}tjgdtd}t||jjtddg}t||jjt|djjt|djjdS) N))ZNGC1001r)ZNGC1002r%)ZNGC1003r%)targetZS20)ZV_magz>f4r6)FTTrr".)rZrecrrerflags writeable)rdrrrrtest_subclass_writeables z$TestIndexing.test_subclass_writeablecCsRtd}tdddj}t||jj|dd}t||dfjjdS)Nr=rr r`r"r)rr@rBr}rr f_contiguousrIrrrtest_memory_orders   zTestIndexing.test_memory_ordercCsBGddd}|}Gddd}td}tt|dtjtd}tt||tjtd}tt||tdftjtt|||ftjtd}tjdtd }||d<tt|dtjt|dg}tt||tjt|dgg}tt||tdftjtt|||ftjdS) Nc@seZdZddZdS)z2TestIndexing.test_scalar_return_type..ZerocSsdSNrrrrrr __index__sz.Zero.__index__N)rrrrrrrrZerosrc@seZdZdddZdS)z7TestIndexing.test_scalar_return_type..ArrayLikeNcSs tdSrrr)rr7rUrrr __array__szATestIndexing.test_scalar_return_type..ArrayLike.__array__)NN)rrrrrrrr ArrayLikesrrr")r"r"rr6)rr8rr3rrrnr:)rrzrrrJrrrtest_scalar_return_types&    z$TestIndexing.test_scalar_return_typecCstdg}tr"tttj}d|tjdgtjd<d|tjdgtjd<tt |j tjdgtjddtt |j tjdgtjddtrt tttj|dS)Nrr"r6) rrr sys getrefcountr7rGZuint8rrrr)rrrefcountrrrtest_small_regressionss z#TestIndexing.test_small_regressionscCs<tjdtjdtddd}|td}tjdtjdtddd}|td}tjdd d|d <t|j}t ||||||<t|jdtjdt d j d }|tj d|j}t|j|d <t || tj |||| tj <||d d k|ddd ||d d k<dS) Nrr6rr"iZS8r{ZbbbbbbbbS.rr )rr8int8ordrr7rr@sizerrGitemsizerAZint16)rrirxrJrrrtest_unaligneds   .zTestIndexing.test_unalignedcCsXtd}Gdddt}dgdgf}||}t||jdkt||fjdkdS)Nrc@s eZdZdS)z7TestIndexing.test_tuple_subclass..TupleSubclassNrrrrrrr TupleSubclasssrr"r")rrdtuplershape)rrErrDrrrtest_tuple_subclasss   z TestIndexing.test_tuple_subclasscCs^Gddd}td}t||||ftjdddgd}t||||fdS)Nc@s$eZdZddZddZddZdS)zDTestIndexing.test_broken_sequence_not_nd_index..SequenceLikecSsdSrrrrrrr szNTestIndexing.test_broken_sequence_not_nd_index..SequenceLike.__index__cSsdS)Nr"rrrrr__len__szLTestIndexing.test_broken_sequence_not_nd_index..SequenceLike.__len__cSs tddS)Nz Not possible)r)ritemrrrrHszPTestIndexing.test_broken_sequence_not_nd_index..SequenceLike.__getitem__N)rrrrrrHrrrr SequenceLike srr=r)f1i8)f2rr6)rr@r r8)rrrErrr!test_broken_sequence_not_nd_indexs  z.TestIndexing.test_broken_sequence_not_nd_indexcCstd}td}tddddddf}t|d}t||||tjdtjd}t|||f|||fdS)Nr=)r=r )r=7r'r'r'r6)rrdr@Z broadcast_tor rUr8rG)rrZx2rZzindrrr!test_indexing_array_weird_stridess   z.TestIndexing.test_indexing_array_weird_stridescCsHtd}|ddddddf}tdgdf}d||<t|ddS)Nrcr`rr"r r.r=g$@)rr8rfr )rZarrorEZslicesrrr$test_indexing_array_negative_strides,s  z1TestIndexing.test_indexing_array_negative_stridescCsHtjddd}td|d<t|dtjddd|ddksDJdS)N)r"rrur6Zasdfgrrr"s)rr8Zstr_r r)rrErrrtest_character_assignment6sz&TestIndexing.test_character_assignmentrDTFrnumrP original_ndimr"cCstd|}tt||f|Wdn1s<0Yttd||f|<Wdn1st0YdS)Nrr%)rrdpytestraisesr)rrDrrrErrrtest_too_many_advanced_indices?s  , z+TestIndexing.test_too_many_advanced_indicesz no threading)reasoncsddlm}tdg}td|fgd}td|fgd}tjjdd|dddftjfdd |d d fd d tdD}|D] }| qj|usJdS)Nr)ThreadPoolExecutor)f8rr )pr[)rcs$jdt|dtjd}||dS)Nrr)rr7)ZintegerslenrrG)rEro)rngrrfunc[sz.funcr[) max_workerscsg|]}qSr)Zsubmit).0_)rErtperr `rzBTestIndexing.test_structured_advanced_indexing..r=) concurrent.futuresrrr7randomuniformrZ default_rngrangeresult)rrdtZfuturesrjr)rErrrr!test_structured_advanced_indexingMs       z.TestIndexing.test_structured_advanced_indexingcCsptdd}t|ddgt|d|dgt|ddgddgftddgtt|jtdgdS)Nr?rrr"rX) rr@rBrrrrrHrfr0rrrtest_nontuple_ndindexfs$$z"TestIndexing.test_nontuple_ndindexN)6rrrrr*r,r1r5r<rFrKrQrSrVr_rarbrgrhrlrprrrsrvrzr~rrrrrrrrrrrrrrrrrrrmark parametrizerrrZskipifr rrrrrrrsd          "     rc@seZdZddZdS)TestFieldIndexingcCs<tddg}tt|dtjtt|dgtjdS)Nr)rrr)rr8rr3r:r0rrrrnsz)TestFieldIndexing.test_scalar_return_typeN)rrrrrrrrrmsrc @s~eZdZddZddZddZddZej d d d d ge d fdd gd dfd d d gd d gfgddZ ddZ ddZ d S)TestBroadcastedAssignmentscCs |||<|Sr+r)rrrvalrrrassignwsz!TestBroadcastedAssignments.assigncCsrtd}td|d<td|gdddf<td|ddddgf<td|dgdgdggddgf<dS)N)r.r )r"r.r .rLrr"r )rr8rdr0rrrtest_prepending_ones{s  z/TestBroadcastedAssignments.test_prepending_onescCsx|j}tj}td}tt|||dtdtt|||gdftdtt|||dgdggftddS)Nr.r r"r-r"r )r r r")rrs_r8rrkrdrrrrrrrtest_prepend_not_ones   z/TestBroadcastedAssignments.test_prepend_not_onecCs|j}tj}td}tt|||dtdtt|||dtdtt|||dddgftdtt|||dddgftdtt|||dgddftddS)N)rr".rt)rrrr)rrrr8rrkrrrrtest_simple_broadcasting_errorss $$z:TestBroadcastedAssignments.test_simple_broadcasting_errorsrD.r"r NrcCsttd}td}t||jdd}tt}|||<Wdn1sR0Yt|j |spJdS)NrTrT)r.r'rrXrZ r) rr8strrreplacerrrkvalueendswith)rrDvaluesrEZ shape_strerrr*test_broadcast_error_reports_correct_shapes    &zETestBroadcastedAssignments.test_broadcast_error_reports_correct_shapecCsRtd}gd|dgdgdgggdf<t|ddddfgdkdS)Nrr r.r'rr"r rLr.)rr8rrr0rrrtest_index_is_largers  z/TestBroadcastedAssignments.test_index_is_largercCsZtd}tddddf}tdddd}|||<t|ddd|kdS)NrrTr`)rr8r@rr)rrrirJrrrtest_broadcast_subspaces  z2TestBroadcastedAssignments.test_broadcast_subspace)rrrrrrrrrrrfrrrrrrrrvs     rc@s$eZdZddZddZddZdS)TestSubclassescCs.Gdddtj}td}||}|dd}tt||ut|j|ut||dd|gd}tt||ut|j|utt|jtjut||gdt|j|gd||dk}tt||ut|j|utt|jtjut|||dkt|j||dkdS)Nc@s eZdZdS)z+TestSubclasses.test_basic..SubClassNrrrrrrsrrr.rLr)rr:r@rrr9r2r )rrrr;Zs_slices_fancyZs_boolrrr test_basics&     zTestSubclasses.test_basiccCsJGdddtj}td}||}d|j_|gd}t|jjdS)Nc@s eZdZdS)z8TestSubclasses.test_fancy_on_read_only..SubClassNrrrrrrsrrFrL)rr:r@rrrr)rrrr;rrrrtest_fancy_on_read_onlys    z&TestSubclasses.test_fancy_on_read_onlycCsGdddtj}td|}|dd}t|j|t|j||gd}t|j|t|j|||dk}t|j|t|j|dS)Nc@seZdZddZdS)z=TestSubclasses.test_finalize_gets_full_info..SubClasscSst||_||_dSr+)rrfinalize_statusrrrrrrs zPTestSubclasses.test_finalize_gets_full_info..SubClass.__array_finalize__Nrrrrrrsrr=r.rr)rr:r@rr rr)rrr;Znew_srrrtest_finalize_gets_full_infos        z+TestSubclasses.test_finalize_gets_full_infoN)rrrrrrrrrrrs rc@seZdZddZdS)TestFancyIndexingCastcCsd}t|t}d|d<t|}tdg||<t|ddtt|jdgdgftdgt|ddtt|j|tdgt|dddS) N)r[?Trr"ry@?r y?) rr8rArerrr rr)rrZ bool_indexZ zero_arrayrrrtest_boolean_index_cast_assigns z4TestFancyIndexingCast.test_boolean_index_cast_assignN)rrrrrrrrrsrc@seZdZddZddZdS)TestFancyIndexingEquivalencecCsTtjdtd}|}gd|dd<gd|gd<t||tjdtddddf}gdg|dgddf<t||d|j}dgdgdgg|dddgf<t||dddftjd td}|}dgd gdgd ggg|ddd f<dgd gdgd ggg|dgd f<t|||d }dgd gdgd ggg|dgd f<t||dS)Nrr6)r"r"r r.r.rLrr"r)r.r'rr r'.F)rr@rnrUr r}rd)rrrJrEZcmp_arrrrrtest_object_assigns& "    z/TestFancyIndexingEquivalence.test_object_assigncCstd}|}tgd|dd<tgd|gd<t||tddddf}tgdg|dgddf<t||ddS)Nr)2-3-1r.)r r r )rr r"r)rr@rUrr rIrrrtest_cast_equivalence0s  z2TestFancyIndexingEquivalence.test_cast_equivalenceN)rrrr r rrrrrs rc@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)TestMultiIndexingAutomateda: These tests use code to mimic the C-Code indexing for selection. NOTE: * This still lacks tests for complex item setting. * If you change behavior of indexing, you might want to modify these tests to try more combinations. * Behavior was written to match numpy version 1.8. (though a first version matched 1.7.) * Only tuple indices are supported by the mimicking code. (and tested as of writing this) * Error types should match most of the time as long as there is only one error. For multiple errors, what gets raised will usually not be the same one. They are *not* tested. Update 2016-11-30: It is probably not worth maintaining this test indefinitely and it can be dropped if maintenance becomes a burden. cCsHttgddddd|_td|_dtdtgd td d gd d ggtd d gd d gggt d dd t dddt dddt dddtjdtj dtgdtd gdgdggtjddgddggt d dtjd dgtj dtjdgdtdtddgg|_tdddgtd gdg|_t dddg|_dS)N)r.r"rrXr.r"rrX)r.rrrXskipr)TFFTFr rTr'r`)rr"r"r6)rr"rrGrr%)rr@prodrBremptyrJr^rrfrGr7Z newbyteorderrr8rRcomplex_indicessimple_indices fill_indicesrrrr setup_methodUs."       " z'TestMultiIndexingAutomated.setup_methodc Cst|}g}d}d}d}d}d}d} t|D]\} } | dur@q,t| tjr~| jtkr~d}| jdkrht|| j7}|| j7}q,| t ur| dur| } q,tt| t r|d7}q,t| tjsztj | tj d} Wnt ytYn0| || <n$| jjdkr| jjdkrtd | jdkr"d}|d7}|d7}q,|j|dkrHt|dkrhd|vrh||fS| durt ddg|j||| | d<t|D]8\} } t| t rtj| |j| } |d | gqnP| dur,|d tj dgtj dg||jd| d |j| d}qt| tjr | jtkr | j|j| | | jkrftz*tjt| |j| | | jd d} Wn2tyd}tj dg| tj d} Yn0| jdkr||jd| t|j| | | jf|j| | jd}| } ntn2| jdkrR| |j| ksN| |j|  krRt| jdkr| |j| ks| |j|  krtt|dkr|dddkr| | kr|d| n|d7}|d| gq|dkr|s|dd}tt|j}g}|ddgd}d}|D]} |d7}| ddkr|d| dd||=|d8}t||t| ddD]} || || qx|t| d7}q |}|j||}d} |D]} | ddkrt| dkrq|j}|| | t| dd}||jd| t| t!f|j| t| ddd}tj"| dd}|j#dkr|rvtt$| dd|D]@\}}|j#dkrqt%||kst%|| krtqt| ddt|krJt|dkr0ztj| dd|d d}Wnty,tdYn0ntj| dd|dd}nt |j&|'| d}z0||jd| |j|j| dd}Wnt ytYn0| |j7} q|j&| d| d}| d7} q||fS)aMimic multi dimensional indexing. Parameters ---------- arr : ndarray Array to be indexed. indices : tuple of index objects Returns ------- out : ndarray An array equivalent to the indexing operation (but always a copy). `arr[indices]` should be identical. no_copy : bool Whether the indexing operation requires a copy. If this is `True`, `np.may_share_memory(arr, arr[indices])` should be `True` (with some exceptions for scalars and possibly 0-d arrays). Notes ----- While the function may mostly match the errors of normal indexing this is generally not the case. TrFNr"r6rJryz;arrays used as indices must be of integer (or boolean) typer;nrraise)moder`rjzinvalid index into 0-sizedwrapr>)(list enumerater3rr:r7rer/rr^rfrrGrkkindrUr@indicesrappendrBZravel_multi_indexZnonzero ExceptionsumrrrinsertextendremoveZ transposerArR broadcastrzipanytakeravel)rrEr!Z in_indicesno_copyZ num_fancyZ fancy_dimZerror_unless_broadcast_to_emptyr/Z ellipsis_posryroaxZ flat_indxZ new_indicesZaxesZ fancy_axesniZaiZ orig_shapeZ orig_slicerZ_indx_sizemirrr_get_multi_indexrs2               &     " "     "     z+TestMultiIndexingAutomated._get_multi_indexc Csz|||\}}Wnnty}zVtr2t|}tt||j|tt||j|dtrlt |t|WYd}~dSd}~00| ||||dS)aCheck a multi index item getting and simple setting. Parameters ---------- arr : ndarray Array to be indexed, must be a reshaped arange. index : tuple of indexing objects Index being tested. rN r2r#r rrrr9rHrr_compare_index_resultrrErD mimic_getr-rZ prev_refcountrrr_check_multi_indexas  z-TestMultiIndexingAutomated._check_multi_indexc Csz|||f\}}Wnnty}zVtr4t|}tt||j|tt||j|dtrnt |t|WYd}~dSd}~00| ||||dS)aWCheck a single index item getting and simple setting. Parameters ---------- arr : ndarray Array to be indexed, must be an arange. index : indexing object Index being tested. Must be a single index and not a tuple of indexing objects (see also `_check_multi_index`). rNr3r5rrr_check_single_indexys  z.TestMultiIndexingAutomated._check_single_indexcCs|}||}t|||jdkrl|jdkrltt|||ktrl|r\tt |dntt |d|}|d||<|jdkrdS|r|jdkr|d7}t||dS|j | d7<t||dS)z4Compare mimicked result to indexing result. rr.r rmN) rUr rr/rrZmay_share_memoryr rrrZflatr,)rrErDr6r-Z indexed_arrrJrrrr4s&    z0TestMultiIndexingAutomated._compare_index_resultcCstd}t|tddd|td<t|d||jtj|jtdf||jtj|jtddf||jtj|jtddfdS)NrTr"r6r])N.)rrrr7rZ zeros_likerer0rrr test_booleans  z'TestMultiIndexingAutomated.test_booleancs0ttddttddtdddD]b}|j|j|j|jg}|j||<t|D]6}t fdd|D}| |j || |j |q\q2Wdn1s0Y| |j d| |j dt t|j jd t t|j jd d t t|j jd d d gd d ft t|j jd d d gd d fd dS) NerrorrcSst|to|dkS)Nr)r3r)rOrrrisskipsz8TestMultiIndexingAutomated.test_multidim..isskip)rr r.c3s|]}|s|VqdSr+r)rryr;rr rz;TestMultiIndexingAutomated.test_multidim..)rrrr)rrrrrrr")warningscatch_warningsfilterwarningsDeprecationWarningrrrrrrr7rrJrrrHr)rZ simple_posZtocheckrDrr<r test_multidims&   0z(TestMultiIndexingAutomated.test_multidimcCs&td}|jD]}|||qdS)Nr=)rr@rr8)rrrDrrrtest_1ds  z"TestMultiIndexingAutomated.test_1dN) rrr__doc__rr2r7r8r4r9rBrCrrrrr?sp rc@s8eZdZdZddZddZddZdd Zd d Zd S) TestFloatNonIntegerArgumentz These test that ``TypeError`` is raised when you try to use non-integers as arguments to for indexing and slicing e.g. ``a[0.0:5]`` and ``a[0.5]``, or other functions like ``array.reshape(1., -1)``. cCsttdggg}|tdg|ddg|ddddgf|dddddf|ddddddfdS)Nrrrr0rrrtest_valid_indexings  z/TestFloatNonIntegerArgument.test_valid_indexingcCs|tdggg}|dd|dd|dd|dd|ddd|ddd|ddd|ddddS)Nrrr r"rr0rrrtest_valid_slicings    z.TestFloatNonIntegerArgument.test_valid_slicingcCsjtdgg}tttj|dtttj|tddftttj|dgdtttj|dgtddS)Nr)r%r%r`r%r`r)rrrr)rBr+rr0rrr test_non_integer_argument_errorss z.multr"r.)rr)rrr4)rrIrrr(test_non_integer_sequence_multiplication szDTestFloatNonIntegerArgument.test_non_integer_sequence_multiplicationcCsNtd}tttj|dtttj|dtttj|dtttj|ddS)N)r.r.r.?)rKr")r"g@)g?g333333?)rr8rr)min)rrrrrtest_reduce_axis_float_indexs  z8TestFloatNonIntegerArgument.test_reduce_axis_float_indexN) rrrrDrFrGrHrJrMrrrrrEs    rEc@s$eZdZddZddZddZdS)TestBooleanIndexingcCsztdggg}tttj|dtttj|tddftttjtdtt tjtj tttj |dgdfddS)Nr")Tr`Tr`rF)args) rrrr)rBreoperatorrDr rAZTrue_r+r0rrr test_bool_as_int_argument_errorss z4TestBooleanIndexing.test_bool_as_int_argument_errorscsZtddjdksJdddgdddgdggfjdksDJttfd d dS) Nr)FT.)rr r.r'Trr"r rcsdddgdfS)NFrr".rrrrrr.rzETestBooleanIndexing.test_boolean_indexing_weirdness..)rrdrrrrrrrtest_boolean_indexing_weirdness)s (z3TestBooleanIndexing.test_boolean_indexing_weirdnesscstdtdgdgttdfddtdgddggttdfd dtdgd gttdfd dtd tdgdgggttd fdddS)N)r.r.Fr\zuboolean index did not match indexed array along axis 0; size of axis is 3 but size of corresponding boolean axis is 1csSr+rr)ridx1rrr:rzETestBooleanIndexing.test_boolean_indexing_fast_path..r[TcsSr+rr)ridx2rrrArr=csSr+rr)ridx3rrrHr)r"r"r zuboolean index did not match indexed array along axis 1; size of axis is 1 but size of corresponding boolean axis is 2csSr+rr)rrOrrrPr)rrdrr rrr)rrOrSrTrUrtest_boolean_indexing_fast_path0s,      z3TestBooleanIndexing.test_boolean_indexing_fast_pathN)rrrrQrRrVrrrrrNs rNc@seZdZdZddZdS)TestArrayToIndexDeprecationz7Creating an index from array not 0-D is an error. cCsRtdggg}tttjtdgtttj||dftttj|dg|dS)Nr"r`r)rrrr)rPrDrBr+r0rrrtest_array_to_index_errorWsz5TestArrayToIndexDeprecation.test_array_to_index_errorN)rrrrDrXrrrrrWSsrWc@seZdZdZddZdS)TestNonIntegerArrayLikezTests that array_likes only valid if can safely cast to integer. For instance, lists give IndexError when they cannot be safely cast to an integer. cCs>td}tt|jddgtt|jddgf|gdS)Nr=rKg?1r )rr@rrrHr0rrrrgs z"TestNonIntegerArrayLike.test_basicNrrrrDrrrrrrY`srYc@seZdZdZddZdS)TestMultipleEllipsisErrorz/An index can only have a single ellipsis. csLtdttfddttjtfdfttjtfdfdS)Nr=csdS)N)..rrrrrrwrz6TestMultipleEllipsisError.test_basic..r r.)rr@rrrHr^rrrrrus z$TestMultipleEllipsisError.test_basicNr[rrrrr\qsr\c@seZdZddZddZdS)TestCApiAccesscCsttd}tt|tddtt|tddtt|tddtt|tddtt|tddtd}t|d||d| dd }t|d ||d dS) Nrrr=rr=r=r'rr ) functoolspartialrrrrrdr@r rB)rZ subscriptrrrr test_getitem}s   zTestCApiAccess.test_getitemcCsttd}tt|tddtt|tdddtt|tdddtt|tdddtt|tdddtt|tdddtd}||ddt |ddk| d d }||ddt |d ddgdS) Nr"r=rrrr^r_r'rr r`) rarbrrrkrrdrr@rrBr )rrrrrr test_setitems     zTestCApiAccess.test_setitemN)rrrrcrdrrrrr]|sr])$rr>rarPrnumpyrZnumpy._core._multiarray_testsr itertoolsrZnumpy.exceptionsrrZ numpy.testingrrrr r r r r rrrrrrrrErNrWrYr\r]rrrrs:  (_ C@0)77