U
    #c                    @   s  d dl Z d dlZd dlZd dlZd dlZd dlm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 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/0ddd e1eD dd Z2ej/0ddd e1eD e3 dd Z4ej/0dej5ej6gdd Z7ej/j8e dddd Z9ej/0dd e:ej;d gd d! Z<ej/j8e!d"dej/0dd e:ej;d gd#d$ Z=d%d& Z>ej/j8e ddej/0d'd ej;d( e:dej; gd)d* Z?ej/j8e!d"dej/0d+ej@jAej@jBejd,d- d.d/ejd0d- d1d/gd2d3 ZCd4d5 ZDej/0d6ejEd7 d8d9 ZFej/0d6ejEd7 ej/0d:d;d<gd=d> ZGG d?d@ d@ZHdS )A    N)param)assert_assert_equalassert_raisesassert_array_equalassert_almost_equalassert_array_almost_equalassert_no_warningsassert_allcloseHAS_REFCOUNTsuppress_warningsIS_WASM)requires_memory)picklec                 C   s   g | ]}t |tjr|qS  )
isinstancenpufunc).0objr   r   ?/tmp/pip-unpacked-wheel-b2rbor69/numpy/core/tests/test_ufunc.py
<listcomp>   s    r   c                 C   s   g | ]}d |j k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)Zcastingx)Zdtypex   )Zextobjx)Zoutxii->i)Zsigx)Z
signaturexF)ZsubokxT)Z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(   r+   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)Zextobjparrotr)   r$   r   r   r   test_extobj_refcount1   s    z$TestUfuncKwargs.test_extobj_refcountN)__name__
__module____qualname__r&   r*   r,   r.   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
   r+   r   r   fullr
   r   r+   r%   Zinput_dtypeZoutput_dtypefxyxsZysr   r   r   test_unary_PyUFunci   s    
z(TestUfuncGenericLoops.test_unary_PyUFuncc                 C   s   | | S Nr   )r:   r;   r   r   r   f2p   s    zTestUfuncGenericLoops.f2c                 C   sB   t jd|||d}|||d d d }t|| t|j| d S r3   r6   r8   r   r   r   test_binary_PyUFuncs   s    
z)TestUfuncGenericLoops.test_binary_PyUFuncc                   @   s   e Zd Zdd Zdd ZdS )zTestUfuncGenericLoops.fooc                 C   s
   t dS Nr   r   bool_r$   r   r   r   	conjugate|   s    z#TestUfuncGenericLoops.foo.conjugatec                 C   s
   t dS rA   rB   r%   r   r   r   r   logical_xor   s    z%TestUfuncGenericLoops.foo.logical_xorN)r/   r0   r1   rD   rF   r   r   r   r   foo{   s   rG   c                 C   s*   t jdtd}tt t |dk d S )Nr4   r5   r   )r   onesobjectr   allabsr%   r:   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 )Nr4   r5   T)r   r7   rI   r   rJ   rD   r%   rG   r:   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 r3   )r   rH   rI   r   rJ   r"   rL   r   r   r   test_binary_PyUFunc_OO_O   s    z.TestUfuncGenericLoops.test_binary_PyUFunc_OO_Oc                 C   s,   t jd| td}tt t || d S )Nr4   r5   r   r7   rI   r   rJ   rF   rN   r   r   r   test_binary_PyUFunc_OO_O_method   s    z5TestUfuncGenericLoops.test_binary_PyUFunc_OO_O_methodc                 C   s,   t jd| td}tt t || d S )N)r4   r      r5   rQ   rN   r   r   r    test_binary_PyUFunc_On_Om_method   s    z6TestUfuncGenericLoops.test_binary_PyUFunc_On_Om_methodc                 C   s^   t jddgdd}t|d ts$tt |}|jt dksBtt|t jddgdd d S )Ny      ?       @y      @      Or5   r   y      ?       y      @      @)r   arrayr   complexAssertionErrorrD   r+   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n z||}W nB tk
r } z$tt| || W 5 Q R X W 5 d}~X Y nX ||}t|	d| W 5 Q R X 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                    s6   zt   W S  tk
r0    fdd Y S X d S )Nc                      s   t tjj S r>   )getattrr   coreumathr   )attrvalr   r   <lambda>       zgTestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full.<locals>.MyFloat.__getattr__.<locals>.<lambda>)super__getattr__AttributeError)r%   ra   )	__class__rb   )ra   r   rf      s    zUTestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full.<locals>.MyFloat.__getattr__)r/   r0   r1   rf   __classcell__r   rb   )rh   r   MyFloat   s   rk   r5   rU   raiserJ   N)
r   float64pirV   errstate	Exceptionr   typer   astype)r%   r   rk   Znum_arrZobj_arrZres_numexcZres_objr   rj   r   "test_unary_PyUFunc_O_O_method_full   s    $z8TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_fullN)r/   r0   r1   __doc__r   ZsingledoubleZcsingleZcdouble
longdoubleclongdoubleZ	np_dtypespytestmarkparametrizeexpr=   r?   r@   rG   rM   rO   rP   rR   rT   r\   UNARY_OBJECT_UFUNCSru   r   r   r   r   r2   6   s0   -
 

 

 

 
r2   c                   C   s   d S r>   r   r   r   r   r   _pickleable_module_global   s    r   c                   @   s  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d3d4d5 d6d5 gd7d8 Z ejd3e!d9d5 d:d;e!d<d5 d=d;gd>d8 Z ejd?d@dAdBgdCdD Z"dEdF Z#dGdH Z$dIdJ Z%dKdL Z&ejdMe'j(e'j)gdNdO Z*dPdQ Z+dRdS Z,ejj-e.dTdUdVdW Z/dXdY Z0dZd[ Z1d\d] Z2d^d_ Z3d`da Z4dbdc Z5ejjdddegdge'6dffdgdge'6dgfe'7dhe'6difgdjdkdlgdmdndo Z8dpdq Z9drds Z:dtdu Z;dvdw Z<dxdy Z=dzd{ Z>d|d} Z?d~d Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXeYddd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`ejddejde'adddge'adgdgdgge'adddgdddgdddggfddń Zbejdde'adddgfdgdddgfdfejde'jc dfdd̄ Zddd΄ ZeddЄ Zfdd҄ ZgddԄ Zhddք Zidd؄ Zjddڄ Zkdd܄ Zlddބ Zmdd Zndd Zodd Zpdd Zqdd Zrdd Zsdd ZtejdMe'jue'jvgejd=ddewfewddfdewdfgdd ZxejdMe'jue'jve'jygejd=ezdewfewdezfdewezfgdd Z{ejdMe'jue'jve'jygdd Z|ejdMe'jue'jve'jygdd Z}ejdMe'jue'jve'jygdd Z~dd Zdd Zdd Zdd Zejd ddgdd Zejddfdddddhgejdddgejd	e'j(je'jjgd
d Zdd Zd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 ]H}tttjtj|dtjk ttjtj	|d}t|tj	k qd S )Nr   r   )protocol)
ranger   HIGHEST_PROTOCOLr   loadsdumpsr   sin_rational_teststest_add)r%   protor[   r   r   r   test_pickle   s    zTestUfunc.test_picklec                 C   s   d}t t|tjk d S )NsM   cnumpy.core
_ufunc_reconstruct
p0
(S'numpy.core.umath'
p1
S'cos'
p2
tp3
Rp4
.)r   r   r   r   cos)r%   Zastringr   r   r   test_pickle_withstring   s    z TestUfunc.test_pickle_withstringc                 C   s,   t jt_tttj}|t jks(td S r>   )umtZ_pickleable_module_global_ufuncr   r   r   r   r   rX   rE   r   r   r   test_pickle_name_is_qualname   s    z&TestUfunc.test_pickle_name_is_qualnamec              	   C   sh   d}t |}t ttt |d t |d d  }tt j||d d d ddddg d S )N   r   r   rS         )	r   arangerV   listzipZravelr   r"   reduceat)r%   Lr:   idxr   r   r   test_reduceat_shifting_sum   s    
0z$TestUfunc.test_reduceat_shifting_sumc                 C   s   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   r]   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%   ZenabledZnum_dimsZixsflagsZsizesr   r   r   test_signature03  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   sV   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   rS   r]   r   r   r   r   r   r   r   r   r   test_signature2G  s      


