o
    1ήc(                 
   @   sn  d dl Z d dlZd dlZd dlZd dlZd dlm  mZ	 d dl
m  mZ d dlm  mZ d dlm  mZ d dlmZmZmZmZmZmZmZmZmZmZ d dlmZ d dl m!Z! dd ejj"j#$ D Z%dd e%D Z&G dd	 d	Z'G d
d dZ(dd Z)G dd dZ*ej+,ddd e-eD dd Z.ej+,ddd e-eD dd Z/ej+,dej0ej1gdd Z2ej+j3e dddd Z4dd Z5ej+j3e ddej+,dd ej6d  e7d!ej6 gd"d# Z8ej+,d$ej9j:ej9j;ej<d%d& d'd(ej<d)d& d*d(gd+d, Z=d-d. Z>ej+,d/ej?d0 d1d2 Z@ej+,d/ej?d0 ej+,d3d4d5gd6d7 ZAdS )8    N)
assert_assert_equalassert_raisesassert_array_equalassert_almost_equalassert_array_almost_equalassert_no_warningsassert_allcloseHAS_REFCOUNTsuppress_warnings)requires_memory)picklec                 C   s   g | ]
}t |tjr|qS  )
isinstancenpufunc).0objr   r   B/tmp/pip-target-vg8gfxp4/lib/python/numpy/core/tests/test_ufunc.py
<listcomp>   s    

r   c                 C   s   g | ]	}d |j v r|qS )zO->O)types)r   ufr   r   r   r      s    c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestUfuncKwargsc                 C   s   t ttjdddd t ttjddtd t ttjdddgd t ttjddd d t ttjddd	d
 t ttjddd	d t ttjdddd t ttjdddgd d S )N      safe)castingx)dtypex   )extobjx)outxii->i)sigx)
signaturexF)subokxT)wherexr   	TypeErrorr   addintselfr   r   r   test_kwarg_exact   s   z TestUfuncKwargs.test_kwarg_exactc                 C   s   t ttjddddd d S )Nr   r   r!   )sig	signaturer   r'   r   r(   r*   r   r   r   test_sig_signature%   s   
z"TestUfuncKwargs.test_sig_signaturec                 C   s0   t ttjdddtd t ttjdddtd d S )Nr   r   r!   )r-   dtype)r.   r1   r&   r*   r   r   r   test_sig_dtype)   s   
zTestUfuncKwargs.test_sig_dtypec                 C   s   t ttjdddgdd d S )Nr   r   r   T)extobjparrotr/   r*   r   r   r   test_extobj_refcount/   s   z$TestUfuncKwargs.test_extobj_refcountN)__name__
__module____qualname__r,   r0   r2   r5   r   r   r   r   r      s
    
r   c                	   @   s
  e Zd ZdZejejfejejfejejfejejfejejfej	ej	fejejfej
ej
fgZejdeejddfddZdd Zejdeeddfd	d
ZG dd dZdd ZefddZdd ZefddZefddZdd Zejdedd ZdS )TestUfuncGenericLoopsab  Test 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.

    zinput_dtype,output_dtyper   r   c                 C   s@   t jd|||d}||d d d }t|| t|j| d S N
   r1   r   r   fullr	   r   r1   r+   input_dtypeoutput_dtypefxyxsysr   r   r   test_unary_PyUFuncg   s   
z(TestUfuncGenericLoops.test_unary_PyUFuncc                 C   s   | | S Nr   )rC   rD   r   r   r   f2n   s   zTestUfuncGenericLoops.f2c                 C   sB   t jd|||d}|||d d d }t|| t|j| d S r:   r=   r?   r   r   r   test_binary_PyUFuncq   s   
z)TestUfuncGenericLoops.test_binary_PyUFuncc                   @   s   e Zd Zdd Zdd ZdS )zTestUfuncGenericLoops.fooc                 C   
   t dS Nr   r   bool_r*   r   r   r   	conjugatez      
z#TestUfuncGenericLoops.foo.conjugatec                 C   rK   rL   rM   r+   r   r   r   r   logical_xor}   rP   z%TestUfuncGenericLoops.foo.logical_xorN)r6   r7   r8   rO   rR   r   r   r   r   fooy   s    rS   c                 C   s*   t jdtd}tt t |dk d S )Nr;   r<   r   )r   onesobjectr   allabsr+   rC   r   r   r   test_unary_PyUFunc_O_O   s   z,TestUfuncGenericLoops.test_unary_PyUFunc_O_Oc                 C   s.   t jd| td}tt t |dk d S )Nr;   r<   T)r   r>   rU   r   rV   rO   r+   rS   rC   r   r   r   $test_unary_PyUFunc_O_O_method_simple   s   z:TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_simplec                 C   s,   t jdtd}tt t ||dk d S r:   )r   rT   rU   r   rV   r(   rX   r   r   r   test_binary_PyUFunc_OO_O   s   z.TestUfuncGenericLoops.test_binary_PyUFunc_OO_Oc                 C   ,   t jd| td}tt t || d S )Nr;   r<   r   r>   rU   r   rV   rR   rZ   r   r   r   test_binary_PyUFunc_OO_O_method      z5TestUfuncGenericLoops.test_binary_PyUFunc_OO_O_methodc                 C   r]   )N)r;   r      r<   r^   rZ   r   r   r    test_binary_PyUFunc_On_Om_method   r`   z6TestUfuncGenericLoops.test_binary_PyUFunc_On_Om_methodc                 C   s^   t jddgdd}t|d tsJ t |}|jt dks!J t|t jddgdd d S )Ny      ?       @y      @      Or<   r   y      ?       y      @      @)r   arrayr   complexrO   r1   r   r+   arrresr   r   r   test_python_complex_conjugate   s
   
z3TestUfuncGenericLoops.test_python_complex_conjugater   c                    s  t t jd  G  fdddt j}t j t jd}t j| dd}t jddP z||}W n, ty] } z tt| || W d   n1 sNw   Y  W Y d}~nd}~ww ||}t|	d| W d   dS W d   dS 1 s}w   Y  dS )	z9Compare the result of the object loop with non-object one   c                       s   e Zd Z fddZ  ZS )zITestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full.<locals>.MyFloatc                    s0   zt   W S  ty    fdd Y S w )Nc                      s   t tjj S rH   )getattrr   coreumathr   )attrvalr   r   <lambda>       zgTestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full.<locals>.MyFloat.__getattr__.<locals>.<lambda>)super__getattr__AttributeError)r+   rn   )	__class__ro   )rn   r   rs      s
   zUTestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full.<locals>.MyFloat.__getattr__)r6   r7   r8   rs   __classcell__r   ro   )ru   r   MyFloat   s    rx   r<   rc   raiserV   N)
r   float64pird   errstate	Exceptionr   typer   astype)r+   r   rx   num_arrobj_arrres_numexcres_objr   rw   r   "test_unary_PyUFunc_O_O_method_full   s$   
" z8TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_fullN)r6   r7   r8   __doc__r   singledoublecsinglecdouble
longdoubleclongdouble	np_dtypespytestmarkparametrizeexprG   rI   rJ   rS   rY   r[   r\   r_   rb   ri   UNARY_OBJECT_UFUNCSr   r   r   r   r   r9   4   s*    -r9   c                   C   s   d S rH   r   r   r   r   r   _pickleable_module_global      r   c                   @   sX  e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdZdZ	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zejd3g d4d5d6 Z d7d8 Z!d9d: Z"d;d< Z#d=d> Z$ejd?e%j&e%j'gd@dA Z(dBdC Z)dDdE Z*dFdG Z+dHdI Z,dJdK Z-dLdM Z.dNdO Z/dPdQ Z0dRdS Z1ejjdTdUgdge%2dVfdWdge%2dWfe%3dXe%2dYfgg dZd[d\d] Z4d^d_ Z5d`da Z6dbdc Z7ddde Z8dfdg Z9dhdi Z:djdk Z;dldm Z<dndo Z=dpdq Z>drds Z?dtdu Z@dvdw ZAdxdy ZBdzd{ ZCd|d} ZDd~d ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTeUddd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\ejddejde%]g de%]dgdgdgge%]g dg dg dgfdd Z^ejdde%]g dfdWg dfdfejde%j_ dfdd Z`dd ZaddÄ Zbddń ZcddǄ ZdddɄ Zedd˄ Zfdd̈́ Zgddτ Zhddф Ziddӄ ZjddՄ Zkddׄ Zlddل Zmddۄ Zndd݄ Zodd߄ Zpejd?e%jqe%jrgejdddesfesddfdesdfgdd Ztejd?e%jqe%jre%jugejdevdesfesdevfdesevfgdd Zwejd?e%jqe%jre%jugdd Zxejd?e%jqe%jre%jugdd Zyejd?e%jqe%jre%jugdd Zzdd Z{dd Z|dd Z}dd Z~ejdddgdd Zejdg dejdddgejde%j&je%jjgdd Zdd Zdd  Zdd Zdd Zejde%de%dgdd Zejde%de%dgdd	 Zejde%de%dgd
d ZdS (  	TestUfuncc                 C   s^   t dtjd D ]$}tttjtj|dtju  ttjtj	|d}t|tj	u  qd S )Nr   r   )protocol)
ranger   HIGHEST_PROTOCOLr   loadsdumpsr   sin_rational_teststest_add)r+   protorh   r   r   r   test_pickle   s   zTestUfunc.test_picklec                 C   s   d}t t|tju  d S )NsM   cnumpy.core
_ufunc_reconstruct
p0
(S'numpy.core.umath'
p1
S'cos'
p2
tp3
Rp4
.)r   r   r   r   cos)r+   astringr   r   r   test_pickle_withstring   s   z TestUfunc.test_pickle_withstringc                 C   s,   t jt_tttj}|t ju sJ d S rH   )umt_pickleable_module_global_ufuncr   r   r   r   r   rQ   r   r   r   test_pickle_name_is_qualname   s   z&TestUfunc.test_pickle_name_is_qualnamec              	   C   sd   d}t |}t ttt |d t |d d  }tt j||d d d g d d S )N   r   )r   ra         )	r   arangerd   listzipravelr   r(   reduceat)r+   LrC   idxr   r   r   test_reduceat_shifting_sum   s   
0&z$TestUfunc.test_reduceat_shifting_sumc                 C      dS )aL  Try 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

        Nr   r*   r   r   r   test_all_ufunc   s   QzTestUfunc.test_all_ufuncr   rj   c                 C   sR   t ddd\}}}}}t|d t|d t|d t|| jf t|d d S )Nr   r   (i),(i)->())r   r   r   r   r   r   test_signaturer   size_inferredr+   enablednum_dimsixsflagssizesr   r   r   test_signature01  s   


