o
    i_                    @   s  d dl Z d dlZd dlZ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
mZmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlm Z  e!j"dkZ#ej$%dZ&dd Z'dd Z(dd Z)dd Z*dd Z+dd Z,G dd deZ-G dd de-Z.G dd de.eZ/G d d! d!e-eZ0G d"d# d#eZ1G d$d% d%eZ2G d&d' d'eZ3G d(d) d)e3Z4e45  G d*d+ d+e3Z6e65  G d,d- d-e3Z7e75  G d.d/ d/e3Z8e85  G d0d1 d1e3Z9e95  G d2d3 d3e3Z:e:5  G d4d5 d5e3Z;e;5  G d6d7 d7e3Z<e<5  G d8d9 d9e3Z=e=5  G d:d; d;e3Z>e>5  G d<d= d=eZ?G d>d? d?eZ@G d@dA dAeZAG dBdC dCeZBeCdDkrfeD  dS dS )E    N)guvectorizenjittypeof	vectorize)types)
from_dtype)LoweringErrorTypingError)TestCaseMemoryLeakMixin)supported_ufuncs)numpy_support)
cpu_target)BaseContext)ufunc_db   win32c                    s   t   fdd}dS )zAn 'expectedFailure' like decorator that only expects compilation errors
    caused by unimplemented functions that fail in no-python modec                     s4   z | i | W tj t y   tt w N)r	   unittestZ_ExpectedFailuresysexc_infoZ_UnexpectedSuccess)argskwargsfunc f/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_ufuncs.pywrapper   s   z_unimplemented.<locals>.wrapperN)	functoolswraps)r   r   r   r   r   _unimplemented   s   r    c                 C   sT   i }d dd t| jD }d|| j}t|t | |d }d| j|_|S )N,c                 S   s   g | ]}d  |qS )za{0})format.0ir   r   r   
<listcomp>(       z'_make_ufunc_usecase.<locals>.<listcomp>zdef fn({0}):
    np.{1}({0})fnz{0}_usecase)joinrangenargsr"   __name__execglobals)ufuncldictZarg_strZfunc_strr(   r   r   r   _make_ufunc_usecase&   s   r1   c                 C   4   i }t d| t | |d }dt| |_|S )Nzdef fn(x):
    return {0}(x)r(   usecase_{0}r-   r"   r.   hashr,   ufunc_opr0   r(   r   r   r   _make_unary_ufunc_op_usecase0   
   r8   c                 C   r2   )Nzdef fn(x,y):
    return x{0}yr(   r3   r4   r6   r   r   r   _make_binary_ufunc_op_usecase8   r9   r:   c                    sR   t  tri }td t | |d }dt |_|S  fdd}|}|S )zGenerates a function to be compiled that performs an inplace operation

    ufunc_op can be a string like '+=' or a function like operator.iadd
    zdef fn(x,y):
    x{0}yr(   r3   c                    s    | | d S r   r   xyr7   r   r   
inplace_opK      z2_make_inplace_ufunc_op_usecase.<locals>.inplace_op)
isinstancestrr-   r"   r.   r5   r,   )r7   r0   r(   r?   r   r>   r   _make_inplace_ufunc_op_usecase@   s   
rC   c                 C   s   dd t | |D S )z5Convert python values into numpy scalar objects.
    c                 S   s$   g | ]\}}t t||qS r   )npdtyperB   type)r$   tyvalr   r   r   r&   T   s   $ z#_as_dtype_value.<locals>.<listcomp>)zip)tyargsr   r   r   r   _as_dtype_valueQ   s   rK   c                       s@   e Zd Z fddZejddd