zTestUfunc.test_signature2c                 C   sV   t ddd\}}}}}t|d t|d t|d t|| jfd  t|d d S )Nr   r   z(i1, i12),   (J_1)->(i12, i2)r   r   r   )r   r   r   r   rS   r]   r   r   r   r   r   r   test_signature3Q  s      


zTestUfunc.test_signature3c                 C   sV   t ddd\}}}}}t|d t|d t|d t|| jfd  t|d d S )Nr   r   z(n,k),(k,m)->(n,m)r   r   r   r   r   r   r   r   r   rS   r   r   r   r   r   r   r   r   test_signature4Z  s      


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_signature5d  s      



zTestUfunc.test_signature5c                 C   sN   t ddd\}}}}}t|d t|d t|d t|d t|d d S )Nr   z(3)->()r   r   r   rS   r   r   r   r   r   test_signature6p  s      



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 )NrS   r   z(3),(03,3),(n)->(9)r   r   r   r   r   r   r   r   r   r   rS   r   	   r   r   r   r   r   test_signature7y  s      


zTestUfunc.test_signature7c                 C   sX   t ddd\}}}}}t|d t|d t|d t|| j| jdf t|d d S )NrS   r   z(3?),(3?,3?),(n)->(9)r   r   r   r   r   r   r   r   r   r   r   r   r   test_signature8  s      


zTestUfunc.test_signature8c                 C   sN   t ddd\}}}}}t|d t|d t|d t|d t|d d S )Nr   z(  3)  -> ( )r   r   r   r   r   r   r   r   test_signature9  s      



zTestUfunc.test_signature9c                 C   sX   t ddd\}}}}}t|d t|d t|d t|| j| jdf t|d d S )NrS   r   z ( 3? ) , (3? ,  3?) ,(n )-> ( 9)r   r   r   r   r   r   r   r   r   test_signature10  s      


zTestUfunc.test_signature10c              	   C   s&   t t tddd W 5 Q R X d S )Nr   r   z((i)),(i)->()r   
ValueErrorr   r   r$   r   r   r   (test_signature_failure_extra_parenthesis  s    
z2TestUfunc.test_signature_failure_extra_parenthesisc              	   C   s&   t t tddd W 5 Q R X d S )Nr   r   z(i),)i(->()r   r$   r   r   r   .test_signature_failure_mismatching_parenthesis  s    
z8TestUfunc.test_signature_failure_mismatching_parenthesisc              	   C   s&   t t tddd W 5 Q R X d S )Nr   r   z(i),->()r   r$   r   r   r   2test_signature_failure_signature_missing_input_arg  s    
z<TestUfunc.test_signature_failure_signature_missing_input_argc              	   C   s&   t t tddd W 5 Q R X d S )Nr   r   r   r$   r   r   r   3test_signature_failure_signature_missing_output_arg  s    
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  s    zTestUfunc.test_get_signaturec              	   C   s  dt jddd }tt |ddddg tt$ tt j|dddd	d
d
dg W 5 Q R X tt j|dddd	d
d
dg tt$ tt j|dddd	d
d
dg W 5 Q R X tt j|dddd	d
d
dg t jddd}t j|d|d t|dddg d
|d d < tt t j|dd|dd W 5 Q R X t|d
d
dg d
|d d < t j|dd|dd t|d
d
dg d
|d d < tt t j|dd|dd W 5 Q R X t|d
d
dg d
|d d < t j|dd|dd t|d
d
dg d S )N      ?rS   f8r5   r         ?iunsafe)r'   castingr   r   )i4)r   r   r   r   out)r'   r   r   )r   r   r   r"   rz   warnsDeprecationWarningzerosr%   abr   r   r   test_forced_sig  s>    (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 5 Q R X d S )NrS   r]   )NNNr'   r>   r(   )r   r"   r   maximumrz   raisesr!   )r%   Zres1Z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 )NrS   r]   r   )rr   r   r+   rn   r"   )r%   Zfloat_dtyper   r   r   test_signature_dtype_type  s    z#TestUfunc.test_signature_dtype_type	get_kwargc                 C   s
   t tdS Nr5   dictr:   dtr   r   r   rc     rd   zTestUfunc.<lambda>c                 C   s   t td d fdS Nr   r   r   r   r   r   rc     rd   c                 C   sn   t d}tt|}||k	s&tt jd||j|ks@tt dd}t j||f|djdksjtd S )Nint64r   r   sZm8m8[s])r   r   )r   r+   r   r   r   rX   r"   	timedelta)r%   r   r   Zint64_2tdr   r   r   &test_signature_dtype_instances_allowed  s    
z0TestUfunc.test_signature_dtype_instances_allowedc                 C   s
   t | dS r   r   r:   r   r   r   rc     rd   r+   idc                 C   s   t | d d fdS r   r   r   r   r   r   rc     rd   r(   c              	   C   s   d}t jt|d  tjd|td  W 5 Q R X t jt|d tjd|td W 5 Q R X t jt|d tjd	|d W 5 Q R X d S )
Nz/The `dtype` and `signature` arguments to ufuncsmatchrS   r   r   zm8[ns])rS   r   )rS   r   )rS   r   )rz   r   r!   r   r"   r+   newbyteorder)r%   r   msgr   r   r   r     s    $ r   r   Z	same_kindr   c              	   C   s   t jt dt ddd}|jdks*tt jt dt ddd}|jdksTttt t jdt 	ddd W 5 Q R X tt t jdt 	ddd W 5 Q R X d S )N      ?r   dr5   )NNr   r   rS   )
r   ldexpfloat32int_r+   rX   rz   r   r!   uint64)r%   r   r[   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 5 Q R X ttdtd t t" tjtdtddd W 5 Q R X d S )Nr   r   )er   Nr   )rz   r   r!   r   r"   float16r   rn   r$   r   r   r   *test_partial_signature_mismatch_with_cache  s
    &z4TestUfunc.test_partial_signature_mismatch_with_cachec              	   C   sr   t jddt jdd}|dks tt jddd d t jfdd}|dksFttt t jddt jd W 5 Q R X d S )Nr   gffffff@r   r+   r   r   )r(   r   r5   )r   powerintprX   rz   r   r!   r%   r[   r   r   r   +test_use_output_signature_for_all_arguments  s    z5TestUfunc.test_use_output_signature_for_all_argumentsc              	   C   s   t jtdd tjdddd W 5 Q R X t t tjdddd W 5 Q R X t t tjdddd W 5 Q R X t t tjddd	d W 5 Q R X t t tjddd
d W 5 Q R X t t tjdddd W 5 Q R X d S )Nz1the signature object to ufunc must be a string orr   rS   r]   g     ^@r   z%^->#s   ii-izii>i)Nr   s   ->i)rz   r   r!   r   r"   r   UnicodeDecodeErrorr$   r   r   r   test_signature_errors#  s    zTestUfunc.test_signature_errorsc                 C   sf   t jdddg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 )
Nz
2010-01-02z
1999-03-14z1833-03z>M8[D]r5   Mr4   r   m)r   rV   r   reducer   r"   )r%   r   rZ   r   r   r   test_forced_dtype_times8  s    z!TestUfunc.test_forced_dtype_timesr   c              	      s    fdd}t jdddgt jd}||j }||}||dd}t|| tt	 ||dd W 5 Q R X ||d	d}t|| tt	 ||t j
d	d
 W 5 Q R X ||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  |S r>   )nin)rZ   kwargsr   r   r   