zTestUfunc.test_signature0c                 C   sN   t ddd\}}}}}t|d t|d t|d t|d t|d d S )Nr   r   z	(),()->()r   r   r   r   r   r   r   r   r   r   r   r   test_signature1;  s   



zTestUfunc.test_signature1c                 C   V   t ddd\}}}}}t|d t|d t|d t|| jfd  t|d d S )Nr   r   z(i1,i2),(J_1)->(_kAB)r   r   r   )r   r   r   ra   rj   r   r   r   r   r   r   r   r   r   test_signature2E     


zTestUfunc.test_signature2c                 C   r   )Nr   r   z(i1, i12),   (J_1)->(i12, i2)r   r   r   )r   r   r   r   ra   rj   r   r   r   r   r   r   test_signature3O     


zTestUfunc.test_signature3c                 C   r   )Nr   r   z(n,k),(k,m)->(n,m)r   r   r   r   r   r   r   r   r   ra   r   r   r   r   r   r   r   r   test_signature4X  r   zTestUfunc.test_signature4c                 C   sf   t ddd\}}}}}t|d t|d t|d t|| j| jB | j| j| jB f t|d d S )Nr   r   z(n?,k),(k,m?)->(n?,m?)r   r   r   )r   r   r   r   
can_ignorer   r   r   r   test_signature5b  s   



zTestUfunc.test_signature5c                 C   N   t ddd\}}}}}t|d t|d t|d t|d t|d d S )Nr   z(3)->()r   r   r   ra   r   r   r   r   r   test_signature6n     



zTestUfunc.test_signature6c                 C   sV   t ddd\}}}}}t|d t|d t|d t|d| jdf t|d d S )Nra   r   z(3),(03,3),(n)->(9)r   r   r   r   r   r   r   r   r   r   ra   r   	   r   r   r   r   r   test_signature7w  r   zTestUfunc.test_signature7c                 C   X   t ddd\}}}}}t|d t|d t|d t|| j| jdf t|d d S )Nra   r   z(3?),(3?,3?),(n)->(9)r   r   r   r   r   r   r   r   r   r   r   r   r   test_signature8     


zTestUfunc.test_signature8c                 C   r   )Nr   z(  3)  -> ( )r   r   r   r   r   r   r   r   test_signature9  r   zTestUfunc.test_signature9c                 C   r   )Nra   r   z ( 3? ) , (3? ,  3?) ,(n )-> ( 9)r   r   r   r   r   r   r   r   r   test_signature10  r   zTestUfunc.test_signature10c                 C   <   t t tddd W d    d S 1 sw   Y  d S )Nr   r   z((i)),(i)->()r   
ValueErrorr   r   r*   r   r   r   (test_signature_failure_extra_parenthesis     
"z2TestUfunc.test_signature_failure_extra_parenthesisc                 C   r   )Nr   r   z(i),)i(->()r   r*   r   r   r   .test_signature_failure_mismatching_parenthesis  r   z8TestUfunc.test_signature_failure_mismatching_parenthesisc                 C   r   )Nr   r   z(i),->()r   r*   r   r   r   2test_signature_failure_signature_missing_input_arg  r   z<TestUfunc.test_signature_failure_signature_missing_input_argc                 C   s<   t t tddd W d    d S 1 sw   Y  d S )Nr   r   r   r*   r   r   r   3test_signature_failure_signature_missing_output_arg  r   z=TestUfunc.test_signature_failure_signature_missing_output_argc                 C   s   t tjjd d S )Nr   )r   r   inner1dr.   r*   r   r   r   test_get_signature     zTestUfunc.test_get_signaturec                 C   s(  dt jddd }tt |dg d tt tt j|ddddg d	 W d    n1 s2w   Y  tt j|dd
ddg d	 tt tt j|ddddg d	 W d    n1 scw   Y  tt j|ddddg d	 t jddd}t j|d|d t|g d d|d d < tt t j|dd|dd W d    n1 sw   Y  t|g d	 d|d d < t j|dd
|dd t|g d	 d|d d < tt t j|dd|dd W d    n1 sw   Y  t|g d	 d|d d < t j|dd|dd t|g d	 d S )N      ?ra   f8r<   )r   r         ?iunsafe)r-   castingr   r   r   r!   )i4)r   r   r   r   outr   )r-   r   r   )r   r   r   r(   r   warnsDeprecationWarningzerosr+   abr   r   r   test_forced_sig  sF   zTestUfunc.test_forced_sigc                 C   s   t jdgdgdd}t dgdg}t|| t jdgdgdd}t dgdg}t|| tt t jdddd W d    d S 1 sGw   Y  d S )Nra   rj   )NNNr-   rH   r.   )r   r(   r   maximumr   raisesr'   )r+   res1res2r   r   r   test_signature_all_None  s   

"z!TestUfunc.test_signature_all_Nonec                 C   s*   t ttj}tjdd||d fd d S )Nra   rj   r  )r   r   r1   r{   r(   )r+   float_dtyper   r   r   test_signature_dtype_type  s   z#TestUfunc.test_signature_dtype_typer   )r   	same_kindr   c                 C   s   t jt dt ddd}|jdksJ t jt dt ddd}|jdks*J tt t jdt ddd W d    n1 sEw   Y  tt t jdt ddd W d    d S 1 sfw   Y  d S )N      ?r   dr<   )NNr  r  ra   )	r   ldexpfloat32int_r1   r   r  r'   uint64)r+   r   rh   r   r   r   test_partial_signature_mismatch  s   "z)TestUfunc.test_partial_signature_mismatchc                 C   s   t t tjtdtddd W d    n1 sw   Y  ttdtd t t tjtdtddd W d    d S 1 sNw   Y  d S )Nr   r   )er  Nr   )r   r  r'   r   r(   float16r  r{   r*   r   r   r   *test_partial_signature_mismatch_with_cache  s   "z4TestUfunc.test_partial_signature_mismatch_with_cachec                 C   s   t jddt jdd}|dksJ t jddd d t jfdd}|dks#J tt t jddt jd W d    d S 1 s=w   Y  d S )Nr   gffffff@r   r1   r   r   )r.   r   r<   )r   powerintpr   r  r'   r+   rh   r   r   r   +test_use_output_signature_for_all_arguments  s   "z5TestUfunc.test_use_output_signature_for_all_argumentsc                 C   sf  t jtdd tjdddd W d    n1 sw   Y  t t tjdddd W d    n1 s7w   Y  t t tjdddd W d    n1 sTw   Y  t t tjddd	d W d    n1 sqw   Y  t t tjddd
d W d    n1 sw   Y  t t tjdddd W d    d S 1 sw   Y  d S )Nz1the signature object to ufunc must be a string ormatchra   rj   g     ^@r  z%^->#s   ii-izii>i)Nr   s   ->i)r   r  r'   r   r(   r   UnicodeDecodeErrorr*   r   r   r   test_signature_errors  s(   "zTestUfunc.test_signature_errorsc                 C   sd   t jg ddd}t j||dd t jj|dd t jddd}t j||dd t j||dd d S )N)z
2010-01-02z
1999-03-14z1833-03z>M8[D]r<   Mr;   zm8[s]m)r   rd   r  reducer   r(   )r+   r   rg   r   r   r   test_forced_dtype_times  s   z!TestUfunc.test_forced_dtype_timesr   c                    s   fdd}t jg dt jd}||j }||}||dd}t|| tt	 ||dd W d   n1 s=w   Y  ||dd}t|| tt	 ||t j
dd	 W d   n1 sew   Y  ||t j
d
d	}||t j
}t|| dS )zBasic test for the safest casts, because ufuncs inner loops can
        indicate a cast-safety as well (which is normally always "no").
        c                    s    | f j  i |S rH   )nin)rg   kwargsr   r   r   
call_ufunc*  s   z.TestUfunc.test_cast_safety.<locals>.call_ufunc)r
         @      @r<   no)r   Nequivr  r   )r   rd   r  r   r1   newbyteorderr   r   r  r'   r{   )r+   r   r$  rg   arr_bsexpectedrh   r   r#  r   test_cast_safety%  s"   

