o 6a@s&ddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZmZmZmZmZGdddZGdddZGd d d ZGd d d ZGd ddZGdddZGdddZGdddZGdddZGdddZGdddZGdddZGdddZdS)N)array_indexing)product)assert_ assert_equal assert_raisesassert_raises_regexassert_array_equal assert_warns HAS_REFCOUNTc@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(e)j*+dMdNdOe,-dPgge)j*+dQdRdSge)j*+dTdUdRgdVdWZ.dXdYZ/dZS)[ TestIndexingcstdgggttfddttfddttfddttfddttfddttfddttfd dttfd dttfd dttfd dttfd dttfddttfddttfddttfddttfddttfddttfddttfddttfddttfddttfdddS)NcdSNrar@/usr/lib/python3/dist-packages/numpy/core/tests/test_indexing.pyz3TestIndexing.test_index_no_floats..cr )N)rrrrrrrrrcr )N)rrrrrrrrrcdddfSrrrrrrrcdddfSrrrrrrrrcdddddfSrrrrrrrcdddddfSrrrrrrrrcr )N)rrrrrrrrrrcr )N)rrrrrrrrrrcr )N)rrrrrrrrrrcr Nffffffrrrrrrrcr )N)rrrrrrrr rcr )N)rrrrrrrr!rcrrrrrrrr"rcrrrrrrrr#rcrrrrrrrr$rcrrrrrrrr%rcr )N)rrrrrrrrr&rcr )N)rrrrrrrrr'rcr )N)rrrrrrrrr(rcsdddfSrrrrrrr)rcsdddddfSrrrrrrr*r)nparrayr IndexErrorselfrrrtest_index_no_floatss.z!TestIndexing.test_index_no_floatscstdggttfddttfddttfddttfddttfddttfddttfd dttfd dttfd dttfd dttfd dttfddttfddttfddttfddttfddttfddttfddttfddttfddttfddttfdddS)Nr cs ddSrrrrrrr0 z5TestIndexing.test_slicing_no_floats..csddddfS)Nrrrrrrrr1cdddddfSNrr%rrrrrrr2rcsdddddfS)Nrr%rrrrrr3rcsddddfSrrrrrrr4r&cs ddSrrrrrrr6r$csddddfS)Nrr)@rrrrrr7r&csdddddfSr(rrrrrr8rcsddddfSrrrrrrr9r&cdddddfS)Nr@r%rrrrrr:rcdddS)N?rrrrrr<csdddddfS)Nrr%r*rrrrrr=rcr')Nr)r,rrrrrrr>rcsdddddfS)N@rrrrrr?rcr+)Nrr*rrrrrr@rcsdddS)Nr.r%r*rrrrrrBr/csdddS)Nr.r*rrrrrrCr/csdddddfS)Nrr*rrrrrrDrcsdddddfS)Nr.r)r,rrrrrrrErcsdddddfS)Nr.r0rrrrrrFrcr+)Ng?r,r*rrrrrrGrcr-rrrrrrrIr/rrr TypeErrorr!rrrtest_slicing_no_floats,s.z#TestIndexing.test_slicing_no_floatscs&tdgggttfdddS)Nr)csSNrrrrrrOr/z;TestIndexing.test_index_no_array_to_index..r2r!rrrtest_index_no_array_to_indexKsz)TestIndexing.test_index_no_array_to_indexcCs<tgd}t|d|tjt|dj|jddS)Nr)r%r))rrrnewaxisndimr"rrrrtest_none_indexQszTestIndexing.test_none_indexcCsPtgd}t|d|t|dj|utd}tt|dtjdS)Nr7rr)rrrrbase isinstanceint_r;rrrtest_empty_tuple_indexWs  z#TestIndexing.test_empty_tuple_indexcCsFtjddd}t|dj|jt|d|tt|dtjdS)NrV4dtype.)rzerosrrCtypendarray)r"srrrtest_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)axis)rarangeastypeuintprreshaperepeat)r"indexu_indexarrrrrtest_same_kind_index_castinges   &z)TestIndexing.test_same_kind_index_castingcCsztgd}t|ggt|gj|jtjgtjd}t|ggt|gj|jtg}tt|j|dS)Nr7rB)rrrrCintprr __getitem__r"rbrrrtest_empty_fancy_indexys z#TestIndexing.test_empty_fancy_indexcCstgdgdgdg}t|d|ut|d|t|dj|ut|d|dt|d|dddft|d|dddft|dtd td }d |tf<t|d dS) Nr7r1r  .)r.r.r)r.r)r%r))rrrrr=EllipsisrXrrrtest_ellipsis_indexs   z TestIndexing.test_ellipsis_indexcCs`tgdgdgdg}t|dgdt|dgdtt|jdtt|jddS)Nr7r[r]ri@l)rrrrr rWr;rrrtest_single_int_indexs z"TestIndexing.test_single_int_indexcCsXtgdgdgdg}t|td|dt|td|ddddS)Nr7r[r]TFrrrrr;rrrtest_single_bool_indexs $z#TestIndexing.test_single_bool_indexcCsxtd}tdg}tt|j|tdgd}tt|j|tjdtd}tt|j|tt|jtd|fdS)N)r r1r8TFr\r1r1rB) ronesrrr rWrDboolslice)r"rTrRrrrtest_boolean_shape_mismatchs  z(TestIndexing.test_boolean_shape_mismatchcCsJtgdg}tjdgtd}t|||d||<t|gdgdS)N)rrrTrBr.)r.r.r.)rrrjrrXrrrtest_boolean_indexing_onedims z)TestIndexing.test_boolean_indexing_onedimcCsPtd}dd}tt||gtt||gdtt||ddgddS)Nr1cSs|||dk<dS)Nrdr)rvrrrfsz>TestIndexing.test_boolean_assignment_value_mismatch..fr7r))rrMr ValueError)r"rrorrr&test_boolean_assignment_value_mismatchs z3TestIndexing.test_boolean_assignment_value_mismatchcCsZtd}tjdtd}d|dd<tjdtd||<td}d|dd<t||dS)NrBTdr))rrDrjriobjectr)r"rTindxexpectedrrr!test_boolean_assignment_needs_apis    z.TestIndexing.test_boolean_assignment_needs_apicCstgdgdgdg}tgdgdgdg}t||gdt||dgdgt||d||d d||<t|gd gd gd gdS) Nr7r[r]TFT)FTF)r)r8r r^r`r)rr%)rr%r)r1rr\)rr_rrfrXrrrtest_boolean_indexing_twodims    z)TestIndexing.test_boolean_indexing_twodimcCsDtgd}gd}t||ddgt|d|fddggdS)Nr7rxr)r8rfrXrrrtest_boolean_indexing_listsz'TestIndexing.test_boolean_indexing_listcCstd}tjdtjdddd}tdddd}|||<t|ddtd}tdddddd}|||ddf<t|dddgdS) Nr rBrdrr r%rIr%r))rrirDrVrMrrP)r"rrYcrrr,test_reverse_strides_and_subspace_bufferinits  z9TestIndexing.test_reverse_strides_and_subspace_bufferinitcCsXtddddf}tdddd}t||||dtddd}dS)NrIrdCr%)rrMrcopyrP)r"rirrr'test_reversed_strides_result_allocationsz4TestIndexing.test_reversed_strides_result_allocationcCsftdd}tdd}tddddj|ddg<tddddj|ddg<t||dS)N)r8r1r%rdr%r1rr))rfullrMrPTrrrXrrr%test_uncontiguous_subspace_assignments  "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 )rrirr rWrr;rrr(test_too_many_fancy_indices_special_case)s  z5TestIndexing.test_too_many_fancy_indices_special_casecCsJtd}t|td|tdt|td|tddS)Nr)TF)rrrbool_r;rrrtest_scalar_array_bool.s "z#TestIndexing.test_scalar_array_boolcCsBtd}t||dut||dut||ddudS)Nr r.)rrMrr;rrrtest_everything_returns_views;s z*TestIndexing.test_everything_returns_viewscCsDtd}tt|jddggdftt|jddggdfddS)Nr r rr)rr)r%)rrDrr rW __setitem__r;rrrtest_broaderrors_indexingCs  z&TestIndexing.test_broaderrors_indexingcCsztd}tjdtjd}d|d<tt|j|tt|j|dtjdtjd}d|d<tt|j|tt|j|ddS)Nr rrBrIrdr )rrDrirVrr rWr)r"rindrrr test_trivial_fancy_out_of_boundsHs z-TestIndexing.test_trivial_fancy_out_of_boundscCsttd}tjdtjdddddddddf}t|||d||<td}d|d<d|d<t||dS)Nr\rBr%r)r8rrd)rrMrVrPr)r"ridxresrrrtest_trivial_fancy_not_possibleSs , z,TestIndexing.test_trivial_fancy_not_possiblecCsGdddtj}td}|j|d}|d||gdddf<t|dk||ddgdf<t|dk|d||d<t|dkdS) Nc@eZdZddZdS)z7TestIndexing.test_nonbaseclass_values..SubClasscSs|ddS)Nc)fillr"oldrrr__array_finalize__dszJTestIndexing.test_nonbaseclass_values..SubClass.__array_finalize__N__name__ __module__ __qualname__rrrrrSubClassc rr)rEr)rr)r%r8r1r.)rrFrDrviewrrall)r"rrrGrrrtest_nonbaseclass_valuesbs   z%TestIndexing.test_nonbaseclass_valuescCstd}tjdtjddd}t||gdddf<t||t||ddgdf<t||t||d<t||dS)NrrLrBr r.)rrDrMfloat64rP memoryviewr)r"rrGrrrtest_array_like_valuesws    z#TestIndexing.test_array_like_valuescCs|tjjgdddgd}tjgdtd}t||jjtddg}t||jjt|djjt|djjdS) N))NGC1001r)NGC1002r.)NGC1003r.)targetS20)V_magz>f4rB)FTTrr).)rrecrrjrflags writeable)r"drrrrtest_subclass_writeables z$TestIndexing.test_subclass_writeablecCsRtd}tdddj}t||jj|dd}t||dfjjdS)NrIr r%rdr)r)rrMrPrrr f_contiguousrXrrrtest_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@r)z2TestIndexing.test_scalar_return_type..ZerocSdSNrrr!rrr __index__z.Zero.__index__N)rrrrrrrrZero rc@r)z7TestIndexing.test_scalar_return_type..ArrayLikecSs tdSrrrr!rrr __array__s zATestIndexing.test_scalar_return_type..ArrayLike.__array__N)rrrrrrrr ArrayLikerrrr))r)r)rrB)rrDrr>float_rrtrF)r"rzrrrYrrrtest_scalar_return_types&    z$TestIndexing.test_scalar_return_typecCstdg}trtttj}d|tjdgtjd<d|tjdgtjd<tt |j tjdgtjddtt |j tjdgtjddtrUt tttj|dSdS)Nrr)rB) rrr sys getrefcountrCrVuint8rr rr)r"rrefcountrrrtest_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) N@rBrr)iS8rbbbbbbbbS.rr%)rrDint8ordrrCrrMsizerrVitemsizerNint16)r"rnrxrYrrrtest_unaligneds   .zTestIndexing.test_unalignedcCsXtd}Gdddt}dgdgf}||}t||jdkt||fjdkdS)Nrc@ eZdZdS)z7TestIndexing.test_tuple_subclass..TupleSubclassNrrrrrrr TupleSubclassrr)r))rrituplershape)r"rTrrRrrrtest_tuple_subclasss  z TestIndexing.test_tuple_subclasscCs^Gddd}td}t||||ftjdddgd}t||||fdS)Nc@$eZdZddZddZddZdS)zDTestIndexing.test_broken_sequence_not_nd_index..SequenceLikecSrrrr!rrrrrzNTestIndexing.test_broken_sequence_not_nd_index..SequenceLike.__index__cSr)Nr)rr!rrr__len__rzLTestIndexing.test_broken_sequence_not_nd_index..SequenceLike.__len__cSstd)Nz Not possible)r )r"itemrrrrWzPTestIndexing.test_broken_sequence_not_nd_index..SequenceLike.__getitem__N)rrrrrrWrrrr SequenceLikes rrIr)f1i8)f2rrB)rrMrrD)r"rrTrrr!test_broken_sequence_not_nd_indexs  z.TestIndexing.test_broken_sequence_not_nd_indexcCstd}td}tddddddf}t|d}t||||tjdtjd}t|||f|||fdS)NrI)rIr%)rI7r1r1r1rB)rrirM broadcast_torrrDrV)r"rx2rzindrrr!test_indexing_array_weird_stridess   "z.TestIndexing.test_indexing_array_weird_stridescCsHtd}|ddddddf}tdgdf}d||<t|ddS)Nrhrdrr)r%r8rIg$@)rrDrkr)r"arrorTslicesrrr$test_indexing_array_negative_stridess z1TestIndexing.test_indexing_array_negative_stridescCsHtjddd}td|d<t|dtjddd|ddks"JdS)N)r)r r|rBasdfgrrr)s)rrDstr_rr)r"rTrrrtest_character_assignmentsz&TestIndexing.test_character_assignmentrRTFrnumr( original_ndimr)cCstd|}tt||f|Wdn1swYttd||f|<WddS1s;wYdS)Nrr.)rripytestraisesr )r"rRrrrTrrrtest_too_many_advanced_indices(s  "z+TestIndexing.test_too_many_advanced_indicescsddlm}tdg}td|fgd}td|fgd}tjjdd|dddftjfdd |d d fd d tdD}|D]}| qOj|us]JdS)Nr)ThreadPoolExecutor)f8rr%)pr_)rcs$jdt|dtjd}||dS)Nrr)rrC)integerslenrrV)rTru)rngrrfuncCs z.funcr_) max_workerscsg|]}qSr)submit).0_)rTrtperr HszBTestIndexing.test_structured_advanced_indexing..rI) concurrent.futuresrrrCrandomuniformr default_rngrangeresult)r"rdtfuturesror)rTrrrr!test_structured_advanced_indexing6s       z.TestIndexing.test_structured_advanced_indexingN)0rrrr#r4r6r<r@rHrUrZrcrergrlrmrqrwryrzr}rrrrrrrrrrrrrrrrrrrrrmark parametrizerrrr rrrrr s\          "    r c@r)TestFieldIndexingcCs<tddg}tt|dtjtt|dgtjdS)Nr)rrr)rrDrr>rFr;rrrrPsz)TestFieldIndexing.test_scalar_return_typeN)rrrrrrrrrOrrc @s~eZdZddZddZddZddZej d d d d ge d fdd gd dfd d d gd d gfgddZ ddZ ddZ d S)TestBroadcastedAssignmentscCs |||<|Sr5r)r"rrvalrrrassignYsz!TestBroadcastedAssignments.assigncCsrtd}td|d<td|gdddf<td|ddddgf<td|dgdgdggddgf<dS)N)r8r%)r)r8r%.rrr)r%)rrDrir;rrrtest_prepending_ones]s &z/TestBroadcastedAssignments.test_prepending_onescCsx|j}tj}td}tt|||dtdtt|||gdftdtt|||dgdggftddS)Nr .r%r)r7r)r%)r%r%r))rrs_rDrrprir"rrrrrrtest_prepend_not_onegs   (z/TestBroadcastedAssignments.test_prepend_not_onecCs|j}tj}td}tt|||dtdtt|||dtdtt|||dddgftdtt|||dddgftdtt|||dgddftddS)N)r r).r{)r rrr)rrrrDrrprrrrtest_simple_broadcasting_errorsqs $$(z:TestBroadcastedAssignments.test_simple_broadcasting_errorsrR.r)r%NrcCsttd}td}t||jdd}tt }|||<Wdn1s)wYt|j |s8JdS)Nrsrs)r8r1r r\r^ r) rrDstrrreplacerrrpvalueendswith)r"rRvaluesrT shape_strerrr*test_broadcast_error_reports_correct_shape|s    zETestBroadcastedAssignments.test_broadcast_error_reports_correct_shapecCsRtd}gd|dgdgdgggdf<t|ddddfgdkdS)Nrr%r8r1rr)r%rr8)rrDrrr;rrrtest_index_is_largers  (z/TestBroadcastedAssignments.test_index_is_largercCsZtd}tddddf}tdddd}|||<t|ddd|kdS)Nrrsrd)rrDrMrr)r"rrnrYrrrtest_broadcast_subspaces z2TestBroadcastedAssignments.test_broadcast_subspace)rrrrrrrrrrrkr#r%r&rrrrrXs      rc@r)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@r)z+TestSubclasses.test_basic..SubClassNrrrrrrrrr r8rr)rrFrMrrrEr=r)r"rrrGs_slices_fancys_boolrrr test_basics&     zTestSubclasses.test_basiccCsJGdddtj}td}||}d|j_|gd}t|jjdS)Nc@r)z8TestSubclasses.test_fancy_on_read_only..SubClassNrrrrrrrrr Fr)rrFrMrrrr)r"rrrGr)rrrtest_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@r)z=TestSubclasses.test_finalize_gets_full_info..SubClasscSst||_||_dSr5)rrfinalize_statusrrrrrrs  zPTestSubclasses.test_finalize_gets_full_info..SubClass.__array_finalize__NrrrrrrrrrIr8rr)rrFrMrrr-r)r"rrGnew_srrrtest_finalize_gets_full_infos        z+TestSubclasses.test_finalize_gets_full_infoN)rrrr+r,r/rrrrr's r'c@r)TestFancyIndexingCastcCsd}t|t}d|d<t|}tdg||<t|ddttj|jdgdgftdgt|ddttj|j|tdgt|dddS) N)r_?Trr)ry@?r%y?) rrDrNrjrrr ComplexWarningr)r"r bool_index zero_arrayrrrtest_boolean_index_cast_assigns z4TestFancyIndexingCast.test_boolean_index_cast_assignN)rrrr5rrrrr0rr0c@eZdZddZddZdS)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)Nr rB)r)r)r%r8r8rrr)r8)r8r1r r%r1.F)rrMrtrrrri)r"rrYrTcmp_arrrrrtest_object_assigns& "    z/TestFancyIndexingEquivalence.test_object_assigncCstd}|}tgd|dd<tgd|gd<t||tddddf}tgdg|dgddf<t||ddS)Nr )2-3-1r8)r<r>r=)rr%r)r)rrMrrrrXrrrtest_cast_equivalences  z2TestFancyIndexingEquivalence.test_cast_equivalenceN)rrrr;r?rrrrr7s r7c@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)r8r)r r\r8r)r r\)r8rr r\skipr)TFFTFr%rsr1rd)rr)r)rB)rr)rCrVrr.)rrMprodrPremptyrYrbrrkrVrC newbyteorderrrDintcomplex_indicessimple_indices fill_indicesr!rrrsetup7s."       " z TestMultiIndexingAutomated.setupc Cst|}g}d}d}d}d}d}d} t|D]}\} } | durqt| tjr>| jtkr>d}| jdkr3t|| j7}|| j7}q| t urK| durI| } qtt| t rU|d7}qt| tjstz tj | tj d} Wn t yntw| || <n| jjdkr| jjdkrtd | jdkrd}|d7}|d7}q|j|dkrt|dkrd|vr||fS| durt ddg|j||| | d<t|D]\} } t| t rtj| |j| } |d | gq| dur|d tj dgtj dg||jd| d |j| d}qt| tjr| jtkr| j|j| | | jkr%tztjt| |j| | | jd d} WntySd}tj dg| tj d} Ynw| jdkr||jd| t|j| | | jf|j| | jd}| } nt| jdkr| |j| ks| |j|  krt| jdkr| |j| ks| |j|  krtt|dkr|dddkr| | kr|d| q|d7}|d| gq|dkrM|sM|dd}tt|j}g}|ddgd}d}|D]C} |d7}| ddkr:|d| dd||=|d8}t||t| ddD] } || || q,|t| d7}q|}|j||}d} |D]} | ddkrGt| dkrdqQ|j}|| | t| dd}||jd| t| t!f|j| t| ddd}tj"| dd}|j#dkr|rtt$| dd|D] \}}|j#dkrqt%||kst%|| krtqt| ddt|krt&|dkrztj| dd|d d}Wntytdwtj| dd|dd}nt |j'|(| d}z||jd| |j|j| dd}Wn t y?tw| |j7} qQ|j'| d| d}| d7} qQ||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)rBrYrz;arrays used as indices must be of integer (or boolean) typerGnrraise)moderdrozinvalid index into 0-sizedwraprJ))list enumerater>rrFrCrjr:r rbrkrrVrpkindrrMindicesrappendrPravel_multi_indexnonzero ExceptionsumrFrr insertextendremove transposerNrI broadcastrzipanyrtakeravel)r"rTrU in_indicesno_copy num_fancy fancy_dimerror_unless_broadcast_to_emptyr: ellipsis_posrruax flat_indx new_indicesaxes fancy_axesniai orig_shape orig_slicer_indx_sizemirrr_get_multi_indexTs8             &    " "      "    z+TestMultiIndexingAutomated._get_multi_indexc Csz |||\}}Wn7tyA}z+trt|}tt||j|tt||j|dtr6t |t|WYd}~dSd}~ww| ||||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 rvrYr rrrrErWrr_compare_index_resultr"rTrR mimic_getrer" prev_refcountrrr_check_multi_indexCs   z-TestMultiIndexingAutomated._check_multi_indexc Csz |||f\}}Wn7tyB}z+trt|}tt||j|tt||j|dtr7t |t|WYd}~dSd}~ww| ||||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`). rNrwryrrr_check_single_index[s   z.TestMultiIndexingAutomated._check_single_indexcCs|}||}t|||jdkr6|jdkr6tt|||ktr6|r.tt |dntt |d|}|d||<|jdkrGdS|rY|jdkrY|d7}t||dS|j | d7<t||dS)z4Compare mimicked result to indexing result. rr8r%rrN) rrrr:rrmay_share_memoryr rrrflatrc)r"rTrRrzre indexed_arrrYrrrrxss&    z0TestMultiIndexingAutomated._compare_index_resultcCstd}t|tddd|td<t|d||jtj|jtdf||jtj|jtddf||jtj|jtddfdS)Nr Tr)rBra)N.)rrrr|r zeros_likerjr;rrr test_booleans  z'TestMultiIndexingAutomated.test_booleancs2tOtddttddtjdddD]1}|j|j|j|jg}|j||<t |D]}t fdd|D}| |j || |j |q/qWdn1sVwY| |j d| |j dtt|j jd tt|j jd d tt|j jd d d gd d ftt|j jd d d gd d fd dS) NerrorrcSst|to|dkS)NrA)r>r)rrrrisskipsz8TestMultiIndexingAutomated.test_multidim..isskip)rr%r8c3s|] }|s|VqdSr5r)rrrrr sz;TestMultiIndexingAutomated.test_multidim..)rrrr)rrrrrrr))warningscatch_warningsfilterwarningsDeprecationWarningrVisibleDeprecationWarningrLrJrKrrr|rrYrr rWr)r" simple_postocheckrRrrr test_multidims,   "z(TestMultiIndexingAutomated.test_multidimcCs&td}|jD]}|||qdS)NrI)rrMrJr})r"rrRrrrtest_1ds  z"TestMultiIndexingAutomated.test_1dN) rrr__doc__rMrvr|r}rxrrrrrrrr@!sp  r@c@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)Nr rrr;rrrtest_valid_indexings  z/TestFloatNonIntegerArgument.test_valid_indexingcCs|tdggg}|dd|dd|dd|dd|ddd|ddd|ddd|ddddS)Nr rr%r)rr;rrrtest_valid_slicings    z.TestFloatNonIntegerArgument.test_valid_slicingcCsjtdgg}tttj|dtttj|tddftttj|dgdtttj|dgtddS)Nr )r.r.rdr.rdr)rrrr3rPrbrr;rrr test_non_integer_argument_errorss z.multr)r8)rr3rrr?)r"rrrr(test_non_integer_sequence_multiplicationszDTestFloatNonIntegerArgument.test_non_integer_sequence_multiplicationcCsNtd}tttj|dtttj|dtttj|dtttj|ddS)N)r8r8r8?)rr))r)g@)g?g333333?)rrDrr3min)r"rrrrtest_reduce_axis_float_indexs z8TestFloatNonIntegerArgument.test_reduce_axis_float_indexN) rrrrrrrrrrrrrrs   rc@r)TestBooleanIndexingcCsztdggg}tttj|dtttj|tddftttjtdtt tjtj tttj |dgdfddS)Nr))TrdTrdrF)args) rrrr3rProperatorrRr rTrue_rbr;rrr test_bool_as_int_argument_errorss z4TestBooleanIndexing.test_bool_as_int_argument_errorscsPtddjdkdddgdddgdggfdkttfd d dS) Nr$)FT.)rr%r8r1Trr)r%r8csdddgdfS)NFrr).rrrrrrszETestBooleanIndexing.test_boolean_indexing_weirdness..)rrirrr r!rrrtest_boolean_indexing_weirdness s "z3TestBooleanIndexing.test_boolean_indexing_weirdnesscstdtdgdgttdfddtdgddggttdfd dtdgd gttdfd dtd tdgdgggttd fdddS)N)r8r8Fr`ztboolean index did not match indexed array along dimension 0; dimension is 3 but corresponding boolean dimension is 1cSr5rr)ridx1rrrrzETestBooleanIndexing.test_boolean_indexing_fast_path..r_Tcrr5rr)ridx2rrr$rrIcrr5rr)ridx3rrr+r)r)r)r%ztboolean index did not match indexed array along dimension 1; dimension is 1 but corresponding boolean dimension is 2crr5rr)rrrrr3r)rrirrr r!r)rrrrrrtest_boolean_indexing_fast_paths,      z3TestBooleanIndexing.test_boolean_indexing_fast_pathN)rrrrrrrrrrrs rc@eZdZdZddZdS)TestArrayToIndexDeprecationz:Creating an an index from array not 0-D is an error. cCsRtdggg}tttjtdgtttj||dftttj|dg|dS)Nr)rdr)rrrr3rrRrPrbr;rrrtest_array_to_index_error:sz5TestArrayToIndexDeprecation.test_array_to_index_errorN)rrrrrrrrrr6 rc@r)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)NrIrg?1r<)rrMrr rWr;rrrr+Js z"TestNonIntegerArrayLike.test_basicNrrrrr+rrrrrCs rc@r)TestMultipleEllipsisErrorz/An index can only have a single ellipsis. csLtdttfddttjtfdfttjtfdfdS)NrIcr )N)..rrrrrrZrz6TestMultipleEllipsisError.test_basic..r%r8)rrMrr rWrbr!rrrr+Xs z$TestMultipleEllipsisError.test_basicNrrrrrrTrrc@r6)TestCApiAccesscCsttd}tt|tddtt|tddtt|tddtt|tddtt|tddtd}t|d||d| dd }t|d ||d dS) NrrrIrrIrIr1r r%) functoolspartialrrr rrirMrrP)r" subscriptrrrr test_getitem`s   zTestCApiAccess.test_getitemcCsttd}tt|tddtt|tdddtt|tdddtt|tdddtt|tdddtt|tdddtd}||ddt |ddk| d d }||ddt |d ddgdS) Nr)rIrrrrrr1r r%rd) rrrrrprrir rMrrPr)r"rrrrr test_setitemps     zTestCApiAccess.test_setitemN)rrrrrrrrrr_s r) rrrrrnumpyrnumpy.core._multiarray_testsr itertoolsr numpy.testingrrrrrr r r rrr'r0r7r@rrrrrrrrrrs:  $B C@0)78