call_ufuncH  s    z.TestUfunc.test_cast_safety.<locals>.call_ufuncr          @      @r5   nor   equivr   r   N)r   rV   r   rs   r+   r   r   rz   r   r!   rn   )r%   r   r
  rZ   Zarr_bsexpectedr[   r   r	  r   test_cast_safetyC  s    

zTestUfunc.test_cast_safetyc                 C   sF  t d}t d}t d}dD ]}t |}||}||}t|| g|| gD ]|\}}	|dkrt|t|	 }nt|t|	 }t ||	}
t	t 
|
jd}t|
||d |dkrt|
jjd	k nt|
jj|jk dD ]"}t |}ttt j||	|d
 qdD ] }t |}|dkrFttt j||	|d
 nt|t|	 }t	t 
|jd}t <}|t t t 
|jst	t 
|jd}nd}W 5 Q R X t jddd t j||	|d
}
W 5 Q R X t |
s|dkrqt|
|||d t|
jj|jk qdD ]}t |}t|t|	 }t	t 
|jd}t <}|t t t 
|jst	t 
|jd}nd}W 5 Q R X t j||	|d
}
t |
s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 )Nr4      r   ZbhilqBHILQefdgFDGZFDGgV瞯<)rtolZ
bhilqBHILQrn   r5   ZefdggwMh ignore)invalidZoverr   )r  atolr   r           )r   rV   r+   rs   	itertoolsproductrW   floattrue_dividemaxfinfo
resolutionr
   r   namer   r!   r   filterUserWarningisnanZtinyrp   isfiniterH   rC   )r%   r   r   tgtZtcr   ZaaZbbr:   r;   r[   r  ZtcoutZdtoutsupr  r   r   r   test_true_divideb  st    






"






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  r5         $@r   r]      )r   rH   r   r   sumsizern   r%   r   r   r   r   test_sum_stability  s    zTestUfunc.test_sum_stabilityfp errors don't work in wasmreasonc                 C   s  t tjtjtjtjfD ]}dD ]}tjdd}tdt	 |||d  d }t
| }tt|d|  tjd|d |d}tt|| tt|d|  tt|d d d | tt|d	|  W 5 Q R X 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  Trecordalwaysr   r   r5   r   rS   r'  g     @o@g     d@r   r  )r#   r   r   r   rn   rx   warningscatch_warningssimplefilterRuntimeWarningr#  r   lenr   r   r*  rH   )r%   r   vwr$  Zoverflowr   r   r   r   test_sum  s0    zTestUfunc.test_sumc              	   C   s  t jt jt jfD ]}dD ]}|||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 )Nr1  r   r   y              ?r5   r   r'  y     @o@     @o@rS   y     d@     d@r<  r=  r>  y       @       @)r   Z	complex64Z
complex128ry   emptyr   realimagr   r*  rH   )r%   r   rD  r$  r   r   r   r   test_sum_complex  s(    ,zTestUfunc.test_sum_complexc                 C   sX   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dddg d S )NrS   r   initialr   g?皙?333333?)r   rS   r   r5   r   r   )axisrL     )r   r   r*  r   rH   r   r$   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         @)rP  rL  rU        "@)r   r   r*  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   rS   r   rP  )r   r   reshaper   r   r   r*  r,  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 5 Q R X t ddd}t d}t d}tttj||| t d}	t|||	}
t|
|	k d S )N	broadcastr]   r   r   r   r   r   rZ  err_msgz"extend & broadcast loop dimensionsr   r   r2  )r]   r   r]   r   r   r   r   rS   )rS   r   r   r   Tr9  r;  r   r   r   r   )r   r   r[  r   r   r   r*  r   r   rV   Zbroadcast_arraysr   stridesr?  r@  rA  rC  r   rH   rG  )r%   r   r   r   urD  r:   rE  r   Zout2cr   r   r   test_broadcast  sB    $$