zTestUfunc.test_cast_safetyc                 C   sx  t d}t d}t d}dD ]v}t |}||}||}t|| g|| gD ]W\}}	|dv rAt|t|	 }nt|t|	 }t ||	}
t	t 
|
jd}t|
||d |dv rlt|
jjd	k n	t|
jj|jk dD ]}t |}ttt j||	|d
 qwdD ]}t |}|dv rttt j||	|d
 qt|t|	 }t	t 
|jd}t "}|t t t 
|jst	t 
|jd}nd}W d    n1 sw   Y  t jdd t j||	|d
}
W d    n1 sw   Y  t |
s	|dkr	qt|
|||d t|
jj|jk qdD ]i}t |}t|t|	 }t	t 
|jd}t #}|t t t 
|jsRt	t 
|jd}nd}W d    n	1 s_w   Y  t j||	|d
}
t |
stqt|
|||d t|
jj|jk qq/qt jdt jd
}t ||}
t|
dk t|
jjd	k t | |}
t|
dk t|
jjd	k d S )Nr;      r   bhilqBHILQefdgFDGFDGgV瞯<)rtol
bhilqBHILQr{   r<   efdggwMh ignoreinvalidr  )r0  atolr   r
          )r   rd   r1   r   	itertoolsproductre   floattrue_dividemaxfinfo
resolutionr	   r   namer   r'   r   filterUserWarningisnantinyr}   isfiniterT   rN   )r+   r   r   tgttcdtaabbrC   rD   rh   r0  tcoutdtoutsupr6  r   r   r   test_true_divideD  s   






"




CzTestUfunc.test_true_dividec                 C   s`   t jdt jd}t|d  |jd  dd t jdt jd}t|d  |jd  dd d S )N  r<         $@r   rj      )r   rT   r  r   sumsizer{   r+   r   r   r   r   test_sum_stability  s   "zTestUfunc.test_sum_stabilityc              
   C   s  t tjtjtjtjfD ]}dD ]^}|||d  d }tjd|d |d}t| }tj	dd4}t
d tt|| tt|d|  tt|d d d | tt|d|  W d    n1 shw   Y  qtjd	|d}tt|d d d d
 tt|dd d d
 tt|d d d d tt|dd d d tt|d d d d
 tt|dd d d
 tt|d d d d tt|dd d d tjd|d}||7 }t|d qd S )Nr   r   r   r      r                     i  r   r   r<   Trecordalwaysr   rN  g     @o@ra   g     d@r   r%  )r)   r   r  r  r{   r   r   rD  warningscatch_warningssimplefilterr   rQ  r   lenrT   )r+   rG  vrE  r  overflowwr   r   r   test_sum  s4   
zTestUfunc.test_sumc              	   C   s  t jt jt jfD ]}dD ]G}|||d  d |||d  d d  }t j||d}t d|d |_t d|d  |_tt 	|| tt 	|d d d | qt j
d|dd }tt 	|d d d d tt 	|dd d d tt 	|d d d	 d
 tt 	|dd d	 d
 tt 	|d d d d tt 	|dd d d tt 	|d d d d
 tt 	|dd d d
 t j
d|dd }||7 }t|d qd S )NrU  r   r   y              ?r<   r   rN  y     @o@     @o@ra   y     d@     d@r`  ra  rb  y       @       @)r   	complex64
complex128r   emptyr   realimagr   rQ  rT   )r+   rG  rg  rE  r  r   r   r   test_sum_complex  s*   ,zTestUfunc.test_sum_complexc                 C   sV   t tjdgddd ttjdgddd t tjtjdtjd	d
ddg d d S )Nra   r   initialr   g?皙?333333?)r   ra   r   r<   r   r   )axisrr  )   rw  rw  )r   r   rQ  r   rT   int64r*   r   r   r   test_sum_initial  s
   zTestUfunc.test_sum_initialc                 C   sT   t tjddgddggddgdd t tjddgddggdd	ddgd
dd	g d S )Nr
  r%  r&        @TFwherer         @)rv  rr  r|        "@)r   r   rQ  r*   r   r   r   test_sum_where  s   $zTestUfunc.test_sum_wherec                 C   sZ   t dd}tt||t j|| dd t d}tt||t ||  d S )Nr   r   ra   r   rv  )r   r   reshaper   r   r   rQ  rS  r   r   r   test_inner1d  s    
 zTestUfunc.test_inner1dc                 C   s  d}t dd}t dd}tt||t j|| dd|d d}t dd	}tt||t j|| dd|d t d
d}t dd}tttj|| t d
d}t 	d}tttj|| t dd}t dd}tttj|| t d}t dd	}t 
||\}}t|jd d || }tjdd"}td ||7 }tt|d t|d |d k W d    n1 sw   Y  t ddd}t d}t d}tttj||| t d}	t|||	}
t|
|	u  d S )N	broadcastrj   r   r   r   r   r   r  err_msgz"extend & broadcast loop dimensionsr   r   rV  )rj   r   rj   r   r   r   r   ra   )ra   r   r   r   Tr]  r_  r   r   r   r   )r   r   r  r   r   r   rQ  r   r   rd   broadcast_arraysr   stridesrc  rd  re  rf  r   rT   rm  )r+   msgr   r   urg  rC   ri  r   out2cr   r   r   test_broadcast  sD   $$





zTestUfunc.test_broadcastc                 C   sj   t ddd}t d}t j|||d |t dd k s#J tj|||d |dk s3J d S )Nra   r   )r   rj   ra   r   r   r   )r   r   r  rm  r(   rV   r   r   r+   rg   r   r   r   r   test_out_broadcasts  s   
zTestUfunc.test_out_broadcastsrg   r   r   r   rj   ra   r  )z(1,)->()z
(2,)->(1,)z(4, 3)->(4, 1))idsc                 C   s   t jtdd tj||d W d    n1 sw   Y  t jtdd tjtd||d W d    d S 1 s<w   Y  d S )Nznon-broadcastabler  r   r   )r   r  r   r   positiver(   rT   r  r   r   r   test_out_broadcast_errors+  s   "z#TestUfunc.test_out_broadcast_errorsc                 C   s   d}t jdddd}tt||t j|| dd|d d	}t dd}|d
 }tt||t j|| dd|d d S )Nz	type castr   shortr<   r  r   r  r  ztype cast on one argumentrs  )r   r   r  r   r   r   rQ  r   )r+   r  r   r   r   r   r   test_type_cast9  s   
zTestUfunc.test_type_castc                 C   sP  d}t jdddd}tt||t j|| dd|d d	}t jdd
dd}tt||t j|| dd|d t jddd}t jddd}t|| jt d t|| jt d t|| jt d t|| jt d tt 	|jt d tt 	|jt d tt 
|jt d tt 
|jt d d S )Nz
big endianr   z>i4r<   r  r   r  r  zlittle endianz<i4r   z>f8z<f8r   )r   r   r  r   r   r   rQ  r   r1   absolutenegative)r+   r  r   BaLar   r   r   test_endianD  s(   zTestUfunc.test_endianc                 C   s   d}t dd}|d d dd d dd d df }|d d dd d dd d df }d|d< d}t|d	 d|d
 tt||t j|| dd|d
 t dddd}|j}|j}d|d< t|d d|d
 tt||t j|| dd|d
 d S )Nz#incontiguous memory layout of array@   )r   r   r   r   r   r   r   r   r   r   z-make sure it references to the original array)r   r   r   r   r   r   r  r     r   ra   rj   )	r   r   r  r   r   r   r   rQ  T)r+   r  rC   r   r   msg2r   r   r   test_incontiguous_array[  s     $(z!TestUfunc.test_incontiguous_arrayc                 C   s  d}t dd}t ddd }t jddd	}t||| t|t j|| d
d|d d
|d d < tj|||d t|t j|| d
d|d d}t jddd	}t||| t|t j|| d
d|d d
|d d < tj|||d t|t j|| d
d|d d}t jddd	}t|||d  t|d t j|| d
d|d d
|d d < tj|||d d t|d t j|| d
d|d d S )Nzoutput argumentrw  r   ra   r   rj   r   r   r  r)   r<   r   r  r  r   zoutput argument with type castint16z(output argument with incontiguous layoutr   ra   rj   ).r   )r   r   r  r   r   r   r   rQ  )r+   r  r   r   r  r   r   r   test_output_argumentk  s.    $zTestUfunc.test_output_argumentc                 C   s  t j}tdd}tddd}|||}t||| d |||g dd}t||| d |||g d	d}t||| d |||g d
d}t||| d |||ddgd}t||| d |||tdtjdtj	dgd}t||| d |||ddgd}t||| d |||ddgd}t||
ddd| d tt|||dd tt|||dgd tt|||ddgd tt|||ddgd tt|||d dgd tt|||g dd tt|||g dd tt|||g dd tt|||ddgd t j}tdd}tddd }|||}t|t|| |||g dd}t|t|| |||g dd}t|t|| |||g dd}t|t|
ddd|
dddd td}||||g dd}t||u  t|t|| td}||||g dd}t||u  t|t||
dddd tt|||dd  tt|||dd tt|||dd tt|||g d tt|||d!gd tt|||g dd tt|||g d"d tt|||d#dgd#dgd#dggd tt|||d!d!d#dggd tt|||g d$d tt|||g d%d td&}tt|||d  tt||||d d df d' tt||d |ddgd tt||||d ddgd tttjd(d(dgd tt|||ddgd)d* d S )+N      ;@ra   ra   ra   rO        3@ra   r   ra   r   r   r   r   )axes)r   r   r   )r   r   r   r<   r   r   r         )r  r   )r   r   r   )r   r`  r   r   rw  r  rV  r   r   r   r   )r  r  r  )r   r   r  r  ))r   r   r  r  ra   )r   r   ra   r   )r   r  )r   r   r   ra   )r  r  )ra   r   r  r  )r  r  r   r`  )r  r  N)r  r  )r`  r`  r  r   r
  T)r  r4   )r   r   r   r   r  r   rQ  int8rd   int32	transposer   r'   r   matrix_multiplymatmulrm  r   r   r(   )r+   r   r   r   r  mmr  zr   r   r   test_axes_argument  s   