ddZ		ddd	Z  ZS )BaseUFuncTestc                    s@  t t|   tdtjftdtjftdtjftdtjftdtjftdtjftdtjftdtjftdtjftdtjft	dtj	ft	dtj	ft	dtj	ft
dtj
ft
dtj
ft
dtj
ftjddgddttjdd	ftjddgd
dttjdd	ftjg dddttjdd	ftjg dddttjdd	ftjg dddttj	dd	ftjg dddttj
dd	ftjddgtjdttjdd	ftjddgtjdttjdd	ftjddgtjdttjdd	ftjddgtjdttjdd	fg| _d S )Nr                          ?u4rE   Cu8)rN   r   rM   i4i8)rO   rP   rQ   f4f8)superrL   setUprD   uint32r   int32uint64int64float32float64arrayArrayint8int16Zuint8Zuint16inputsself	__class__r   r   r[   Y   sD       """
zBaseUFuncTest.setUpN)maxsizeFc                 C   s   t ||dd|S )NT)Z_nrtZno_rewrites)r   )rh   pyfuncr   nrtr   r   r   _compile   s   zBaseUFuncTest._compilec                 C   s   |}t |tjr|j}|j}nd}|tjv r*|r!t||d}|S t||d}|S |tjv rC|r:t||d}|S t||d}|S |rNt||d}|S t||d}|S )NrM   rT   )rA   r   rc   ndimrE   Zsigned_domainZunsigned_domain)rh   
input_typeint_output_typefloat_output_typerG   ro   output_typer   r   r   _determine_output_type   s,   

z$BaseUFuncTest._determine_output_type)F)NN)	r,   
__module____qualname__r[   r   	lru_cachern   rt   __classcell__r   r   ri   r   rL   W   s    
&rL   c                   @   s2   e Zd Zdd Zg g ddddfddZdd	 ZdS )
BasicUFuncTestc                 C   s   t |S r   )r1   rh   r/   r   r   r   r1         z"BasicUFuncTest._make_ufunc_usecaseNZifcFc                    s(  |  t | |}t| j| }	|	D ]}
|
d }|
d }t|t}|r'| n|f|j  ||v r2q|r>t	 d dk r>q d j
j|vrGq| |||}|f|j }|f|j }|| }| ||}t d tjr fdd|D } fdd|D }ndd |D }dd |D }d}tjd	d
-}td |g  |R   d}|D ]}t|jtrt|j|rd	}qW d    n1 sw   Y  |g  |R   t||D ]8\}}dg d|j|||||j
|}ztjj||d|d W q ty   |rtd|
|| n Y qw qd S )Nr   rM   c                    $   g | ]}t j d  j|jjdqS r   rS   rD   zerosshaperE   namer$   Zout_tyr   r   r   r&      s    z3BasicUFuncTest.basic_ufunc_test.<locals>.<listcomp>c                    r|   r}   r~   r   r   r   r   r&      s    c                 S      g | ]}t jd |jjdqS rM   rS   rD   r   rE   r   r   r   r   r   r&          c                 S   r   r   r   r   r   r   r   r&      r   FT)recordalwayszinvalid value encountered
)zufunc '{0}' failedzinputs ({1}):z{2}zgot({3})z{4}zexpected ({5}):z{6}   )decimalerr_msgz!Output mismatch for invalid input) Zreset_module_warningsr,   r1   listrf   rA   tupleninrD   anyrE   kindrt   noutrn   ndarraywarningscatch_warningssimplefilter
issubclasscategoryRuntimeWarningrB   message
startswithrI   r)   r"   testingassert_array_almost_equalAssertionErrorprint)rh   r/   skip_inputsadditional_inputsrq   rr   kindspositive_onlyrl   rf   input_tupleinput_operandrp   is_tuplers   input_typesoutput_typesargtyscfuncresultsexpectedZinvalid_flagZwarnlistZwarnmsgZthiswarnZ
expected_iZresult_imsgr   r   r   basic_ufunc_test   s   






zBasicUFuncTest.basic_ufunc_testc                 C   s  |  | tjdk rd S tdtdftdtdftdtdftdtdftdtdftdtdftdtdftdtdftdtdftdtdftdtdftdtdftjg dtjdtjg dtjdftjg dtjdtjg dtjdff}| |}|D ]O\}}t|t|f}t	
t	jdd}||f }| ||}	t|tjrtj|jtjd}
ntjdtjd}
t|
}|||| |	|||
 tj||
 qd S )	N)rM      rN   r   rM   )rN   rN   r   r   rM   rM   rS   )r   rM   r   rM   r   rM   rT   )r   r   Znumpy_versionrD   r_   r^   rb   r1   r   r   rc   bool_rn   rA   r   r   r   
zeros_liker   Zassert_equal)rh   Zcomparison_ufuncr   rl   abr   rs   r   r   resultr   r   r   r   signed_unsigned_cmp_test  sH   




z'BasicUFuncTest.signed_unsigned_cmp_test)r,   ru   rv   r1   r   r   r   r   r   r   ry      s    
_ry   c                   @   s  e Zd Zdd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ejfd&d'Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&dFdG Z'dHdI Z(dJdK Z)dLdM Z*dNdO Z+dPdQ Z,dRdS Z-dTdU Z.dVdW Z/dXdY Z0dZd[ Z1d\d] Z2d^d_ Z3d`da Z4dbdc Z5ddde Z6dfdg Z7dhdi Z8djdk Z9dldm Z:dndo Z;dpdq Z<drds Z=dtdu Z>dvdw Z?dxdy Z@dzd{ ZAd|d} ZBd~d ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTeUdd ZVeUdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd ZadS )
TestUFuncsNc                 C   s:   t jt jt t jddt t jddg}| j||d d S NrM   rT   )r   )r   r`   ra   rc   r   )rh   r   r   r   r   r   basic_int_ufunc_test7  s   zTestUFuncs.basic_int_ufunc_testc                 C      |  tj d S r   )r   rD   addrg   r   r   r   test_add_ufuncC     zTestUFuncs.test_add_ufuncc                 C   r   r   )r   rD   subtractrg   r   r   r   test_subtract_ufuncF  r   zTestUFuncs.test_subtract_ufuncc                 C   r   r   )r   rD   multiplyrg   r   r   r   test_multiply_ufuncI  r   zTestUFuncs.test_multiply_ufuncc                 C   s   d }t j}| jtj|d d S Nrq   )r   ra   r   rD   dividerh   Zint_out_typer   r   r   test_divide_ufuncL  s
   
zTestUFuncs.test_divide_ufuncc                 C      | j tjdd d S Nfr   )r   rD   Z	logaddexprg   r   r   r   test_logaddexp_ufuncU     zTestUFuncs.test_logaddexp_ufuncc                 C   r   r   )r   rD   
logaddexp2rg   r   r   r   test_logaddexp2_ufuncX  r   z TestUFuncs.test_logaddexp2_ufuncc                 C   s   | j tjtjd d S r   )r   rD   true_divider   ra   rg   r   r   r   test_true_divide_ufunc[  s   
z!TestUFuncs.test_true_divide_ufuncc                 C   r   r   )r   rD   floor_dividerg   r   r   r   test_floor_divide_ufunc_  r   z"TestUFuncs.test_floor_divide_ufuncc                 C   s.   t t jddt jg}| jtjt j|d d S )NrM   rT   )rq   r   )r   rc   r\   r   rD   negativer_   )rh   r   r   r   r   test_negative_ufuncb  s   
zTestUFuncs.test_negative_ufuncc                 C   r   r   )r   rD   Zpositiverg   r   r   r   test_positive_ufunci  r   zTestUFuncs.test_positive_ufuncc                 C   r   )NT)r   )r   rD   powerrg   r   r   r   test_power_ufuncl  r   zTestUFuncs.test_power_ufuncc                 C   r   )NZfcr   )r   rD   Zfloat_powerrg   r   r   r   test_float_power_ufunco  r   z!TestUFuncs.test_float_power_ufuncc                 C   r   Niur   )r   rD   gcdrg   r   r   r   test_gcd_ufuncr  r   zTestUFuncs.test_gcd_ufuncc                 C   r   r   )r   rD   lcmrg   r   r   r   test_lcm_ufuncu  r   zTestUFuncs.test_lcm_ufuncc                 C   r   r   )r   rD   	remainderrg   r   r   r   test_remainder_ufuncx  r   zTestUFuncs.test_remainder_ufuncc                 C   s<   t t t jjt dftjfg}| jt jd|d d S )N   Zifcur   r   )rD   r^   iinfomaxr   r   mod)rh   r   r   r   r   test_mod_ufunc{  s
   "

zTestUFuncs.test_mod_ufuncc                 C   r   r   )r   rD   fmodrg   r   r   r   test_fmod_ufunc  r   zTestUFuncs.test_fmod_ufuncc                 C   sv   t t t jjtjft t t jjtjft t t jjtjft 	t t j	jtj	fg}| j
||d d S )N)r   )rD   r\   r   r   r   r^   r`   Zfinfominra   r   )rh   r/   r   r   r   r   test_abs_ufunc  s   
zTestUFuncs.test_abs_ufuncc                 C   s   | j tjd d S )N)r/   )r   rD   absoluterg   r   r   r   test_absolute_ufunc     zTestUFuncs.test_absolute_ufuncc                 C   r   r   )r   rD   fabsrg   r   r   r   test_fabs_ufunc  r   zTestUFuncs.test_fabs_ufuncc                 C   r   Ncfr   )r   rD   Zrintrg   r   r   r   test_rint_ufunc  r   zTestUFuncs.test_rint_ufuncc                 C   r   r   )r   rD   signrg   r   r   r   test_sign_ufunc  r   zTestUFuncs.test_sign_ufuncc                 C   r   r   )r   rD   Zconjrg   r   r   r   test_conj_ufunc  r   zTestUFuncs.test_conj_ufuncc                 C   r   r   )r   rD   exprg   r   r   r   test_exp_ufunc  r   zTestUFuncs.test_exp_ufuncc                 C   r   r   )r   rD   Zexp2rg   r   r   r   test_exp2_ufunc  r   zTestUFuncs.test_exp2_ufuncc                 C   r   r   )r   rD   logrg   r   r   r   test_log_ufunc  r   zTestUFuncs.test_log_ufuncc                 C   r   r   )r   rD   log2rg   r   r   r   test_log2_ufunc  r   zTestUFuncs.test_log2_ufuncc                 C   r   r   )r   rD   log10rg   r   r   r   test_log10_ufunc  r   zTestUFuncs.test_log10_ufuncc                 C   r   r   )r   rD   expm1rg   r   r   r   test_expm1_ufunc  r   zTestUFuncs.test_expm1_ufuncc                 C   r   r   )r   rD   log1prg   r   r   r   test_log1p_ufunc  r   zTestUFuncs.test_log1p_ufuncc                 C   r   r   )r   rD   sqrtrg   r   r   r   test_sqrt_ufunc  r   zTestUFuncs.test_sqrt_ufuncc                 C   r   r   )r   rD   Zsquarerg   r   r   r   test_square_ufunc  r   zTestUFuncs.test_square_ufuncc                 C   r   r   )r   rD   cbrtrg   r   r   r   test_cbrt_ufunc  r   zTestUFuncs.test_cbrt_ufuncc                 C   s`   t t jddt jt t jddt jt t jddt jt t jddt jg}| jtj|d d S r   )	r   rc   r\   r]   r^   r_   r   rD   
reciprocalrh   Zto_skipr   r   r   test_reciprocal_ufunc  s   z TestUFuncs.test_reciprocal_ufuncc                 C   r   r   )r   rD   	conjugaterg   r   r   r   test_conjugate_ufunc  r   zTestUFuncs.test_conjugate_ufuncc                 C   r   r   )r   rD   sinrg   r   r   r   test_sin_ufunc  r   zTestUFuncs.test_sin_ufuncc                 C   r   r   )r   rD   cosrg   r   r   r   test_cos_ufunc  r   zTestUFuncs.test_cos_ufuncc                 C   r   r   )r   rD   tanrg   r   r   r   test_tan_ufunc  r   zTestUFuncs.test_tan_ufuncc                 C   r   r   )r   rD   arcsinrg   r   r   r   test_arcsin_ufunc  r   zTestUFuncs.test_arcsin_ufuncc                 C   r   r   )r   rD   arccosrg   r   r   r   test_arccos_ufunc  r   zTestUFuncs.test_arccos_ufuncc                 C   r   r   )r   rD   Zarctanrg   r   r   r   test_arctan_ufunc  r   zTestUFuncs.test_arctan_ufuncc                 C   r   r   )r   rD   Zarctan2rg   r   r   r   test_arctan2_ufunc  r   zTestUFuncs.test_arctan2_ufuncc                 C   r   r   )r   rD   hypotrg   r   r   r   test_hypot_ufunc  r   zTestUFuncs.test_hypot_ufuncc                 C   r   r   )r   rD   sinhrg   r   r   r   test_sinh_ufunc  r   zTestUFuncs.test_sinh_ufuncc                 C   r   r   )r   rD   coshrg   r   r   r   test_cosh_ufunc  r   zTestUFuncs.test_cosh_ufuncc                 C   r   r   )r   rD   tanhrg   r   r   r   test_tanh_ufunc  r   zTestUFuncs.test_tanh_ufuncc                 C   r   r   )r   rD   Zarcsinhrg   r   r   r   test_arcsinh_ufunc  r   zTestUFuncs.test_arcsinh_ufuncc                 C   r   r   )r   rD   Zarccoshrg   r   r   r   test_arccosh_ufunc  r   zTestUFuncs.test_arccosh_ufuncc                 C   sb   t t jddt jt t jddt jt t jddt jt t jddt jg}| jtj|dd d S )NrM   rT   r   )r   r   )	r   rc   r\   r]   r^   r_   r   rD   Zarctanhr	  r   r   r   test_arctanh_ufunc  s   	zTestUFuncs.test_arctanh_ufuncc                 C   r   r   )r   rD   Zdeg2radrg   r   r   r   test_deg2rad_ufunc  r   zTestUFuncs.test_deg2rad_ufuncc                 C   r   r   )r   rD   Zrad2degrg   r   r   r   test_rad2deg_ufunc  r   zTestUFuncs.test_rad2deg_ufuncc                 C   r   r   )r   rD   degreesrg   r   r   r   test_degrees_ufunc	  r   zTestUFuncs.test_degrees_ufuncc                 C   r   r   )r   rD   radiansrg   r   r   r   test_radians_ufunc  r   zTestUFuncs.test_radians_ufuncc                 C   r   r   )r   rD   Zbitwise_andrg   r   r   r   test_bitwise_and_ufunc  r   z!TestUFuncs.test_bitwise_and_ufuncc                 C   r   r   )r   rD   Z
bitwise_orrg   r   r   r   test_bitwise_or_ufunc  r   z TestUFuncs.test_bitwise_or_ufuncc                 C   r   r   )r   rD   Zbitwise_xorrg   r   r   r   test_bitwise_xor_ufunc  r   z!TestUFuncs.test_bitwise_xor_ufuncc                 C   r   r   )r   rD   invertrg   r   r   r   test_invert_ufunc  r   zTestUFuncs.test_invert_ufuncc                 C   r   r   )r   rD   Zbitwise_notrg   r   r   r   test_bitwise_not_ufunc  r   z!TestUFuncs.test_bitwise_not_ufuncc                 C   r   r   )r   rD   greaterrg   r   r   r   test_greater_ufunc-  r   zTestUFuncs.test_greater_ufuncc                 C   r   r   )r   rD   greater_equalrg   r   r   r   test_greater_equal_ufunc0  r   z#TestUFuncs.test_greater_equal_ufuncc                 C   r   r   )r   rD   lessrg   r   r   r   test_less_ufunc3  r   zTestUFuncs.test_less_ufuncc                 C   r   r   )r   rD   
less_equalrg   r   r   r   test_less_equal_ufunc6  r   z TestUFuncs.test_less_equal_ufuncc                 C   r   r   )r   rD   	not_equalrg   r   r   r   test_not_equal_ufunc9  r   zTestUFuncs.test_not_equal_ufuncc                 C   r   r   )r   rD   equalrg   r   r   r   test_equal_ufunc<  r   zTestUFuncs.test_equal_ufuncc                 C   r   r   )r   rD   logical_andrg   r   r   r   test_logical_and_ufunc?  r   z!TestUFuncs.test_logical_and_ufuncc                 C   r   r   )r   rD   
logical_orrg   r   r   r   test_logical_or_ufuncB  r   z TestUFuncs.test_logical_or_ufuncc                 C   r   r   )r   rD   logical_xorrg   r   r   r   test_logical_xor_ufuncE  r   z!TestUFuncs.test_logical_xor_ufuncc                 C   r   r   )r   rD   Zlogical_notrg   r   r   r   test_logical_not_ufuncH  r   z!TestUFuncs.test_logical_not_ufuncc                 C   r   r   )r   rD   maximumrg   r   r   r   test_maximum_ufuncK  r   zTestUFuncs.test_maximum_ufuncc                 C   r   r   )r   rD   minimumrg   r   r   r   test_minimum_ufuncN  r   zTestUFuncs.test_minimum_ufuncc                 C   r   r   )r   rD   Zfmaxrg   r   r   r   test_fmax_ufuncQ  r   zTestUFuncs.test_fmax_ufuncc                 C   r   r   )r   rD   Zfminrg   r   r   r   test_fmin_ufuncT  r   zTestUFuncs.test_fmin_ufuncc                 C   s&   t jddgt jdttjddfgS )NTFrS   rM   rT   )rD   rb   r   r   rc   rg   r   r   r   bool_additional_inputsZ  s   z!TestUFuncs.bool_additional_inputsc                 C      | j tjd|  d d S NZifcbr   )r   rD   isfiniterI  rg   r   r   r   test_isfinite_ufunc`     
zTestUFuncs.test_isfinite_ufuncc                 C   rJ  rK  )r   rD   isinfrI  rg   r   r   r   test_isinf_ufuncf  rN  zTestUFuncs.test_isinf_ufuncc                 C   rJ  rK  )r   rD   isnanrI  rg   r   r   r   test_isnan_ufuncl  rN  zTestUFuncs.test_isnan_ufuncc                 C   r   r   )r   rD   signbitrg   r   r   r   test_signbit_ufuncr  r   zTestUFuncs.test_signbit_ufuncc                 C   r   r   )r   rD   copysignrg   r   r   r   test_copysign_ufuncu  r   zTestUFuncs.test_copysign_ufuncc                 C   r   r   )r   rD   	nextafterrg   r   r   r   test_nextafter_ufuncx  r   zTestUFuncs.test_nextafter_ufuncc                 C   r   r   )r   rD   modfrg   r   r   r   test_modf_ufunc{     zTestUFuncs.test_modf_ufuncc                 C   r   r   )r   rD   frexprg   r   r   r   test_frexp_ufunc  r[  zTestUFuncs.test_frexp_ufuncc                 C   r   r   )r   rD   floorrg   r   r   r   test_floor_ufunc  r   zTestUFuncs.test_floor_ufuncc                 C   r   r   )r   rD   ceilrg   r   r   r   test_ceil_ufunc  r   zTestUFuncs.test_ceil_ufuncc                 C   r   r   )r   rD   truncrg   r   r   r   test_trunc_ufunc  r   zTestUFuncs.test_trunc_ufuncc                 C   sB   t jt jt j gt jdttjddfg}| jt jd|d d S )NrS   rM   rT   r   r   )rD   rb   infra   r   rc   r   spacing)rh   
additionalr   r   r   test_spacing_ufunc  s   

zTestUFuncs.test_spacing_ufuncc                 C   s  |j }t|}dtjfdtjfdtjftjddgddttjddftjddgddttjddftjd	dgd
dttjddfg}|}ttjddttjddg}|}t	
|||D ]}|\}}	}
|d }|d }|	d }|	d }|dkr|ttjddks|ttjddkrq`|dkr|ttjddkr|tjkrttjddrq`|dkr|ttjddkr|tjkrttjddrq`t|tjst|tjrt|
tjsq`|||
f}| ||}t|tjrtj|j|
jjd}tj|j|
jjd}n.t|tjrtj|j|
jjd}tj|j|
jjd}ntjd|
jjd}tjd|
jjd}|||| |||| t|
d|
}|tjtjfv rMdnd}| j|||d q`d S )NrM   rN   rQ   r   rU   rS   rT   rW   rO   rY   r   r   rE   singledouble)prec)r,   r1   r   r^   r_   ra   rD   rb   rc   	itertoolsproductr\   rA   rn   r   r   sizerE   r   getattrr`   	complex64assertPreciseEqual)rh   r/   Z
ufunc_nameZinputs1Zinputs2r   rl   valsZinput1Zinput2rs   Zinput1_operandinput1_typeZinput2_operandinput2_typer   r   r   r   Zscalar_typerj  r   r   r   binary_ufunc_mixed_types_test  s     






z(TestUFuncs.binary_ufunc_mixed_types_testc                 C   s  t tj}tjdddtjdddddtjdddddtjdddddtjdddddtjdddddg}tjdddddtjdddddtj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}t||D ]:\}}ttj	|j
d}ttj|j
d}||f}| ||}	tj|j|jd}
t||
 |	|| | ||
 qt tj}tjdddtjdddddtjddddddtjdddddtj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tjddddddg	}|}t||D ]I\}}ttj	|j
d}ttj	|j
d}ttj	t|j
|j
d}|||f}| ||}	t||}
tj|
jdd}|	||| | ||
 q*d S )	N   rU   rS   rM   	   rW      rT   )r1   rD   r   arangereshaper   rI   r   rc   r^   ro   r_   rn   r   rE   rp  r   rk  rl  r   )rh   rl   Zinput_operandsZoutput_operandsr<   r   rp   rs   r   r   r   input1_operandsinput2_operandsr=   rr  rs  r   r   r   test_broadcasting  s^   
	


zTestUFuncs.test_broadcastingc                 C   sF   t t jdd}||f}t||fdd }| |j| jj| d S )NrM   rT   c                 S      t | |S r   rD   r   a0a1r   r   r   myadd2  s   z2TestUFuncs.test_implicit_output_npm.<locals>.myadd)r   rc   r^   r   assertEqual	overloads	signaturereturn_type)rh   Zarr_tysigr  r   r   r   test_implicit_output_npm,  s
   

z#TestUFuncs.test_implicit_output_npmc                 C   s@  dd }t jdddt jdddddt jddddddt jdddddt j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t jddddddg	}|}t||D ]4\}}ttj|jd	}ttj|jd	}||f}| j	||d
d}	t 
||}
|	||}t j|
| qid S )Nc                 S   r}  r   r~  r  r   r   r   rl   9     zATestUFuncs.test_broadcast_implicit_output_npm_nrt.<locals>.pyfuncru  rU   rS   rv  rw  rM   rT   Trm   )rD   rx  ry  rk  rl  r   rc   r^   ro   rn   r   r   assert_array_equal)rh   rl   rz  r{  r<   r=   rr  rs  r   r   r   r   r   r   r   &test_broadcast_implicit_output_npm_nrt8  s*   
z1TestUFuncs.test_broadcast_implicit_output_npm_nrtc                 C   sd  dd }t ddddd}t j|dd	}|ddjd }t|}|jjr,|jd
ks.J t|}|jj	r;|jdks=J t|}|jdksHJ |jjrNJ |jj	rTJ t
t|||gd}|||fg7 }|||fg7 }|||fg7 }|D ]9\}	}
t|	t|
f}| j||dd}||	|
}||	|
}| |jj|jj | |jj	|jj	 t j|| qvd S )Nc                 S   r}  r   r~  r  r   r   r   rl   V  r  z=TestUFuncs.test_implicit_output_layout_binary.<locals>.pyfuncr   rM      r   r   ForderrT   A   Tr  )rD   linspacery  rb   Tr   flagsc_contiguouslayoutf_contiguousr   rk  permutationsrn   r  r   r  )rh   rl   XYZXtyYtyZtyZ	testcasesarg0Zarg1r   r   r   r   r   r   r   "test_implicit_output_layout_binaryU  s:   



z-TestUFuncs.test_implicit_output_layout_binaryc                 C   s  dd }t ddddd}t j|dd	}|ddjd }t|}|jjr,|jd
ks.J t|}|jj	r;|jdks=J t|}|jdksHJ |jjrNJ |jj	rTJ |||fD ]2}t|f}	| j
||	dd}
||}|
|}| |jj|jj | |jj	|jj	 t j|| qYd S )Nc                 S   
   t | S r   rD   r  )r  r   r   r   rl   {     
z<TestUFuncs.test_implicit_output_layout_unary.<locals>.pyfuncr   rM   r  r   r   r  r  rT   r  Tr  )rD   r  ry  rb   r  r   r  r  r  r  rn   r  r   r  )rh   rl   r  r  r  r  r  r  r  r   r   r   r   r   r   r   !test_implicit_output_layout_unaryz  s2   


z,TestUFuncs.test_implicit_output_layout_unaryr   )br,   ru   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rD   absr   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,  r.  r/  r1  r3  r5  r7  r9  r;  r=  r?  rA  rB  rD  rF  rG  rH  rI  rM  rP  rR  rT  rV  rX  r    rZ  r]  r_  ra  rc  rg  rt  r|  r  r  r  r  r   r   r   r   r   6  s    
	



NC%r   c                   @   s  e Zd Zdd Zdg g ddfddZdg g dddfdd	Zd
d Zdd Zdd Z	d\ddZ		d\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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Z d@dA Z!dBdC Z"dDdE Z#dFdG Z$dHdI Z%dJdK Z&dLdM Z'dNdO Z(dPdQ Z)dRdS Z*dTdU Z+dVdW Z,dXdY Z-dZd[ Z.dS )]TestArrayOperatorsc                 C   s&   |  |jj|jj tj|| d S r   )r  rE   r   rD   r   r   )rh   r   gotr   r   r   _check_results  s   z!TestArrayOperators._check_resultsTNc                 C   sz   t |}t| j}|| |}	|D ](}
|
\}}||v s"t|tjs#q| j|	|f|d}|	|}||}| || qd S )Nr  )	r8   r   rf   extendrA   r   rc   rn   r  )rh   operatorrm   r   r   rq   rr   operator_funcrf   rl   r   r   rp   r   r   r  r   r   r   unary_op_test  s   


z TestArrayOperators.unary_op_testFc                 C   s  t |}t| j}	|	| |}
tjd}|	D ]g}|\}}tt	|d|}|}||v r.q|r9tj
d|dd }t|tjrN|}|}|rMt||k rMqn|ddd|}t|}|rc||k rcq||f}| j|
||d}|
||}|||}| || qd S )NrM   rE   rS   r   d   
   r  )r:   r   rf   r  rD   randomZRandomStater   Zas_dtypern  r   rA   r   rc   r   uniformZastyper   rn   r  )rh   r  rm   r   r   rq   rr   positive_rhsr  rf   rl   Zrandom_stater   Zinput_operand1rp   Zinput_dtypeZinput_type1zeroZinput_operand0Zinput_type0r   r   r   r  r   r   r   binary_op_test  sB   




z!TestArrayOperators.binary_op_testc                 C   s0   dt jfdt jftddgt t jddfgS )NTFrM   rT   )r   booleanrD   rb   rc   rg   r   r   r   bitwise_additional_inputs  s   z,TestArrayOperators.bitwise_additional_inputsc              	   O   sH   | dg }|tjtjttjddttjddg7 }| j|i |S )Nr   rM   rT   )
setdefaultr   r`   ra   rc   r  )rh   r   kwsr   r   r   r   binary_int_op_test  s   z%TestArrayOperators.binary_int_op_testc                 O   s(   | dg }||  7 }| j|i |S )Nr   )r  r  r  )rh   r   r  r   r   r   r   binary_bitwise_op_test  s   z)TestArrayOperators.binary_bitwise_op_testc                    s   t |}|}|r| j}	ntjj}	 fdd|D }
fddD }fddD }|| }t|
|D ]-\}}t|}t|}||f}| ||}|	 }||| |	 }||| |	|| q5d S )Nc                       g | ]	}t j |d qS rS   rD   rb   r$   rE   )
lhs_valuesr   r   r&         z6TestArrayOperators.inplace_op_test.<locals>.<listcomp>c                    r  r  r  r  )
rhs_valuesr   r   r&     r  c                    s   g | ]} D ]}||qqS r   r   )r$   vrE   )
rhs_dtypesr   r   r&         )
rC   rp  rD   r   Zassert_allcloserk  rl  r   rn   copy)rh   r  r  r  Z
lhs_dtypesr  preciser  rl   Z	assertionZ
lhs_inputsZ
rhs_arraysZrhs_scalarsZ
rhs_inputslhsrhsZlhs_typeZrhs_typer   r   r   r  r   )r  r  r  r   inplace_op_test  s0   



z"TestArrayOperators.inplace_op_testc                 C   s*   | j |||tjtjftjtjtjf|dS )Nr  )r  rD   r`   ra   r_   )rh   r  r  r  r  r   r   r   inplace_float_op_test  s
   

z(TestArrayOperators.inplace_float_op_testc                 C   s*   |  |||tjtjtjftjtjf d S r   )r  rD   re   r]   r_   r\   rh   r  r  r  r   r   r   inplace_int_op_test  s   

z&TestArrayOperators.inplace_int_op_testc                 C   s0   |  ||| | |||tjftjtjf d S r   )r  r  rD   r   r  r   r   r   inplace_bitwise_op_test"  s   
z*TestArrayOperators.inplace_bitwise_op_testc                 C      |  d d S N+r  rg   r   r   r   test_unary_positive_array_op*  r@   z/TestArrayOperators.test_unary_positive_array_opc                 C   r  N-r  rg   r   r   r   test_unary_negative_array_op-  r@   z/TestArrayOperators.test_unary_negative_array_opc              
   C   s<   | j dtjtjttjddttjddg|  d d S )N~rM   rT   )r   r   )r  r   r`   ra   rc   r  rg   r   r   r   test_unary_invert_array_op0  s   
z-TestArrayOperators.test_unary_invert_array_opc                 C   2   |  dg dg d |  tjg dg d d S )Nz+=rN         ?ru  r         @)r  r  iaddrg   r   r   r   test_inplace_add:     z#TestArrayOperators.test_inplace_addc                 C   r  )Nz-=r  r  )r  r  isubrg   r   r   r   test_inplace_sub>  r  z#TestArrayOperators.test_inplace_subc                 C   r  )Nz*=r  r  )r  r  imulrg   r   r   r   test_inplace_mulB  r  z#TestArrayOperators.test_inplace_mulc                 C   r  )Nz//=r  r  g      ?r  )r  r  	ifloordivrg   r   r   r   test_inplace_floordivF     z(TestArrayOperators.test_inplace_floordivc                 C   s2   |  dg dg d |  tjg dg d d S )Nz/=r  r  r  )r  r  itruedivrg   r   r   r   test_inplace_divK  r  z#TestArrayOperators.test_inplace_divc                 C   r  )Nz%=r  r  r  r  )r  r  imodrg   r   r   r   test_inplace_remainderP  r  z)TestArrayOperators.test_inplace_remainderc                 C   s:   | j dg dg ddd | j tjg dg ddd d S )Nz**=r  r  Fr  )r  r  ipowrg   r   r   r   test_inplace_powT  s   
z#TestArrayOperators.test_inplace_powc                 C   r  )Nz&=r   rM   r  ru  3   r      r   *      )r  r  iandrg   r   r   r   test_inplace_andZ     z#TestArrayOperators.test_inplace_andc                 C   r  )Nz|=r  r  )r  r  iorrg   r   r   r   test_inplace_or`  r  z"TestArrayOperators.test_inplace_orc                 C   r  )Nz^=r  r  )r  r  ixorrg   r   r   r   test_inplace_xorf  r  z#TestArrayOperators.test_inplace_xorc                 C   r  )Nz<<=r   r   iir   rM   r      )r  r  ilshiftrg   r   r   r   test_inplace_lshiftl  r  z&TestArrayOperators.test_inplace_lshiftc                 C   r  )Nz>>=r  r  )r  r  irshiftrg   r   r   r   test_inplace_rshiftq  r  z&TestArrayOperators.test_inplace_rshiftc                 C   s   dd }t d}||}| |d |d ko|d |d k t d}t||}| |d |d ko<|d |d k t j|| t j|| dS )z
        Verify that the unary positive operator copies values, and doesn't
        just alias to the input array (mirrors normal Numpy/Python
        interaction behavior).
        c                 S   s   | 
 }d| d< d|d< |S )Nru  r   r   rM   r   )r  a2r   r   r   r   }  s   z<TestArrayOperators.test_unary_positive_array_op_2.<locals>.fr  r   rM   N)rD   r   
assertTruer   r   r  )rh   r   r  r  a3Za4r   r   r   test_unary_positive_array_op_2v  s   
&
&z1TestArrayOperators.test_unary_positive_array_op_2c                 C   r  r  r  rg   r   r   r   test_add_array_op  r@   z$TestArrayOperators.test_add_array_opc                 C   r  r  r	  rg   r   r   r   test_subtract_array_op  r@   z)TestArrayOperators.test_subtract_array_opc                 C   r  )N*r	  rg   r   r   r   test_multiply_array_op  r@   z)TestArrayOperators.test_multiply_array_opc                 C   s   d }t j}| jd|d d S )N/r   )r   ra   r  r   r   r   r   test_divide_array_op  s   z'TestArrayOperators.test_divide_array_opc                 C   s`  t dtjft dtjft dtjft dtjft dtjft dtjft dtjft dtjft dtjft d	tjft jdd
gddt	tjddft jddgddt	tjddft jg dddt	tjddft jg dddt	tjddft jddgddt	tjddft jdd	gddt	tjddfg| _
| d d S )NrM   r   r   r  rO   r  g      g      @r  rR   rS   rT   ru  rU   )rN   rM   r   rV   )rN   rM      rW   rX   rY   z//)rD   r\   r   r]   r^   r_   r`   ra   rb   rc   rf   r  rg   r   r   r   test_floor_divide_array_op  s,       z-TestArrayOperators.test_floor_divide_array_opc                 C   r  )N%r	  rg   r   r   r   test_remainder_array_op  r@   z*TestArrayOperators.test_remainder_array_opc                 C      | j ddd d S )Nz**Tr  r	  rg   r   r   r   test_power_array_op  r   z&TestArrayOperators.test_power_array_opc                 C   r  )Nz<<Tr  r  rg   r   r   r   test_left_shift_array_op  r   z+TestArrayOperators.test_left_shift_array_opc                 C   r  )Nz>>Tr  r  rg   r   r   r   test_right_shift_array_op  r   z,TestArrayOperators.test_right_shift_array_opc                 C   r  )N&r  rg   r   r   r   test_bitwise_and_array_op  r@   z,TestArrayOperators.test_bitwise_and_array_opc                 C   r  )N|r  rg   r   r   r   test_bitwise_or_array_op  r@   z+TestArrayOperators.test_bitwise_or_array_opc                 C   r  )N^r  rg   r   r   r   test_bitwise_xor_array_op  r@   z,TestArrayOperators.test_bitwise_xor_array_opc                 C   r  )Nz==r	  rg   r   r   r   test_equal_array_op  r@   z&TestArrayOperators.test_equal_array_opc                 C   r  )N>r	  rg   r   r   r   test_greater_array_op  r@   z(TestArrayOperators.test_greater_array_opc                 C   r  )Nz>=r	  rg   r   r   r   test_greater_equal_array_op  r@   z.TestArrayOperators.test_greater_equal_array_opc                 C   r  )N<r	  rg   r   r   r   test_less_array_op  r@   z%TestArrayOperators.test_less_array_opc                 C   r  )Nz<=r	  rg   r   r   r   test_less_equal_array_op  r@   z+TestArrayOperators.test_less_equal_array_opc                 C   r  )Nz!=r	  rg   r   r   r   test_not_equal_array_op  r@   z*TestArrayOperators.test_not_equal_array_op)T)/r,   ru   rv   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!  r"  r$  r%  r'  r(  r)  r   r   r   r   r    sl    

*		
 
	
r  c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )TestScalarUFuncsa  check the machinery of ufuncs works when the result is an scalar.
    These are not exhaustive because:
    - the machinery to support this case is the same for all the functions of a
      given arity.
    - the result of the inner function itself is already tested in TestUFuncs
    c                 C   s.  t ||D ]\}}t||}|| }|t|| }d||}	ttjtjftjtjftjtjftjtjfg}
||
v rAt	|}n&t
|jt
jrNt	|}nt
|jt
jr[t|}nt
|jt
jrgt|}||j| jjf }tdd |D r}d}ntdd |D rd}nd}| j|||	|d qd S )	Nzfor args {0} typed {1}c                 S      g | ]}|t jkqS r   )r   r`   r$   tr   r   r   r&     r'   z.TestScalarUFuncs.run_ufunc.<locals>.<listcomp>rh  c                 S   r+  r   )r   ra   r,  r   r   r   r&     r'   ri  exact)r   rj  )rI   r   rK   r"   setr   r]   r^   r_   floatrD   Z
issubdtyperE   Zinexactintegerintr   boolr  r  r  r   rp  )rh   rl   Z	arg_typesZ
arg_valuesrJ   r   r   r  r   r   ZspecialZalltypesrj  r   r   r   	run_ufunc  s6   




	

zTestScalarUFuncs.run_ufuncc                 C   sJ   dd }g d}t jft jft jft jft jft jfg}| ||| d S )Nc                 S   r  r   r  r<   r   r   r   _func  r  z7TestScalarUFuncs.test_scalar_unary_ufunc.<locals>._func)r  r7  )rM   r7  )皙?)皙?)r   r]   r\   r_   r^   r`   ra   r4  rh   r6  rq  Ztysr   r   r   test_scalar_unary_ufunc  s   z(TestScalarUFuncs.test_scalar_unary_ufuncc                 C   sJ   dd }g d}t jt jt jt jt jt jg}| |t||t|| d S )Nc                 S   r}  r   r~  r;   r   r   r   r6  '  r  z@TestScalarUFuncs.test_scalar_binary_uniform_ufunc.<locals>._funcr  r  rM   r  r8  r9  )	r   r]   r\   r_   r^   r`   ra   r4  rI   r:  r   r   r    test_scalar_binary_uniform_ufunc&  s   z1TestScalarUFuncs.test_scalar_binary_uniform_ufuncc                 C   sN   dd }g d}t jt jt jt jt jt jg}| |t	||t	|| d S )Nc                 S   r}  r   r~  r;   r   r   r   r6  0  r  z>TestScalarUFuncs.test_scalar_binary_mixed_ufunc.<locals>._funcr<  )
r   r]   r\   r_   r^   r`   ra   r4  rk  rl  r:  r   r   r   test_scalar_binary_mixed_ufunc/  s   
z/TestScalarUFuncs.test_scalar_binary_mixed_ufuncN)r,   ru   rv   __doc__r4  r;  r=  r>  r   r   r   r   r*    s    3
	r*  c                   @      e Zd Zdd Zdd ZdS )TestUfuncIssuesc                 C   sP   t dgdd }tjddd}tjddd}| ||||| ||   d S )Nz(float64,float64)c                 S   s   t | |t | | S r   r~  )x1Zx2r   r   r   foo?  s   z+TestUfuncIssues.test_issue_651.<locals>.foor  rY   rS   )r   rD   rx  rp  )rh   rC  r   r   r   r   r   test_issue_651=  s
   
"zTestUfuncIssues.test_issue_651c                    s|   dd }|t   fdd}tg dtg dg}|D ]}||d ||td ||tg d q"d	S )
zF
        <float32 ** int> should return float32, not float64.
        c                 S   r}  r   )rD   r   r;   r   r   r   rC  K  r  z,TestUfuncIssues.test_issue_2006.<locals>.fooc                    s2    | |}t j|| | |j| j d S r   )rD   r   r   r  rE   )r<   r=   r  r   rl   rh   r   r   checkP  s   
z.TestUfuncIssues.test_issue_2006.<locals>.check)rM   r  ru  )              ?r  y      @      ru  )r  r  ru  N)r   rD   r`   ro  r^   r_   )rh   rC  rF  Zxsr<   r   rE  r   test_issue_2006G  s   
zTestUfuncIssues.test_issue_2006N)r,   ru   rv   rD  rH  r   r   r   r   rA  ;  s    
rA  c                   @   sn   e Zd ZdZdZddddddddZddd	Zd
d Zdd Zdd Z	e
dd Ze
dd Ze
dd ZdS )_LoopTypesTestera  Test code generation for the different loop types defined by ufunc.

    This test relies on class variables to configure the test. Subclasses
    of this class can just override some of these variables to check other
    ufuncs in a different compilation context. The variables supported are:

    _funcs: the ufuncs to test
    _skip_types: letter types that force skipping the loop when testing
                 if present in the NumPy ufunc signature.
    _supported_types: only test loops where all the types in the loop
                      signature are in this collection. If unset, all.

    Note that both, _skip_types and _supported_types must be met for a loop
    to be tested.

    The NumPy ufunc signature has a form like 'ff->f' (for a binary ufunc
    loop taking 2 floats and resulting in a float). In a NumPy ufunc object
    you can get a list of supported signatures by accessing the attribute
    'types'.
    ZOegGr  r   r   ))r  r  )r  D)r  r  )r   rJ  )r  r  )r  d)r   rK  r   c                 C   s  |dv rt jg d|dS |dv rt jg d|dS |dv r't jg d|dS |d d	kr>t|d
kr5d}t jg d|dS |d dkrUt|d
krLd}t jg d|dS |dv rft jdddtdg|dS |dv rtjdkrrd}nd}t j|ddtd dg|dS td|f )z<return a suitable array argument for testing the letter typeZbhilq)rM   r   r   r  rS   ZBHILQ)rM   r  r   r   ?)TFFTr   mrM   zm8[D])r  ZNaTr   MzM8[D])ZNatrM   r   r   fdr  g      rP   nanFDr   y             y              y      ?      ?rG  y                ztype %r not understood)rD   rb   lenr0  r   platformRuntimeError)rh   a_letter_typeindexZnegzeror   r   r   _arg_for_type  s4   
z_LoopTypesTester._arg_for_typec                    s   |d |j  ||j d    t| dg r$tfdd D r$d S t| dg tfdd D r7d S t| dg }|rLt fdd|D sLd S | ||  d S )NZ_supported_typesc                 3   s    | ]}| vV  qd S r   r   r$   l)supported_typesr   r   	<genexpr>      z/_LoopTypesTester._check_loop.<locals>.<genexpr>_skip_typesc                 3       | ]}| v V  qd S r   r   rY  )
skip_typesr   r   r\    r]  _required_typesc                 3   r_  r   r   rY  )letter_typesr   r   r\    s    )r   r   rn  r   _check_ufunc_with_dtypes)rh   r(   r/   loopZrequired_typesr   )rb  r`  r[  r   _check_loop  s   z_LoopTypesTester._check_loopc                    s>  g }|D ]}|dv r|d }| | qdd |D }tdd |D }t||} fddt|D }	|	D ]}
 j|
 q7dd |	D }||	  ||  t|||	D ]G\}}} |||\}}|jj	} j
|j|fd}|d	v rwd
nd}|dv rdn|}dg d}||j|	|||} j|||||d qUd S )N)rM  rO  z8[D]c                 S   s   g | ]}t |qS r   )rD   rE   r,  r   r   r   r&     r'   z=_LoopTypesTester._check_ufunc_with_dtypes.<locals>.<listcomp>c                 S   s   g | ]}t t|d dqS )rM   rT   )r   rc   r   r,  r   r   r   r&     r  c                    s$   g | ]\}} j ||d dqS )rW  r  )rX  repeat)r$   rW  r-  rg   r   r   r&     s    c                 S   s   g | ]}|  qS r   )r  )r$   r   r   r   r   r&     s    rM   ZfFrh  r.  ZdDri  r   )z ufunc '{0}' arrays differ ({1}):z	args: {2}zexpected {3}zgot {4})rj  r   ulps)appendr   r   	enumerater  shufflerI   _fixup_resultsrE   char_ulpsgetr,   r)   r"   rp  )rh   r(   r/   ZdtypesZdtypes_with_unitsr-  Zarg_dtyZarg_nbtyr   Zc_argsZarrZpy_argsrE   py_argc_argZtypecharrh  rj  r   r   rg   r   rc    s8   
z)_LoopTypesTester._check_ufunc_with_dtypesc                 C   s   ||fS r   r   )rh   rE   rp  rq  r   r   r   rl    r{   z_LoopTypesTester._fixup_resultsc                 C   s   |j D ]}| || qd S r   )r   _inject_test)clsr/   rd  r   r   r   _check_ufunc_loops  s   
z#_LoopTypesTester._check_ufunc_loopsc              	      s0    fdd}t | dj dd| d S )Nc                    s   t }| |  d S r   )r1   re  )rh   r(   rd  r/   r   r   test_template  s   z4_LoopTypesTester._inject_test.<locals>.test_templateztest_{0}_{1}z->_)setattrr"   r,   replace)rs  r/   rd  rv  r   ru  r   rr    s   
z_LoopTypesTester._inject_testc                 C   s   | j D ]}| | qd S r   )_ufuncsrt  )rs  r/   r   r   r   autogenerate  s   
z_LoopTypesTester.autogenerateNr   )r,   ru   rv   r?  r^  rn  rX  re  rc  rl  classmethodrt  rr  r{  r   r   r   r   rI  _  s*    
	'(

rI  c                   @   sn   e Zd Zedd Zeej eej eej	 eej
 eej eej dZdej ZdS )TestLoopTypesIntNz?bBhHiIlLqQfdFDmMO)r,   ru   rv   r   rz  removerD   r   r  
left_shiftright_shiftr   r   ra  rI  r^  r   r   r   r   r~    s    r~  c                   @   s*   e Zd ZejejgZdZdej	 d Z	dS ) TestLoopTypesSubtractAndNegativez?bBhHiIlLqQfdFDmMOrL  N)
r,   ru   rv   rD   r   r   rz  ra  rI  r^  r   r   r   r   r    s    r  c                       4   e Zd ZejgZdZdej Zd fdd	Z	  Z
S )TestLoopTypesReciprocalbBhHiIlLqQfdFDr  r   c                    s.   t | j| j||d}|dv rd||dk< |S )Nrf  
bBhHiIlLqQr  r   rZ   rj   rX  rh   rV  rW  resri   r   r   rX    s   z%TestLoopTypesReciprocal._arg_for_typer|  )r,   ru   rv   rD   r  rz  ra  rI  r^  rX  rx   r   r   ri   r   r    
    
r  c                       r  )TestLoopTypesPowerr  r  r   c                    s6   t | j| j||d}|dv r|dkrd||dk < |S )Nrf  r  rM   ru  r   r  r  ri   r   r   rX  /  s   z TestLoopTypesPower._arg_for_typer|  )r,   ru   rv   rD   r   rz  ra  rI  r^  rX  rx   r   r   ri   r   r  *  r  r  c                       r  )TestLoopTypesIntLeftShiftr  r  r   c                    s@   t | j| j||d}|dkr|jjd }t|d|d }|S Nrf  rM      r   )rZ   rj   rX  rE   itemsizerD   cliprh   rV  rW  r  	bit_countri   r   r   rX  B  s   z'TestLoopTypesIntLeftShift._arg_for_typer|  )r,   ru   rv   rD   r  rz  ra  rI  r^  rX  rx   r   r   ri   r   r  =  r  r  c                       r  )TestLoopTypesIntRightShiftr  r  r   c                    sR   t | j| j||d}|dkr|jjd }t|d|d }|dkr't|}|S r  )rZ   rj   rX  rE   r  rD   r  r  r  ri   r   r   rX  Y  s   

z(TestLoopTypesIntRightShift._arg_for_typer|  )r,   ru   rv   rD   r  rz  ra  rI  r^  rX  rx   r   r   ri   r   r  T  r  r  c                   @   s2   e Zd ZejejejgZdZde	j
 Z
dd ZdS )TestLoopTypesFloorDivider  r  c                 C   sF   |j dkrt|t|@ }||dk|dk@ O }|| ||< ||fS )Nr   rP   )r   rD   rO  rQ  )rh   rE   rp  rq  predr   r   r   rl  {  s
   
z'TestLoopTypesFloorDivide._fixup_resultsN)r,   ru   rv   rD   r   r   divmodrz  ra  rI  r^  rl  r   r   r   r   r  v  s
    
r  c                   @   sf   e Zd Zedd Zereej eej	 eej
 eej eej dZdej ZdS )TestLoopTypesFloatNrP  ZFDmMO)r,   ru   rv   r   rz  	iswindowsr  rD   rS  r   r   r  r   ra  rI  r^  r   r   r   r   r    s    r  c                   @   s&   e Zd Zedd ZdZdej ZdS )TestLoopTypesComplexNrR  r  )r,   ru   rv   r   rz  ra  rI  r^  r   r   r   r   r    s    r  c                   @   s`   e Zd Zedd Zeej dZdd Z	dd Z
dd Zd	d
 Zdd Zdd Zdd ZdS )TestLoopTypesDatetimeNZmMc                 C      t j}t|}| ||g d | ||g d | ||g d | ||g d | t | ||g d W d    d S 1 sEw   Y  d S )N)m8[s]m8[m]r  )r  r  r  )r  r  m8[ms])r  r  r  )r  r  r  )rD   r   r1   rc  assertRaisesr   rh   r/   r(   r   r   r   test_add     "zTestLoopTypesDatetime.test_addc                 C   r  )N)M8[s]M8[m]r  )r  r  r  )r  r  r  )r  r  r  )r  r  r  )rD   r   r1   rc  r  r   r  r   r   r   test_subtract  r  z#TestLoopTypesDatetime.test_subtractc                 C   t   t j}t|}| ||g d | ||g d | t | ||g d W d    d S 1 s3w   Y  d S )N)r  qm8[us])r  r  r  r  r  r  )rD   r   r1   rc  r  r   r  r   r   r   test_multiply     "z#TestLoopTypesDatetime.test_multiplyc                 C   r  )N)r  r  rK  )r  r  rK  r  r  r  r  rK  r  r  )rD   r   r1   rc  r  r   r  r   r   r   test_true_divide  s   "z&TestLoopTypesDatetime.test_true_dividec                 C   r  )Nr  r  r  )rD   r   r1   rc  r  r   r  r   r   r   test_floor_divide  r  z'TestLoopTypesDatetime.test_floor_dividec                 C   sT   t |}| ||g d | ||g d | ||g d | ||g d d S )N)r  r  rL  )r  r  rL  )r  r  rL  )r  r  rL  )r1   rc  r  r   r   r   _check_comparison  s
   z'TestLoopTypesDatetime._check_comparisonc                 C   s0   t jt jt jt jt jt jfD ]}| | qd S r   )rD   r:  r8  r4  r6  r0  r2  r  rz   r   r   r   test_comparisons  s
   z&TestLoopTypesDatetime.test_comparisons)r,   ru   rv   r   rz  r  rD   r  ra  r  r  r  r  r  r  r  r   r   r   r   r    s    


	r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestUFuncBadArgsc                 C   N   dd }|  t tttjg| W d    d S 1 s w   Y  d S )Nc                 S   s   t | }|S )zerror: np.add requires two argsr~  )r<   r   r   r   r   r     s   
z0TestUFuncBadArgs.test_missing_args.<locals>.funcr  r	   r   r   ra   rh   r   r   r   r   test_missing_args     "z"TestUFuncBadArgs.test_missing_argsc                 C   s`   dd }t t jdd}||||}| t t|| W d    d S 1 s)w   Y  d S )Nc                 S   s   t | | ||}|S )zerror: too many argsr~  )r<   outZout2r   r   r   r   r     s   z1TestUFuncBadArgs.test_too_many_args.<locals>.funcrM   rT   )r   rc   ra   r  r	   r   )rh   r   Z
array_typer  r   r   r   test_too_many_args  s   "z#TestUFuncBadArgs.test_too_many_argsc                 C   r  )Nc                 S   s   d}t | | | dS )z0error: scalar as a return value is not supportedr   Nr~  r;   r   r   r   r     s   zATestUFuncBadArgs.test_no_scalar_result_by_reference.<locals>.funcr  r  r   r   r   "test_no_scalar_result_by_reference  r  z3TestUFuncBadArgs.test_no_scalar_result_by_referenceN)r,   ru   rv   r  r  r  r   r   r   r   r    s    	r  c                   @      e Zd Zdd ZdS ) TestUFuncCompilationThreadSafetyc                    sf   g  t dd  fddfddtdD }|D ]}|  q|D ]}|  q%|   dS )	z{
        Test that (lazy) compiling from several threads at once doesn't
        produce errors (see issue #2403).
        c                 S   s   | d S )NrM   r   r5  r   r   r   rC  .  s   z7TestUFuncCompilationThreadSafety.test_lock.<locals>.fooc               
      sn   zt jdt jd} t jdt jdd }t j| | W d S  ty6 } z | W Y d }~d S d }~ww )N)r  rS   g      ?)rD   Zonesra   r   r  	Exceptionri  )r   r   e)errorsrC  r   r   r   2  s   z;TestUFuncCompilationThreadSafety.test_lock.<locals>.wrapperc                    s   g | ]}t j d qS ))target)	threadingThreadr#   )r   r   r   r&   :  s    z>TestUFuncCompilationThreadSafety.test_lock.<locals>.<listcomp>r   N)r   r*   startr)   ZassertFalse)rh   threadsr-  r   )r  rC  r   r   	test_lock'  s   


z*TestUFuncCompilationThreadSafety.test_lockN)r,   ru   rv   r  r   r   r   r   r  %  s    r  c                   @   r@  )TestUfuncOnContextc                 C   s   t j}|tj}| |t ttj}| || t	 }| 
t}t| W d    n1 s3w   Y  | |jj|f d S r   )r   Ztarget_contextget_ufunc_inforD   r   ZassertIsInstancedictr   r  objectr  KeyError	exceptionr   )rh   	targetctxZadd_infor   Zbadkeyraisesr   r   r   test_cpu_get_ufunc_infoC  s   z*TestUfuncOnContext.test_cpu_get_ufunc_infoc                 C   sX   t tjd}| t}|tj W d    n1 sw   Y  | t	|j
d d S )Ncpuz<<numba\..*\.BaseContext object at .*> does not support ufunc)r   r   Ztyping_contextr  NotImplementedErrorr  rD   r   assertRegexrB   r  )rh   r  r  r   r   r   test_base_get_ufunc_infoS  s   z+TestUfuncOnContext.test_base_get_ufunc_infoN)r,   ru   rv   r  r  r   r   r   r   r  B  s    r  c                   @   r  )TestUfuncWriteInputc                 C   sf   t dgddd }tjdd}tj|tjd}||| tjtjg dtj	d|j
d	d
 d S )Nzvoid(float64[:], uint8[:])z(n)->(n)c                 S   s(   t | jD ]}|d dkrd||< qd S )Nr   r   rM   )r*   rm  )r<   r  r%   r   r   r   r   `  s
   z6TestUfuncWriteInput.test_write_input_arg.<locals>.funcr  r   rS   )TFFFTr   )Zaxis)r   rD   r  Zrandr   rd   r   r  rb   r   r   )rh   r   r<   r  r   r   r   test_write_input_arg_  s   



z(TestUfuncWriteInput.test_write_input_argN)r,   ru   rv   r  r   r   r   r   r  ^  s    r  __main__)Er   rk  r   r   r  r  numpyrD   r   Znumbar   r   r   r   Z
numba.corer   Znumba.np.numpy_supportr   Znumba.core.errorsr   r	   Znumba.tests.supportr
   r   Znumba.core.typing.npydeclr   Znumba.npr   Znumba.core.registryr   Znumba.core.baser   r   r   __itemsize__Zis32bitsrT  r   r  r    r1   r8   r:   rC   rK   rL   ry   r   r  r*  rA  rI  r~  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r,   mainr   r   r   r   <module>   s    

I     i  HZ$ 	^ 