zTestUfunc.test_broadcastc                 C   sj   t ddd}t d}t j|||d |t dd k sFttj|||d |dk sftd S )NrS   r   )r   r]   rS   r   r   r   )	r   r   r[  rG  r"   rJ   rX   r   r   r%   rZ   r   r   r   r   test_out_broadcasts>  s    
zTestUfunc.test_out_broadcastsrZ   r   r   r   )r]   rS   rb  z(1,)->()z
(2,)->(1,)z(4, 3)->(4, 1))idsc              	   C   s\   t jtdd tj||d W 5 Q R X t jtdd tjtd||d W 5 Q R X d S )Nznon-broadcastabler   r   r   )rz   r   r   r   positiver"   rH   rg  r   r   r   test_out_broadcast_errorsM  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   shortr5   rY  r   rZ  r_  ztype cast on one argumentrM  )r   r   r[  r   r   r   r*  r   )r%   r   r   r   r   r   r   test_type_cast[  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>i4r5   rY  r   rZ  r_  zlittle endianz<i4r   z>f8z<f8r   )r   r   r[  r   r   r   r*  r   r+   absolutenegative)r%   r   r   ZBaZLar   r   r   test_endianf  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_  rZ     r   rS   r]   )	r   r   r[  r   r   r   r   r*  T)r%   r   r:   r   r   Z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 argumentrQ  r   rS   r   r]   r   r   rY  r#   r5   r   rZ  r_  r   zoutput argument with type castint16z(output argument with incontiguous layoutr   rS   r]   ).r   )r   r   r[  r   r   r   r   r*  )r%   r   r   r   re  r   r   r   test_output_argument  s.     zTestUfunc.test_output_argumentc                 C   s,  t j}tdd}tddd}|||}t||| d |||dddgd	}t||| d |||dddgd	}t||| d |||dddg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|||dddgd	 tt|||dddgd	 tt|||dddgd	 tt|||ddgd	 t j}tdd}tddd }|||}t|t|| |||dddgd	}t|t|| |||dddgd	}t|t|| |||dddgd	}t|t|
ddd|
dddd td}||||dddgd}t||k t|t|| td}||||dddgd}t||k 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|||dddgd	 tt|||dddg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|||ddd gd	 tt|||ddd g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      ;@rS   rS   rS   r(        3@rS   r   rS   r   r   r   )axesr5   r   r   r         )r~  r<  r   rQ  ru  r2  r   r   r   r   r   r   rY  )r   r   rS   )r   r   rS   r   )r   r}  )r   r   r   rS   )rS   r   rZ  )r  r  r  r<  )r<  r<  ra  r   r   T)r}  r-   )r   r   r   r   r[  r   r*  Zint8rV   int32	transposer   r!   r   matrix_multiplymatmulrG  r   r   r"   )r%   r   r   r   re  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||k 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||k t|tj
|d	d t j
||dd}t||k 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 )Nry  rz  r(  r{  r|  r   rZ  )rP  r   r   r   rY  r4   r4  r     r   rP  r   )rP  r}  r   r   rS   r5   r   )r   r   r   r   r[  r   r*  
zeros_liker   innerwtcumsumZ
empty_liker   r!   r  rG  r+   r   r"   )	r%   r   r   r   re  r   r   rE  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||k 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 |||dddgdd}t||| d |||dddgd	d}t||| jdd	d |||ddgdd}t||| d |||dddg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 |||dddgd	d}t||	ddd| jdd	d |||dddgd	d}t|||	ddd jdd	d |||dddg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 )Nry  rz  r(  r{  r|  r   FkeepdimsT)r  r   rP  r  r   r   r   )r}  r  r   r   rS   rS  r   rY  r4   r4  r  r  truer   )r   r   r   r   r[  r   r*  r  r   r  eyenewaxisumldetZslogdetr  r   r!   r  r"   )r%   r   r   r   re  r   r   r  Z
expected_sZ
expected_lcsZclrE  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   rY  r4   r4  r  r  r   rZ  d   |   rw        ,  iD  )r   r   r[  r   r   r  r*  r%   r   r   rE  r   r   r   test_innerwt  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   r5   r   rZ  N)r   rV   r   r   r  r*  r  r   r   r   test_innerwt_empty  s    zTestUfunc.test_innerwt_emptyc                 C   s   t d}tt||t d t d}t|d ||}t||k 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.rS   rS   rS   r   r   r   r]   rS  r  )rS   r]   N)r   r  r   r   Zcross1dr   r   Zvstackr   r   r   )r%   r   r   resultr   r   r   test_cross1d  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 )NrQ  ru  r   r2  r  r   rS   rr  )r]   r   r   r   rS   r<  r   r   r   )r   r   r[  r  r   r  r  r   r   r   squeezers  swapaxesr  )r%   matZ
single_vecZcol_vecZcol_vec_arrayZ
mm_col_vecZmatmul_col_vecZ
matmul_colZrow_vecZrow_vec_arrayZ
mm_row_vecZmatmul_row_vecZ
matmul_rowZmm_row_col_vecZmatmul_row_col_vecZmatmul_row_colZmm_row_col_arrayZ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 r>   )compare_matrix_multiply_resultsr   r   rw   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   r4   )r4   r   r   )r4   r4   )r   r  r   rH   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 ]}	|D ]}
|D ]}|D ]}||	| }||
| }|o|jd k	}|o|jd k	}|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 qqqqt|ddd d S )Nr   rS   r]   r5   zmatrix multiply on type %sc                    sp   | dkrdgfS d} | d }|D ]F}t | D ]8}|| d g }|| || d < | d ||< ||f7 }q0q$|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 rA   r   )s1s2r   r   r   broadcastable  s    z@TestUfunc.compare_matrix_multiply_results.<locals>.broadcastabler   Tr<  r   .r=  rZ  z %s %sr_  zreference check)r   rV   randomZrandr+   r  r  r  r  shaper   r   r  r*  r  r  strr   )r%   tpd1Zd2r   r  Z	permute_3Zslice_3refp1p2r  r  Za1Za2r   )r  r  r   r    s@    

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 )
NrQ  r5   r]   rS   r   r   r   r   rZ  )r   r   r  r[  rG  r  r+   r   Zeuclidean_pdistsqrtr*  Ztriboolr   r   r   )r%   r   r   r   r   r   r   test_euclidean_pdist1  s    *(
zTestUfunc.test_euclidean_pdistc                 C   s&   t d}t|}t||  d S )Nr4   )r   r   r   r  r   )r%   r   r  r   r   r   test_cumsum;  s    

zTestUfunc.test_cumsumc                 C   s  t jdd ddddg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 )NrS   TFtest r5   c                 S   s   g | ]}|pd qS r>   r   r   r:   r   r   r   r   C  s     z1TestUfunc.test_object_logical.<locals>.<listcomp>c                 S   s   g | ]}|pd qS Tr   r  r   r   r   r   E  s     rQ  c                 S   s   g | ]}|pd qS rQ  r   r  r   r   r   r   G  s     blahc                 S   s   g | ]}|pd qS r  r   r  r   r   r   r   I  s     c                 S   s   g | ]}|od qS r>   r   r  r   r   r   r   L  s     c                 S   s   g | ]}|od qS r  r   r  r   r   r   r   N  s     c                 S   s   g | ]}|od qS r  r   r  r   r   r   r   P  s     c                 S   s   g | ]}|od qS r  r   r  r   r   r   r   R  s     c                 S   s   g | ]
}| qS r   r   r  r   r   r   r   U  s     )r   rV   rI   r   
logical_orlogical_andZlogical_notr  r,  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                   @   s   e Zd Zdd ZdS )z8TestUfunc.test_object_comparison.<locals>.HasComparisonsc                 S   s   dS )N==r   r%   otherr   r   r   __eq__\  s    z?TestUfunc.test_object_comparison.<locals>.HasComparisons.__eq__N)r/   r0   r1   r  r   r   r   r   HasComparisons[  s   r  Tr5   r  )r   rV   r   equalrI   )r%   r  Zarr0dZarr1dr   r   r   test_object_comparisonZ  s    z TestUfunc.test_object_comparisonc                 C   sP  t jdddgtd}tt |d tt |d tt |d t jdddg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d	ddg d S )Nr   r   re  r5   abcTFr   r   r   r   r   rK  rS   )rL  rU  )
r   rV   rI   r   r*  r  minprodanyrJ   r,  r   r   r   test_object_array_reductionh  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 )Nr]   r5   c                 S   s   g | ]
}d gqS r>  r   r   r   r   r   r   r   ~  s     zBTestUfunc.test_object_array_accumulate_inplace.<locals>.<listcomp>r   c                 S   s   g | ]}d g| qS r>  r   r  r   r   r   r     s     )r   rS   r   r4   r   r]   c                 S   s   g | ]
}d gqS r   r   r  r   r   r   r     s     r   r   r  c                 S   s   g | ]}d g| qS r  r   r  r   r   r   r     s     )r   rH   rI   r   r"   
accumulater   rV   )r%   rZ   r   r   r   $test_object_array_accumulate_inplace{  s    z.TestUfunc.test_object_array_accumulate_inplacec              	   C   sb   t jt jdddgtd}t|t jdddgtd tt t jdd dg W 5 Q R X d S )Nr   r   r   r5   rS   )	r   r"   r  rV   rI   r   rz   r   r!   r   r   r   r   $test_object_array_accumulate_failure  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 )Nr]   r5   c                 S   s   g | ]
}d gqS r>  r   r  r   r   r   r     s     z@TestUfunc.test_object_array_reduceat_inplace.<locals>.<listcomp>c                 S   s   g | ]
}d gqS r>  r   r  r   r   r   r     s     r   r  c                 S   s   g | ]
}d gqS r  r   r  r   r   r   r     s     r   c                 S   s   g | ]
}d gqS r  r   r  r   r   r   r     s     r   r  )	r   rG  rI   r   r"   r   r   r   rH   rg  r   r   r   "test_object_array_reduceat_inplace  s    
z,TestUfunc.test_object_array_reduceat_inplacec              	   C   sl   t jt jdd dgtdddg}t|t jd dgtd tt t jdd dgddg W 5 Q R X d S )Nr   r   r5   r   )	r   r"   r   rV   rI   r   rz   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 ]`}tt |d tt |d tt |d tt |d tt	t j
| tt	t j| qd S )Nr5   r   r   FT)r   rV   rI   r   r*  r  r  rJ   r   r   r  r  r,  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   rZ  r<  )r   rV   r   Z	AxisErrorrJ   r  r,  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k t
ttjtdddtjk t
ttjtdddtjk t
ttjtdddtjk t
ttjdddtjk G dd	 d	tj}td
|}t
tt||k d S )NrS   r   rZ        @TFg      @c                   @   s   e Zd ZdS )z0TestUfunc.test_scalar_reduction.<locals>.MyArrayNr/   r0   r1   r   r   r   r   MyArray  s   r  r   )r   r   r*  r  r  rJ   r  r  r   r  r   rr   r   rC   ndarrayrV   view)r%   r  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   r5   r   )	r   rH   r   rn   r"   r   r   r   subtractr%   r   r   re  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|dddddddg 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   rU  r   r]   r   rS      r4  r   TF   )	r   r   rH   r   r"   r   r[  r   r  r  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|||ddddddddddg
d t|ddddddddddg
 d S )Nr4   r   r   r   r  r   )r   rH   r   rn   r"   r   r  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   r5   TrT  )r   rV   r   r  r   r  rn   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~t
