a :jgO @sddlZddlZddlZddlZddlZddlZddlmZddlZ ddl m m Z ddlm mZddlmmZddlm mZddlm mZddlmZddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*dde j j j+,DZ-dde-DZ.e./e0e d Gd d d Z1Gd d d Z2ddZ3GdddZ4ej56ddde7e DddZ8ej56ddde7e De 9ddZ:ej56de j;e je% ddddZ?ej56dde@e jAd gd!d"ZBej5j>e'd#dej56dde@e jAd gd$d%ZCd&d'ZDej5j>e% ddej56d(de jAd)e@d e jAgd*d+ZEd,d-ZFej5j>e'd#dej56d.e jGjHe jGjIejd/d0d1d2ejd3d0d4d2gd5d6ZJd7d8ZKej56d9e jLd:d;d<ZMej56d9e jLd:ej56d=d>d?gd@dAZNej56dBdCggdDdEdFZOej56dGgdHdIdJZPej56d9e jQe jRe jSe jTgdKdLZUdMdNZVGdOdPdPZWdS)QN)param) AxisError) assert_ assert_equal assert_raisesassert_array_equalassert_almost_equalassert_array_almost_equalassert_no_warningsassert_allclose HAS_REFCOUNTsuppress_warningsIS_WASMIS_PYPY)requires_memorycCsg|]}t|tjr|qS) isinstancenpufunc).0objrrF/usr/local/lib/python3.9/site-packages/numpy/_core/tests/test_ufunc.py s rcCsg|]}d|jvr|qS)zO->O)types)rufrrrrZ bitwise_countc@s,eZdZddZddZddZddZd S) TestUfuncKwargscCstttjddddtttjddtdtttjdddgdtttjddddtttjddd d tttjddd d tttjddd d tttjdddgddS)Nsafe)Zcastingx)Zdtypex)Zextobjx)Zoutxii->i)Zsigx)Z signaturexF)ZsubokxT)Zwherexr TypeErrorraddintselfrrrtest_kwarg_exact"sz TestUfuncKwargs.test_kwarg_exactcCstttjddddddS)Nrrr!)sig signaturerr#rr$r&rrrtest_sig_signature,sz"TestUfuncKwargs.test_sig_signaturecCs0tttjdddtdtttjdddtddS)Nrrr!)r)dtype)r*r-r"r&rrrtest_sig_dtype0s zTestUfuncKwargs.test_sig_dtypecCstttjdddgddS)Nrrr )Zextobjr+r&rrrtest_extobj_removed6sz#TestUfuncKwargs.test_extobj_removedN)__name__ __module__ __qualname__r(r,r.r/rrrrr!s rc @s eZdZdZejejfejejfejejfejejfejejfej ej fejejfej ej fgZ e j de ejddfddZddZe j de eddfd d ZGd d d Zd dZefddZddZefddZefddZddZe j deddZdS)TestUfuncGenericLoopsabTest generic loops. The loops to be tested are: PyUFunc_ff_f_As_dd_d PyUFunc_ff_f PyUFunc_dd_d PyUFunc_gg_g PyUFunc_FF_F_As_DD_D PyUFunc_DD_D PyUFunc_FF_F PyUFunc_GG_G PyUFunc_OO_O PyUFunc_OO_O_method PyUFunc_f_f_As_d_d PyUFunc_d_d PyUFunc_f_f PyUFunc_g_g PyUFunc_F_F_As_D_D PyUFunc_F_F PyUFunc_D_D PyUFunc_G_G PyUFunc_O_O PyUFunc_O_O_method PyUFunc_On_Om Where: f -- float d -- double g -- long double F -- complex float D -- complex double G -- complex long double O -- python object It is difficult to assure that each of these loops is entered from the Python level as the special cased loops are a moving target and the corresponding types are architecture dependent. We probably need to define C level testing ufuncs to get at them. For the time being, I've just looked at the signatures registered in the build directory to find relevant functions. zinput_dtype,output_dtyperrcCs@tjd|||d}||ddd}t||t|j|dSN r-rrfullr rr-r'Z input_dtypeZ output_dtypefxyZxsZysrrrtest_unary_PyUFuncms z(TestUfuncGenericLoops.test_unary_PyUFunccCs||SNr)r;r<rrrf2tszTestUfuncGenericLoops.f2cCsBtjd|||d}|||ddd}t||t|j|dSr4r7r9rrrtest_binary_PyUFuncws z)TestUfuncGenericLoops.test_binary_PyUFuncc@seZdZddZddZdS)zTestUfuncGenericLoops.foocCs tdSNrrboolr&rrr conjugatesz#TestUfuncGenericLoops.foo.conjugatecCs tdSrArBr'rrrr logical_xorsz%TestUfuncGenericLoops.foo.logical_xorN)r0r1r2rDrFrrrrfoosrGcCs*tjdtd}ttt|dkdS)Nr5r6r)ronesobjectrallabsr'r;rrrtest_unary_PyUFunc_O_Osz,TestUfuncGenericLoops.test_unary_PyUFunc_O_OcCs.tjd|td}ttt|dkdS)Nr5r6T)rr8rIrrJrDr'rGr;rrr$test_unary_PyUFunc_O_O_method_simplesz:TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_simplecCs,tjdtd}ttt||dkdSr4)rrHrIrrJr$rLrrrtest_binary_PyUFunc_OO_Osz.TestUfuncGenericLoops.test_binary_PyUFunc_OO_OcCs,tjd|td}ttt||dS)Nr5r6rr8rIrrJrFrNrrrtest_binary_PyUFunc_OO_O_methodsz5TestUfuncGenericLoops.test_binary_PyUFunc_OO_O_methodcCs,tjd|td}ttt||dS)N)r5rr6rQrNrrr test_binary_PyUFunc_On_Om_methodsz6TestUfuncGenericLoops.test_binary_PyUFunc_On_Om_methodcCs^tjddgdd}t|dts$Jt|}|jtdksBJt|tjddgdddS)Ny?@y@Or6ry?y@@)rarrayrcomplexrDr-rr'arrresrrrtest_python_complex_conjugates  z3TestUfuncGenericLoops.test_python_complex_conjugaterc sttjdGfdddtj}tjtjd}tj|dd}tjddz ||}WnXty}z@tt|||Wdn1s0YWYd}~n"d}~00||}t| d|Wdn1s0YdS) z9Compare the result of the object loop with non-object onecseZdZfddZZS)zITestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full..MyFloatcs4ztWSty.fddYS0dS)NcsttjjSr>)getattrr_coreumathr)attrvalrrrzgTestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full..MyFloat.__getattr__..)super __getattr__AttributeError)r'r`) __class__ra)r`rrds zUTestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full..MyFloat.__getattr__)r0r1r2rd __classcell__rra)rfrMyFloatsrir6rUraiserJN) rfloat64pirVerrstate Exceptionrtyper astype)r'rriZnum_arrobj_arrZres_numexcZres_objrrhr"test_unary_PyUFunc_O_O_method_fulls <z8TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_fullN)r0r1r2__doc__rsingledoubleZcsingleZcdouble longdouble clongdoubleZ np_dtypespytestmark parametrizeexpr=r?r@rGrMrOrPrRrTr[UNARY_OBJECT_UFUNCSrtrrrrr3:s(-      r3cCsdSr>rrrrr_pickleable_module_globalsrc @s eZdZddZddZejjeddddZ d d Z d d Z d Z dZ ddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Z ej!d5d6d7d8d7gd9d:Z"ej!d5e#d;d7dd7d?d=gd@d:Z"ej!dAgdBdCdDZ$dEdFZ%ejj&e'(dGkdHddIdJZ)dKdLZ*dMdNZ+ej!dOe'j,e'j-gdPdQZ.dRdSZ/dTdUZ0ejje1dVddWdXZ2dYdZZ3d[d\Z4d]d^Z5d_d`Z6dadbZ7dcddZ8dedfZ9dgdhZ:didjZ;dkdlZdqe'=drfggdsdtdudvZ?dwdxZ@dydzZAd{d|ZBd}d~ZCddZDddZEddZFddZGddZHddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddZXddZYddZZddZ[ddZ\ddZ]ddZ^ddZ_e`dejjeajbdkddddZcddZdddZeddZfddÄZgddńZhddDŽZiddɄZjdd˄Zkej!dd͡ej!de'lgdϢe'ldgdgdgge'lgdҢgdӢgdϢgfddՄZmej!dde'lgdآfdpgd٢fdfej!de'jn dfddބZoddZpddZqddZrddZsddZtddZuddZvddZwddZxddZyej!de'jzde{de'jzde|j}dfddZ~e'j,e'je'je'je'je'je'je'jgZej!de'jde'jdej!dOeddZej!de'jdej!dOe'j,e'je'jgddZddZddZddZddZej!de'>dpe'>doe'd d gd d Zd d ZddZddZddZddZej!dd?Zej!d@ddgdAdBZej!dCgdDej!dEddgej!dFe'j,je'jjgdGdHZdIdJZdKdLZdMdNZdOdPZej!dQe'dQe'dQgdRdSZej!dQe'dQe'dQgdTdUZej!dQe'dQe'dQgdVdWZd(S(X TestUfunccCs^tdtjdD]H}tttjtj|dtjuttjtj |d}t|tj uqdS)Nrr)protocol) rangepickleHIGHEST_PROTOCOLrloadsdumpsrsin_rational_teststest_add)r'protorZrrr test_pickles zTestUfunc.test_picklecCsd}tt|tjudS)NsNcnumpy.core _ufunc_reconstruct p0 (S'numpy._core.umath' p1 S'cos' p2 tp3 Rp4 .)rrrrcos)r'Zastringrrrtest_pickle_withstringsz TestUfunc.test_pickle_withstringz 'is' check does not work on PyPyreasoncCs,tjt_tttj}|tjus(JdSr>)umtZ_pickleable_module_global_ufuncrrrrrrErrrtest_pickle_name_is_qualnamesz&TestUfunc.test_pickle_name_is_qualnamec Csdd}t|}tttt|dt|dd}ttj||dddgddS)Nr)rrS) rarangerVlistzipZravelrr$reduceat)r'Lr;idxrrrtest_reduceat_shifting_sums 0z$TestUfunc.test_reduceat_shifting_sumcCsdS)aLTry to check presence and results of all ufuncs. The list of ufuncs comes from generate_umath.py and is as follows: ===== ==== ============= =============== ======================== done args function types notes ===== ==== ============= =============== ======================== n 1 conjugate nums + O n 1 absolute nums + O complex -> real n 1 negative nums + O n 1 sign nums + O -> int n 1 invert bool + ints + O flts raise an error n 1 degrees real + M cmplx raise an error n 1 radians real + M cmplx raise an error n 1 arccos flts + M n 1 arccosh flts + M n 1 arcsin flts + M n 1 arcsinh flts + M n 1 arctan flts + M n 1 arctanh flts + M n 1 cos flts + M n 1 sin flts + M n 1 tan flts + M n 1 cosh flts + M n 1 sinh flts + M n 1 tanh flts + M n 1 exp flts + M n 1 expm1 flts + M n 1 log flts + M n 1 log10 flts + M n 1 log1p flts + M n 1 sqrt flts + M real x < 0 raises error n 1 ceil real + M n 1 trunc real + M n 1 floor real + M n 1 fabs real + M n 1 rint flts + M n 1 isnan flts -> bool n 1 isinf flts -> bool n 1 isfinite flts -> bool n 1 signbit real -> bool n 1 modf real -> (frac, int) n 1 logical_not bool + nums + M -> bool n 2 left_shift ints + O flts raise an error n 2 right_shift ints + O flts raise an error n 2 add bool + nums + O boolean + is || n 2 subtract bool + nums + O boolean - is ^ n 2 multiply bool + nums + O boolean * is & n 2 divide nums + O n 2 floor_divide nums + O n 2 true_divide nums + O bBhH -> f, iIlLqQ -> d n 2 fmod nums + M n 2 power nums + O n 2 greater bool + nums + O -> bool n 2 greater_equal bool + nums + O -> bool n 2 less bool + nums + O -> bool n 2 less_equal bool + nums + O -> bool n 2 equal bool + nums + O -> bool n 2 not_equal bool + nums + O -> bool n 2 logical_and bool + nums + M -> bool n 2 logical_or bool + nums + M -> bool n 2 logical_xor bool + nums + M -> bool n 2 maximum bool + nums + O n 2 minimum bool + nums + O n 2 bitwise_and bool + ints + O flts raise an error n 2 bitwise_or bool + ints + O flts raise an error n 2 bitwise_xor bool + ints + O flts raise an error n 2 arctan2 real + M n 2 remainder ints + real + O n 2 hypot real + M ===== ==== ============= =============== ======================== Types other than those listed will be accepted, but they are cast to the smallest compatible type for which the function is defined. The casting rules are: bool -> int8 -> float32 ints -> double Nrr&rrrtest_all_ufuncsQzTestUfunc.test_all_ufuncrr\cCsRtddd\}}}}}t|dt|dt|dt||jft|ddS)Nrr (i),(i)->())rrrrrrtest_signaturer size_inferredr'enabledZnum_dimsZixsflagssizesrrrtest_signature09s   zTestUfunc.test_signature0cCsNtddd\}}}}}t|dt|dt|dt|dt|ddS)Nrrz (),()->()rrrrrrrrrrrrtest_signature1Cs    zTestUfunc.test_signature1cCsVtddd\}}}}}t|dt|dt|dt||jfdt|ddS)Nrrz(i1,i2),(J_1)->(_kAB)rrr)rrrrSr\rrrrrrrrrtest_signature2Ms   zTestUfunc.test_signature2cCsVtddd\}}}}}t|dt|dt|dt||jfdt|ddS)Nrrz(i1, i12), (J_1)->(i12, i2)rrr)rrrrrSr\rrrrrrtest_signature3Ws   zTestUfunc.test_signature3cCsVtddd\}}}}}t|dt|dt|dt||jfdt|ddS)Nrrz(n,k),(k,m)->(n,m)rrrrrrrrrrSrrrrrrrrtest_signature4`s   zTestUfunc.test_signature4cCsftddd\}}}}}t|dt|dt|dt||j|jB|j|j|jBft|ddS)Nrrz(n?,k),(k,m?)->(n?,m?)rrr)rrrr can_ignorerrrrtest_signature5js    zTestUfunc.test_signature5cCsNtddd\}}}}}t|dt|dt|dt|dt|ddS)Nrz(3)->()rrrrSrrrrrtest_signature6vs    zTestUfunc.test_signature6cCsVtddd\}}}}}t|dt|dt|dt|d|jdft|ddS)NrSrz(3),(03,3),(n)->(9)rrrrrrrrrrrSr rrrrrtest_signature7s   zTestUfunc.test_signature7cCsXtddd\}}}}}t|dt|dt|dt||j|jdft|ddS)NrSrz(3?),(3?,3?),(n)->(9)rrrrrrrrrrrrrtest_signature8s   zTestUfunc.test_signature8cCsNtddd\}}}}}t|dt|dt|dt|dt|ddS)Nrz ( 3) -> ( )rrrrrrrrtest_signature9s    zTestUfunc.test_signature9cCsXtddd\}}}}}t|dt|dt|dt||j|jdft|ddS)NrSrz ( 3? ) , (3? , 3?) ,(n )-> ( 9)rrrrrrrrrtest_signature10s   zTestUfunc.test_signature10cCs:tttdddWdn1s,0YdS)Nrrz ((i)),(i)->()r ValueErrorrrr&rrr(test_signature_failure_extra_parenthesiss z2TestUfunc.test_signature_failure_extra_parenthesiscCs:tttdddWdn1s,0YdS)Nrrz (i),)i(->()rr&rrr.test_signature_failure_mismatching_parenthesiss z8TestUfunc.test_signature_failure_mismatching_parenthesiscCs:tttdddWdn1s,0YdS)Nrrz(i),->()rr&rrr2test_signature_failure_signature_missing_input_args z())rrvecdotr*r&rrrtest_get_signatureszTestUfunc.test_get_signaturecCs,dtjddd}tt|dgdtt,ttj|ddddgd Wdn1sd0Yttj|dd ddgd tt,ttj|dd ddgd Wdn1s0Yttj|dd ddgd tjd dd}tj|d|dt|gdd|dd<tt$tj|dd|ddWdn1sZ0Yt|gd d|dd<tj|dd |ddt|gd d|dd<tt$tj|dd |ddWdn1s0Yt|gd d|dd<tj|dd |ddt|gd dS)N?rSf8r6)rr?iunsafe)r)castingrrrr!)i4)rrrroutr)r)rr)rrrr$rzwarnsDeprecationWarningzerosr'abrrrtest_forced_sigs> : "   4   4 zTestUfunc.test_forced_sigcCstjdgdgdd}tdgdg}t||tjdgdgdd}tdgdg}t||tt tjddddWdn1s0YdS)NrSr\NNNr)r>r*)rr$rmaximumrzraisesr#)r'Zres1Zres2rrrtest_signature_all_Nones   z!TestUfunc.test_signature_all_NonecCs*tttj}tjdd||dfddS)NrSr\r)rprr-rlr$)r'Z float_dtyperrrtest_signature_dtype_typesz#TestUfunc.test_signature_dtype_type get_kwargcCs ttdSNr6dictr;dtrrrrbrzTestUfunc.cCsttddfdSNrrrrrrrbrcCsvtd}tt|}||us&Jtjdi||j|ksDJtdd}tj||fi|djdksrJdS)Nint64rrsZm8m8[s])rr)rr-rrrr$ timedelta)r'rrZint64_2tdrrr&test_signature_dtype_instances_alloweds    z0TestUfunc.test_signature_dtype_instances_allowedcCs t|dSrrr;rrrrbrr-idcCst|ddfdSrrrrrrrbrr*cCsd}tjt|d.tjdi|tdWdn1sF0Ytjt|d*tjdi|tdWdn1s0Ytjt|d$tjd i|dWdn1s0YdS) Nz/The `dtype` and `signature` arguments to ufuncsmatchrSrrzm8[ns])rSr)rSr)rSr)rzrr#rr$r- newbyteorder)r'rmsgrrrrs<8r)rZ same_kindrcCstjtdtddd}|jdks*Jtjtdtddd}|jdksTJtt&tjdtdddWdn1s0Ytt&tjdtdddWdn1s0YdS)N?rdr6)NNrrrS) rldexpfloat32int_r-rzrr#uint64)r'rrZrrrtest_partial_signature_mismatchs 4 z)TestUfunc.test_partial_signature_mismatchcCstt,tjtdtdddWdn1s<0Yttdtdtt,tjtdtdddWdn1s0YdS)Nrr)erNr)rzrr#rr$float16rrlr&rrr*test_partial_signature_mismatch_with_caches  : z4TestUfunc.test_partial_signature_mismatch_with_cachelegacyzUNEP 50 impl breaks casting checks when `dtype=` is used together with python scalars.cCstjddtjdd}|dks Jtjddddtjfdd}|dksFJtt"tjddtjdWdn1sx0YdS)Nrgffffff@rr-rr)r*rr6)rpowerintprzrr#r'rZrrr+test_use_output_signature_for_all_argumentss   z5TestUfunc.test_use_output_signature_for_all_argumentscCshtjtdd tjddddWdn1s40Ytt tjddddWdn1sn0Ytt tjddddWdn1s0Ytt tjddd dWdn1s0Ytt tjddd dWdn1s0Ytt tjddd dWdn1sZ0YdS) Nz1the signature object to ufunc must be a string orrrSr\g^@rz%^->#sii-izii>i)Nrs->i)rzrr#rr$rUnicodeDecodeErrorr&rrrtest_signature_errors,s. . . . 0 zTestUfunc.test_signature_errorscCsdtjgddd}tj||ddtjj|ddtjddd}tj||ddtj||dddS)N)z 2010-01-02z 1999-03-14z1833-03z>M8[D]r6Mr5rm)rrVrreducerr$)r'rrYrrrtest_forced_dtype_timesAs z!TestUfunc.test_forced_dtype_timesrcsfdd}tjgdtjd}||j}||}||dd}t||tt ||ddWdn1sz0Y||dd}t||tt  ||tj dd Wdn1s0Y||tj d d }||tj }t||dS) zBasic test for the safest casts, because ufuncs inner loops can indicate a cast-safety as well (which is normally always "no"). cs|fji|Sr>)nin)rYkwargsrrr call_ufuncQsz.TestUfunc.test_cast_safety..call_ufunc)r@@r6norNequivrr) rrVrrqr-rrrzrr#rl)r'rrrYZarr_bsexpectedrZrrrtest_cast_safetyLs    *   .zTestUfunc.test_cast_safetyc Cstd}td}td}dD]}t|}||}||}t|| g|| gD]\}} |dvrt|t| }nt|t| }t|| } t t | j d} t | || d|dvrt | jjd knt | jj|jkdD]"} t| } tttj|| | d qd D],} t| } |dvrFtttj|| | d nt|t| }t t | j d} tF}|ttt | jst t | jd }nd }Wdn1s0Ytjd d d tj|| | d } Wdn1s0Yt| s | dkr qt | || |dt | jj| jkqdD]} t| } t|t| }t t | j d} tF}|ttt | jst t | jd }nd }Wdn1s0Ytj|| | d } t| sqJt | || |dt | jj| jkqJq^q"tjdtjd }t||} t | dkt | jjd kt||} t | dkt | jjd kdS)Nr5rZbhilqBHILQefdgFDGZFDGgV瞯<)rtolZ bhilqBHILQrlr6ZefdggwMhignore)invalidZoverr)ratolrr)rrVr-rq itertoolsproductrWfloat true_dividemaxfinfo resolutionr rnamerr#r filter UserWarningisnanZtinyrnisfiniterHrC)r'rrtgttcraaZbbr;r<rZrZtcoutZdtoutsuprrrrtest_true_dividekst       "      $0  $    zTestUfunc.test_true_dividecCs`tjdtjd}t|d|jdddtjdtjd}t|d|jddddS)Nr6$@rr\ )rrHrrsumsizerlr'rrrrtest_sum_stabilityszTestUfunc.test_sum_stabilityfp errors don't work in wasmc CsttjtjtjtjfD]}dD]}tjdd}tdt |||dd}t | }t t |d|tj d|d|d}tt||t t |d|tt|ddd|t t |d |Wdq 1s0Yq tjd |d}tt|dddd tt|dddd tt|ddd d tt|ddd d tt|ddd d tt|ddd d tt|dddd tt|dddd tjd|d}||7}t|dqdS)N rrrrriTrecordalwaysrrr6rrSr1g@o@gd@rr)r%rrrrlrxwarningscatch_warnings simplefilterRuntimeWarningr+rlenrrr4rH)r'rvwr,overflowrrrrtest_sums0  2zTestUfunc.test_sumc CstjtjtjfD]}dD]}|||dd|||ddd}tj||d}td|d|_td|d |_tt ||tt |ddd|qtj d|dd}tt |ddddtt |ddddtt |ddd d tt |ddd d tt |ddd dtt |ddd dtt |ddd d tt |ddd d tj d |dd}||7}t|dqdS)Nr9rr?r6rr1y@o@@o@rSyd@d@rDrErFy@@) rZ complex64Z complex128ryemptyrrealimagrr4rH)r'rrLr,rrrrtest_sum_complexs(,zTestUfunc.test_sum_complexcCsVttjdgdddttjdgdddttjtjdtjd d dd gd dS) NrSrinitialrg?皙?333333?)rrSrr6rraxisrV) r\r\)rrr4rrHrr&rrrtest_sum_initials zTestUfunc.test_sum_initialcCsTttjddgddggddgddttjddgddggdd ddgd d d gdS) Nrrr@TFwherer@)r[rVr`"@)rrr4r&rrrtest_sum_wheres $zTestUfunc.test_sum_wherecCstdd}tdd}t||}tddg}t||tj|j|jdd}t||t|d |}t||d dS) NrrrSrSrrSrrDr[rI)rrreshaperrVrTrqr'arr1arr2actualrZactual2Zactual3rrr test_vecdots   zTestUfunc.test_vecdotcCstgd}tgd}t||}tdg}t||t||}t||t|d|d}t||ddS)N)ry@rSrrrSy$@rI)rrVrrZconjrqrjrrrtest_vecdot_complex%s    zTestUfunc.test_vecdot_complexcCs\Gdddtj}tdd|}tdd|}t||}t||sXJdS)Nc@s eZdZdS)z2TestUfunc.test_vecdot_subclass..MySubclassNr0r1r2rrrr MySubclass4srrrrdrSre)rndarrayrrhviewrr)r'rrrkrlresultrrrtest_vecdot_subclass3s  zTestUfunc.test_vecdot_subclasscCsPtjddgtd}tjtddt||Wdn1sB0YdS)N12r6rDr)rrVrIrzrrerr'rYrrrtest_vecdot_object_no_conjugate<sz)TestUfunc.test_vecdot_object_no_conjugatecCstdt}|}d|d<tdt}tjtdd tj |||dWdn1sd0Y|ddks~J|d|d krdksnJdS) NrSrSrrrSz\*: 'float' and 'NoneType'rrrrr) rrHrqrIcopyrrzrr#r)r'rkrlrrrr-test_vecdot_object_breaks_outer_loop_on_errorAs.z7TestUfunc.test_vecdot_object_breaks_outer_loop_on_errorc Csd}tdd}tdd}tt||tj||dd|dd}tdd }tt||tj||dd|dtd d }tdd }tttj||td d }td }tttj||tdd}tdd}tttj||td}tdd }t ||\}}t |j dd||}t j ddD}t d||7}t t|dt|d|dkWdn1s0Ytddd}td}td}tttj|||td} t||| } t| | udS)N broadcastr\rrrrrrgerr_msgz"extend & broadcast loop dimensionsrrr:)r\rr\rrrrrS)rSrrrTrArCrrrr)rrrhrrr4rrrVZbroadcast_arraysrstridesrGrHrIrKrrHrQ) r'rrrurLr;rMrZout2crrrtest_broadcastKsB$$   4   zTestUfunc.test_broadcastcCsjtddd}td}tj|||d|tddksFJtj|||d|dksfJdS)NrSr)rr\rSrrr)rrrhrQr$rJrr'rYrrrrtest_out_broadcastsvs  zTestUfunc.test_out_broadcastsrYrrrr\rSr)z(1,)->()z (2,)->(1,)z(4, 3)->(4, 1))ZidscCstjtddtj||dWdn1s20Ytjtdd&tjtd||dWdn1sv0YdS)Nznon-broadcastablerrr)rzrrrpositiver$rHrrrrtest_out_broadcast_errorss,z#TestUfunc.test_out_broadcast_errorscCsd}tjdddd}tt||tj||dd|dd }tdd}|d }tt||tj||dd|ddS) Nz type castrshortr6rdrrgrztype cast on one argumentrW)rrrhrrr4r )r'rrrrrrtest_type_castszTestUfunc.test_type_castcCsPd}tjdddd}tt||tj||dd|dd }tjdd dd}tt||tj||dd|dtjd d d}tjd d d}t||jtdt||jtdt||jtdt||jtdtt|jtdtt|jtdtt |jtdtt |jtddS)Nz big endianrz>i4r6rdrrgrz little endianzf8z)compare_matrix_multiply_resultsrrrwr&rrrtest_matrix_multiply(s zTestUfunc.test_matrix_multiplycCsTttdtd}t|tdttdtd}t|tddS)N)rr5)r5rr)r5r5)rrrrHrrrrrr test_matrix_multiply_umath_empty,sz*TestUfunc.test_matrix_multiply_umath_emptyc stjtjddd|d}tjtjddd|d}d|jj}fddfdd d d }d}dtddd fdf}d }|D]} |D]} |D]} |D]} || | } || | }|o| jdu}|o|jdu}| j d |j dkr|| j d|j drt t | |tj |dtjfdd | dtjddfd d|dt| j t|j fdqqqqt|d dddS)NrrSr\r6zmatrix multiply on type %scsp|dkrdgfSd}|d}|D]F}t|D]8}||dg}||||d<|d||<||f7}q0q$|S)Nrrr)r)nretbasepermrnew) permute_nrrr7s   z.permute_ncsT|dkr dSd}|d}|D].}||tdff7}||tddff7}q |S)Nr)rrr)slice)rrrsl)slice_nrrrDs z:TestUfunc.compare_matrix_multiply_results..slice_ncSs||kp|dkp|dkSrAr)s1s2rrr broadcastableNsz@TestUfunc.compare_matrix_multiply_results..broadcastablerTrDr.rErgz %s %srzreference check)rrVrandomZrandr-r'rrrshaper rrr4rrstrr)r'tpZd1Zd2rrZ permute_3Zslice_3refp1Zp2rrZa1Za2r)rrrr2s@    z)TestUfunc.compare_matrix_multiply_resultscCstjdtddd}tj|jd|jdddf|jd}t||t tj |dddf|ddd }|tj |jdt d}t ||tttj|dS) Nr\r6r\rSrrrrrg)rrr"rhrQrr-rZeuclidean_pdistsqrtr4ZtrirCrrr)r'rrrrrrtest_euclidean_pdisths* ( zTestUfunc.test_euclidean_pdistcCs&td}t|}t||dS)Nr5)rrrrr)r'rrurrr test_cumsumrs  zTestUfunc.test_cumsumcCstjgdtd}tt|dtjdd|Dtdtt|dtjdd|Dtdtt|dtjdd|Dtdtt|d tjd d|Dtdtt|dtjd d|Dtdtt|dtjd d|Dtdtt|dtjd d|Dtdtt|d tjdd|Dtdtt|tjdd|Dtdttj|dttj|ddS)N)rSNTFtestr6cSsg|] }|pdqSr>rrr;rrrrzrz1TestUfunc.test_object_logical..TcSsg|] }|pdqSTrrrrrr|rr\cSsg|] }|pdqSr\rrrrrr~rblahcSsg|] }|pdqSrrrrrrrrcSsg|] }|odqSr>rrrrrrrcSsg|] }|odqSrrrrrrrrcSsg|] }|odqSrrrrrrrrcSsg|] }|odqSrrrrrrrrcSsg|] }| qSrrrrrrrrrS)rrVrIr logical_or logical_andZ logical_notr r6rrrtest_object_logicalws<         zTestUfunc.test_object_logicalcCsGddd}t|}t||kdtt||dt|g}t||ktdgtt||tdgttj||tdtdgdS)Nc@seZdZddZdS)z8TestUfunc.test_object_comparison..HasComparisonscSsdS)N==rr'otherrrr__eq__sz?TestUfunc.test_object_comparison..HasComparisons.__eq__N)r0r1r2rrrrrHasComparisonssrTr6r)rrVrequalrI)r'rZarr0dZarr1drrrtest_object_comparisons z TestUfunc.test_object_comparisoncCsJtjgdtd}tt|dtt|dtt|dtjgdtd}tt|dtt|dtt|d tt |d tt|d tt|d ttjd ggtdd ttjd dgggtdd d dgttjd gtdjd d dttjd gddggtdjdgd d gdgddS)N)rrrr6abcrrTFTrrTFrrrrUrS)rVr`)rrrS) rrVrIrr4r$minprodanyrJr6rrrtest_object_array_reductions&& z%TestUfunc.test_object_array_reductioncCstjdtd}ddtdD|dd<tjj||dtjj||dt|tjdddDtdtjdtd}d dtdD|d ddf<tjj||d d tjj||d d t|d ddftjd ddDtddS)Nr\r6cSsg|] }dgqSrFrrrrrrrrzBTestUfunc.test_object_array_accumulate_inplace..rcSsg|]}dg|qSrFrrrrrrr)rrSrr5rr\cSsg|] }dgqSrrrrrrrrrrrcSsg|]}dg|qSrrrrrrrr)rrHrIrr$ accumulaterrVryrrr$test_object_array_accumulate_inplacesz.TestUfunc.test_object_array_accumulate_inplacecCsptjtjgdtd}t|tjgdtdtt tjgdWdn1sb0YdS)N)rrrr6)rrrSrNr) rr$rrVrIrrzrr#rrrr$test_object_array_accumulate_failures z.TestUfunc.test_object_array_accumulate_failurecCs$tjdtd}ddtdD|dd<tjdtd}ddtdD|dd<tjj|td|dtjj|td|dt||tjdtd}ddtdD|d ddf<tjdtd}d dtdD|d ddf<tjj|td|d d tjj|td|d d t||dS) Nr\r6cSsg|] }dgqSrFrrrrrrrz@TestUfunc.test_object_array_reduceat_inplace..cSsg|] }dgqSrFrrrrrrrrrcSsg|] }dgqSrrrrrrrrrcSsg|] }dgqSrrrrrrrrrr) rrQrIrr$rrrrHrrrr"test_object_array_reduceat_inplaces z,TestUfunc.test_object_array_reduceat_inplacecCs|tjtjgdtdddg}t|tjddgtdtt&tjgdddgWdn1sn0YdS)Nrr6rrr) rr$rrVrIrrzrr#rrrr"test_object_array_reduceat_failures  z,TestUfunc.test_object_array_reduceat_failurecCsxgtjgtdfD]`}tt|dtt|dtt|dtt|dtt tj |tt tj |qdS)Nr6rrFT) rrVrIrr4rrrJrrr$rr6rrrtest_zerosize_reductionsz!TestUfunc.test_zerosize_reductioncCs|tddg}tt|jddtddg}tt|jddtddg}tt|jddtddg}tt|jdddS)NFrrgrD)rrVrrrJrr6rrrtest_axis_out_of_boundssz!TestUfunc.test_axis_out_of_boundscCsjttjddddttjddddttjddddttjddddttjddddttjddddttj ddt t tjt dddtj ut t tjt dddtj ut t tjt dddtj ut t tjt dddtj ut t tjdddtj uGdd d tj}td |}t t t||udS) NrSrrg @TFg@c@s eZdZdS)z0TestUfunc.test_scalar_reduction..MyArrayNrqrrrrMyArraysrr)rrr4rrrJr$rrr rrprrCrsrVrt)r'rrrrrtest_scalar_reductions""""zTestUfunc.test_scalar_reductioncCs|tdtj}tdtj}tdtj}tj|||dt|dtd}tjdtjd}tj|d|dt|ddS)N)rrrrir6r) rrHrrlr$rrrsubtractr'rrrrrrtest_casting_out_params  z TestUfunc.test_casting_out_paramcCstd}td}td}tj||||ddkdt|gdtdddd}tj|ddg|ddgddggdt|dd gd d ggtj|d|d d gdt|dd gdd ggdS)Nrrrrr`)rrrr\rrrr\rSrr<rTFrf) rrrHrr$rrhrrr rrrtest_where_param(s   "zTestUfunc.test_where_paramcCsVtdtj}tdtj}dtdtj}tj|||gddt|gddS)Nr5r) rrrrrrrrrrr ) rrrrrrrrrr)rrHrrlr$rr rrrtest_where_param_buffer_output7s z(TestUfunc.test_where_param_buffer_outputcCsttjdgtjd}tjdgtd}ttj||ddgtjdgtjd}tjdgtd}ttj||ddgdS)Nrr6Tr_)rrVrrCrrrlr'rr rrrtest_where_param_allocBs z TestUfunc.test_where_param_alloccCstjd}tjd}|dk}t|d}tj||||dt||j|}t|||k||t|| r~JdS)N)r\)rrrXr)r`r) rr full_likelessZ broadcast_torrrqrCr)r'rrr`rZb_whererrrtest_where_with_broadcastingMs   z&TestUfunc.test_where_with_broadcastingcCsd|d<d|d<ttjj|dddttjj|ddgdttjj|ddgd ttjj|d dddgttjj|ddgdgd gd gttjj|ddgd gdgttjj|d dgd gd gttjj|dd|d|d<d|d<ttjj|dddttjj|ddgdttjj|ddgdttjj|d dddgttjj|ddgd gdgd gttjj|ddgdgd gttjj|d dgdgd gttjj|dd|d|d<d|d<ttjj|dddttjj|ddgdttjj|ddgd ttjj|d dddgttjj|ddgdgd gd gttjj|ddgdgd gttjj|d dgd gd gttjj|dd|dS)Nr.r)rrrrgr)rrrrrY)rrrr)rrrrr)rrrr)rrr)rrrr)rrrr)rrminimumr r6rrrcheck_identityless_reductionYs`z&TestUfunc.check_identityless_reductionllz'test array too large for 32bit platformcCsjtdd}ddg|dddf<ddg|dddf<tjj|dd}~|ddksVJ|ddksfJdS) N)rluint8rrSrr\rrg)rrrr rXrrr&test_identityless_reduction_huge_arrays z0TestUfunc.test_identityless_reduction_huge_arraycCstjddd}||dS)NrCorderrrQrr6rrr"test_identityless_reduction_cordersz,TestUfunc.test_identityless_reduction_cordercCstjddd}||dS)NrFrrr6rrr"test_identityless_reduction_fordersz,TestUfunc.test_identityless_reduction_fordercCs$tjddddd}||dS)N)rr\rSrrrrrrQrrr6rrr&test_identityless_reduction_otherordersz0TestUfunc.test_identityless_reduction_otherordercCs>tjddddd}|ddddddf}||dS)N)rSrr\rrrrr r6rrr%test_identityless_reduction_noncontigsz/TestUfunc.test_identityless_reduction_noncontigcCsPtjddd}|ddjdd}d|_|ddddddf}||dS)N)ii1r6rrrSr\r)rrQrtrrr6rrr/test_identityless_reduction_noncontig_unaligneds z9TestUfunc.test_identityless_reduction_noncontig_unalignedcCsVttjjgtdtusJtjdtd}tjjg|tjdt|dtusRJdS)z The type of the result should always depend on the selected loop, not necessarily the output (only relevant for object arrays). r6Nrr-r) rprr$r rIr%rVrlr")r'rrrr$test_reduce_identity_depends_on_loopsz.TestUfunc.test_reduce_identity_depends_on_loopcCsZttjjgdddttjjgtjdtjttjjgtj dtj ttjjdgdddttjjdgdddttjjdgdddttjjdgdddtttjjgddtttjjgddt t"tjjgdt dWdn1s 0Yttjjgtj ddtj dgt d}tjj|dd}t|ddS) NrrUrr\)rVr-r5r6r;)rrrr rinfrrr$rzrrIZ_NoValuerVr'rrZrrrtest_initial_reductions 2z TestUfunc.test_initial_reductioncCstd}tjj|ddjdks$Jtt tjj|ddWdn1sT0Ytd}tt tjj|ddWdn1s0Ytjj|ddd}t|t ddS)N)rrrrgrr)rrrrZ) rrr#r rrzrrrrHrXrrr!test_empty_reduction_and_identitys  .  .z+TestUfunc.test_empty_reduction_and_identityr[)rrNr`)FTTTF)TFFFTFcCshtddd}|}t|}tj|||dtjj|||d}||}t ||t ||dS)NrbrSr r[r`) rrrhr}rrr$r r4rr)r'r[r`ra_copya_checkrZcheckrrrtest_reduction_with_wheres   z#TestUfunc.test_reduction_with_wherer-rr)TTF)NTrVrac Csltddd}|}t|jtj }tj|||dtjj ||||d}|j ||d}t ||dS)NrbrSr )r[r`rVrU) rrrhr}r8rr(rrr r$r) r'r[r`rVrr.r/rZr0rrr%test_reduction_with_where_and_initialsz/TestUfunc.test_reduction_with_where_and_initialcCs2tddd}gd}tttjj||ddS)NrbrSr,r_)rrrhrrrr rrrr#test_reduction_where_initial_needed sz-TestUfunc.test_reduction_where_initial_neededcCstgdgdg}tjj|dd}t|gdtjj|dd}t|ddgtjj|d d}t||tttjj|d ddS) N) @rr)rrg?rrg)r4r^r4rrr4rr)rrVdivider rrrr)rrr*test_identityless_reduction_nonreorderables z4TestUfunc.test_identityless_reduction_nonreorderablecCsddd}dd}dd}ttjjd||tjjdd||tjjdd||tjjdd||tjjdd|tjjgtjjtd d d ||tjjdd||tjjdd||tjjdd||tjjddtjgtjjtd d d tjtjfD]V}|jtd dd |jtd dd |jtddd |jtd dd qdS)Nc_s||i|dSr>rr:argsrrrrok,sz+TestUfunc.test_reduce_zero_axis..okc_stt|g|Ri|dSr>)rrr7rrrerr/sz,TestUfunc.test_reduce_zero_axis..errc Ssp||t||fdd||t||fdd||t|d|d|fdd||t|d||dfdd||t||d|dfdd||t|d||dfdd||t|d|d|d|d|dfdd||td ||fd d||td ||fdd||t|d |fdd||td ||fdd||td ||fdddS) NrrgrrrrYrSrrrr5r)rr)expectfuncrr rrrt2s """" z*TestUfunc.test_reduce_zero_axis..trrrrg)r?r)rr?)r?r?)rrridentityr rr$r)r'r9r:r>rrrrtest_reduce_zero_axiss* zTestUfunc.test_reduce_zero_axiscCsztjgdtd}tttj|dgdtttj|d|ddd}tt||dttj|d|dd t|gd dS) Nror6g?)g@g@gffffff@rcSs ||7}dSr>r)rrrrr add_inplacejsz0TestUfunc.test_safe_casting..add_inplacerrrr)rrVr%rr r$rr#)r'rrBrrrtest_safe_casting_szTestUfunc.test_safe_castingcCstjgddd}tjgddd}tjdtjd}t|||}tjgdtjd}t||t||}t||tj||tj|d}t||t|td}tjgdtjd}t||dS) Nr;i8r6rS)rrr\rrr) rrVrQrrationalrrrquint16)r'rrrrutargetrrrtest_ufunc_custom_outrs    zTestUfunc.test_ufunc_custom_outc Cstjdtddd}tjdtddd}t|ddddf|t|tgdgdgd gd gtd }t|dt|dt|ddgt|d dS) Nr<r6r\rrSr)rrr\rS)rr r)rfr<rJ)r\r3rfr;rr5)rrr%rh opflag_testsZ inplace_addrrVrrrrtest_operand_flagss    zTestUfunc.test_operand_flagscCsdddlmm}tjdgdd}tjdgdd}|||}t|tjdgddtt|j dS)Nrrozu8,u8,u8r6)rr\r) Znumpy._core._struct_ufunc_testsr^Z_struct_ufunc_testsrrVZ add_tripletrr RuntimeErrorZ register_fail)r'Z struct_ufuncrrrurrrtest_struct_ufuncs  zTestUfunc.test_struct_ufunccCstjtddtddtddgtjd}tjtddtddtddgtjd}t||}tjtdtddtddgtjd}t||dS)NrrrSr\r6)rrVrrFZtest_add_rationalsr)r'rrrurrrrtest_custom_ufuncs.         zTestUfunc.test_custom_ufunccCsJtt.tjtddtjtdfdWdn1s<0YdS)Nrr)rr#rmultiplyrrFr%r&rrrtest_custom_ufunc_forced_sigs  z&TestUfunc.test_custom_ufunc_forced_sigcsLGfdddtddtjdkjtjdkjdS)Ncs@eZdZdZdZdZddZddZfddZfd d Z d S) z1TestUfunc.test_custom_array_like..MyThingrcSs ||_dSr>r)r'rrrr__init__sz:TestUfunc.test_custom_array_like..MyThing.__init__cSs |jdSNrrTr&rrr__len__sz9TestUfunc.test_custom_array_like..MyThing.__len__csJjd7_t|ts|f}t||jkr4td|jt|dS)Nrboo) getitem_countrtuplerKndim IndexErrorr)r'rMyThingrr __getitem__s  z=TestUfunc.test_custom_array_like..MyThing.__getitem__csjd7_|SrA) rmul_countrr]rr__rmul__sz:TestUfunc.test_custom_array_like..MyThing.__rmul__N) r0r1r2Z__array_priority__r`rYrUrWr_rarr]rrr^s r^rr{rr)rrlrr`rYr&rr]rtest_custom_array_likesz TestUfunc.test_custom_array_likerr5r6cCsT|}tj|gddt|gdtt"tj|gdWdn1s\0Y|}tj|gdt|gd|}t gd}tj|gd|t|gdtt(tj|gdgdWdn1s0Ytt,tj|gddd gdgWdn1sF0YdS) Nrrrr) rrr\rSr\rrrr:r)rrrS) rrrDrEr\rrr:rrrr) rrrSr\irrr:rror) r}rr$atrrzrrrrV)r'rr.rrrrtest_ufunc_at_basics  0 6 zTestUfunc.test_ufunc_at_basictypecode AllIntegerFloatc Cs|tjurL|tjdvrLtjd|d}tjjddtjd}tjdd|d}n0tjd|d}tjjdd tjd}tjd |d}|}t j d d (}t d | |||Wdn1s0Yt j d d N}t d t ||D](\} } ||| | || | dd dqWdn1s*0Yt||t|dkrt|dks^J|dj|djksxJt|djddt|djddksJdS)Nrkrr6r?)r5r-rrSi TrArCrrCrr5)rr5 typecodesrHrrandintrrr}rGrHrIrhrrrKcategoryrmessage) r'rjrrindxvalsZatagZw_atZw_looprrLrrrtest_ufunc_at_inner_loopss( , B z#TestUfunc.test_ufunc_at_inner_loopsComplexcCstjd|d}ttjdtjdtjddtjdg}|jd}||||t|}|tj urvd|d<|d<nH|dd|tj ur|n| 7<|dd|tj ur|n| 7<t ||dS) Nr5r6rrKr\rPrr) rrHZ concatenaterr8r-rprhZ ones_likerQr$r)r'rjrrrrvaluerrrr!test_ufunc_at_inner_loops_complex!s   $$z+TestUfunc.test_ufunc_at_inner_loops_complexcCs8td}tj|tdtdt|tddS)Nr)rrr$rhrrHrryrrrtest_ufunc_at_ellipsis2s z TestUfunc.test_ufunc_at_ellipsiscCsBtjdtjd}td}tj||t|gdks>JdS)Nrr6)rrri8r)rrHrrrZindexed_negativerhrJ)r'rYrrrrrtest_ufunc_at_negative9s z TestUfunc.test_ufunc_at_negativecCsptjdtjd}tjdtd}d|d<d|d<d|dd<tjdtd}tj||||d|kslJdS) Ni r6r5rrrri )rrrr"r$rhr4)r'indicesrrrrrtest_ufunc_at_large@s zTestUfunc.test_ufunc_at_largecCsPtd}td}tjt|tjd}tj||||dt|ksLJdS)Nr5ir6r)rrrHrKrr$rh)r'rYvaluesindexrrrtest_cast_index_fastpathKs   z"TestUfunc.test_cast_index_fastpathrvrcCsFtd}ttdd}tj|||t|t|d|dS)NrSr)rrrepeatrr$rhrr)r'rvrYr}rrr#test_ufunc_at_scalar_value_fastpathSs z-TestUfunc.test_ufunc_at_scalar_value_fastpathcCsHtddd}tgdgdgdg}tj|tdgdf|t|gdgdgd gtd ddd}tgd }tj|tdtdgdf|t|gd gdgd ggdgdgdggdgdgdggtddd}tgdgdgdg}tj|gdtdf|t|gdgdgdgtd ddd}tgd }tj|tdgdtdf|t|gdgdgdggdgdgdggdgdgdggtddd}tgd }tj|dgdf|t|gd gd gd!gtd ddd}tgd }tj|gddtdf|t|gdgd gd!ggd"gd#gd$ggd%gd&gd'ggtd ddd}tgd }tj|tdtdtdf|t|gd(gd)gdggd*gd+gdggd%gd,gdggdS)-NrrSre)rrr)rrrrrr)rf)rS)ri_4r )rrr)rirf)ri)r)r\)r;i)rKi))rir;)iri)r)ri])jrr)rr5rJ)rif)si=)rKr=r)rio)riFrr$)rrr:)ric)r\r3rf)r;r<)vi@)r)rr)rri.)gi1)mi7)pi:)yiC)rrrhrVr$rhrrrrrrtest_ufunc_at_multiD\s" "  "zTestUfunc.test_ufunc_at_multiDcCsPtd}tj|ddt|dtttjj|ddtttjj|gddS)Nrrr)rrVr$rhrrr\r6rrrtest_ufunc_at_0Ds   zTestUfunc.test_ufunc_at_0DcCs6td}tj|gddt|tgddS)Nr5)rrrSrr) rri>.r\rrrr:r)rrrrhrrVr6rrrtest_ufunc_at_dtypess zTestUfunc.test_ufunc_at_dtypescCsjtd}|ddk}tj||gdt|gdtjddd}tj|gdt|gd dS) Nr5rr)rrr\rr:) rrrrSrrrrrrZu4r6rc) rrrrSr\lrrr:r)rrrrhrinvert)r'rr}rrrtest_ufunc_at_booleans  zTestUfunc.test_ufunc_at_booleancCs4td}|dddfddddf}tj|ddgdt|tdtgdtd}tgdtd}tj||dt|gd tjd dgtd }t t tjj|ddgdt|tjd dgtd t t tj jtd dgtgd }tj |dgdt|tgd dS)Nr\rrrSrr)rrrSr\r:)rr:rr\rr6r5ro)rrr$rhrrVr-rrIrr#rmodfrr)r'origrr}r|rrrtest_ufunc_at_advanceds  z TestUfunc.test_ufunc_at_advancedc Cstdd|}tgdtj}tjgd|jd}|}t||D]\}}||||||<qN||||t ||t |gdksJdS)Nrr5)rrrr)rrrr5r6) rrrqrVrr-r}rrhrrJ) r'r-rrZindxsrsrrrLrrrtest_at_negative_indexess z"TestUfunc.test_at_negative_indexescCs^td}td}tttjj|dg|tddgddggg}tttjjj j|dgdS)NrrrrrrSr\) rrHrr#rrhrVlinalg _umath_linalgrrrrrtest_at_not_none_signatures   z$TestUfunc.test_at_not_none_signaturecCsZtjdtd}ttjjj(tj |ddgddgWdn1sL0YdS)Nr5r6rr) rrHrrzrr^ _exceptionsZ_UFuncNoLoopErrorr$rhryrrrtest_at_no_loop_for_opsz TestUfunc.test_at_no_loop_for_opcCs4tdg}tj|dgdg|ddks0JdS)Nrr)rrVrrhryrrrtest_at_output_casting s z TestUfunc.test_at_output_castingcCsPtd}tt(tj|ddggdWdn1sB0YdS)Nrrrro)rrrzrrr$rhryrrrtest_at_broadcast_failure s  z#TestUfunc.test_at_broadcast_failurec CsBtjj}tjdtd}tjd|jd}|d}t|||t||dd|t||d|t||ddd|t||ddd|t||dd|t||dd|t||dddd|t||dd|d|t||dd||t||ddd|t||dddd d |t||dddd |d |jt||dddd d|t||dddd dd |t||dddd dd |t||dddd dd d|t||dddd d|t||dddd d|t||dddd d|t||dddd dd d|t t |t t ||dddd dd d t t ||dt t ||ddt t ||ddd dt t ||ddt t ||ddt t ||dddt t ||dddt t ||ddt t ||dddt t ||dddddt t ||ddddt t ||ddt t ||dd dddt t ||ddd dddt t ||ddddddS)N)rrr6rrrrgrrFrTrFrUr_)r[r-rr)r-rr)rr)rrrVr`rr)r[r-r)r-rr&)rr-r)r[r-rr)rrr)r[r-rrr)r[r-rr) rr$r rHr%r-rrhrrr#)r'r:rorrrrtest_reduce_arguments sp"   zTestUfunc.test_reduce_argumentscCspGdddtj}tddd}|jdd}||}tjgdtd}tt |||d kkd dS) Nc@seZdZddZdS)z,TestUfunc.test_structured_equal..MyAc_st||dd|Di|S)Ncss|]}|tjVqdSr>)rtrrs)rinputrrr P szOTestUfunc.test_structured_equal..MyA.__array_ufunc__..)r])r'rmethodinputsrrrr__array_ufunc__O s z.MyA.__array_ufunc__N)r0r1r2rrrrrMyAN sr(@r\rSzf8,f8,f8r6)TFFFrT) rrsrrhrtrrVrCrrJ)r'rrraZmrarHrrrtest_structured_equalK s  zTestUfunc.test_structured_equalcCsLtd}td}t||kt||kt||k t||k dS)Nrr)rrVrrrrrtest_scalar_equalY s     zTestUfunc.test_scalar_equalcCstjtjtjtjtjtjtjtjtj tj tj tj tj tjtjtjtjtjtjtjtjtjtjtjtjtjtjg}td}d}tddg}|D] }tt|||tt|||qdS)Nrwrrr)rrr$rrQr5r# floor_divideZ bitwise_andZ bitwise_orZ bitwise_xorZ left_shiftZ right_shiftfmaxfminfmodhypotZ logaddexpZ logaddexp2rrmodZgreaterZ greater_equalrZ less_equalr not_equalrVrr#)r'Z binary_funcsrrrr:rrr test_NotImplemented_not_returnedc s  z*TestUfunc.test_NotImplemented_not_returnedNcCs2tjgdtd}||||d}|jtks.JdS)NTNFr6r)rrVrIr-)r'rr*rrZrrr%test_logical_ufuncs_object_signaturesv sz/TestUfunc.test_logical_ufuncs_object_signaturescCsJtgd}tt||||dWdn1s<0YdS)Nrr)rrVrzrr#)r'rr*rrrr+test_logical_ufuncs_mixed_object_signatures s z5TestUfunc.test_logical_ufuncs_mixed_object_signaturescCstjddd}tddg}t||||ddgd||dksHJtjdtjd}|ddgd|j}t||||d|tjd tjd}|j||ddksJtjd gd d}tjd |jd}|j||dd ksJdS) N1ZV3r6rrTrrrrSrr)rrVrr rrrqr-)r'rrrrrrrr$test_logical_ufuncs_support_anything sz.TestUfunc.test_logical_ufuncs_support_anythingSUr|)rwhi0rcCsdtj||d}tj|td}|||}|||td}t||||}|j|td}t||dSr)rrVrIrCrr )r'rr-r|rYrrrZrrrr#test_logical_ufuncs_supports_string s   z-TestUfunc.test_logical_ufuncs_supports_stringcCs^td}tddg}|}tt ||||ddWdn1sP0YdS)NrwrrrrC)rrVr}rzrr#)r'rrrrrrr"test_logical_ufuncs_out_cast_check s   z,TestUfunc.test_logical_ufuncs_out_cast_checkcCsxtjddd}tjddd}tj|tj|ks8Jttj|tj|ttj|dgtj|dgdS)Nr5z>i8r6z.MyArrNrqrrrrMyArr6 srrrr)rrsrQr$r rHrtrp)r'rrrrrtest_reduce_output_subclass_ok5 s   z(TestUfunc.test_reduce_output_subclass_okcCstdtjjvdS)N )rrZinner1d_no_docrur&rrrtest_no_doc_string? szTestUfunc.test_no_doc_stringcCs"tttjd}|dsJdS)Nzloop of ufunc does not support)rzrr#rrr)r'rsrrrtest_invalid_argsC szTestUfunc.test_invalid_argsnatcCs*zt|rJWnty$Yn0dSr>)rr+r#r'rrrrtest_nat_is_not_finiteI s z TestUfunc.test_nat_is_not_finitecCs*zt|sJWnty$Yn0dSr>)rr*r#rrrrtest_nat_is_nanP s zTestUfunc.test_nat_is_nancCs*zt|rJWnty$Yn0dSr>)risinfr#rrrrtest_nat_is_not_infW s zTestUfunc.test_nat_is_not_inf)r0r1r2rrrzr{skipifrrrrrrrrrrrrrrrrrrrrrrrrrr|rrrrxfailrZ_get_promotion_staterr rr$rrr0r7rrOrTr]rcrnrprvrzr~rrrQrHrrrrrrrrrrrrrrrrrrrrrrrrrrrr r rrrrrsysmaxsizerrrr!r"r%r'r*r+rVr1r(r2r3r6rArDrIrMrOrPrRrbrr%rrFrirrQrrrrrZindexed_ufuncsrnrtrwrxryr{r~rlrrrrrrr5rrrrrrrrrrrrIrrFrCrrrrrrrrrr rrrrrZ datetime64Z timedelta64rrrrrrrrs  T                  W "   +   h+N G6        .        A            P       @             """rrcCs(g|] }ttt|tjrtt|qSrrr]rrrrrrr_ sc Cs|jD]}d|vsd|vrq|d\}}dd|D}tjdd"td||}Wd n1sl0Yt|trt|}t|t|ksJt||D]\}}|j t |ksJqq|j t |ksJqd S) z Check all ufuncs that the correct type is returned. Avoid object and boolean types since many operations are not defined for for them. Choose the shape so even dot and matmul will succeed rU?->cSsg|]}td|qS)r{)rrHrr>rrrrn rz$test_ufunc_types..TrArCN) rsplitrGrHfilterwarningsrrZrKrr-r) rtypinprr8rZZoutsrr>rrrtest_ufunc_types_ s  & rcCs(g|] }ttt|tjrtt|qSrrrrrrrz sc Cs6|jD](}ttdt|@r"q|d\}}dd|D}dd|D}|D]}tdd|_qP|D]}tdd|_qftjdd *td ||}||}Wd n1s0Yt |dkr|f}|f}t ||D]N\} } | j } t | t jr$t | j} d | } t||| | d qt| | qqd S)zs Check that contiguous and non-contiguous calls to ufuncs have the same results for values in range(9) zO?mMrcSsg|]}td|qS)rrrQrrrrr rz,test_ufunc_noncontiguous..cSs"g|]}td|dddqS)rKNrSrrrrrr rrrTrArCNr)rr)rrsetrrZflatrGrHrrKrr-rZ issubdtypeZfloatingr%epsr r)rrrrZargs_cZargs_nrZres_cZres_nZc_arZn_arrZres_epsZtolrrrtest_ufunc_noncontiguousz s0  &  rcCs\tdgdd}t|s"J|jdkr6||n"|jdkrP|||ntddS)NlrErrrzufunc with more than 2 inputs)rrVrtr*rr}r)rrrrrtest_ufunc_warn_with_nan s   rzPython lacks refcountsrcCs"d}tj|gttjddg|gtdtjtd}tjt|tjd}t |}t t "tj|||ddWdn1s0Y|t |ksJ|ddksJt t &tj|||tjdd Wdn1s0Y|t |ks J|ddksJdS) N{rstringr6rrCrr)rr-r)rrVr%ncuBUFSIZErIrHrKrr getrefcountrzrrr$)rvrYrcountrrrtest_ufunc_out_casterrors s$  0 4r  bad_offsetrcCstd}tj|g|dg|gtdtjtd}tt$tj ||tj ddWdn1sf0YdS)Nrrrr6rr) rrVr%rrrIrzrrr$rr rvrYrrrtest_ufunc_input_casterrors s  rr8c Csd}t|g|tjg|gtdtj}tjddNtt $tj ||tj ddWdn1sr0YWdn1s0YdS)Nrrrjrrr) rrVnanr%rrrnrzrFloatingPointErrorr$rr rrr$test_ufunc_input_floatingpoint_error s rcCsJtjtdd(tjtdddddWdn1s<0YdS)Nzcast ufunc 'add' input 0rrzi,irSzdd->dr)rzrr#rr$rVrrrrtest_trivial_loop_invalid_cast sroffsetrcCsd}tj|g|dg|gtdtjtd}tjdtjd}t|}t j t dd&tj j |tj|ddWdn1s0Y|t|ksJ|d ||ksJdS) Nrrrr6rzinvalid literalr)r-rrVr)rrVr%rrrIrrr rzrrr$r )rrvrYrr rrrtest_reduce_casterrors s  4rcCs|tt$tjjgdddWdn1s40Ytt tjgdWdn1sn0YdS)N)rrNr\rU)rzrr#rr$r rrrr%test_object_reduce_cleanup_on_failure s 2 rrcCstj|dgSrV)rr$rrrrrrb rrbrrcCstj|dgS)Nr)rlogrhrrrrrb rrhc Csttjdtj g}tjddFtjtdd||Wdn1sP0YWdn1sn0Yttjdtj g}tjddBtt||Wdn1s0YWdn1s0YdS)Nrwarnrkz invalid valuerrj) rrVr(rnrzrrJrr)rrYrrrtest_ufunc_methods_floaterrors sD rcCs8|dkr dSt|jsdS|jjdkr4t|jSdS)NrFrT)rsignbitrRr-kindrS)rvrrr_check_neg_zero* s   rr-ZAllFloatcCslt|}|jdkr&|tdd}n |d}t|}t|}t||sTJ||7}t|shJdS)Nr)rr-rrprWrVr)r-neg_zerorYrlrrrtest_addition_negative_zero3 s     r use_initialTFcCst|}|jdkr&|tdd}n |d}i}|rB||d<n tdtddD]d}tj|g||d}tj |fi|}|dks|rt |sJqVt |j rJt |j rVJqVdS)NrrrVz1-0. propagation in sum currently requires initialrr6)rr-rrprWrzrrrVr4rrrRrS)r-rrrrrYrZrrr"test_addition_reduce_negative_zeroD s      r!dt1dt2))rr)rr)rr)rV)rlcCs`tjdg|d}tjdg|d}ttjjj}t||Wdn1sR0YdS)Ni:r6s423)rrVrzrr^rZUFuncTypeErrorr$)r"r#rkrlrsrrrtest_addition_string_types` sr&z order1,order2))>r')JdS)Nsabcdsebcdscderr) rrVr^r_r,Ziinforr$rJ)rYrurrrtest_find_access_past_buffer~ sr0c @seZdZddZddZddZddZd d Zej d e d e d fd e d e dfe d d e dfdgddZ ddZej jeed ddddZej dgdddZddZdd Zd S)!TestLowlevelAPIAccesscCstd}td}td}tj||df}||||fksBJtjj||dfdd}||||fksjJtj|tdf}||||fksJtt&tjj||dfddWdn1s0YdS)Nrf4r)NNr2rrr)rr-r$resolve_dtypesr%rzrr#)r'rr2rrrrrtest_resolve_dtypes_basic s    z/TestLowlevelAPIAccess.test_resolve_dtypes_basiccCsFtd}td}td}tj||df}||||fksBJdS)NrrEr)rr-rr3)r'rrErrrrrtest_resolve_dtypes_comparison s    z4TestLowlevelAPIAccess.test_resolve_dtypes_comparisoncCs~td}tj||df}|||ttfks4Jtd}tt"tj||dfWdn1sp0YdS)NS0Z10i)rr-rr3rCrzrr#)r'r6rdtsrrrtest_weird_dtypes s    z'TestLowlevelAPIAccess.test_weird_dtypescCsBtd}ttj}tjjd|dfdd}||||fks>JdS)Ni2TZ reduction)rr-rr$r3)r'r9Z default_int_rZrrrtest_resolve_dtypes_reduction s  z3TestLowlevelAPIAccess.test_resolve_dtypes_reductioncCsNtd}tt&tjj|||fddWdn1s@0YdS)NrTr:)rr-rzrr#r$r3)r'rrrr'test_resolve_dtypes_reduction_no_output s  z=TestLowlevelAPIAccess.test_resolve_dtypes_reduction_no_outputdtypesrNr:)rrNcCs:tttj|Wdn1s,0YdSr>)rzrr#rr$r3)r'r=rrrtest_resolve_dtypes_errors s z0TestLowlevelAPIAccess.test_resolve_dtypes_errorscCstd}tt"tjd||fWdn1s<0YtttjdWdn1sr0YdS)Nr9)NNr)rr-rzrr#r$r3r*)r'r9rrr$test_resolve_dtypes_reduction_errors s   0 z:TestLowlevelAPIAccess.test_resolve_dtypes_reduction_errors pythonapiz2`ctypes.pythonapi` required for capsule unpacking.rc s(tjd}tjd}tjd}ttjtj|||tjGfdddtj}td}tj ||f\}}|||fks|Jtj |tjtj j _tj t|td}t|t|j}tjd|d} ||j|| jj| jj| jj|| jjd | jjd |jt| tjd|d dS) Nrrcs6eZdZdfdejfdejfdejfdejfgZdS)z;TestLowlevelAPIAccess.test_loop_access..call_info_t strided_loopcontextauxdataZrequires_pyapiZno_floatingpoint_errorsN)r0r1r2ctc_void_pZc_byteZ_fields_rZstrided_loop_trr call_info_t s rGrsnumpy_1.24_ufunc_call_infor5r6r)rDc_char_pZ c_ssize_tZ CFUNCTYPEZc_intrEZ Structurerr-r_resolve_dtypes_and_context_get_strided_loopr@ZPyCapsule_GetPointerrestypeZ py_objectcastZPOINTERcontentsrrArBctypesdatarrrCr) r'Zdata_tZdim_tZ strides_trGrrZ call_info_obj call_inforYrrFrtest_loop_access s4      z&TestLowlevelAPIAccess.test_loop_accessr)rro)rrxcCs`td}tj||f\}}tjtdd tjj||dWdn1sR0YdS)Nrzfixed_strides.*tuple.*or Noner)Z fixed_strides)rr-rrIrzrr#rJ)r'rrrrPrrr)test__get_strided_loop_errors_bad_strides s z?TestLowlevelAPIAccess.test__get_strided_loop_errors_bad_stridescCstd}tj||f\}}tjtddtjdWdn1sN0Ytjtddtj |Wdn1s0Ytj|tttj|Wdn1s0YdS)NrZ PyCapsulerznot the capsule!z.*incompatible context) rr-rrIrzrrrJr#r$)r'rrrPrrr+test__get_strided_loop_errors_bad_call_info s **  zATestLowlevelAPIAccess.test__get_strided_loop_errors_bad_call_infocCsPtjdtjd}d|dd<d|dd<t|}t|dd|dddS)N)iir6rri)rrrvrr)r'r>r-rrrtest_long_arrays s    z&TestLowlevelAPIAccess.test_long_arrays)r0r1r2r4r5r8r;r<rzr{r|rr-r>r?rhasattrrDrQrRrSrUrrrrr1 s*    * r1)XrGr rrNrDrrzrnumpyrZnumpy._core.umathr^r_rZnumpy._core._umath_testsZ _umath_testsrZnumpy.linalg._umath_linalgrrrZnumpy._core._operand_flag_testsZ_operand_flag_testsrLZnumpy._core._rational_testsrZnumpy.exceptionsrZ numpy.testingrrrrrr r r r r rrZnumpy.testing._private.utilsr__dict__r|Z UNARY_UFUNCSr~remover]rr3rrr{r|dirrZ_no_nep50_warningrsignrrrr r%rrrrrrr$rr rrrnrr!r&r+rrrrr/r0r1rrrrs  8 1  %