$



zTestUfunc.test_axes_argumentc           	      C   s>  t j}tdd}tddd}|||}t||| d |||dd}t||| d t|}|||d|d}t||u  t|| |||d	d}t||| d	 td
d}tddd}tddd}tt j	|||d	dtj|| | d	d tt j
|d	dtj
|d	d tt j
|ddtj
|dd t|}t j
||d	d}t||u  t|tj
|d	d t j
||dd}t||u  t|tj
|dd tt|||d	d	d	gd tt|||d	gd t j}tt|||dd tjd|jd}ttt j
||d	d tttjddd	d d S )Nr  r  rO  r  r  r   r  )rv  r   r   r   r  r;   rX  r-     r   rv  r   )rv  r  r   r   ra   r<   r
  )r   r   r   r   r  r   rQ  
zeros_liker   innerwtcumsum
empty_liker   r'   r  rm  r1   r   r(   )	r+   r   r   r   r  r   r  ri  r  r   r   r   test_axis_argument  sF   



zTestUfunc.test_axis_argumentc                 C   s  t j}tdd}tddd}|||}t||| d |||dd}t||| d |||d	d}t||| jdd	d t|}|||d	|d
}t||u  t|| |||ddd}t||| jddd |||dd	d}t||| jdd	d |||ddd}t||| jddd |||dd	d}t||| jdd	d |||g ddd}t||| d |||g dd	d}t||| jdd	d |||ddgdd}t||| d |||g dd	d}t||| jdd	d |||ddgdd}t||	ddd| d |||ddgd	d}t||	ddd| jdd	d |||g dd	d}t||	ddd| jdd	d |||g dd	d}t|||	ddd jdd	d |||g dd	d}t||	ddd|	ddd jdd	d t
dtdd d tjtjf  }t|}tj|dd}t|| tj|d	d}t||d d tjtjf  t
dtdd d tjtjf  }t|\}}	tj|dd\}
}t|
| t||	 tj|d	d\}
}t|
|d d tjtjf  t||	d d tjtjf  tdd}tddd}tddd}tt j|||d	dtj|| | dd	d tt j|||dd	dtj|| | dd	d tt|||dd t j}tt|||d	d tt|||dd tttjdddd d S ) Nr  r  rO  r  r  r   FkeepdimsT)r  r   rv  r  r   r  )r  r  )r   r   r   r   r   r   )r   r   r   )r   r   r   )r   r   r   ra   rz  r   r  r;   rX  r-  r  truer
  )r   r   r   r   r  r   rQ  r  r   r  eyenewaxisumldetslogdetr  r   r'   r  r(   )r+   r   r   r   r  r   r  r+  
expected_s
expected_lcsclri  r  r   r   r   test_keepdims_argument  s   


"&

&

z TestUfunc.test_keepdims_argumentc                 C   s   t dd}t ddd}t ddd}tt|||t j|| | dd t d	d
d}t ddd}t ddd}tt|||t j|| | dd d S )Nr   r  r;   rX  r-  r  r   r  d   |   r        ,  iD  )r   r   r  r   r   r  rQ  r+   r   r   ri  r   r   r   test_innerwth  s   &*zTestUfunc.test_innerwtc                 C   sT   t jg dd}t jg dd}t jg dd}tt|||t j|| | dd dS )z/Test generalized ufunc with zero-sized operandsr   r<   r   r  N)r   rd   r   r   r  rQ  r  r   r   r   test_innerwt_emptyr  s   *zTestUfunc.test_innerwt_emptyc                 C   s   t d}tt||t d t d}t|d ||}t||u  t|t t d|d |d  f tt	tjt dt d tt	tj|t 
d tt	tj|t 
dt d	 tt	tj|t 
dt d d
S )z Test with fixed-sized signature.ra   ra   ra   r   r   r   rj   rz  r&  )ra   rj   N)r   r  r   r   cross1dr   r   vstackr   r   r   )r+   r   r   resultr   r   r   test_cross1dy  s   

&"zTestUfunc.test_cross1dc                 C   sR  t dd}t d}|d d t jf }t ddd }t||}t||}t|| tt	tj|| t||}t||
  t||}t||}t|| t d}|t jd d f }t dd	d }	t||}
t||}t||
 tt	tj|| t||}t||

  t|	|}
t|	|}t||
 |j}|	d
d}t||}t||}t|| tt	tj|| t||}t||
  t|	|}t|	|}t|| t |}tj|	||d}t|| d|d d < tj|	||d}t|| t |}tt	tj||| t|||}t||
  d S )Nrw  r  r   rV  r  r   ra   r  )rj   r   r   r   ra   r`  r   r   r   )r   r   r  r  r   r  r  r   r   r   squeezer  swapaxesr  )r+   mat
single_veccol_veccol_vec_array
mm_col_vecmatmul_col_vec
matmul_colrow_vecrow_vec_array
mm_row_vecmatmul_row_vec
matmul_rowmm_row_col_vecmatmul_row_col_vecmatmul_row_colmm_row_col_arraymatmul_row_col_arrayr   r   r   r   test_can_ignore_signature  s`   











z#TestUfunc.test_can_ignore_signaturec                 C   s   |  tj |  tj d S rH   )compare_matrix_multiply_resultsr   rx  r   r*   r   r   r   test_matrix_multiply  s   zTestUfunc.test_matrix_multiplyc                 C   sT   t tdtd}t|td t tdtd}t|td d S )N)r   r;   )r;   r   r   )r;   r;   )r   r  r   rT   r   r   r  r   r   r    test_matrix_multiply_umath_empty  s   z*TestUfunc.test_matrix_multiply_umath_emptyc                    s  t jt jddd|d}t jt jddd|d}d|jj } fdd fdd	d
d } d}dtd d dfd f }d}|D ]q}	|D ]l}
|D ]g}|D ]b}||	| }||
| }|oh|jd u}|oo|jd u}|j	d |j	d kr||j	d |j	d rt
t||t j|dt jf dd|dt jd d f  dd|dt|j	t|j	f  d qRqNqJqFt|ddd d S )Nr   ra   rj   r<   zmatrix multiply on type %sc                    sp   | dkrdgfS d} | d }|D ]#}t | D ]}|| d g }|| || d < | d ||< ||f7 }qq|S )Nr   r   r   )r   )nretbasepermr   new)	permute_nr   r   r    s   z<TestUfunc.compare_matrix_multiply_results.<locals>.permute_nc                    sT   | dkrdS d} | d }|D ]}||t d f f7 }||t ddf f7 }q|S )Nr   )r   r   r   )slice)r  r  r  sl)slice_nr   r   r    s   z:TestUfunc.compare_matrix_multiply_results.<locals>.slice_nc                 S   s   | |kp| dkp|dkS rL   r   )s1s2r   r   r   broadcastable  s   z@TestUfunc.compare_matrix_multiply_results.<locals>.broadcastabler   Tr`  r   .ra  r  z %s %sr  zreference check)r   rd   randomrandr1   r?  r  r  r  shaper   r   r  rQ  r  r  strr   )r+   tpd1d2r  r  	permute_3slice_3refp1p2r  r  a1a2r   )r  r  r   r    sH   

z)TestUfunc.compare_matrix_multiply_resultsc                 C   s   t jdtddd}t j|jd |jd d  d f|jd}t|| t 	t j
|d d d f | d dd	}|t j|jd td  }t|| tttj| d S )
Nrw  r<   rj   ra   r   r   r   r   r  )r   r   r:  r  rm  r  r1   r   euclidean_pdistsqrtrQ  triboolr   r   r   )r+   r   r   r   r   r   r   test_euclidean_pdist  s   *(
zTestUfunc.test_euclidean_pdistc                 C   s&   t d}t|}t||  d S )Nr;   )r   r   r   r  r   )r+   r   r  r   r   r   test_cumsum  s   