d S )N)  r]   )r  r   rN  r   )rU  r   )r   r  Z	full_likelessZbroadcast_tor  r   rs   r  r  rX   )r%   r   r   rU  r   Z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ddddg t tjj|dddddg t tjj|ddddg t tjj|ddddddgddddgddddgg t tjj|ddddddgddddgg t tjj|d	ddddgdddgg t tjj|d
d| d|d< d|d< t tjj|d dd t tjj|ddddddg t tjj|dddddg t tjj|ddddg t tjj|ddddddgddddgddddgg t tjj|ddddddgddddgg t tjj|d	ddddgdddgg t tjj|d
d| d|d< d|d< t tjj|d dd t tjj|ddddddg t tjj|dddddg t tjj|ddddg t tjj|ddddddgddddgddddgg t tjj|ddddddgddddgg t tjj|d	ddddgdddgg t tjj|d
d| d S )Nr   .r   )r   r   r   rZ  r  rO  r  r   r   )r   r   r   )r   r   r   )r   r   minimumr  r,  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sVt|d dksftd S )	N)r   l        uint8r   rS   r   r]   r   rZ  )r   r   r   r  rX   rY   r   r   r   &test_identityless_reduction_huge_arrayP  s    z0TestUfunc.test_identityless_reduction_huge_arrayc                 C   s   t jddd}| | d S )Nrw  Corderr   rG  r  r,  r   r   r   "test_identityless_reduction_corder[  s    z,TestUfunc.test_identityless_reduction_corderc                 C   s   t jddd}| | d S )Nrw  Fr  r  r,  r   r   r   "test_identityless_reduction_forder_  s    z,TestUfunc.test_identityless_reduction_forderc                 C   s$   t jddddd}| | d S )N)r   r]   rS   r  r  r   r   r   rG  r  r  r,  r   r   r   &test_identityless_reduction_otherorderc  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)rS   r   r]   r  r  r   r   r  r,  r   r   r   %test_identityless_reduction_noncontigg  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  i1r5   r   r   )rS   r]   r   )r   rG  r  r  r  r,  r   r   r   /test_identityless_reduction_noncontig_unalignedl  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   rK  r   r]   r4   r5   r3  )r   r   r   r  r  infr   r   r"   Z_NoValuerV   rI   r%   r   r[   r   r   r   test_initial_reductions  s    z TestUfunc.test_initial_reductionrP  )r   r   NrU  FTc                 C   sh   t ddd}| }t |}t j|||d t jj|||d}||}t	|| t
|| d S )NrW  rS   r  rP  rU  )r   r   r[  copyr  rj  r"   r  r*  r   r   )r%   rP  rU  r   a_copya_checkr[   checkr   r   r   test_reduction_with_where  s    


z#TestUfunc.test_reduction_with_wherer  r   )NTrL  rV  c           	      C   sl   t ddd}| }t |jt j }t j|||d t jj	||||d}|j
||d}t|| d S )NrW  rS   r  )rP  rU  rL  rK  )r   r   r[  r  r7   r  r  rj  r   r  r  r   )	r%   rP  rU  rL  r   r  r  r[   r  r   r   r   %test_reduction_with_where_and_initial  s    z/TestUfunc.test_reduction_with_where_and_initialc                 C   s4   t ddd}dddg}ttt jj||d d S )NrW  rS   FTrT  )r   r   r[  r   r   r   r  r  r   r   r   #test_reduction_where_initial_needed  s    
z-TestUfunc.test_reduction_where_initial_neededc                 C   s   t dddgdddgg}t jj|dd}t|dddg t jj|d	d}t|ddg t jj|d
d}t|| ttt jj|dd d S )Ng       @r  r   r   g      ?r   rZ  rS  r   r   r  )r   rV   divider  r   r   r   r	  r   r   r   *test_identityless_reduction_nonreorderable  s    
z4TestUfunc.test_identityless_reduction_nonreorderablec                 C   sd  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 ]V}|jtddd |jtddd |jtddd |jtd	dd qd S )Nc                 _   s   | || d S r>   r   r9   argsr  r   r   r   ok  s    z+TestUfunc.test_reduce_zero_axis.<locals>.okc                 _   s   t t| f|| d S r>   )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   rZ  r   r   r  rO  rS   )r   r   r   r4   r  )r   r   )expectfuncr  r  r   r   r   t  s"    """" z*TestUfunc.test_reduce_zero_axis.<locals>.t   r   r   r   rZ  )r  r   )r   r  )r  r  )r   r   r   identityr  r   r"   r  )r%   r  r  r  r   r   r   r   test_reduce_zero_axis  s*    zTestUfunc.test_reduce_zero_axisc                 C   s   t jdddgtd}ttt j|ddddg ttt j|d|d	 d
d }tt||d tt j|d|dd t|dddg d S )Nr   r   rS   r5   g?g @g@gffffff@r   c                 S   s   | |7 } d S r>   r   )r   r   r   r   r   add_inplace  s    z0TestUfunc.test_safe_casting.<locals>.add_inplacer   r   r   r]   )r   rV   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dddgdd}t jdddgdd}t jdtjd}t|||}t jdddgtjd}t|| t||}t|| tj||t j|d}t|| t	t
 t|t d W 5 Q R X d S )	Nr   r   r   i8r5   rS   r]   r   )r   rV   rG  r   rationalr   r   rs   uint16r   r!   )r%   r   r   re  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dd	ddgd
ddd
gddddgddddggdd t d}t|d t|d t|ddg t|d d S )Nr4  lr5   r]   r   rS   r   r   r   r      r     rQ  r)  r3  r4   )r   r   r[  opflag_testsZinplace_addr   rV   r   r   r   r   test_operand_flags4  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,u8r5   )r   r]   r   )
Znumpy.core._struct_ufunc_testsr_   Z_struct_ufunc_testsr   rV   Zadd_tripletr   r   RuntimeErrorZregister_fail)r%   Zstruct_ufuncr   r   r  r   r   r   test_struct_ufuncA  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   rS   r]   r5   )r   rV   r   r#  Ztest_add_rationalsr   )r%   r   r   r  r  r   r   r   test_custom_ufuncK  s.    







zTestUfunc.test_custom_ufuncc              	   C   s6   t t$ tjtddtjtd fd W 5 Q R X 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 r>   r  )r%   r  r   r   r   __init__m  s    z:TestUfunc.test_custom_array_like.<locals>.MyThing.__init__c                 S   s
   | j d S Nr   r2  r$   r   r   r   __len__p  s    z9TestUfunc.test_custom_array_like.<locals>.MyThing.__len__c                    sJ     j d7  _ t|ts|f}t|| jkr4td | jt|d  S )Nr   Zboo)getitem_countr   tuplerC  ndim
IndexErrorr  )r%   r   MyThingr   r   __getitem__s  s    
z=TestUfunc.test_custom_array_like.<locals>.MyThing.__getitem__c                    s     j d7  _ | S rA   )
rmul_countr  r:  r   r   __rmul__|  s    z:TestUfunc.test_custom_array_like.<locals>.MyThing.__rmul__N)
r/   r0   r1   Z__array_priority__r=  r6  r3  r5  r<  r>  r   r:  r   r   r;  g  s   	r;  r   r  r   r   )r   rn   r   r=  r6  r$   r   r:  r   test_custom_array_likee  s    z TestUfunc.test_custom_array_likec                 C   s  t d}t j|dddgd t|dddddddd	d
dg
 t d}t dddg}t j|dddg| t|dddddddd	d
dg
 t ddd}t dddgdddgdddgg}t j|td dddgf| t|dddgdddgdddgg t dddd}t dddg}t j|td td dddgf| t|dddgdddgdddggdddgdddgd d!d"ggd#d$d%gd&d'd(gd)d*d+ggg t ddd}t dddgdddgdddgg}t j|dddgtd f| t|dddgd,dd-gd.d/dgg t dddd}t dddg}t j|td dddgtd f| t|dddgd0dd1gd2d/dggddd3gd4dd5gd6d7d8ggd#d9d:gd;d'd<gd=d>d?ggg t ddd}t dddg}t j|ddddgf| t|dddgdddgdd	d
gg t dddd}t dddg}t j|dddgdtd f| t|dddgdddgdd	d
ggd@ddAgddBdCgd dDdEggdFdGdHgd&dIdJgd)dKdLggg t dddd}t dddg}t j|td td td f| t|dddMgdNdOdPgd2d/dggdQdRdSgdTdUdVgd6d7d8ggdFdGdHgdWdXdYgd=d>d?ggg t d}t j|dddg t|ddddddZdd	d
dg
 t d}t j|d[d t|d t	t
t jj|dd t	t
t jj|g d t d}t j|ddddgd\ t|t ddd]d^dddd	d
dg
 t d}|d dk}t j||ddddd
g t|dddddddd	ddg
 t jdd_d`}t j|dddg t|ddddddadd	d
dg
 t d}|d d d f d d ddf }t j|ddgd t|t d t dddgt db }t ddddgt dc }t j||d t|dd
ddg t jdddgtd`}t	tt jj|ddgd t|t jdddgtd` t	tt jjt ddg t dddg}t j|dgd tt dddg| d S )eNr4   r   r   r   r   r]   rS   r   r   r2  r   r     i   r  r     f   i     i_  i4  r  i  i     i     rQ  i     r3  i     r)  i        i     rr  i     i  i           i]  j   r(     if  s      i=  r5  r     io  r     iF     ic  r)  r  r4     v      i@           r  i.  g      i1  m      i7  p      i:  y      iC  r   r  i>  .   Zu4r5   l    r   r9   r   )r   r   r"   atr   rV   r[  r  ro  r   r9  r   r  invertr   r+   r   rI   r!   r   modfr   )r%   r   r   indexorigvaluesr   r   r   test_inplace_fancy_indexing  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   rS   r]   )
r   rH   r   r!   r  rg  rV   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   r5   r  r   r   rZ  r   r   Fr  Tr>  rK  rT  )rP  r+   r   r  )r+   r   r  )r   r  )r   r  rL  rU  r   r  )rP  r+   r  r+   r   r   r+   )r  r+   r   )rP  r+   r  r  )r  r  r   )rP  r+   r  r   r  )rP  r+   r   r  )r   r"   r  rH   r#   r+   r   r[  r  r   r!   )r%   r9   r   orr   r   r   test_reduce_arguments  st    "
  zTestUfunc.test_reduce_argumentsc                 C   st   G dd dt j}t ddd}|jdd }||}t jdd	d	d	gtd}tt 	|||d
 kkd d S )Nc                   @   s   e Zd Zdd ZdS )z,TestUfunc.test_structured_equal.<locals>.MyAc                 _   s   t ||dd |D |S )Nc                 s   s   | ]}| tjV  qd S r>   )r  r   r  )r   inputr   r   r   	<genexpr>a  s   zOTestUfunc.test_structured_equal.<locals>.MyA.__array_ufunc__.<locals>.<genexpr>)r^   )r%   r   methodinputsr  r   r   r   __array_ufunc__`  s
    z<TestUfunc.test_structured_equal.<locals>.MyA.__array_ufunc__N)r/   r0   r1   r{  r   r   r   r   MyA_  s   r|        (@r]   rS   zf8,f8,f8r5   TFr   )
r   r  r   r[  r  r  rV   r  r   rJ   )r%   r|  r   raZ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 )Nr  r   )r   rV   r   r   r   r   r   test_scalar_equalj  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||| qd S )N1r   r   r  )r   r   r"   r  r/  r  r  Zfloor_divideZbitwise_andZ
bitwise_orZbitwise_xorZ
left_shiftZright_shiftZfmaxZfminfmodhypotZ	logaddexpZ
logaddexp2r   r  modZgreaterZgreater_equalr  Z
less_equalr  	not_equalrV   r   r!   )r%   Zbinary_funcsr   r   re  r9   r   r   r    test_NotImplemented_not_returnedt  sD                        	
z*TestUfunc.test_NotImplemented_not_returnedNc                 C   s4   t jdd dgtd}||||d}|jtks0td S )NTFr5   r   )r   rV   rI   r+   rX   )r%   r   r(   r   r[   r   r   r   %test_logical_ufuncs_object_signatures  s    z/TestUfunc.test_logical_ufuncs_object_signaturesc              	   C   s8   t dd dg}tt ||||d W 5 Q R X d S )NTFr   )r   rV   rz   r   r!   )r%   r   r(   r   r   r   r   +test_logical_ufuncs_mixed_object_signatures  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sHtt jdt jd}|ddgd|j}t||||d| t jd	t jd}|j||ddkstt jd
gdd}t jd	|jd}|j||ddkstd S )N   1ZV3r5   r   r  Tr   r   r   rS   r   r   )	r   rV   r   r  rX   r   r  rs   r+   )r%   r   r   re  r   r  r   r   r   $test_logical_ufuncs_support_anything  s    z.TestUfunc.test_logical_ufuncs_support_anythingc              	   C   sV   t jtdd |dgdg W 5 Q R X t jtdd |dddg W 5 Q R X 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  320N)rz   r   r!   r  )r%   r   r   r   r   !test_logical_ufuncs_reject_string  s    z+TestUfunc.test_logical_ufuncs_reject_stringc              	   C   sJ   t d}t ddg}| }tt ||||dd W 5 Q R X d S )Nr  r   r  r  r   )r   rV   r  rz   r   r!   )r%   r   r   re  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s8ttt j|t j| tt j|dgt j|dg d S )Nr4   z>i8r5   z<i8r   )r   r   r"   r  rX   r   r  r   )r%   Zarr_beZ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s8td|d d< t jj||ddks\t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std S )Nr1  r5   r   r   r   r4   r8  r   irr  )r   rH   r  r   r$  r"   r  rX   r/  r7   r   r   )r%   rZ   r   r[   Z
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   r5   r   r   r   r   r   )r   rH   rG  r+   r   r"   r  r   r   r  r  )r%   rZ   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  r5   r   r)  r2  r]   r   r   r(  r   r   r   r4  r  rS   )	r   r   rv  r[  r  r  r"   r  r   )r%   r:   Zy_baser;   Zy_base_copyZr0Z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 5 Q R X tjtdd t jj	||d W 5 Q R X d S )Nr   rS   z(shape|size)r   r   r   )
r   r   rs   rn   rz   r   r   r"   r   r  )r%   r  rZ   r   r   r   r   /test_reduceat_and_accumulate_out_shape_mismatch	  s    

 z9TestUfunc.test_reduceat_and_accumulate_out_shape_mismatch	out_shaper>  r   r   r   )r   rS   r  f_reducec              	   C   s   t ddd}t ||j}||d|d}||jkr^tt ||d||d W 5 Q R X n&||d||d}t||k t	|| d S )Nr}  r]   rS   r   r  rP  r   r  )
r   r   r[  rG  r+   r  r   r   r   r   )r%   r  r  r  r   r   Zcorrect_outr  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 5 Q R X tt& t jj|d|d d df dd W 5 Q R X d S )	N)r   r4   r  )rS   r   r   Tr  r   F)r   rH   rG  r"   r  r   r   )r%   r   Zout_correctZout_incorrectr   r   r   +test_reduce_output_does_not_broadcast_input9	  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|ksZttt j||ksrtd S )Nc                   @   s   e Zd ZdS )z7TestUfunc.test_reduce_output_subclass_ok.<locals>.MyArrNr  r   r   r   r   MyArrG	  s   r  r   r   r   )	r   r  rG  r"   r  rH   r  rX   rr   )r%   r  r   r   r   r   test_reduce_output_subclass_okF	  s    

z(TestUfunc.test_reduce_output_subclass_okc                 C   s   t dtjjk d S )N
)r   r   Zinner1d_no_docrv   r$   r   r   r   test_no_doc_stringP	  s    zTestUfunc.test_no_doc_stringc                 C   s"   t ttjd }|dstd S )Nzloop of ufunc does not support)rz   r   r!   r   r  r   rX   )r%   rt   r   r   r   test_invalid_argsT	  s    zTestUfunc.test_invalid_argsnatc                 C   s,   zt |rtW n tk
r&   Y nX d S r>   )r   r#  rX   r!   r%   r  r   r   r   test_nat_is_not_finiteZ	  s    z TestUfunc.test_nat_is_not_finitec                 C   s,   zt |stW n tk
r&   Y nX d S r>   )r   r"  rX   r!   r  r   r   r   test_nat_is_nana	  s    zTestUfunc.test_nat_is_nanc                 C   s,   zt |rtW n tk
r&   Y nX d S r>   )r   isinfrX   r!   r  r   r   r   test_nat_is_not_infh	  s    zTestUfunc.test_nat_is_not_inf)r/   r0   r1   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   rz   r{   r|   r   r   r   r   r   r  r  r   r"   r  r  r&  r-  skipifr   rF  rJ  rR  rX  r\  rf  rh  rG  rH   rk  rm  rp  rt  rx  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
  rV   r  r  r  r  r  r  r!  r&  r+  r-  r.  r0  r?  rm  rp  rv  r  r  r  r  r  rI   r  rF   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Z
datetime64Ztimedelta64r  r  r  r   r   r   r   r      sx  	T


	
					



	
W
"+
	g,O
G6
	
.


A
 	@






"""r   r   c                 C   s(   g | ] }t tt|tjrtt|qS r   r   r^   r   r   r  r   r   r   r   p	  s    c           	   
   C   s   | j D ]}d|ksd|krq|d\}}dd |D }tjdd td | | }W 5 Q R X t|trt|}t|t|kstt	||D ]\}}|j
