o 6a@sddlZddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z ddl m Z ddlZddlmZmZmZmZmZmZmZmZmZmZejejejejejej ej!ej"ej#ej$ej%ej&ej'ej(ej)ej*ej+gZ,ej-.Z/ej0.Z1GdddZ2GdddZ3Gd d d Z4d d Z5d dZ6GdddZ7GdddZ8GdddZ9GdddZ:esGdddZ;GdddZGdd d Z?Gd!d"d"Z@Gd#d$d$ZAejBd%d&ZCeDdgZEejFejGejHejIejJejKejLejMejNejOejPejQejRejSgZTee eEe eTe e,e e jUd'd(d)ZVee eEe eTe e,d*d+ZWee eTe e,e e,d,d-ZXejYZd.eTd/d0Z[ejYZd.eTd1d2Z\dS)3N)givensettings Verbosityassume) sampled_from) assert_ assert_equal assert_raisesassert_almost_equalassert_array_equalIS_PYPYsuppress_warnings_gen_alignment_data assert_warnsassert_raises_regexc@s,eZdZddZddZddZddZd S) TestTypescCs,tD]}|d}t|dkd||fqdS)Nerror with %r: got %r)typesr)selfatypearB/usr/lib/python3/dist-packages/numpy/core/tests/test_scalarmath.py test_typesszTestTypes.test_typesc CsttD]C\}}|d}tjdg|d}ttD].\}}|d}tjdg|d}||} ||} t| j| jd|t|j|t|jfqqdS)Ndtyperz$error with types (%d/'%c' + %d/'%c')) enumeraternparrayrrchar) rkra_scalara_arraylbtypeb_scalarb_arrayc_scalarc_arrayrrr test_type_add#s zTestTypes.test_type_addcCs<ttD]\}}tgd|}|gd}t||qdS)Nrr)rrrr r)rr"rrbrrrtest_type_create7s   zTestTypes.test_type_createcCstdD]}tddqdS)Ni@ r)rangeradd)rirrr test_leak=s zTestTypes.test_leakN)__name__ __module__ __qualname__rr+r/r3rrrrrs  rc@eZdZddZddZdS) TestBaseMathc CstjdftjdftjdffD]\}}t|d|dD]\}}}}t|}t||d<t||d<tt||||dtt|d|d|dttd|||dtj|||d t|||d|dtj |j |d d7<tt |t |||d|tjkrtt |td||dt||d<tj|d|d t||d|dt||d<tjd||d t||d|dqqdS) N binary)rtypemax_size.err_msgr-routr)rfloat32float64int32r ones_like zeros_liker r1arangesizesquaremultiply reciprocaldivide)rdtszrAinp1inp2msgexp1rrr test_blockedEs:$       zTestBaseMath.test_blockedcCstjdtjdddtj}tjdtjdddtj}t|||dtj|||dtjt|||dtj|t||dtt||t|t|dS)Nrr-r@)rzerosint8viewrCr r1rE)rdorrrtest_lower_alignes  zTestBaseMath.test_lower_alignN)r4r5r6rSr\rrrrr8D r8c@4eZdZddZddZddZddZd d Zd S) TestPowercCs@tjtjtjfD]}|d}|d}t|dkd||fqdS)NrrUQr)rrXint16float16rrtrr.rrrtest_small_typesss zTestPower.test_small_typescCsjtjtjtjtjtjfD]&}|d}|d}d||f}t|tjr+t|dk|q t |d|dq dS)N3rUri:gr>) rrDint64rBrC longdouble issubdtypeintegerrr )rrdrr.rQrrrtest_large_typesys zTestPower.test_large_typescCsPdddD}dddD}t||D]'\}}|jtjkr'tttj||qt||}t |jj tj ut |dqdddD}t||D]'\}}|jtjkr\tttj||qIt||}t |jj tj ut |dqId ddD}t||D]'\}}|jtjkrtttj||q~t||}t |jj tj ut |d q~dS) NcSg|] }td|dqSrrr .0rMrrr zETestPower.test_integers_to_negative_integer_power..bhilqcSrl)rrrorprrrrrrs bhilqBHILQ?cSrlrmrorprrrrrrscSrl)r-rrorprrrrrrsg?) itertoolsproductrruint64r ValueErroroperatorpowrr<rCr )rexpbasei1i2resrrr'test_integers_to_negative_integer_powers.         z1TestPower.test_integers_to_negative_integer_powerc Cstjtjtjtjtjtjtjtjtjg }|D]4}|D]/}|d}|d}||}d|||df}tt |tj rBt |dk|qt |d|dqqdS)Nrr-z(error with %r and %r:got %r, expected %r r>) rrXrarbrBrCrDrgrirrjrr )rtypelistt1t2rr.resultrQrrrtest_mixed_typess"    zTestPower.test_mixed_typescCsdd}d}d}t|||}tjtjtjfD]}tttj||||tttjt||||qdS)NrU ) r}rrDrB complex64r TypeErrorr|r )rrr.cexpectedrdrrrtest_modular_powers zTestPower.test_modular_powerN)r4r5r6rerkrrrrrrrr_rs  $ r_cCs||||fSNr)xyrrrfloordiv_and_modsrcCs|tjdvr dSdS)NUnsignedInteger)rrrn)r typecodes)rMrrr_signssrc@r^) TestModulusc Cstjdtjd}ttfD]s}t||D]j\}}tt|t|D][\}}d}||j||||f}tj|d|dd} tj|d|dd} || | \} } t | | | | |d|d krpt | | kojd kn|q$t | | kozd kn|q$qqdS) N AllIntegerFloat*op: %s, dt1: %s, dt2: %s, sg1: %s, sg2: %sGrrr>rnr) rrrdivmodrxryrr4r rr rrMopdt1dt2sg1sg2fmtrQrr.divremrrrtest_modulus_basics    zTestModulus.test_modulus_basiccs8ttdd}ttdd}|dg|}||}tt||}tdd|D}tj|tdj\}}tj|tdj\} } t | dk|dk|dkA@d | } t | dk|dk@d | } t t fD]9tj d D]1} d j | f} || } || }tfd d t| |D\}}t|| | dt|| | dqgq`dS)Nirrcss|]}t|VqdSr)r)rqrdrrr sz7TestModulus.test_float_modulus_exact..rrzop: %s, dtype: %scsg|] \}}||qSrr)rqa_b_rrrrrsz8TestModulus.test_float_modulus_exact..r>)listr0rxryrr intTfloatwhererrrr4astypezipr)rnlstplstdividenddivisorargtgtrr.tgtdivtgtremrMrQfafbrrrrrtest_float_modulus_exacts("    z$TestModulus.test_float_modulus_exactc Cstjd}ttfD]q}t||D]h\}}tddD]]\}}d}||j||||f}tj|dd|dd} tj|d|dd} || | \} } t| | | | |d|d krit | | kocd kn|qt | | kosd kn|qqq dS) NrrrNg+i)+p>rrr>rnr) rrrrrxryr4r rrrrrrtest_float_modulus_roundoffs    z'TestModulus.test_float_modulus_roundoffc CstjdD]6}tjd|d}ttjd|d| }t||}t||kd|t| | }t|| kd|qt}|t d|t d|t d|t d |t d tjdD]l}tjd|d}tjd|d}tjtj |d}tjtj |d} t||}tt |d|t|| }tt |d|t||}tt |d|t tfD]} | ||\} } tt| ott | qqcWddS1swYdS) Nrrvrrzdt: %sz&invalid value encountered in remainderz'divide by zero encountered in remainderz*divide by zero encountered in floor_dividez$divide by zero encountered in divmodz#invalid value encountered in divmod)rrr nextafterr|modrr filterRuntimeWarninginfnanisnanrrisinf) rrMr.rrsupfonefzerfinffnanrrrrrrtest_float_modulus_corner_cases s>          "z+TestModulus.test_float_modulus_corner_casescCs`tddgtj}tddgtj}d}tt| ||}WddS1s)wYdS)Nrr-z1could not be coerced to provided output parameter)rr rgrzrr)rrr.patternrrrtest_inplace_floordiv_handling0s   "z*TestModulus.test_inplace_floordiv_handlingN)r4r5r6rrrrrrrrrrs  #rc@s$eZdZddZddZddZdS)TestComplexDivisioncCstjddxtjtjfD]h}|d}|d}tt|||ttjtj}tt|||ttjtj}tt|||ttjtj}tt|||ttjtj}tt |||d}tt ||q WddS1swYdS)Nignoreallrrv) rerrstater complex128rrcomplexrrrrcrrrtest_zero_division<s""z&TestComplexDivision.test_zero_divisionc CstjddKtjtjfD];}d}|D]4}|d}|d}|d}|t|d|d|t|d|d}t|j|dt|j|dqq WddS1sTwYdS)Nrr))rrwrrvrwrrrrvr)rrrwrvr)rrrvrwr)rrrr)rrr)rrrrrr-)rrrrrrrealimagrrddatacasesnrZexrrrrtest_signed_zerosMs ,"z%TestComplexDivision.test_signed_zerosc CstjddVtjtjfD]F}t}|d|d|D]4}|d}|d}|d}|t|d|d|t|d|d}t|j|dt|j |dqq WddS1s_wYdS)Nrr)@rvrr)rvrrrrrr-) rrrrrappendrrrrrrrr test_branchesfs  ,"z!TestComplexDivision.test_branchesN)r4r5r6rrrrrrrr;s rc@seZdZddZddZddZddZejj e d d d d Z ejj e e je e jkd d ejj eddd ddZddZddZddZdS)TestConversioncCs~gd}gd}dtjtjfD]}tj||d}tdd|D|qtj|ddtjd}tdd|D|dddS)N)g.AgmBgNgmCg.gmgNgm)i@BlJ)lNZoilJ)lNZorcSg|]}t|qSrrrq_mrrrrrz5TestConversion.test_int_from_long..rcSrrrrrrrrrr)rrCrgr rrz)rr%lirrrrrtest_int_from_longs z!TestConversion.test_int_from_longcCsdD]}tjt|jd|d}t|j}t||kqtjdD]}tjt|j|d}t|j}t||kq#tjdD]}t|t|j}t|j}t||kqBdS)NbBhHrrr) rr iinfomaxminrrrr<)rcoderrrrrtest_iinfo_long_valuess   z%TestConversion.test_iinfo_long_valuescCs2dd}tjtjtjtjfD]}tt||qdS)NcSs|t|jddSNr)rrrrrrroverflow_error_funcszDTestConversion.test_int_raise_behaviour..overflow_error_func)rint_uintlonglong ulonglongr OverflowError)rrrrrrtest_int_raise_behavioursz'TestConversion.test_int_raise_behaviourcCsxttj}ttt|t#}|tjt tj}ttt|t t |j dWddS1s5wYdSr) rrhrr rrr recordComplexWarning clongdoublerlenlogrrrrrr!test_int_from_infinite_longdouble     "z0TestConversion.test_int_from_infinite_longdoublezTest is PyPy only (gh-9972))reasoncCsxttj}tt|jt#}|tjt tj}tt|jt t |j dWddS1s5wYdSr) rrhrr r__int__r r r r rr r rrrr)test_int_from_infinite_longdouble___int__rz8TestConversion.test_int_from_infinite_longdouble___int__zlong double is same as doubleppczIBM double doublecCsPttjjd}dtd|}dd|}t|tjktt||dS)Nri r-) rfinfodoublemaxexprhrrrr)rr~huge_ldhuge_irrrtest_int_from_huge_longdoubles  z,TestConversion.test_int_from_huge_longdoublecCs4td}tt|dtd}tt|ddS)N?rg%i)rrhrr)rrrrrtest_int_from_longdoubles  z'TestConversion.test_int_from_longdoublecCstjdD]`}tdtjd|ddkd|ftdtjd|ddk d|ftjdD]5}ttjd|ddtjd|ddkd||fttjd|ddtjd|ddk d||fq/qdD]}td tjd|ddkd|ftd tjd|ddk d|ftd tjd|ddkd|fd D]N}ttjd|ddtjd |ddkd||fttjd|ddtjd |ddk d||fttjd|ddtjd |ddkd||fqqhd tjd D]}tdtjd |ddkd|ftdtjd |ddk d|ftd tjd |ddkd|fd tjd D]O}ttjd|ddtjd |ddkd||fttjd|ddtjd |ddk d||fttjd |ddtjd |ddkd||fq4qdS) Nrrrrrztype %s failedztype %s and %s failedBHILQPrnbhilqpbhlqpr)rrrr )rrrrrr&test_numpy_scalar_relational_operatorssT"$$ & "$"$ & $  "$"$ & $ z5TestConversion.test_numpy_scalar_relational_operatorscCstjddH}tddtttddk ttddk ttddk ttddkttddkttddkWdn1sQwYtt |dktt tdddS) NT)r alwaysrtestNaTr) warningscatch_warningsfilterwarnings FutureWarningrrrBstr_ datetime64r equal)rwrrrtest_scalar_comparison_to_nones z-TestConversion.test_scalar_comparison_to_noneN)r4r5r6rrrrpytestmarkskipifr rrrrrhplatformmachine startswithrrr r-rrrrrs"      )rc@r7)TestReprc Cst|}|j|j}|j}t|jd}dD]Y}tjdg|tjd}|dkr:|d}d|d} d| >||<n|dkrO|d}d|d} d| >||<ntd | |d} t | } |t | } | dkrl| d ksqt | | qdS) N) small denorm small normrrr6r:rr7hmmg0.++) rrnexpnmantritemsizer uint8r{rYreprevalr) rrdrlast_fraction_bit_idxlast_exponent_bit_idx storage_byteswhichconstrbytebytebitvalval_reprval2rrr_test_type_reprs,      zTestRepr._test_type_reprcCs tjtjfD]}||qdSr)rrBrCrI)rrdrrrtest_float_repr.s zTestRepr.test_float_reprN)r4r5r6rIrJrrrrr4s r4c@r7) TestSizeOfcCs*tD]}|d}tt||jkqdS)Nr)rrsys getsizeofnbytes)rr<rrrrtest_equal_nbytes9szTestSizeOf.test_equal_nbytescCst}tt|jddS)Nr)rrBr r __sizeof__)rrZrrr test_error>szTestSizeOf.test_errorN)r4r5r6rOrQrrrrrK7s rKc@r7) TestMultiplycCs$ttjd}dh}ttjd||}|dh8}ttfD]q}|gd}|D] }t|d}t|||t|t||t||q(|D]'}t|}tt t t j |||t|tt t t j ||t||qK|D]}t|}t tt j ||t tt j ||quqdS)Nr?AllVr,r-)setrrrtuplerr<rrrDeprecationWarningr|mulr r)raccepted_typesdeprecated_typesforbidden_typesseq_typeseq numpy_typer2rrrtest_seq_repeatDs6     zTestMultiply.test_seq_repeatcCsGddd}|tdttdfD]:}t|tdtddttd|tddt|tdtddttd|tddqdS)Nc@r7)zCTestMultiply.test_no_seq_repeat_basic_array_like..ArrayLikecSs ||_dSrarr)rrbrrr__init__is zLTestMultiply.test_no_seq_repeat_basic_array_like..ArrayLike.__init__cSs|jSrra)rrrr __array__kszMTestMultiply.test_no_seq_repeat_basic_array_like..ArrayLike.__array__N)r4r5r6rcrdrrrr ArrayLikehs rerg@)rones memoryviewr rBfullr)rrearr_likerrr#test_no_seq_repeat_basic_array_likeds z0TestMultiply.test_no_seq_repeat_basic_array_likeN)r4r5r6r`rjrrrrrRCr]rRc@r7) TestNegativecCs&tjdtjdd}tttj|dSNrr)rrfbool_r rr|negrrrrrtest_exceptionswszTestNegative.test_exceptionscCsztjdtjd}t&}|t|D]}tjd|dd}tt||dqWddS1s6wYdSNrAllFloatrrr) rrr rrrfrr|rnrrrrMrrrr test_result{s "zTestNegative.test_resultNr4r5r6rprtrrrrrkv rkc@r7) TestSubtractcCs(tjdtjdd}tttj||dSrl)rrfrmr rr|subrorrrrpszTestSubtract.test_exceptionscCsxtjdtjd}t%}|t|D]}tjd|dd}tt||dqWddS1s5wYdSrq) rrr rrrfrr|rxrsrrrrts "zTestSubtract.test_resultNrurrrrrwrvrwc@sHeZdZddZejdeeddZ ejdeeddZ dS) TestAbscCs|d}t||d|d}||}t|d|d}||}t|d|t|j}t|||j|t|j}t|||j|t|j}t|||j dS)Ngrrr)rrrrrtinyr)rabsfunc test_dtyperrrrr_test_abs_funcs  zTestAbs._test_abs_funcrcCs|t|dSr)r}absrrrrrtest_builtin_absszTestAbs.test_builtin_abscCs|tj|dSr)r}rr~rrrrtest_numpy_absszTestAbs.test_numpy_absN) r4r5r6r}r.r/ parametrizefloating_typescomplex_floating_typesrrrrrrrys  ryc@sFeZdZejdejdejjdej ej gddgdddZ d S) TestBitShifts type_coderrz>>z<<)idsc Cst|}|jd}dD]L}||dfD]C}||}||}|||} |dkr4|tjur4t| dnt| dtj|gd|d} tj|gd|d} || | } t| | qq dS) zA Shifts where the shift amount is the width of the type or wider r5)rrUrrn rN)rrr;r<r|rshiftrr ) rrrrMnbitsrFshiftval_scl shift_sclres_sclval_arr shift_arrres_arrrrrtest_shift_all_bitss         z!TestBitShifts.test_shift_all_bitsN) r4r5r6r.r/rrrr|rlshiftrrrrrrs rc@s`eZdZejdejdddZejdejdddZ ejdejdd d Z d S) TestHashrrcCs6t|j}tdD]}t|t||ksJq dS)Nr)rrr<r0hash)rrscalarr2rrrtest_integer_hashess  zTestHash.test_integer_hashesrrcCst|j}tjtjddfD].}||}|jjdkrt|}nt|}||ks)Jtt |t |t |t |kss 0  '.QmH! 3"