zTestUfunc.test_cumsumc                 C   s  t jg dtd}tt |d t jdd |D td tt |dt jdd |D td tt |dt jdd |D td tt |d	t jd
d |D td tt |d t jdd |D td tt |dt jdd |D td tt |dt jdd |D td tt |d	t jdd |D td tt |t jdd |D td tt j|d tt j|d  d S )N)ra   NTFtest r<   c                 S      g | ]}|pd qS rH   r   r   rC   r   r   r   r   !      z1TestUfunc.test_object_logical.<locals>.<listcomp>Tc                 S   r  Tr   r  r   r   r   r   #  r  rw  c                 S   r  rw  r   r  r   r   r   r   %  r  blahc                 S   r  r  r   r  r   r   r   r   '  r  c                 S      g | ]}|od qS rH   r   r  r   r   r   r   *  r  c                 S   r  r  r   r  r   r   r   r   ,  r  c                 S   r  r  r   r  r   r   r   r   .  r  c                 S   r  r  r   r  r   r   r   r   0  r  c                 S   s   g | ]}| qS r   r   r  r   r   r   r   3  rq   ra   )r   rd   rU   r   
logical_orlogical_andlogical_notr  rS  r   r   r   test_object_logical  s<   
zTestUfunc.test_object_logicalc                 C   s   G dd d}t | }t||kd tt ||d t | g}t||kt dg tt ||t dg tt j||tdt dg d S )Nc                   @      e Zd Zdd ZdS )z8TestUfunc.test_object_comparison.<locals>.HasComparisonsc                 S   r   )N==r   r+   otherr   r   r   __eq__:  r   z?TestUfunc.test_object_comparison.<locals>.HasComparisons.__eq__N)r6   r7   r8   r%  r   r   r   r   HasComparisons9      r&  Tr<   r"  )r   rd   r   equalrU   )r+   r&  arr0darr1dr   r   r   test_object_comparison8  s   "z TestUfunc.test_object_comparisonc                 C   sJ  t jg dtd}tt |d tt |d tt |d t jg dtd}tt |d tt |d tt |d	 tt 	|d
 tt |d	 tt |d
 tt jdggtd d tt jddgggtddddg tt jdgtdjddd tt jdgddggtdjdgd
d	gdg d d S )N)r   r   r  r<   abcr  r   TFTr   r   TFr   r   r   rq  ra   )rr  r|  )r   r   ra   )
r   rd   rU   r   rQ  r<  minprodanyrV   rS  r   r   r   test_object_array_reductionF  s&   &z%TestUfunc.test_object_array_reductionc                 C   s   t jdtd}dd tdD |d d < t jj||d t jj||d t|t jdd dD td t jdtd}d	d tdD |d
d d f< t jj||dd t jj||dd t|d
d d f t jdd dD td d S )Nrj   r<   c                 S      g | ]}d gqS rb  r   r   r   r   r   r   r   \  rq   zBTestUfunc.test_object_array_accumulate_inplace.<locals>.<listcomp>r   c                 S      g | ]}d g| qS rb  r   r4  r   r   r   r   a      )r   ra   r   r;   r   rj   c                 S   r3  r   r   r4  r   r   r   r   f  rq   r   r   r  c                 S   r5  r8  r   r4  r   r   r   r   j  r6  )r   rT   rU   r   r(   
accumulater   rd   )r+   rg   r   r   r   $test_object_array_accumulate_inplaceY  s   z.TestUfunc.test_object_array_accumulate_inplacec                 C   sr   t jt jg dtd}t|t jg dtd tt t jg d W d    d S 1 s2w   Y  d S )N)r   r   r   r<   )r   r   ra   r   Nr   )	r   r(   r9  rd   rU   r   r   r  r'   r  r   r   r   $test_object_array_accumulate_failurem  s
   "z.TestUfunc.test_object_array_accumulate_failurec                 C   s$  t jdtd}dd tdD |d d < t jdtd}dd tdD |d d < t jj|t d|d t jj|t d|d t|| t jdtd}dd tdD |d	d d f< t jdtd}d
d tdD |d	d d f< t jj|t d|dd t jj|t d|dd t|| d S )Nrj   r<   c                 S   r3  rb  r   r4  r   r   r   r   x  rq   z@TestUfunc.test_object_array_reduceat_inplace.<locals>.<listcomp>c                 S   r3  rb  r   r4  r   r   r   r   z  rq   r   r7  c                 S   r3  r8  r   r4  r   r   r   r     rq   r   c                 S   r3  r8  r   r4  r   r   r   r     rq   r   r  )	r   rm  rU   r   r(   r   r   r   rT   r  r   r   r   "test_object_array_reduceat_inplaceu  s   
z,TestUfunc.test_object_array_reduceat_inplacec                 C   s~   t jt jg dtdddg}t|t jd dgtd tt t jg dddg W d    d S 1 s8w   Y  d S )Nr;  r<   r   r   r   )	r   r(   r   rd   rU   r   r   r  r'   r  r   r   r   "test_object_array_reduceat_failure  s
    "z,TestUfunc.test_object_array_reduceat_failurec                 C   sx   g t jg tdfD ]0}tt |d tt |d tt |d tt |d tt	t j
| tt	t j| q	d S )Nr<   r   r   FT)r   rd   rU   r   rQ  r0  r1  rV   r   r   r<  r/  rS  r   r   r   test_zerosize_reduction  s   z!TestUfunc.test_zerosize_reductionc                 C   s   t ddg}tt j|jdd t ddg}tt j|jdd t ddg}tt j|jdd t ddg}tt j|jdd d S )NFr   r  r`  )r   rd   r   	AxisErrorrV   r1  rS  r   r   r   test_axis_out_of_bounds  s   z!TestUfunc.test_axis_out_of_boundsc                 C   sj  t tjdddd t tjdddd t tjdddd t tjdddd t tjdddd t tjdddd t tj	dd t
ttjtdddtju  t
ttjtdddtju  t
ttjtdddtju  t
ttjtdddtju  t
ttjdddtju  G dd	 d	tj}td
|}t
tt||u  d S )Nra   r   r        @TFg      @c                   @      e Zd ZdS )z0TestUfunc.test_scalar_reduction.<locals>.MyArrayNr6   r7   r8   r   r   r   r   MyArray      rE  r   )r   r   rQ  r0  r1  rV   r<  r/  r  r  r   r   r  rN   ndarrayrd   view)r+   rE  r   r   r   r   test_scalar_reduction  s   """"zTestUfunc.test_scalar_reductionc                 C   s|   t dt j}t dt j}t dt j}t j|||d t|d t d}t jdt jd}t j|d|d t|d d S )N)r  r  r   r   i   r<   r   )	r   rT   rx  r{   r(   r   r   r  subtractr+   r   r   r  r   r   r   test_casting_out_param  s   

z TestUfunc.test_casting_out_paramc                 C   s   t d}t d}t d}t j||||d dkd t|g d t dddd }t j|ddg|ddgddggd t|dd	gd
dgg t j|d|ddgd t|dd	gddgg d S )Nr   r   r   r   r|  )r   r   r   rj   r   r   r   rj   ra   r      rX  r   TF   )	r   r   rT   r   r(   r   r  r  rJ  rK  r   r   r   test_where_param  s   


"zTestUfunc.test_where_paramc                 C   sV   t dt j}t dt j}dt dt j }t j|||g dd t|g d d S )Nr;   r   )
r   r   r   r   r   r   r   r   r   r   rM  )
r   r   r   r   r   r   r   r   r   r   )r   rT   rx  r{   r(   r   rK  r   r   r   test_where_param_buffer_output  s
   z(TestUfunc.test_where_param_buffer_outputc                 C   st   t jdgt jd}t jdgtd}tt j||ddg t jdgt jd}t jdgtd}tt j||ddg d S )Nr   r<   Tr{  )r   rd   rx  r  r   r  r{   r+   r   r  r   r   r   test_where_param_alloc  s   z TestUfunc.test_where_param_allocc                 C   s   t jd}t jd}|dk}t |d}t j||||d t ||j| }t|| |k || t ||  	 r?J d S )N)  rj   )rT  r   rt  r   )r|  r   )
r   r  	full_likelessbroadcast_tor  r   r   r  r1  )r+   r   r   r|  r   b_wherer   r   r   test_where_with_broadcasting  s   z&TestUfunc.test_where_with_broadcastingc                 C   s  d|d< d|d< t tjj|d dd t tjj|ddg d t tjj|ddg d	 t tjj|d
dddg t tjj|ddg dg dg dg t tjj|ddg dg dg t tjj|ddg dg d	g t tjj|dd| d|d< d|d< t tjj|d dd t tjj|ddg d t tjj|ddg d t tjj|d
dddg t tjj|ddg dg dg dg t tjj|ddg dg dg t tjj|ddg dg dg t tjj|dd| d|d< d|d< t tjj|d dd t tjj|ddg d t tjj|ddg d	 t tjj|d
dddg t tjj|ddg dg dg dg t tjj|ddg dg dg t tjj|ddg d	g dg t tjj|dd| d S )Nr   .r   )r   r   r   r  r.  )r   r   r   r   ru  )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   minimumr  rS  r   r   r   check_identityless_reduction   s`   z&TestUfunc.check_identityless_reductionl        c                 C   sj   t dd}ddg|d d df< ddg|d d df< t jj|dd}~|d dks+J |d dks3J d S )	N)r   l        uint8r   ra   r   rj   r   r  )r   r   r  r  rf   r   r   r   &test_identityless_reduction_huge_array.  s   z0TestUfunc.test_identityless_reduction_huge_arrayc                 C      t jddd}| | d S )Nr  Corderr   rm  r[  rS  r   r   r   "test_identityless_reduction_corder9     z,TestUfunc.test_identityless_reduction_corderc                 C   r^  )Nr  Fr`  rb  rS  r   r   r   "test_identityless_reduction_forder=  rd  z,TestUfunc.test_identityless_reduction_forderc                 C   s$   t jddddd}| | d S )N)r   rj   ra   r_  r`  r   r   r   rm  r  r[  rS  r   r   r   &test_identityless_reduction_otherorderA  s   z0TestUfunc.test_identityless_reduction_otherorderc                 C   s>   t jddddd}|dd dd dd f }| | d S )N)ra   r   rj   r_  r`  r   r   rg  rS  r   r   r   %test_identityless_reduction_noncontigE  s   z/TestUfunc.test_identityless_reduction_noncontigc                 C   sP   t jddd}|dd  jdd}d|_|dd dd dd f }| | d S )N)i  i1r<   r   r   ra   rj   r   )r   rm  rH  r  r[  rS  r   r   r   /test_identityless_reduction_noncontig_unalignedJ  s
   z9TestUfunc.test_identityless_reduction_noncontig_unalignedc                 C   s  t tjjg ddd t tjjg tjdtj t tjjg tj dtj  t tjjdgddd t tjjdgddd t tjjdgddd t tjjdgddd tttjjg d d tttjjg d d t tjjg tj	dd tj
dgtd}tjj|dd}t |d d S )Nr   rq  r   rj   r;   r<   rW  )r   r   r  r  rZ  infr   r   r(   _NoValuerd   rU   r+   r   rh   r   r   r   test_initial_reductionQ  s   z TestUfunc.test_initial_reductionrv  )r   r   Nr|  )FTTTF)TFFFTFc                 C   sh   t ddd}| }t |}t j|||d t jj|||d}||}t	|| t
|| d S )Nr~  ra   rM  rv  r|  )r   r   r  copyr  r  r(   r  rQ  r   r   )r+   rv  r|  r   a_copya_checkrh   checkr   r   r   test_reduction_with_wheren  s   


