o
    8ή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Zd dlZd dlZd dl	Z	d dl
mZmZmZ d dlmZmZmZ d dlmZmZmZ d dlmZ d dl
mZmZ d dlmZmZmZ d dlmZm Z 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, e-j.dkZ/ej01dZ2e Z3de3_4de3_5e Z6de6_5e Z7de7_8de7_5dd Z9d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?eZ@G d!d" d"e?eZAG d#d$ d$eZBG d%d& d&eBZCG d'd( d(eZDG d)d* d*eZEG d+d, d,eEZFeFG  G d-d. d.eEZHeHG  G d/d0 d0eEZIeIG  G d1d2 d2eEZJeJG  G d3d4 d4eEZKeKG  G d5d6 d6eEZLeLG  G d7d8 d8eEZMeMG  G d9d: d:eEZNeNG  G d;d< d<eEZOeOG  G d=d> d>eEZPePG  G d?d@ d@eZQG dAdB dBeZRG dCdD dDeZSG dEdF dFeZTeUdGkre	V  dS dS )H    N)typeofnjitguvectorize)typestypingutils)compile_isolatedFlagsDEFAULT_FLAGS)
from_dtype)jit	vectorize)LoweringErrorTypingErrorNumbaTypeError)TestCaseCompilationCacheMemoryLeakMixintag)supported_ufuncs
all_ufuncs)numpy_support)
cpu_target)BaseContext)ufunc_db   win32Tc                    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   unittest_ExpectedFailuresysexc_info_UnexpectedSuccess)argskwargsfunc >/tmp/pip-target-vg8gfxp4/lib/python/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>8       z'_make_ufunc_usecase.<locals>.<listcomp>zdef fn({0}):
    np.{1}({0})fnz{0}_usecase)joinrangenargsr.   __name__execglobals)ufuncldictarg_strfunc_strr4   r'   r'   r(   _make_ufunc_usecase6   s   r?   c                 C   4   i }t d| t | |d }dt| |_|S )Nzdef fn(x):
    return {0}(x)r4   usecase_{0}r9   r.   r:   hashr8   ufunc_opr<   r4   r'   r'   r(   _make_unary_ufunc_op_usecase?   
   rF   c                 C   r@   )Nzdef fn(x,y):
    return x{0}yr4   rA   rB   rD   r'   r'   r(   _make_binary_ufunc_op_usecaseF   rG   rH   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}yr4   rA   c                    s    | | d S r   r'   xyrE   r'   r(   
inplace_opY      z2_make_inplace_ufunc_op_usecase.<locals>.inplace_op)
isinstancestrr9   r.   r:   rC   r8   )rE   r<   r4   rM   r'   rL   r(   _make_inplace_ufunc_op_usecaseN   s   
rQ   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dtyperP   type)r0   tyvalr'   r'   r(   r2   b   s   $ z#_as_dtype_value.<locals>.<listcomp>)zip)tyargsr#   r'   r'   r(   _as_dtype_value_   s   rY   c                       s*   e Zd Z fddZ		dddZ  ZS )BaseUFuncTestc                    sH  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| _t | _d S )Nr                          ?u4rS   Cu8)r\   r   r[   i4i8)r]   r^   r_   f4f8)superrZ   setUprR   uint32r   int32uint64int64float32float64arrayArrayint8int16uint8uint16inputsr   cacheself	__class__r'   r(   ri   h   s:         """" zBaseUFuncTest.setUpNc                 C   s   |}t |tjr|j}|tjv r$|rt|dd}|S t|dd}|S |tjv r=|r4t|dd}|S t|dd}|S |rHt|dd}|S t|dd}|S )Nr[   rb   )rO   r   rq   rS   signed_domainunsigned_domain)ry   
input_typeint_output_typefloat_output_typerU   output_typer'   r'   r(   _determine_output_type   s(   

z$BaseUFuncTest._determine_output_type)NN)r8   
__module____qualname__ri   r   __classcell__r'   r'   rz   r(   rZ   f   s
    $rZ   c                   @   s^  e Zd Zeg g ddddfddZdefddZefdd	Zefd
dZefddZefddZ	dd Z
dd ZefddZdd ZefddZefddZefddZefddZefd d!Zefd"d#Zefd$d%Zefd&d'Zefd(d)Zeejfd*d+Zefd,d-Zefd.d/Zefd0d1Zefd2d3Zefd4d5Zefd6d7Zefd8d9Z efd:d;Z!efd<d=Z"efd>d?Z#efd@dAZ$efdBdCZ%efdDdEZ&efdFdGZ'efdHdIZ(efdJdKZ)efdLdMZ*efdNdOZ+efdPdQZ,efdRdSZ-efdTdUZ.efdVdWZ/efdXdYZ0efdZd[Z1efd\d]Z2efd^d_Z3efd`daZ4efdbdcZ5efdddeZ6efdfdgZ7efdhdiZ8efdjdkZ9efdldmZ:efdndoZ;efdpdqZ<efdrdsZ=efdtduZ>efdvdwZ?efdxdyZ@efdzd{ZAefd|d}ZBefd~dZCefddZDefddZEefddZFefddZGefddZHefddZIefddZJefddZKefddZLefddZMefddZNefddZOdd ZPefddZQefddZRefddZSefddZTefddZUefddZVeWefddZXeWefddZYefddZZefddZ[efddZ\efddZ]efddZ^dd Z_dd Z`dd Zadd Zbdd ZcdS )
TestUFuncsNifcFc	                    s0  |  t 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 }| jj|	|| |d}|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   r[   flagsc                    $   g | ]}t j d  j|jjdqS r   ra   rR   zerossizerS   namer0   out_tyr#   r'   r(   r2          z/TestUFuncs.basic_ufunc_test.<locals>.<listcomp>c                    r   r   r   r   r   r'   r(   r2      r   c                 S      g | ]}t jd |jjdqS r[   ra   rR   r   rS   r   r   r'   r'   r(   r2          c                 S   r   r   r   r   r'   r'   r(   r2      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)"reset_module_warningsr8   r?   listrv   rO   tupleninrR   anyrS   kindr   noutrw   compileentry_pointndarraywarningscatch_warningssimplefilter
issubclasscategoryRuntimeWarningrP   message
startswithrW   r5   r.   testingassert_array_almost_equalAssertionErrorprint)ry   r;   r   skip_inputsadditional_inputsr   r   kindspositive_onlypyfuncrv   input_tupleinput_operandr~   is_tupler   input_typesoutput_typescrcfuncresultsexpectedinvalid_flagwarnlistwarnmsgthiswarn
expected_iresult_imsgr'   r   r(   basic_ufunc_test   s   