t
|kstqq|j
t
|kst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
    rU   ?->c                 S   s   g | ]}t d |qS )r  )r   rH   r   r  r   r   r   r   	  s     z$test_ufunc_types.<locals>.<listcomp>Tr9  r;  N)r   splitr?  r@  filterwarningsr   r7  rC  rX   r   r+   r   )	r   typinpr   r  r[   Zoutsru  r  r   r   r   test_ufunc_typesp	  s    



r  c                 C   s(   g | ] }t tt|tjrtt|qS r   r  r  r   r   r   r   	  s    c              
   C   s"  | j D ]}ttdt|@ r"q|d\}}dd |D }dd |D }|D ]}tdd|_qP|D ]}tdd|_qftjdd	  td
 | | }| | }W 5 Q R X t	|dkr|f}|f}t
||D ]N\}	}
|	j}t|tjrt|j}d| }t||||d qt|	|
 qqdS )zs
    Check that contiguous and non-contiguous calls to ufuncs
    have the same results for values in range(9)
    zO?mMr  c                 S   s   g | ]}t d |qS )r   r   rG  r  r   r   r   r   	  s     z,test_ufunc_noncontiguous.<locals>.<listcomp>c                 S   s"   g | ]}t d |ddd qS )r)  NrS   r  r  r   r   r   r   	  s     r   r   Tr9  r;  r   )r  r  N)r   r  setr  r   Zflatr?  r@  r  rC  r   r+   r   Z