z#TestUfunc.test_reduction_with_whererr  r   r-  )TTF)NTrr  r}  c           	      C   sl   t ddd}| }t |jt j }t j|||d t jj	||||d}|j
||d}t|| d S )Nr~  ra   rM  )rv  r|  rr  rq  )r   r   r  rs  r>   r  rm  r  r  r  r<  r   )	r+   rv  r|  rr  r   rt  ru  rh   rv  r   r   r   %test_reduction_with_where_and_initial  s   z/TestUfunc.test_reduction_with_where_and_initialc                 C   s2   t ddd}g d}ttt jj||d d S )Nr~  ra   rq  r{  )r   r   r  r   r   r  r  rR  r   r   r   #test_reduction_where_initial_needed  s   z-TestUfunc.test_reduction_where_initial_neededc                 C   s   t g dg dg}t jj|dd}t|g d t jj|dd}t|ddg t jj|d	d}t|| ttt jj|d
d d S )N)       @r%  r%  )r
  r   g      ?r   r  )rz  rz  rz  r   r%  rz  r   r.  )r   rd   divider  r   r   r   ro  r   r   r   *test_identityless_reduction_nonreorderable  s   
z4TestUfunc.test_identityless_reduction_nonreorderablec                 C   sb  dd }dd }dd }t tjjd  ||tjjdd ||tjjdd ||tjjdd ||tjjdd |tjjg  tjjtd	d
d ||tjjdd ||tjjdd ||tjjdd ||tjjdd tjg  tjjtd	d
d tjtjfD ]*}|jtddd |jtddd |jtddd |jtd	dd qd S )Nc                 _   s   | |i | d S rH   r   rB   argsr"  r   r   r   ok  r   z+TestUfunc.test_reduce_zero_axis.<locals>.okc                 _   s   t t| g|R i | d S rH   )r   r   r}  r   r   r   err  s   z,TestUfunc.test_reduce_zero_axis.<locals>.errc              
   S   sp  | |t ||fdd | |t ||fdd | |t |d |d |fdd | |t |d ||d fdd | |t ||d |d fdd | |t |d ||d fdd | |t |d |d |d |d |d fdd | |t d	||fd
d | |t d	||fdd | |t |d	|fdd | |t d	||fdd | |t d	||fdd d S )Nr   r  r   r   r  ru  ra   r   r   r   r;   r.  )r   r   )expectfuncr  r  r   r   r   t  s    """"z*TestUfunc.test_reduce_zero_axis.<locals>.t   r   r   r   r  )r  r   )r   r  )r  r  )r   r   r  identityr  r   r(   r9  )r+   r  r  r  r   r   r   r   test_reduce_zero_axis  s,   zTestUfunc.test_reduce_zero_axisc                 C   sz   t jg dtd}ttt j|dg d ttt j|d|d dd }tt||d tt j|d|dd	 t|g d
 d S )Nr  r<   g?)g @g@gffffff@r   c                 S   s   | |7 } d S rH   r   )r   r   r   r   r   add_inplace  s   z0TestUfunc.test_safe_casting.<locals>.add_inplacer   r   r   r  )r   rd   r)   r   r   r(   r   r'   )r+   r   r  r   r   r   test_safe_casting  s   zTestUfunc.test_safe_castingc                 C   s   t jg ddd}t jg ddd}t jdtjd}t|||}t jg dtjd}t|| t||}t|| tj||t j|d}t|| t	t
 t|t d W d    d S 1 sew   Y  d S )Nr  i8r<   ra   )r   r   rj   r   r   )r   rd   rm  r   rationalr   r   r   uint16r   r'   )r+   r   r   r  r  targetr   r   r   test_ufunc_custom_out  s   



"zTestUfunc.test_ufunc_custom_outc                 C   s   t jddddd}t jddddd}t|d dd df | t|t jg dg d	g d
g dgdd t d}t|d t|d t|ddg t|d d S )NrX  lr<   rj   r   ra   r   )r   r   rj   ra   )r   r      r   )rO  rX     r  )rw  rP  rO  rW  r   r;   )r   r   r  opflag_testsinplace_addr   rd   r   r   r   r   test_operand_flags  s   

zTestUfunc.test_operand_flagsc                 C   sd   dd l m  m} tjdgdd}tjdgdd}|||}t|tjdgdd tt|j	 d S )Nr   r  zu8,u8,u8r<   )r   rj   r   )
numpy.core._struct_ufunc_testsrl   _struct_ufunc_testsr   rd   add_tripletr   r   RuntimeErrorregister_fail)r+   struct_ufuncr   r   r  r   r   r   test_struct_ufunc  s   zTestUfunc.test_struct_ufuncc                 C   s   t jtddtddtddgtjd}t jtddtddtddgtjd}t||}t jtdtddtddgtjd}t|| d S )Nr   r   ra   rj   r<   )r   rd   r   r  test_add_rationalsr   )r+   r   r   r  r+  r   r   r   test_custom_ufunc)  s.   







zTestUfunc.test_custom_ufuncc                 C   sL   t t tjtddtjtd fd W d    d S 1 sw   Y  d S )Nr   r  )r   r'   r   multiplyr   r  r)   r*   r   r   r   test_custom_ufunc_forced_sig=  s
   

"z&TestUfunc.test_custom_ufunc_forced_sigc                    sL   G  fddd t d d  t jdk j t jdk j d S )Nc                       s@   e Zd ZdZdZdZdd Zdd Z fddZ fd	d
Z	dS )z1TestUfunc.test_custom_array_like.<locals>.MyThing  r   c                 S   s
   || _ d S rH   r  )r+   r  r   r   r   __init__K  rP   z:TestUfunc.test_custom_array_like.<locals>.MyThing.__init__c                 S   s
   | j d S Nr   r  r*   r   r   r   __len__N  rP   z9TestUfunc.test_custom_array_like.<locals>.MyThing.__len__c                    sJ     j d7  _ t|ts|f}t|| jkrtd | jt|d  S )Nr   boo)getitem_countr   tuplerf  ndim
IndexErrorr  )r+   r   MyThingr   r   __getitem__Q  s   
z=TestUfunc.test_custom_array_like.<locals>.MyThing.__getitem__c                    s     j d7  _ | S rL   )
rmul_countr#  r  r   r   __rmul__Z  s   z:TestUfunc.test_custom_array_like.<locals>.MyThing.__rmul__N)
r6   r7   r8   __array_priority__r  r  r  r  r  r  r   r  r   r   r  E  s    	r  r   r  r   r   )r   r{   r   r  r  r*   r   r  r   test_custom_array_likeC  s   z TestUfunc.test_custom_array_likec                 C   s  t d}t j|g dd t|g d t d}t g d}t j|g d| t|g d t ddd}t g dg d	g d
g}t j|td g df| t|g dg dg dg t dddd}t g d}t j|td td g df| t|g dg dg dgg dg dg dgg dg dg dgg t ddd}t g dg d	g d
g}t j|g dtd f| t|g dg dg dg t dddd}t g d}t j|td g dtd f| t|g dg dg dgg dg dg d gg d!g d"g d#gg t ddd}t g d}t j|d$g df| t|g dg d%g d&g t dddd}t g d}t j|g dd$td f| t|g dg d%g d&gg d'g d(g d)gg d*g d+g d,gg t dddd}t g d}t j|td td td f| t|g d-g d.g dgg d/g d0g d gg d*g d1g d#gg t d}t j|g d t|g d2 t d$}t j|d3d t|d t	t
t jj|d$d t	t
t jj|g d t d}t j|g d4d5 t|t g d6 t d}|d7 d$k}t j||g d8 t|g d9 t jdd:d;}t j|g d t|g d< t d=}|d d d f d d d$d$f }t j|d$dgd t|t d= t g dt d> }t g d?t d@ }t j||d t|g dA t jdBdgtd;}t	tt jj|d$dgd t|t jdBdgtd; t	tt jjt ddg t g dC}t j|d$gd$ tt g dC| d S )DNr;   )r   r   r   r   )
r   r   rj   ra   rj   r   r   r   rV  r   )r  r  r  )
r   r      ra   rj   i   r   r   rV  r   r   ra   )r  r  r  )r  r  r  )r   r   r   )r      f   )ra        )r   i_  4  rN  )r  r  r  )r   i  r  )r   i     )r        )rw       )rW  i     )r  i     )        )r  i     r  )i  r  i  )      r  )   r  i]  )j   r  r  )r   r;   r  )   r  if  )s      i=  )r  rY  r-  )   r  io  )r     iF  r   rk  )r   r   rV  )   r  ic  )rw  rP  rO  )rW  rX     )v      i@  )r        )r     r  )r  r  i.  )g      i1  )m      i7  )p      i:  )y      iC  )
r   r   r   ra   rj   r   r   rV  r   r   )r   r   ra   r   rB  )
r   r   i>  .   rj   r   r   r   rV  r   r   )r   r   rj   r   rV  )
r   r   r   ra   r   r   r   r   r   r   u4r<   )
r   r   r   ra   rj   l    r   r   rV  r   rj   r   )r   r   ra   rj   rB   )r   rV  r   rj   r   r  )r   r   r(   atr   rd   r  r  r  r   r  r  r(  invertr   r1   r)  rU   r'   r   modfr  )r+   r   r   indexorigvaluesr   r   r   test_inplace_fancy_indexingb  s   

"""





 z%TestUfunc.test_inplace_fancy_indexingc                 C   s^   t d}t d}ttt jj|dg| t ddgddggg}ttt jjj	j|dg d S )Nr   r  r   r   r   ra   rj   )