zTestUFuncs.basic_ufunc_testc                 C   s8   | j ||tjtjttjddttjddgd d S )Nr[   rb   )r   r   )r   r   rn   ro   rq   )ry   r   r   r'   r'   r(   basic_int_ufunc_test  s   
zTestUFuncs.basic_int_ufunc_testc                 C      | j tj|d d S Nr   )r   rR   addry   r   r'   r'   r(   test_add_ufunc     zTestUFuncs.test_add_ufuncc                 C   r   r   )r   rR   subtractr   r'   r'   r(   test_subtract_ufunc  r   zTestUFuncs.test_subtract_ufuncc                 C   r   r   )r   rR   multiplyr   r'   r'   r(   test_multiply_ufunc  r   zTestUFuncs.test_multiply_ufuncc                 C   s    d }t j}| jtj||d d S N)r   r   )r   ro   r   rR   divide)ry   r   int_out_typer'   r'   r(   test_divide_ufunc  s   zTestUFuncs.test_divide_ufuncc                 C      | j tjdd d S Nf)r   )r   rR   	logaddexprx   r'   r'   r(   test_logaddexp_ufunc"  r   zTestUFuncs.test_logaddexp_ufuncc                 C   r   r   )r   rR   
logaddexp2rx   r'   r'   r(   test_logaddexp2_ufunc%  r   z TestUFuncs.test_logaddexp2_ufuncc                 C   s   | j tj|tjd d S r   )r   rR   true_divider   ro   r   r'   r'   r(   test_true_divide_ufunc(  s   z!TestUFuncs.test_true_divide_ufuncc                 C   s   |  tj d S r   )r   rR   floor_dividerx   r'   r'   r(   test_floor_divide_ufunc+  s   z"TestUFuncs.test_floor_divide_ufuncc                 C   s,   | j tjtjttjddtjg|d d S )Nr[   rb   )r   r   r   )r   rR   negativer   rm   rq   rj   r   r'   r'   r(   test_negative_ufunc.  s   
zTestUFuncs.test_negative_ufuncc                 C   r   r   )r   rR   positiver   r'   r'   r(   test_positive_ufunc5  r   zTestUFuncs.test_positive_ufuncc                 C      | j tj|dd d S )NT)r   r   )r   rR   powerr   r'   r'   r(   test_power_ufunc8  s   

zTestUFuncs.test_power_ufuncc                 C   r   )Nfcr   r   )r   rR   float_powerr   r'   r'   r(   test_float_power_ufunc<     z!TestUFuncs.test_float_power_ufuncc                 C   r   Niur   )r   rR   gcdr   r'   r'   r(   test_gcd_ufunc?  r   zTestUFuncs.test_gcd_ufuncc                 C   r   r   )r   rR   lcmr   r'   r'   r(   test_lcm_ufuncB  r   zTestUFuncs.test_lcm_ufuncc                 C   r   r   )r   rR   	remainderr   r'   r'   r(   test_remainder_ufuncE  r   zTestUFuncs.test_remainder_ufuncc              	   C   s:   | j tj|dtttjjtdftjfgd d S )Nifcu   r   r   r   )r   rR   modrl   iinfomaxr   r   r'   r'   r(   test_mod_ufuncH  s   "
zTestUFuncs.test_mod_ufuncc                 C   r   r   )r   rR   fmodr   r'   r'   r(   test_fmod_ufuncN  r   zTestUFuncs.test_fmod_ufuncc                 C   st   | j ||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d d S )N)r   r   )r   rR   rj   r   r   r   rl   rn   finfominro   )ry   r   r;   r'   r'   r(   test_abs_ufuncQ  s   
zTestUFuncs.test_abs_ufuncc                 C   s   | j |tjd d S )N)r   r;   )r  rR   absoluter   r'   r'   r(   test_absolute_ufuncZ  r   zTestUFuncs.test_absolute_ufuncc                 C   r   Nr   r   )r   rR   fabsr   r'   r'   r(   test_fabs_ufunc]  r   zTestUFuncs.test_fabs_ufuncc                 C   r   Ncfr   )r   rR   rintr   r'   r'   r(   test_rint_ufunc`  r   zTestUFuncs.test_rint_ufuncc                 C   r   r   )r   rR   signr   r'   r'   r(   test_sign_ufuncc  r   zTestUFuncs.test_sign_ufuncc                 C   r   r   )r   rR   conjr   r'   r'   r(   test_conj_ufuncf  r   zTestUFuncs.test_conj_ufuncc                 C   r   r	  )r   rR   expr   r'   r'   r(   test_exp_ufunci  r   zTestUFuncs.test_exp_ufuncc                 C   r   r	  )r   rR   exp2r   r'   r'   r(   test_exp2_ufuncl  r   zTestUFuncs.test_exp2_ufuncc                 C   r   r	  )r   rR   logr   r'   r'   r(   test_log_ufunco  r   zTestUFuncs.test_log_ufuncc                 C   r   r	  )r   rR   log2r   r'   r'   r(   test_log2_ufuncr  r   zTestUFuncs.test_log2_ufuncc                 C   r   r	  )r   rR   log10r   r'   r'   r(   test_log10_ufuncu  r   zTestUFuncs.test_log10_ufuncc                 C   r   r	  )r   rR   expm1r   r'   r'   r(   test_expm1_ufuncx  r   zTestUFuncs.test_expm1_ufuncc                 C   r   r	  )r   rR   log1pr   r'   r'   r(   test_log1p_ufunc{  r   zTestUFuncs.test_log1p_ufuncc                 C   r   r	  )r   rR   sqrtr   r'   r'   r(   test_sqrt_ufunc~  r   zTestUFuncs.test_sqrt_ufuncc                 C   r   r   )r   rR   squarer   r'   r'   r(   test_square_ufunc  r   zTestUFuncs.test_square_ufuncc                 C   r   r  )r   rR   cbrtr   r'   r'   r(   test_cbrt_ufunc  r   zTestUFuncs.test_cbrt_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 S )Nr[   rb   )r   r   )	r   rq   rj   rk   rl   rm   r   rR   
reciprocalry   r   to_skipr'   r'   r(   test_reciprocal_ufunc  s   z TestUFuncs.test_reciprocal_ufuncc                 C   r   r   )r   rR   	conjugater   r'   r'   r(   test_conjugate_ufunc  r   zTestUFuncs.test_conjugate_ufuncc                 C   r   r	  )r   rR   sinr   r'   r'   r(   test_sin_ufunc  r   zTestUFuncs.test_sin_ufuncc                 C   r   r	  )r   rR   cosr   r'   r'   r(   test_cos_ufunc  r   zTestUFuncs.test_cos_ufuncc                 C   r   r	  )r   rR   tanr   r'   r'   r(   test_tan_ufunc  r   zTestUFuncs.test_tan_ufuncc                 C   r   r	  )r   rR   arcsinr   r'   r'   r(   test_arcsin_ufunc  r   zTestUFuncs.test_arcsin_ufuncc                 C   r   r	  )r   rR   arccosr   r'   r'   r(   test_arccos_ufunc  r   zTestUFuncs.test_arccos_ufuncc                 C   r   r	  )r   rR   arctanr   r'   r'   r(   test_arctan_ufunc  r   zTestUFuncs.test_arctan_ufuncc                 C   r   r	  )r   rR   arctan2r   r'   r'   r(   test_arctan2_ufunc  r   zTestUFuncs.test_arctan2_ufuncc                 C   r   r   )r   rR   hypotr   r'   r'   r(   test_hypot_ufunc  r   zTestUFuncs.test_hypot_ufuncc                 C   r   r	  )r   rR   sinhr   r'   r'   r(   test_sinh_ufunc  r   zTestUFuncs.test_sinh_ufuncc                 C   r   r	  )r   rR   coshr   r'   r'   r(   test_cosh_ufunc  r   zTestUFuncs.test_cosh_ufuncc                 C   r   r	  )r   rR   tanhr   r'   r'   r(   test_tanh_ufunc  r   zTestUFuncs.test_tanh_ufuncc                 C   r   r	  )r   rR   arcsinhr   r'   r'   r(   test_arcsinh_ufunc  r   zTestUFuncs.test_arcsinh_ufuncc                 C   r   r	  )r   rR   arccoshr   r'   r'   r(   test_arccosh_ufunc  r   zTestUFuncs.test_arccosh_ufuncc                 C   sd   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 )Nr[   rb   r
  )r   r   r   )	r   rq   rj   rk   rl   rm   r   rR   arctanhr&  r'   r'   r(   test_arctanh_ufunc  s   	
zTestUFuncs.test_arctanh_ufuncc                 C   r   r  )r   rR   deg2radr   r'   r'   r(   test_deg2rad_ufunc  r   zTestUFuncs.test_deg2rad_ufuncc                 C   r   r  )r   rR   rad2degr   r'   r'   r(   test_rad2deg_ufunc  r   zTestUFuncs.test_rad2deg_ufuncc                 C   r   r  )r   rR   degreesr   r'   r'   r(   test_degrees_ufunc  r   zTestUFuncs.test_degrees_ufuncc                 C   r   r  )r   rR   radiansr   r'   r'   r(   test_radians_ufunc  r   zTestUFuncs.test_radians_ufuncc                 C   r   r   )r   rR   bitwise_andr   r'   r'   r(   test_bitwise_and_ufunc  r   z!TestUFuncs.test_bitwise_and_ufuncc                 C   r   r   )r   rR   
bitwise_orr   r'   r'   r(   test_bitwise_or_ufunc  r   z TestUFuncs.test_bitwise_or_ufuncc                 C   r   r   )r   rR   bitwise_xorr   r'   r'   r(   test_bitwise_xor_ufunc  r   z!TestUFuncs.test_bitwise_xor_ufuncc                 C   r   r   )r   rR   invertr   r'   r'   r(   test_invert_ufunc  r   zTestUFuncs.test_invert_ufuncc                 C   r   r   )r   rR   bitwise_notr   r'   r'   r(   test_bitwise_not_ufunc  r   z!TestUFuncs.test_bitwise_not_ufuncc                 C   r   r   )r   rR   greaterr   r'   r'   r(   test_greater_ufunc  r   zTestUFuncs.test_greater_ufuncc                 C   r   r   )r   rR   greater_equalr   r'   r'   r(   test_greater_equal_ufunc  r   z#TestUFuncs.test_greater_equal_ufuncc                 C   r   r   )r   rR   lessr   r'   r'   r(   test_less_ufunc   r   zTestUFuncs.test_less_ufuncc                 C   r   r   )r   rR   
less_equalr   r'   r'   r(   test_less_equal_ufunc  r   z TestUFuncs.test_less_equal_ufuncc                 C   r   r   )r   rR   	not_equalr   r'   r'   r(   test_not_equal_ufunc  r   zTestUFuncs.test_not_equal_ufuncc                 C   r   r   )r   rR   equalr   r'   r'   r(   test_equal_ufunc	  r   zTestUFuncs.test_equal_ufuncc                 C   r   r   )r   rR   logical_andr   r'   r'   r(   test_logical_and_ufunc  r   z!TestUFuncs.test_logical_and_ufuncc                 C   r   r   )r   rR   
logical_orr   r'   r'   r(   test_logical_or_ufunc  r   z TestUFuncs.test_logical_or_ufuncc                 C   r   r   )r   rR   logical_xorr   r'   r'   r(   test_logical_xor_ufunc  r   z!TestUFuncs.test_logical_xor_ufuncc                 C   r   r   )r   rR   logical_notr   r'   r'   r(   test_logical_not_ufunc  r   z!TestUFuncs.test_logical_not_ufuncc                 C   r   r   )r   rR   maximumr   r'   r'   r(   test_maximum_ufunc  r   zTestUFuncs.test_maximum_ufuncc                 C   r   r   )r   rR   minimumr   r'   r'   r(   test_minimum_ufunc  r   zTestUFuncs.test_minimum_ufuncc                 C   r   r   )r   rR   fmaxr   r'   r'   r(   test_fmax_ufunc  r   zTestUFuncs.test_fmax_ufuncc                 C   r   r   )r   rR   fminr   r'   r'   r(   test_fmin_ufunc!  r   zTestUFuncs.test_fmin_ufuncc                 C   s&   t jddgt jdttjddfgS )NTFra   r[   rb   )rR   rp   bool_r   rq   rx   r'   r'   r(   bool_additional_inputs(  s   z!TestUFuncs.bool_additional_inputsc                 C      | j tj|d|  d d S Nifcbr   )r   rR   isfiniterv  r   r'   r'   r(   test_isfinite_ufunc.     
zTestUFuncs.test_isfinite_ufuncc                 C   rw  rx  )r   rR   isinfrv  r   r'   r'   r(   test_isinf_ufunc4  r|  zTestUFuncs.test_isinf_ufuncc                 C   rw  rx  )r   rR   isnanrv  r   r'   r'   r(   test_isnan_ufunc:  r|  zTestUFuncs.test_isnan_ufuncc                 C   r   r   )r   rR   signbitr   r'   r'   r(   test_signbit_ufunc@  r   zTestUFuncs.test_signbit_ufuncc                 C   r   r  )r   rR   copysignr   r'   r'   r(   test_copysign_ufuncC  r   zTestUFuncs.test_copysign_ufuncc                 C   r   r  )r   rR   	nextafterr   r'   r'   r(   test_nextafter_ufuncF  r   zTestUFuncs.test_nextafter_ufuncc                 C   r   r  )r   rR   modfr   r'   r'   r(   test_modf_ufuncI     zTestUFuncs.test_modf_ufuncc                 C   r   r  )r   rR   frexpr   r'   r'   r(   test_frexp_ufuncQ  r  zTestUFuncs.test_frexp_ufuncc                 C   r   r  )r   rR   floorr   r'   r'   r(   test_floor_ufuncU  r   zTestUFuncs.test_floor_ufuncc                 C   r   r  )r   rR   ceilr   r'   r'   r(   test_ceil_ufuncX  r   zTestUFuncs.test_ceil_ufuncc                 C   r   r  )r   rR   truncr   r'   r'   r(   test_trunc_ufunc[  r   zTestUFuncs.test_trunc_ufuncc                 C   r   r  )r   rR   spacingr   r'   r'   r(   test_spacing_ufunc^  r   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`| jj||||
f|d}|j}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 rOdnd}| j|||d q`d S )Nr[   r\   r_   r   rc   ra   rb   re   r]   rg   r   r   r   rS   singledouble)prec)r8   r?   r   rl   rm   ro   rR   rp   rq   	itertoolsproductrj   rO   rw   r   r   r   r   r   rS   r   getattrrn   	complex64assertPreciseEqual)ry   r;   r   
ufunc_nameinputs1inputs2r   r   input1input2r   input1_operandinput1_typeinput2_operandinput2_typer   r   resultr   scalar_typer  r'   r'   r(   binary_ufunc_mixed_types_testd  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}| jj|||ftd}|j}	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 ]M\}}ttj	|j
d}ttj	|j
d}ttj	t|j
|j
d}| jj||||ftd}|j}	t||}
tj|
jd	d}|	||| | ||
 q.d S )
N   re   ra   r[   	      rb   r   rc   )r?   rR   r   arangereshaper   rW   r   rq   rl   ndimrm   rw   r   no_pyobj_flagsr   shaperS   r  r   r  r  r   )ry   r   input_operandsoutput_operandsrJ   r  r~   r   r   r   r   input1_operandsinput2_operandsrK   r  r  r'   r'   r(   test_broadcasting  sf   
	

zTestUFuncs.test_broadcastingc                 C   sZ   |  t dd }ttjdd}t|||ftd}W d    d S 1 s&w   Y  d S )Nc                 S      t | |S r   rR   r   a0a1r'   r'   r(   myadd     z2TestUFuncs.test_implicit_output_npm.<locals>.myaddr[   rb   r   )assertRaisesr   r   rq   rl   r   r  )ry   r  arr_tyr   r'   r'   r(   test_implicit_output_npm  s   
"z#TestUFuncs.test_implicit_output_npmc                 C   sD  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 ]6\}}ttj|jd	}ttj|jd	}| j	j
|||ftd
}|j}	t ||}
|	||}t j|
| qid S )Nc                 S   r  r   r  r  r'   r'   r(   r     r  zATestUFuncs.test_broadcast_implicit_output_npm_nrt.<locals>.pyfuncr  rc   ra   r  r  r[   rb   r   )rR   r  r  r  r  r   rq   rl   r  rw   r   enable_nrt_flagsr   r   r   assert_array_equal)ry   r   r  r  rJ   rK   r  r  r   r   r   r  r'   r'   r(   &test_broadcast_implicit_output_npm_nrt  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\}	}
| jj|t|	t|
ftd}||	|
}||	|
}| |jj|jj | |jj	|jj	 t j|| qvd S )Nc                 S   r  r   r  r  r'   r'   r(   r     r  z=TestUFuncs.test_implicit_output_layout_binary.<locals>.pyfuncr   r[      r   r   Forderrb   A   r   )rR   linspacer  rp   Tr   r   c_contiguouslayoutf_contiguousr   r  permutationsrw   r   r  r   assertEqualr   r  )ry   r   XYZXtyYtyZty	testcasesarg0arg1r   r   r  r'   r'   r(   "test_implicit_output_layout_binary  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}| j
j|t|ftd}	||}
|	|}| |
jj|jj | |
jj	|jj	 t j|
| qYd S )Nc                 S   
   t | S r   rR   r  )r  r'   r'   r(   r   =     
z<TestUFuncs.test_implicit_output_layout_unary.<locals>.pyfuncr   r[   r  r   r   r  r  rb   r  r   )rR   r  r  rp   r  r   r   r  r  r  rw   r   r  r   r  r   r  )ry   r   r  r  r  r  r  r  r  r   r   r  r'   r'   r(   !test_implicit_output_layout_unary<  s4   


z,TestUFuncs.test_implicit_output_layout_unary)dr8   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rR   absr  r  r  r  r  r  r  r  r  r  r  r  r  r   r"  r$  r(  r*  r,  r.  r0  r2  r4  r6  r8  r:  r<  r>  r@  rB  rD  rF  rH  rJ  rL  rN  rP  rR  rT  rV  rX  rZ  r\  r^  r`  rb  rd  rf  rh  rj  rl  rn  rp  rr  rt  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      s    
b		
ID%r   c                   @   s  e Zd Zdd Zeg g ddfddZeg g dddf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)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d 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.dS )ZTestArrayOperatorsc                 C   s&   |  |jj|jj tj|| d S r   )r  rS   r   rR   r   r   )ry   r   gotr'   r'   r(   _check_results`  s   z!TestArrayOperators._check_resultsNc                 C   s   t |}t| j}|| |}	|D ],}
|
\}}||v s"t|tjs#q| jj|	|f|d}|j	}|	|}||}| 
|| qd S r   )rF   r   rv   extendrO   r   rq   rw   r   r   r  )ry   operatorr   r   r   r   r   operator_funcrv   r   r   r   r~   r   r   r   r  r'   r'   r(   unary_op_testd  s$   


z TestArrayOperators.unary_op_testFc                 C   s  t |}t| j}	|	| |}
tjd}|	D ]i}|\}}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| jj|
||f|d}|j}|
||}|||}| || qd S )Nr[   rS   ra   r   d   
   r   )rH   r   rv   r  rR   randomRandomStater   as_dtyper  r   rO   r   rq   r   uniformastyper   rw   r   r   r  )ry   r  r   r   r   r   r   positive_rhsr  rv   r   random_stater   input_operand1r~   input_dtypeinput_type1zeroinput_operand0input_type0r   r   r   r  r'   r'   r(   binary_op_testy  sF   




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 )NTFr[   rb   )r   booleanrR   rp   rq   rx   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   r[   rb   )
setdefaultr   rn   ro   rq   r  )ry   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  )ry   r#   r  r   r'   r'   r(   binary_bitwise_op_test  s   z)TestArrayOperators.binary_bitwise_op_testc                    s   t |}|} fdd|D }fddD }	fddD }
|	|
 }t||D ]2\}}t|}t|}| jj|||ftd}|j}| }||| | }||| | 	|| q+d S )Nc                       g | ]	}t j |d qS ra   rR   rp   r0   rS   )
lhs_valuesr'   r(   r2         z6TestArrayOperators.inplace_op_test.<locals>.<listcomp>c                    r  r  r  r  )
rhs_valuesr'   r(   r2     r   c                    s   g | ]} D ]}||qqS r'   r'   )r0   vrS   )
rhs_dtypesr'   r(   r2         r   )
rQ   r  r  r   rw   r   r  r   copyr  )ry   r  r  r  
lhs_dtypesr  r  r   
lhs_inputs
rhs_arraysrhs_scalars
rhs_inputslhsrhslhs_typerhs_typer   r   r   r  r'   )r  r  r  r(   inplace_op_test  s.   



z"TestArrayOperators.inplace_op_testc              	   C   s&   |  |||tjtjftjtjtjfS r   )r  rR   rn   ro   rm   ry   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  rR   rs   rk   rm   rj   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  rR   ru  r  r'   r'   r(   inplace_bitwise_op_test  s   
z*TestArrayOperators.inplace_bitwise_op_testc                 C      |  d d S N+r  rx   r'   r'   r(   test_unary_positive_array_op  rN   z/TestArrayOperators.test_unary_positive_array_opc                 C   r  N-r  rx   r'   r'   r(   test_unary_negative_array_op  rN   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~r[   rb   )r   r   )r  r   rn   ro   rq   r  rx   r'   r'   r(   test_unary_invert_array_op  s   
z-TestArrayOperators.test_unary_invert_array_opc                 C   2   |  dg dg d |  tjg dg d d S )Nz+=r\         ?r  r         @)r  r  iaddrx   r'   r'   r(   test_inplace_add     z#TestArrayOperators.test_inplace_addc                 C   r  )Nz-=r  r!  )r  r  isubrx   r'   r'   r(   test_inplace_sub  r&  z#TestArrayOperators.test_inplace_subc                 C   r  )Nz*=r  r!  )r  r  imulrx   r'   r'   r(   test_inplace_mul  r&  z#TestArrayOperators.test_inplace_mulc                 C   r  )Nz//=r  r"  g      ?r#  )r  r  	ifloordivrx   r'   r'   r(   test_inplace_floordiv  r&  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  itruedivrx   r'   r'   r(   test_inplace_div
  r&  z#TestArrayOperators.test_inplace_divc                 C   r  )Nz%=r  r"  r  r#  )r  r  imodrx   r'   r'   r(   test_inplace_remainder  r&  z)TestArrayOperators.test_inplace_remainderc                 C   r  )Nz**=r  r0  )r  r  ipowrx   r'   r'   r(   test_inplace_pow  r&  z#TestArrayOperators.test_inplace_powc                 C   r  )Nz&=r   r[   r  r  3   r      r   *      )r  r  iandrx   r'   r'   r(   test_inplace_and  r&  z#TestArrayOperators.test_inplace_andc                 C   r  )Nz|=r5  r7  )r  r  iorrx   r'   r'   r(   test_inplace_or  r&  z"TestArrayOperators.test_inplace_orc                 C   r  )Nz^=r5  r7  )r  r  ixorrx   r'   r'   r(   test_inplace_xor  r&  z#TestArrayOperators.test_inplace_xorc                 C   r  )Nz<<=r   r   iir   r[   r      )r  r  ilshiftrx   r'   r'   r(   test_inplace_lshift"  r&  z&TestArrayOperators.test_inplace_lshiftc                 C   r  )Nz>>=rA  rB  )r  r  irshiftrx   r'   r'   r(   test_inplace_rshift&  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 )Nr  r   r   r[   r'   )r  a2r'   r'   r(   r   1  s   z:TestArrayOperators.test_unary_positive_array_op.<locals>.fr  r   r[   N)rR   r   
assertTruer   r   r  )ry   r   r  rH  a3a4r'   r'   r(   r  *  s   
&
&c                 C   r  r  r  rx   r'   r'   r(   test_add_array_opC  rN   z$TestArrayOperators.test_add_array_opc                 C   r  r  rL  rx   r'   r'   r(   test_subtract_array_opF  rN   z)TestArrayOperators.test_subtract_array_opc                 C   r  )N*rL  rx   r'   r'   r(   test_multiply_array_opI  rN   z)TestArrayOperators.test_multiply_array_opc                 C   s   d }t j}| jd|d d S )N/)r   )r   ro   r  )ry   r   r'   r'   r(   test_divide_array_opL  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 )Nr[   r   r   r"  r]   r   g      g      @r  r`   ra   rb   r  rc   )r\   r[   r   rd   )r\   r[      re   rf   rg   z//)rR   rj   r   rk   rl   rm   rn   ro   rp   rq   rv   r  rx   r'   r'   r(   test_floor_divide_array_opQ  s$         z-TestArrayOperators.test_floor_divide_array_opc                 C   r  )N%rL  rx   r'   r'   r(   test_remainder_array_opk  rN   z*TestArrayOperators.test_remainder_array_opc                 C      | j ddd d S )Nz**Tr  rL  rx   r'   r'   r(   test_power_array_opn     z&TestArrayOperators.test_power_array_opc                 C   rX  )Nz<<TrY  r  rx   r'   r'   r(   test_left_shift_array_opq  r[  z+TestArrayOperators.test_left_shift_array_opc                 C   rX  )Nz>>TrY  r\  rx   r'   r'   r(   test_right_shift_array_opt  r[  z,TestArrayOperators.test_right_shift_array_opc                 C   r  )N&r  rx   r'   r'   r(   test_bitwise_and_array_opw  rN   z,TestArrayOperators.test_bitwise_and_array_opc                 C   r  )N|r`  rx   r'   r'   r(   test_bitwise_or_array_opz  rN   z+TestArrayOperators.test_bitwise_or_array_opc                 C   r  )N^r`  rx   r'   r'   r(   test_bitwise_xor_array_op}  rN   z,TestArrayOperators.test_bitwise_xor_array_opc                 C   r  )Nz==rL  rx   r'   r'   r(   test_equal_array_op  rN   z&TestArrayOperators.test_equal_array_opc                 C   r  )N>rL  rx   r'   r'   r(   test_greater_array_op  rN   z(TestArrayOperators.test_greater_array_opc                 C   r  )Nz>=rL  rx   r'   r'   r(   test_greater_equal_array_op  rN   z.TestArrayOperators.test_greater_equal_array_opc                 C   r  )N<rL  rx   r'   r'   r(   test_less_array_op  rN   z%TestArrayOperators.test_less_array_opc                 C   r  )Nz<=rL  rx   r'   r'   r(   test_less_equal_array_op  rN   z+TestArrayOperators.test_less_equal_array_opc                 C   r  )Nz!=rL  rx   r'   r'   r(   test_not_equal_array_op  rN   z*TestArrayOperators.test_not_equal_array_op)/r8   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r(  r*  r-  r/  r2  r4  r<  r>  r@  rE  rG  rM  rN  rP  rR  rU  rW  rZ  r]  r^  ra  rc  re  rf  rh  ri  rk  rl  rm  r'   r'   r'   r(   r  ^  sh    

+		
r  c                   @   s8   e Zd ZdZeZdd Zdd Zdd Zefdd	Z	d
S )TestScalarUFuncsai  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

    This class tests regular uses. A subclass tests the no python backend.
    c                 C   s6  t ||D ]\}}t||| jd}|j}|| }|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 rFt|	}	n&t|	jtjrSt|	}	nt|	jtjr`t|	}	nt|	jtjrlt|	}	|jj|jjf }tdd |D rd}ntdd |D rd}nd}| j||	|
|d	 qd S )
Nr   zfor args {0} typed {1}c                 S      g | ]}|t jkqS r'   )r   rn   r0   tr'   r'   r(   r2     r3   z.TestScalarUFuncs.run_ufunc.<locals>.<listcomp>r  c                 S   ro  r'   )r   ro   rp  r'   r'   r(   r2     r3   r  exact)r   r  )rW   r   _compile_flagsr   rY   r.   setr   rk   rl   rm   floatrR   
issubdtyperS   inexactintegerintru  bool	signaturer#   return_typer   r  )ry   r   	arg_types
arg_valuesrX   r#   r   r   r  r   r   specialalltypesr  r'   r'   r(   	run_ufunc  s2   


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  rJ   r'   r'   r(   _func  r  z7TestScalarUFuncs.test_scalar_unary_ufunc.<locals>._func)r  r  )r[   r  )皙?)皙?)r   rk   rj   rm   rl   rn   ro   r  ry   r  vals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  rI   r'   r'   r(   r    r  z@TestScalarUFuncs.test_scalar_binary_uniform_ufunc.<locals>._funcr  r  r[   r  r  r  )	r   rk   rj   rm   rl   rn   ro   r  rW   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  rI   r'   r'   r(   r    r  z>TestScalarUFuncs.test_scalar_binary_mixed_ufunc.<locals>._funcr  )
r   rk   rj   rm   rl   rn   ro   r  r  r  )ry   r   r  r  r  r'   r'   r(   test_scalar_binary_mixed_ufunc  s   
z/TestScalarUFuncs.test_scalar_binary_mixed_ufuncN)
r8   r   r   __doc__enable_pyobj_flagsrs  r  r  r  r  r'   r'   r'   r(   rn    s    	/
rn  c                   @   s   e Zd ZdZeZdS )TestScalarUFuncsNoPythonz:Same tests as TestScalarUFuncs, but forcing no python modeN)r8   r   r   r  r  rs  r'   r'   r'   r(   r    s    r  c                   @   s6   e Zd Zdd Zeejdkd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  )x1x2r'   r'   r(   foo  s   z+TestUfuncIssues.test_issue_651.<locals>.foor  rg   ra   )r   rR   r  r  )ry   r  abr'   r'   r(   test_issue_651  s
   
"zTestUfuncIssues.test_issue_651)r[      z4Complex floor division support removed in NumPy 1.22c                 C   s8   dd }t |tjtjg}| |dd|dd d S )Nc                 S   r  r   )rR   r   rI   r'   r'   r(   r    r  z+TestUfuncIssues.test_issue_713.<locals>.foo              ?)r   r   
complex128r  r   )ry   r  r   r'   r'   r(   test_issue_713   s   zTestUfuncIssues.test_issue_713c                    s   dd }|t dd  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   )rR   r   rI   r'   r'   r(   r    r  z,TestUfuncIssues.test_issue_2006.<locals>.fooTnopythonc                    s2    | |}t j|| | |j| j d S r   )rR   r   r   r  rS   )rJ   rK   r  r   r   ry   r'   r(   check  s   
z.TestUfuncIssues.test_issue_2006.<locals>.check)r[   r  r  )r  r  y      @      r  )r  r  r  N)r   rR   rn   r  rl   rm   )ry   r  r  xsrJ   r'   r  r(   test_issue_2006	  s   
zTestUfuncIssues.test_issue_2006N)
r8   r   r   r  r   skipIfr   numpy_versionr  r  r'   r'   r'   r(   r    s    

r  c                   @   sl   e Zd ZdZdZ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
    _compile_flags: compilation flags to use (to force nopython mode)
    _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'.
    OegGr  r   r   ))r3  r  )r1  D)r1  r  )r  r  )r?  r  )r#  dr   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 typebhilq)r[   r   r   rS  ra   BHILQ)r[   r  r   r   ?)TFFTr   mr[   zm8[D])r  NaTr   MzM8[D])Natr[      r   fdr   g      r^   nanFDr   y             y              y      ?      ?r  y                ztype %r not understood)rR   rp   lenru  r    platformRuntimeError)ry   a_letter_typeindexnegzeror'   r'   r(   _arg_for_typeB  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 )N_supported_typesc                 3   s    | ]}| vV  qd S r   r'   r0   l)supported_typesr'   r(   	<genexpr>s      z/_LoopTypesTester._check_loop.<locals>.<genexpr>_skip_typesc                 3       | ]}| v V  qd S r   r'   r  )
skip_typesr'   r(   r  v  r  _required_typesc                 3   r  r   r'   r  )letter_typesr'   r(   r  {  s    )r   r   r  r   _check_ufunc_with_dtypes)ry   r4   r;   looprequired_typesr'   )r  r  r  r(   _check_loopj  s   z_LoopTypesTester._check_loopc                    s  dd |D }dd |D }t || jd} fddt|D }|D ]} j| q#dd |D }	|j|  ||	  t||	|D ]G\}
}} |
||\}}|jj	} j
|j|fd}|dv rdd	nd
}|dv rldn|}dg d}||j||||} j|||||d qBd S )Nc                 S   s   g | ]}t |qS r'   )rR   rS   rp  r'   r'   r(   r2     r3   z=_LoopTypesTester._check_ufunc_with_dtypes.<locals>.<listcomp>c                 S   s   g | ]}t t|d dqS )r[   rb   )r   rq   r   rp  r'   r'   r(   r2     r  r   c                    s$   g | ]\}} j ||d dqS )r  r  )r  repeat)r0   r  rq  rx   r'   r(   r2     s    c                 S   s   g | ]}|  qS r'   )r  )r0   r  r'   r'   r(   r2     s    r[   fFr  rr  dDr  r   )z ufunc '{0}' arrays differ ({1}):z	args: {2}zexpected {3}zgot {4})r  r   ulps)r   rs  	enumerater  shuffler   rW   _fixup_resultsrS   char_ulpsgetr8   r5   r.   r  )ry   r4   r;   dtypesarg_dtyarg_nbtyr   c_argsarrpy_argsrS   py_argc_argtypecharr  r  r   r'   rx   r(   r    s.   

z)_LoopTypesTester._check_ufunc_with_dtypesc                 C   s   ||fS r   r'   )ry   rS   r  r  r'   r'   r(   r    s   z_LoopTypesTester._fixup_resultsc                 C   s   |j D ]}| || qd S r   )r   _inject_test)clsr;   r  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   )r?   r  )ry   r4   r  r;   r'   r(   test_template  s   z4_LoopTypesTester._inject_test.<locals>.test_templateztest_{0}_{1}z->_)setattrr.   r8   replace)r  r;   r  r  r'   r  r(   r    s   
z_LoopTypesTester._inject_testc                 C   s   | j D ]}| | qd S r   )_ufuncsr  )r  r;   r'   r'   r(   autogenerate  s   
z_LoopTypesTester.autogenerateNr   )r8   r   r   r  r  r  r  r  r  r  classmethodr  r  r  r'   r'   r'   r(   r  !  s(    
(

r  c                   @   sr   e Zd Ze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 )TestLoopTypesIntNoPythonNz?bBhHiIlLqQfdFDmMO)r8   r   r   r  rs  r   r  removerR   r   r%  
left_shiftright_shiftr   r   r  r  r  r'   r'   r'   r(   r    s    r  c                   @   s.   e Zd ZeZejejgZdZ	de
j d ZdS )(TestLoopTypesSubtractAndNegativeNoPythonz?bBhHiIlLqQfdFDmMOr  N)r8   r   r   r  rs  rR   r   r   r  r  r  r  r'   r'   r'   r(   r    s
    r  c                       8   e Zd ZeZejgZdZde	j
 Z
d fdd	Z  ZS )TestLoopTypesReciprocalNoPythonbBhHiIlLqQfdFDr  r   c                    s.   t | j| j||d}|dv rd||dk< |S )Nr  
bBhHiIlLqQr9  r   rh   r{   r  ry   r  r  resrz   r'   r(   r    s   z-TestLoopTypesReciprocalNoPython._arg_for_typer  )r8   r   r   r  rs  rR   r%  r  r  r  r  r  r   r'   r'   rz   r(   r        
r  c                       r  )TestLoopTypesPowerNoPythonr  r  r   c                    s6   t | j| j||d}|dv r|dkrd||dk < |S )Nr  r  r[   r  r   r  r  rz   r'   r(   r    s   z(TestLoopTypesPowerNoPython._arg_for_typer  )r8   r   r   r  rs  rR   r   r  r  r  r  r  r   r'   r'   rz   r(   r    r  r  c                       r  )!TestLoopTypesIntLeftShiftNoPythonr  r  r   c                    s@   t | j| j||d}|dkr|jjd }t|d|d }|S Nr  r[      r   )rh   r{   r  rS   itemsizerR   clipry   r  r  r  	bit_countrz   r'   r(   r    s   z/TestLoopTypesIntLeftShiftNoPython._arg_for_typer  )r8   r   r   r  rs  rR   r  r  r  r  r  r  r   r'   r'   rz   r(   r    r  r  c                       r  )"TestLoopTypesIntRightShiftNoPythonr  r  r   c                    sR   t | j| j||d}|dkr|jjd }t|d|d }|dkr't|}|S r  )rh   r{   r  rS   r  rR   r  r  r  rz   r'   r(   r    s   

z0TestLoopTypesIntRightShiftNoPython._arg_for_typer  )r8   r   r   r  rs  rR   r  r  r  r  r  r  r   r'   r'   rz   r(   r    r  r  c                   @   s6   e Zd ZeZejejejgZ	dZ
dej Zdd ZdS ) TestLoopTypesFloorDivideNoPythonr  r  c                 C   sF   |j dkrt|t|@ }||dk|dk@ O }|| ||< ||fS )Nr   r^   )r   rR   r}  r  )ry   rS   r  r  predr'   r'   r(   r  4  s
   
z/TestLoopTypesFloorDivideNoPython._fixup_resultsN)r8   r   r   r  rs  rR   r   r   divmodr  r  r  r  r  r'   r'   r'   r(   r  .  s    
r  c                   @   sj   e Zd Ze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 )TestLoopTypesFloatNoPythonNr  FDmMO)r8   r   r   r  rs  r   r  	iswindowsr  rR   r  r   r   r  r   r  r  r  r'   r'   r'   r(   r  A  s    r  c                   @   s*   e Zd ZeZedd ZdZdej	 Z	dS )TestLoopTypesComplexNoPythonNr  r  )
r8   r   r   r  rs  r   r  r  r  r  r'   r'   r'   r(   r  P  s
    r  c                   @   sd   e Zd Ze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 )TestLoopTypesDatetimeNoPythonN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  )rR   r   r?   r  r  r   ry   r;   r4   r'   r'   r(   test_addo     "z&TestLoopTypesDatetimeNoPython.test_addc                 C   r  )N)M8[s]M8[m]r  )r  r  r  )r  r  r  )r  r  r  )r  r  r  )rR   r   r?   r  r  r   r  r'   r'   r(   test_subtract|  r  z+TestLoopTypesDatetimeNoPython.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  )rR   r   r?   r  r  r   r  r'   r'   r(   test_multiply     "z+TestLoopTypesDatetimeNoPython.test_multiplyc                 C   r  )N)r  r  r  )r  r  r  r  r  r  r  r  r  r  )rR   r   r?   r  r  r   r  r'   r'   r(   test_true_divide  r  z.TestLoopTypesDatetimeNoPython.test_true_dividec                 C   r  )Nr  r  r  )rR   r   r?   r  r  r   r  r'   r'   r(   test_floor_divide  r  z/TestLoopTypesDatetimeNoPython.test_floor_dividec                 C   sT   t |}| ||g d | ||g d | ||g d | ||g d d S )N)r  r  r  )r  r  r  )r  r  r  )r  r  r  )r?   r  r  r'   r'   r(   _check_comparison  s
   z/TestLoopTypesDatetimeNoPython._check_comparisonc                 C   s0   t jt jt jt jt jt jfD ]}| | qd S r   )rR   rc  ra  r]  r_  rY  r[  r  )ry   r;   r'   r'   r(   test_comparisons  s
   z.TestLoopTypesDatetimeNoPython.test_comparisons)r8   r   r   r  rs  r   r  r  rR   r  r  r  r  r  r  r  r  r   r'   r'   r'   r(   r	  \  s    


	r	  c                   @   s(   e Zd ZeZdd Zdd Zdd ZdS )TestUFuncBadArgsNoPythonc                 C   *   dd }| j tt|tjgtj| jd d S )Nc                 S   s   t | }|S )zerror: np.add requires two argsr  )rJ   r  r'   r'   r(   r&     s   
z8TestUFuncBadArgsNoPython.test_missing_args.<locals>.funcr|  r   r  r   r   r   ro   rs  ry   r&   r'   r'   r(   test_missing_args  s   
z*TestUFuncBadArgsNoPython.test_missing_argsc                 C   s:   dd }t t jdd}| jtt||gd || jd d S )Nc                 S   s   t | | ||}|S )zerror: too many argsr  )rJ   outout2r  r'   r'   r(   r&     s   z9TestUFuncBadArgsNoPython.test_too_many_args.<locals>.funcr[   rb   r  r#  )r   rq   ro   r  r   r   rs  )ry   r&   
array_typer'   r'   r(   test_too_many_args  s
   
z+TestUFuncBadArgsNoPython.test_too_many_argsc                 C   r"  )Nc                 S   s   d}t | | | dS )z0error: scalar as a return value is not supportedr   Nr  rI   r'   r'   r(   r&     s   zITestUFuncBadArgsNoPython.test_no_scalar_result_by_reference.<locals>.funcr#  r$  r%  r'   r'   r(   "test_no_scalar_result_by_reference  s   
z;TestUFuncBadArgsNoPython.test_no_scalar_result_by_referenceN)r8   r   r   r  rs  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 )Nr[   r'   r  r'   r'   r(   r    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  ra   g      ?)rR   onesro   r   r  	Exceptionappend)r  r   e)errorsr  r'   r(   r)     s   z;TestUFuncCompilationThreadSafety.test_lock.<locals>.wrapperc                    s   g | ]}t j d qS ))target)	threadingThreadr/   )r)   r'   r(   r2     s    z>TestUFuncCompilationThreadSafety.test_lock.<locals>.<listcomp>r   N)r   r6   startr5   assertFalse)ry   threadsrq  r'   )r2  r  r)   r(   	test_lock  s   


z*TestUFuncCompilationThreadSafety.test_lockN)r8   r   r   r9  r'   r'   r'   r(   r-    s    r-  c                   @   s   e Zd Zdd Zdd ZdS )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   target_contextget_ufunc_inforR   r   assertIsInstancedictr   r  objectr  KeyError	exceptionr#   )ry   	targetctxadd_infor   badkeyraisesr'   r'   r(   test_cpu_get_ufunc_info  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   typing_contextr  NotImplementedErrorr<  rR   r   assertRegexrP   rA  )ry   rB  rE  r'   r'   r(   test_base_get_ufunc_info  s   z+TestUfuncOnContext.test_base_get_ufunc_infoN)r8   r   r   rF  rK  r'   r'   r'   r(   r:    s    r:  c                   @   r,  )TestUfuncWriteInputc                 C   sj   t dgdd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)Tr  c                 S   s(   t | jD ]}|d dkrd||< qd S )Nr   r   r[   )r6   r   )rJ   r'  r1   r'   r'   r(   r&     s
   z6TestUfuncWriteInput.test_write_input_arg.<locals>.funcr  r   ra   )TFFFTr   )axis)r   rR   r  rand
zeros_likerr   r   r  rp   ru  r   )ry   r&   rJ   r'  r'   r'   r(   test_write_input_arg  s   


z(TestUfuncWriteInput.test_write_input_argN)r8   r   r   rP  r'   r'   r'   r(   rL    s    rL  __main__)Wr*   r  rer    r   r4  r  numpyrR   r   numbar   r   r   
numba.corer   r   r   numba.core.compilerr   r	   r
   numba.np.numpy_supportr   r   r   numba.core.errorsr   r   r   numba.tests.supportr   r   r   r   numba.core.typing.npydeclr   r   numba.npr   numba.core.registryr   numba.core.baser   r   r   __itemsize__is32bitsr  r   r  r  enable_pyobjectno_rewritesr  r  nrtr,   r?   rF   rH   rQ   rY   rZ   r   r  rn  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r!  r-  r:  rL  r8   mainr'   r'   r'   r(   <module>   s    
	>     ?  7\- 	\