issubdtypeZfloatingr  Zepsr
   r   )r   r  r  r   Zargs_cZargs_nr   Zres_cZres_nZc_arZn_arr   Zres_epsZtolr   r   r   test_ufunc_noncontiguous	  s0    
r  c                 C   s\   t dgdd}t |s"t| jdkr6| | n"| jdkrP| ||  ntdd S )Nl         r"  r   r   r   zufunc with more than 2 inputs)r   rV   r  r"  rX   r  r  r   )r   r   r   r   r   test_ufunc_warn_with_nan	  s    


r  zPython lacks refcountsr/  c               	   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 5 Q R X |t	| kst|d dkstt
t t j|||t jdd	 W 5 Q R X |t	| kst|d dkstd S )
N{   r   stringr5   r   r   r   r   )r   r+   r   )r   rV   r#   BUFSIZErI   rH   rC  r   sysgetrefcountrz   r   r   r"   rX   )valuerZ   r   countr   r   r   test_ufunc_out_casterrors	  s$    
 r  
bad_offsetr   c              	   C   s`   d}t j|g|  dg |gtdt j   td}tt t j||t j	dd W 5 Q R X d S )Nr  r  r   r5   r   r   )
r   rV   r#   r  rI   rz   r   r   r"   r   r  r  rZ   r   r   r   test_ufunc_input_casterrors	  s    r  r.  c              
   C   sv   d}t |g|  t jg |gtdt j   }t jdd0 tt t j	||t j
dd W 5 Q R X W 5 Q R X d S )Nr  r   rl   rs  r   r   )r   rV   nanr#   r  rp   rz   r   FloatingPointErrorr"   r   r  r   r   r   $test_ufunc_input_floatingpoint_error	  s    r  c                	   C   s6   t jtdd tjtddddd W 5 Q R X d S )Nzcast ufunc 'add' input 0r   r   zi,irS   zdd->dr   )rz   r   r!   r   r"   rV   r   r   r   r   test_trivial_loop_invalid_cast	  s    r  offsetr   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 5 Q R X |t|kst|d	 ||  k std S )
Nr  r  r   r5   r   zinvalid literalr   rq  r   )r   rV   r#   r  rI   r   r  r  rz   r   r   r"   r  rX   )r  r  rZ   r   r  r   r   r   test_reduce_casterrors
  s    
r  ry  c                 C   s   t j| dgS r4  )r   r"   r   r   r   r   r   rc   !
  rd   rc   r   r   c                 C   s   t j| dgS )Nr   )r   logrg  r   r   r   r   rc   "
  rd   rg  c              
   C   s   t t jdt j g}t jdd( tjtdd | | W 5 Q R X W 5 Q R X t t jdt j g}t jdd$ tt | | W 5 Q R X W 5 Q R X d S )Nr   warnrm   zinvalid valuer   rl   )	r   rV   r  rp   rz   r   rB  r   r  )ry  rZ   r   r   r   test_ufunc_methods_floaterrors
  s    r  c                 C   s8   | dkrdS t | jsdS | jjdkr4t | jS dS )Nr  Fre  T)r   signbitrH  r+   kindrI  )r  r   r   r   _check_neg_zero0
  s    r  r+   ZAllFloatc                 C   sl   t | } | jdkr&| tdd}n
| d}t |}t |}t|| sTt||7 }t|shtd S )Nre         )r   r+   r  rr   rW   rV   r  rX   )r+   neg_zerorZ   Zarr2r   r   r   test_addition_negative_zero9
  s    




r  use_initialTFc                 C   s   t | } | jdkr&| tdd}n
| d}i }|rB||d< n
td tddD ]`}t j|g| | d}t j	|f|}|dks|rt
|stqVt |jrtt |jrVtqVd S )Nre  r  rL  z1-0. propagation in sum currently requires initialr      r5   )r   r+   r  rr   rW   rz   Zxfailr   rV   r*  r  rX   r  rH  rI  )r+   r  r  r  r   rZ   r[   r   r   r   "test_addition_reduce_negative_zeroJ
  s    




r  c                
   @   s   e Zd Zdd Zdd Zdd Zejde	
de	
dfd	e	
de	
d
fe	
dd	e	
d
fdgdd Zdd Zdd Zejjeed dddd Zejddddgdd Zdd Zd	S )TestLowlevelAPIAccessc              	   C   s   t d}t d}t d}t j||d f}||||fksBtt jj||d fdd}||||fksjtt j|td f}||||fksttt t jj||d fdd W 5 Q R X d S )Nr   f4r   )NNr  r   r  r  )	r   r+   r"   resolve_dtypesrX   r#   rz   r   r!   )r%   r   r  r   ru  r   r   r   test_resolve_dtypes_basicf
  s"    


  z/TestLowlevelAPIAccess.test_resolve_dtypes_basicc              	   C   sj   t d}t j||d f}|||t tfks4tt d}tt t j||d f W 5 Q R X d S )NS0Z10i)	r   r+   r  r  r  rX   rz   r   NotImplementedError)r%   r  ru  Zdtsr   r   r   test_weird_dtypes|
  s    