r   rT   r   r'   r  r  rd   linalg_umath_linalgr  r   r   r   r   test_at_not_none_signature  s
   

z$TestUfunc.test_at_not_none_signaturec                 C   sB  t jj}t jdtd}t jd|jd}|d }t||| t||dd| t||d| t||dd d| t||ddd| t||dd| t||dd | t||dd d d| t||dd |d| t||dd || t||dd d | t||dd d d	d
| t||dd d d|d|j  t||dd d d	d| t||dd d d	dd| t||dd d d	dd| t||dd d d	ddd| t||dd d d	d| t||dd d d	d| t||dd d d	d| t||dd d d	ddd| t	t
| t	t
||dd d d	ddd
 t	t
||d t	t
||dd t	t
||dd dd t	t
||dd t	t
||dd t	t
||dd d t	t
||dd d t	t
||dd t	t
||dd d t	t
||dddd d t	t
||dd dd t	t
||dd t	t
||dddd d t	t
||dd dd dd t	t
||dd d dd d S )N)r   r   r<   r8  r   r   r  r   r   Fr  Trb  rq  r{  )rv  r1   r   r  )r1   r   r  )r   r  )r   r  rr  r|  r   r5  )rv  r1   r  r1   r   r   r1   )r  r1   r   )rv  r1   r5  r4  )r  r5  r   )rv  r1   r  r   r5  )rv  r1   r   r5  )r   r(   r  rT   r)   r1   r   r  r  r   r'   )r+   rB   r  orr   r   r   test_reduce_arguments  sp   "

zTestUfunc.test_reduce_argumentsc                 C   sp   G dd dt j}t ddd}|jdd }||}t jg dtd}tt 	|||d	 kkd
 d S )Nc                   @   r!  )z,TestUfunc.test_structured_equal.<locals>.MyAc                 _   s   t ||dd |D i |S )Nc                 s   s    | ]	}| tjV  qd S rH   )rH  r   rG  )r   inputr   r   r   	<genexpr>?  s    zOTestUfunc.test_structured_equal.<locals>.MyA.__array_ufunc__.<locals>.<genexpr>)rk   )r+   r   methodinputsr"  r   r   r   __array_ufunc__>  s
   z<TestUfunc.test_structured_equal.<locals>.MyA.__array_ufunc__N)r6   r7   r8   r  r   r   r   r   MyA=  r'  r        (@rj   ra   zf8,f8,f8r<   )TFFFr   T)
r   rG  r   r  rH  r  rd   r  r   rV   )r+   r  r   ramrar  r   r   r   test_structured_equal:  s   
 zTestUfunc.test_structured_equalc                 C   sL   t d}t d}t||k t||k t||k  t||k  d S )Nr7  r   )r   rd   r   r   r   r   r   test_scalar_equalH  s   

zTestUfunc.test_scalar_equalc                 C   s   t jt jt jt jt jt jt jt jt j	t j
t jt jt jt jt jt jt jt jt jt jt jt jt jt jt jt jt jg}t d}d}t ddg}|D ]}tt||| tt||| qHd S )N1r   r
  r%  )r   r  r(   rJ  r  r{  r;  floor_dividebitwise_and
bitwise_orbitwise_xor
left_shiftright_shiftfmaxfminfmodhypot	logaddexp
logaddexp2r  rZ  modgreatergreater_equalrV  
less_equalr(  	not_equalrd   r   r'   )r+   binary_funcsr   r   r  rB   r   r   r    test_NotImplemented_not_returnedR  s   
	z*TestUfunc.test_NotImplemented_not_returnedr.   Nc                 C   s2   t jg dtd}||||d}|jtksJ d S )NTNFr<   r  )r   rd   rU   r1   )r+   r   r.   r   rh   r   r   r   %test_logical_ufuncs_object_signaturese  s   z/TestUfunc.test_logical_ufuncs_object_signaturesc                 C   sL   t g d}tt ||||d W d    d S 1 sw   Y  d S )Nr  r  )r   rd   r   r  r'   )r+   r   r.   r   r   r   r   +test_logical_ufuncs_mixed_object_signatureso  s   "z5TestUfunc.test_logical_ufuncs_mixed_object_signaturesc                 C   s   t jddd}t ddg}t||||ddgd ||dks$J t jdt jd}|ddgd|j}t||||d| t jd	t jd}|j||ddksTJ t jd
gdd}t jd	|jd}|j||ddksoJ d S )N   1V3r<   r
  r%  Tr   r   r   ra   r   r   )r   rd   r   r  r   r  r   r1   )r+   r   r   r  r   r+  r   r   r   $test_logical_ufuncs_support_anythingz  s   z.TestUfunc.test_logical_ufuncs_support_anythingc                 C   s~   t jtdd |dgdg W d   n1 sw   Y  t jtdd |g d W d   dS 1 s8w   Y  dS )a  
        Logical ufuncs are normally well defined by working with the boolean
        equivalent, i.e. casting all inputs to bools should work.

        However, casting strings to bools is *currently* weird, because it
        actually uses `bool(int(str))`.  Thus we explicitly reject strings.
        This test should succeed (and can probably just be removed) as soon as
        string to bool casts are well defined in NumPy.
        zcontain a loop with signaturer  r  3N)r  20)r   r  r'   r  )r+   r   r   r   r   !test_logical_ufuncs_reject_string  s   "z+TestUfunc.test_logical_ufuncs_reject_stringc                 C   s`   t d}t ddg}| }tt ||||dd W d    d S 1 s)w   Y  d S )Nr  r
  r%  r(  r  )r   rd   rs  r   r  r'   )r+   r   r   r  r   r   r   r   "test_logical_ufuncs_out_cast_check  s   
"z,TestUfunc.test_logical_ufuncs_out_cast_checkc                 C   sx   t jddd}t jddd}t j|t j|ksJ tt j|t j| tt j|dgt j|dg d S )Nr;   z>i8r<   z<i8r   )r   r   r(   r  r   r9  r   )r+   arr_bearr_ler   r   r   $test_reducelike_byteorder_resolution  s   z.TestUfunc.test_reducelike_byteorder_resolutionc                 C   s   t jdt jd}t jdt jd}t jj||ddksJ d|d d< t jj||ddks.J t jdd	t j	d}t jdt j
d}t jdt j
d}t jj||t j
d
 ||ksWJ d S )Nr  r<   r   r   r   r;   r\  r   ir  )r   rT   r\  r   r  r(   r  r  r>   rx  r  )r+   rg   r   rh   
single_resr   r   r   test_reducelike_out_promotes  s   z&TestUfunc.test_reducelike_out_promotesc                 C   s   t jddd}t jd|j d}t j|}t jj||d t|| t jd|j d}t j|ddg}t jj|ddg|d t|| t j|j	|j d}t j
|}t jj
||d t|| d S )	Nr-  r   r<   r   r   r   r   r   )r   rT   rm  r1   r)  r(   r  r   r   r  r9  )r+   rg   r   r+  r   r   r   +test_reducelike_output_needs_identical_cast  s   

z5TestUfunc.test_reducelike_output_needs_identical_castc                 C   s   t jdt jdddd}|dddd	ddd
f ddd}t jdt jddd}|d d dd d f }| }t jj|| dd}t jj||dd}t|| t|dd d f |dd d f  t|dd d f |dd d f  d S )Ni  r<   r   rP  rV  rj   r   r   r  r   r   r   rX  r  ra   )	r   r   r  r  r  rs  r(   r  r   )r+   rC   y_baserD   y_base_copyr0r1r   r   r   test_reduce_noncontig_output  s   &
"&z&TestUfunc.test_reduce_noncontig_output	with_castc                 C   s   t d}t d}|r|t j}tjtdd t jj|ddg|d W d    n1 s/w   Y  tjtdd t jj	||d W d    d S 1 sOw   Y  d S )Nr   ra   z(shape|size)r  r   r   )
r   r   r   r{   r   r  r   r(   r   r9  )r+   r#  rg   r   r   r   r   /test_reduceat_and_accumulate_out_shape_mismatch  s   

"z9TestUfunc.test_reduceat_and_accumulate_out_shape_mismatch	out_shape)r   rb  r   r   r   )r   ra   r  r  f_reducec                 C   s   t ddd}t ||j}||d|d}||jkr;tt ||d||d W d    d S 1 s4w   Y  d S ||d||d}t||u  t	|| d S )Nr  rj   ra   r   r  rv  r   r  )
r   r   r  rm  r1   r  r   r   r   r   )r+   r'  r  r%  r   r   correct_outrv  r   r   r   "test_reduce_wrong_dimension_output	  s   