z'TestLowlevelAPIAccess.test_weird_dtypesc              	   C   s:   t d}tt t jj|||fdd W 5 Q R X d S )Nr   TZ	reduction)r   r+   rz   r   r  r"   r  )r%   r   r   r   r   test_resolve_dtypes_reduction
  s    
z3TestLowlevelAPIAccess.test_resolve_dtypes_reductiondtypesr   Nr9   )r   r   Nc              	   C   s&   t t tj| W 5 Q R X d S r>   )rz   r   r!   r   r"   r  )r%   r  r   r   r   test_resolve_dtypes_errors
  s    z0TestLowlevelAPIAccess.test_resolve_dtypes_errorsc                 C   s@   t d}t d}t jjd |d fdd}||||fks<td S )Ni2longTr  )r   r+   r"   r  rX   )r%   r  Zlong_r[   r   r   r   r  
  s    

c              	   C   sX   t d}tt t jd ||f W 5 Q R X tt t jd W 5 Q R X d S )Nr  )NNr   )r   r+   rz   r   r!   r"   r  r(   )r%   r  r   r   r   $test_resolve_dtypes_reduction_errors
  s
    
z:TestLowlevelAPIAccess.test_resolve_dtypes_reduction_errors	pythonapiz2`ctypes.pythonapi` required for capsule unpacking.r/  c           
   	      s4  t t jd}t t jd}t t jd}t t jt j|||t j G  fdddt j}t	d}tj
||f\}}|||fksttj
| t jt jj_t jt |t d}t |t |j}tjd|d}	||j||	jj|	jj|	jj||	jjd	 |	jjd	 |j t|	tjd|d  d S )
Nr   r   c                       s6   e Zd Zd fdejfdejfdejfdejfgZdS )z;TestLowlevelAPIAccess.test_loop_access.<locals>.call_info_tstrided_loopcontextauxdataZrequires_pyapiZno_floatingpoint_errorsN)r/   r0   r1   ctc_void_pc_byte_fields_r   Zstrided_loop_tr   r   call_info_t
  s   r  r   s   numpy_1.24_ufunc_call_infor4   r5   r   )r  ARRAYc_char_p	c_ssize_t	CFUNCTYPEc_intr  	Structurer   r+   ro  _resolve_dtypes_and_contextrX   _get_strided_loopr  ZPyCapsule_GetPointerrestype	py_objectcastPOINTERcontentsr   r  r  ctypesdatar  rc  r  r   )
r%   Zdata_tZdim_tZ	strides_tr  r   r   Zcall_info_obj	call_inforZ   r   r  r   test_loop_access
  s>         	
z&TestLowlevelAPIAccess.test_loop_accessrc  r   r  )r   r  c              	   C   sL   t d}t j||f\}}tjtdd t jj||d W 5 Q R X d S )Nr   zfixed_strides.*tuple.*or Noner   )Zfixed_strides)r   r+   ro  r  rz   r   r!   r  )r%   rc  r   r   r  r   r   r   )test__get_strided_loop_errors_bad_strides
  s    
z?TestLowlevelAPIAccess.test__get_strided_loop_errors_bad_stridesc              	   C   s   t d}t j||f\}}tjtdd t jd W 5 Q R X tjtdd t j	| W 5 Q R X t j| tt t j| W 5 Q R X d S )Nr   Z	PyCapsuler   znot the capsule!z.*incompatible context)
r   r+   ro  r  rz   r   r   r  r!   r"   )r%   r   r   r  r   r   r   +test__get_strided_loop_errors_bad_call_info
  s    
zATestLowlevelAPIAccess.test__get_strided_loop_errors_bad_call_info)r/   r0   r1   r  r  r  rz   r{   r|   r   r+   r  r  r  hasattrr  r  r  r  r   r   r   r   r  e
  s&   
	
*
r  )Ir?  r  r  r  r  rz   r   Znumpyr   Znumpy.core._umath_testsr_   Z_umath_testsr   Znumpy.linalg._umath_linalgrn  ro  r  Znumpy.core._operand_flag_testsZ_operand_flag_testsr*  Znumpy.core._rational_testsr   Znumpy.testingr   r   r   r   r   r   r	   r
   r   r   r   Znumpy.testing._private.utilsr   Znumpy.compatr   r`   __dict__rl  ZUNARY_UFUNCSr~   r   r2   r   r   r{   r|   dirr  Z_no_nep50_warningr  signr  r  r  r  r#   r  r  r  r  r  r"   r  r  r  r  Z	typecodesr  r  r  r   r   r   r   <module>   s   4                  D
%




	