"z,TestUfunc.test_reduce_wrong_dimension_outputc                 C   s   t d}t d}t d}t jj|d|dd t jj|d|d d df dd tt t jj|d|dd W d    n1 sBw   Y  tt t jj|d|d d df dd W d    d S 1 sgw   Y  d S )	N)r   r;   r&  )ra   r   r   Tr(  r   F)r   rT   rm  r(   r  r   r   )r+   r   out_correctout_incorrectr   r   r   +test_reduce_output_does_not_broadcast_input	  s   


 

""z5TestUfunc.test_reduce_output_does_not_broadcast_inputc                 C   sv   G dd dt j}t d}t jjt d|d ||}t jjt d|d|u s-J tt j||u s9J d S )Nc                   @   rC  )z7TestUfunc.test_reduce_output_subclass_ok.<locals>.MyArrNrD  r   r   r   r   MyArr%	  rF  r.  r   r   r   )r   rG  rm  r(   r  rT   rH  r   )r+   r.  r   r   r   r   test_reduce_output_subclass_ok$	  s   

z(TestUfunc.test_reduce_output_subclass_okc                 C   s   t dtjjv d S )N
)r   r   inner1d_no_docr   r*   r   r   r   test_no_doc_string.	  s   zTestUfunc.test_no_doc_stringc                 C   s"   t ttjd }|dsJ d S )Nzloop of ufunc does not support)r   r  r'   r   r  r  )r+   r   r   r   r   test_invalid_args2	  s   zTestUfunc.test_invalid_argsnatc                 C   *   z
t |rJ W d S  ty   Y d S w rH   )r   rD  r'   r+   r4  r   r   r   test_nat_is_not_finite8	  
   z TestUfunc.test_nat_is_not_finitec                 C   s*   z
t |sJ W d S  ty   Y d S w rH   )r   rB  r'   r6  r   r   r   test_nat_is_nan?	  r8  zTestUfunc.test_nat_is_nanc                 C   r5  rH   )r   isinfr'   r6  r   r   r   test_nat_is_not_infF	  r8  zTestUfunc.test_nat_is_not_inf)r6   r7   r8   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,  rM  rT  rj  rp  ry  r  r  r  r  rm  rT   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r+  r2  r:  r<  r=  r>  r?  rA  rI  rL  rP  rQ  rS  rY  r[  r   r]  rc  rf  rh  ri  rl  rp  rd   rw  rm  rx  ry  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rU   r  rR   r  r  r  r  r  r  r  r  r"  r$  r  rZ  r*  r-  r/  r2  r3  
datetime64timedelta64r7  r9  r;  r   r   r   r   r      sd   	T


	
					
	
V +
	g,O
G6
	
.




A
 	@







"""r   r   c                 C   (   g | ]}t tt|tjrtt|qS r   r   rk   r   r   r  r   r   r   r   N	      c           	   	   C   s   | j D ]j}d|v sd|v rq|d\}}dd |D }tjdd td | | }W d	   n1 s6w   Y  t|trct|}t|t|ksNJ t||D ]\}}|j	t
	|ksaJ qSq|j	t
	|ksmJ qd	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
    rc   ?->c                 S      g | ]}t d |qS )r  )r   rT   r   r  r   r   r   r   ]	      z$test_ufunc_types.<locals>.<listcomp>Tr]  r_  N)r   splitrc  rd  filterwarningsr   r  rf  r   r1   r   )	r   typinpr   r~  rh   outsr  r  r   r   r   test_ufunc_typesN	  s"   




rK  c                 C   r>  r   r?  r  r   r   r   r   i	  r@  c              	   C   s2  | j D ]}ttdt|@ rq|d\}}dd |D }dd |D }|D ]}tdd|_q'|D ]}tdd|_q2tjdd	 td
 | | }| | }W d   n1 sYw   Y  t	|dkrj|f}|f}t
||D ]&\}	}
|	j}t|tjrt|j}d| }t||||d qot|	|
 qoqdS )zs
    Check that contiguous and non-contiguous calls to ufuncs
    have the same results for values in range(9)
    zO?mMrB  c                 S   rC  )r   r   rm  rD  r   r   r   r   v	  rE  z,test_ufunc_noncontiguous.<locals>.<listcomp>c                 S   s"   g | ]}t d |ddd qS )r  Nra   rL  rD  r   r   r   r   w	  s   " r   r   Tr]  r_  Nr   )r6  r0  )r   r1  setrF  r   flatrc  rd  rG  rf  r   r1   r   
issubdtypefloatingr=  epsr	   r   )r   rH  rI  r   args_cargs_nr   res_cres_nc_arn_arrG  res_epstolr   r   r   test_ufunc_noncontiguousi	  s6   


rZ  c                 C   s\   t dgdd}t |sJ | jdkr| | d S | jdkr*| ||  d S td)Nl         r  r   r   r   zufunc with more than 2 inputs)r   rd   rH  rB  r!  rs  r   )r   r   r   r   r   test_ufunc_warn_with_nan	  s   

r[  zPython lacks refcounts)reasonc                  C   s  d} t j| gtt jd  dg | gtdt j   td}t jt|t jd}t	| }t
t t j|||dd W d    n1 sFw   Y  |t	| ksTJ |d dks\J t
t t j|||t jdd	 W d    n1 sww   Y  |t	| ksJ |d dksJ d S )
N{   r   stringr<   r   r  r   r   )r   r1   r   )r   rd   r)   BUFSIZErU   rT   rf  r  sysgetrefcountr   r  r   r(   )valuerg   r   countr   r   r   test_ufunc_casterrors	  s(   
rd  c                   C   sL   t jtdd tjtddddd W d    d S 1 sw   Y  d S )Nzcast ufunc 'add' input 0r  r   zi,ira   zdd->dr  )r   r  r'   r   r(   rd   r   r   r   r   test_trivial_loop_invalid_cast	  s
   "re  offsetr   r   c                 C   s   d}t j|g|  dg |gtdt j   td}t jdt jd}t|}tj	t
dd t jj|t j|d W d    n1 sBw   Y  |t|ksPJ |d	 ||  k sZJ d S )
Nr]  r^  r   r<   r   zinvalid literalr  r  r   )r   rd   r)   r_  rU   r  r`  ra  r   r  r   r(   r  )rf  rb  rg   r   rc  r   r   r   test_reduce_casterrors	  s   
rg  r  c                 C      t j| dgS r  )r   r(   r   rC   r   r   r   rp   	      rp   r   )idc                 C   rh  )Nr   )r   logr  ri  r   r   r   rp   	  rj  r  c              	   C   s  t t jdt j g}t jdd# tjtdd | | W d    n1 s(w   Y  W d    n1 s7w   Y  t t jdt j g}t jdd* tt | | W d    n1 sbw   Y  W d    d S W d    d S 1 szw   Y  d S )Nr   warnrz   zinvalid valuer  ry   )	r   rd   rm  r}   r   r   RuntimeWarningr  FloatingPointError)r  rg   r   r   r   test_ufunc_methods_floaterrors	  s   

"rp  c                 C   s8   | dkrdS t | jsdS | jjdkrt | jS dS )Nr7  Fr  T)r   signbitrn  r1   kindro  )rb  r   r   r   _check_neg_zero	  s   rs  r1   AllFloatc                 C   sl   t | } | jdkr| tdd}n| d}t |}t |}t|| s*J ||7 }t|s4J d S )Nr         )r   r1   rr  r   re   rd   rs  )r1   neg_zerorg   arr2r   r   r   test_addition_negative_zero	  s   




rx  use_initialTFc                 C   s   t | } | jdkr| tdd}n| d}i }|r!||d< ntd tddD ]2}t j|g| | d}t j	|fi |}|dksF|rMt
|sLJ q+t |jrUJ t |jr]J q+d S )Nr  ru  rr  z1-0. propagation in sum currently requires initialr      r<   )r   r1   rr  r   re   r   xfailr   rd   rQ  rs  rq  rn  ro  )r1   ry  rv  r"  r   rg   rh   r   r   r   "test_addition_reduce_negative_zero
  s    




r|  )Brc  r8  r`  r   numpyr   numpy.core._umath_testsrl   _umath_testsr   numpy.linalg._umath_linalgr  r  r  numpy.core._operand_flag_tests_operand_flag_testsr  numpy.core._rational_testsr   numpy.testingr   r   r   r   r   r   r   r	   r
   r   numpy.testing._private.utilsr   numpy.compatr   rm   __dict__r  UNARY_UFUNCSr   r   r9   r   r   r   r   dirrK  rZ  signr(  r[  skipifrd  re  r_  r)   rg  r(   r9  r  paramrp  rs  	typecodesrx  r|  r   r   r   r   <module>   s~    0                  $

%


	
