U
    9%e                    @   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reD  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                     s<   z | | W n" t k
r0   tt Y nX tjd S N)r	   unittestZ_ExpectedFailuresysexc_infoZ_UnexpectedSuccess)argskwargsfunc V/var/www/html/Darija-Ai-API/env/lib/python3.8/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>(   s     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    r0   c                 C   s4   i }t d| t | |d }dt| |_|S )Nzdef fn(x):
    return {0}(x)r'   usecase_{0}r,   r"   r-   hashr+   ufunc_opr/   r'   r   r   r   _make_unary_ufunc_op_usecase0   s
    r6   c                 C   s4   i }t d| t | |d }dt| |_|S )Nzdef fn(x,y):
    return x{0}yr'   r1   r2   r4   r   r   r   _make_binary_ufunc_op_usecase8   s
    r7   c                    sP   t  tr<i }td t | |d }dt |_n 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'   r1   c                    s    | | d S r   r   xyr5   r   r   
inplace_opK   s    z2_make_inplace_ufunc_op_usecase.<locals>.inplace_op)
isinstancestrr,   r"   r-   r3   r+   )r5   r/   r'   r<   r   r;   r   _make_inplace_ufunc_op_usecase@   s    
r?   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dtyper>   type)r$   tyvalr   r   r   r&   T   s     z#_as_dtype_value.<locals>.<listcomp>)zip)tyargsr   r   r   r   _as_dtype_valueQ   s    rG   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                    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dddgddttjdd	ftjdddgddttjdd	ftjdddgddttj	dd	ftjdddg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rA   Cu8i4i8f4f8)superrH   setUpr@   uint32r   int32uint64int64float32float64arrayArrayint8int16Zuint8Zuint16inputsself	__class__r   r   rW   Y   sD      """""zBaseUFuncTest.setUpN)maxsizeFc                 C   s   t ||dd|S )NT)Z_nrtZno_rewrites)r   )rd   pyfuncr   nrtr   r   r   _compile   s    zBaseUFuncTest._compilec                 C   s   |}t |tjr|j}|j}nd}|tjkrP|r@t||d}qt||d}nP|tjkr~|rnt||d}qt||d}n"|rt||d}nt||d}|S )NrI   rP   )r=   r   r_   ndimrA   Zsigned_domainZunsigned_domain)rd   
input_typeint_output_typefloat_output_typerC   rk   output_typer   r   r   _determine_output_type   s"    

z$BaseUFuncTest._determine_output_type)F)NN)	r+   
__module____qualname__rW   r   	lru_cacherj   rp   __classcell__r   r   re   r   rH   W   s   &
  rH   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   )r0   rd   r.   r   r   r   r0      s    z"BasicUFuncTest._make_ufunc_usecaseNZifcFc                    s"  |  t | |}t| j| }	|	D ]}
|
d }|
d }t|t}|rP| n|f|j  ||krfq&|r~t	 d dk r~q& d j
j|krq&| |||}|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
P}td | |  d}|D ]*}t|jtrNt|j|rNd	}qNW 5 Q R X | |  t||D ]\}}ddddddddg|j|||||j
|}ztjj||d|d W n. tk
r   |rtd|
|| n Y nX qq&d S )Nr   rI   c                    s$   g | ]}t j d  j|jjdqS r   rO   r@   zerosshaperA   namer$   Zout_tyr   r   r   r&      s   z3BasicUFuncTest.basic_ufunc_test.<locals>.<listcomp>c                    s$   g | ]}t j d  j|jjdqS rw   rx   r|   r}   r   r   r&      s   c                 S   s   g | ]}t jd |jjdqS rI   rO   r@   ry   rA   r{   r|   r   r   r   r&      s   c                 S   s   g | ]}t jd |jjdqS r~   r   r|   r   r   r   r&      s   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+   r0   listrb   r=   tupleninr@   anyrA   kindrp   noutrj   ndarraywarningscatch_warningssimplefilter
issubclasscategoryRuntimeWarningr>   message
startswithrE   r(   r"   testingassert_array_almost_equalAssertionErrorprint)rd   r.   skip_inputsadditional_inputsrm   rn   kindspositive_onlyrh   rb   input_tupleinput_operandrl   is_tuplero   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ddddddgtjdtjddddddgtjdftjddddddgtjdtjddddddgtjdff}| |}|D ]\}}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||
 qnd S )N)rI      rJ   r   rI   rO   rP   )r   r   Znumpy_versionr@   r[   rZ   r^   r0   r   r   r_   bool_rj   r=   r   ry   rz   
zeros_liker   Zassert_equal)rd   Zcomparison_ufuncr   rh   abr   ro   r   r   resultr   r   r   r   signed_unsigned_cmp_test  sF    




z'BasicUFuncTest.signed_unsigned_cmp_test)r+   rq   rr   r0   r   r   r   r   r   r   ru      s     
_ru   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 NrI   rP   )r   )r   r\   r]   r_   r   )rd   r{   r   r   r   r   basic_int_ufunc_test7  s    zTestUFuncs.basic_int_ufunc_testc                 C   s   |  tj d S r   )r   r@   addrc   r   r   r   test_add_ufuncC  s    zTestUFuncs.test_add_ufuncc                 C   s   |  tj d S r   )r   r@   subtractrc   r   r   r   test_subtract_ufuncF  s    zTestUFuncs.test_subtract_ufuncc                 C   s   |  tj d S r   )r   r@   multiplyrc   r   r   r   test_multiply_ufuncI  s    zTestUFuncs.test_multiply_ufuncc                 C   s   d }t j}| jtj|d d S Nrm   )r   r]   r   r@   dividerd   Zint_out_typer   r   r   test_divide_ufuncL  s
    zTestUFuncs.test_divide_ufuncc                 C   s   | j tjdd d S Nfr   )r   r@   Z	logaddexprc   r   r   r   test_logaddexp_ufuncU  s    zTestUFuncs.test_logaddexp_ufuncc                 C   s   | j tjdd d S r   )r   r@   
logaddexp2rc   r   r   r   test_logaddexp2_ufuncX  s    z TestUFuncs.test_logaddexp2_ufuncc                 C   s   | j tjtjd d S r   )r   r@   true_divider   r]   rc   r   r   r   test_true_divide_ufunc[  s    z!TestUFuncs.test_true_divide_ufuncc                 C   s   |  tj d S r   )r   r@   floor_dividerc   r   r   r   test_floor_divide_ufunc_  s    z"TestUFuncs.test_floor_divide_ufuncc                 C   s.   t t jddt jg}| jtjt j|d d S )NrI   rP   )rm   r   )r   r_   rX   r   r@   negativer[   )rd   r   r   r   r   test_negative_ufuncb  s    zTestUFuncs.test_negative_ufuncc                 C   s   |  tj d S r   )r   r@   Zpositiverc   r   r   r   test_positive_ufunci  s    zTestUFuncs.test_positive_ufuncc                 C   s   | j tjdd d S )NT)r   )r   r@   powerrc   r   r   r   test_power_ufuncl  s    zTestUFuncs.test_power_ufuncc                 C   s   | j tjdd d S )Nfcr   )r   r@   Zfloat_powerrc   r   r   r   test_float_power_ufunco  s    z!TestUFuncs.test_float_power_ufuncc                 C   s   | j tjdd d S Niur   )r   r@   gcdrc   r   r   r   test_gcd_ufuncr  s    zTestUFuncs.test_gcd_ufuncc                 C   s   | j tjdd d S r   )r   r@   Zlcmrc   r   r   r   test_lcm_ufuncu  s    zTestUFuncs.test_lcm_ufuncc                 C   s   |  tj d S r   )r   r@   	remainderrc   r   r   r   test_remainder_ufuncx  s    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   )r@   rZ   iinfomaxr   r   mod)rd   r   r   r   r   test_mod_ufunc{  s
    "
zTestUFuncs.test_mod_ufuncc                 C   s   |  tj d S r   )r   r@   fmodrc   r   r   r   test_fmod_ufunc  s    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   )r@   rX   r   r   r   rZ   r\   Zfinfominr]   r   )rd   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   r@   absoluterc   r   r   r   test_absolute_ufunc  s    zTestUFuncs.test_absolute_ufuncc                 C   s   | j tjdd d S r   )r   r@   fabsrc   r   r   r   test_fabs_ufunc  s    zTestUFuncs.test_fabs_ufuncc                 C   s   | j tjdd d S Ncfr   )r   r@   Zrintrc   r   r   r   test_rint_ufunc  s    zTestUFuncs.test_rint_ufuncc                 C   s   |  tj d S r   )r   r@   signrc   r   r   r   test_sign_ufunc  s    zTestUFuncs.test_sign_ufuncc                 C   s   |  tj d S r   )r   r@   Zconjrc   r   r   r   test_conj_ufunc  s    zTestUFuncs.test_conj_ufuncc                 C   s   | j tjdd d S r   )r   r@   exprc   r   r   r   test_exp_ufunc  s    zTestUFuncs.test_exp_ufuncc                 C   s   | j tjdd d S r   )r   r@   Zexp2rc   r   r   r   test_exp2_ufunc  s    zTestUFuncs.test_exp2_ufuncc                 C   s   | j tjdd d S r   )r   r@   logrc   r   r   r   test_log_ufunc  s    zTestUFuncs.test_log_ufuncc                 C   s   | j tjdd d S r   )r   r@   log2rc   r   r   r   test_log2_ufunc  s    zTestUFuncs.test_log2_ufuncc                 C   s   | j tjdd d S r   )r   r@   log10rc   r   r   r   test_log10_ufunc  s    zTestUFuncs.test_log10_ufuncc                 C   s   | j tjdd d S r   )r   r@   expm1rc   r   r   r   test_expm1_ufunc  s    zTestUFuncs.test_expm1_ufuncc                 C   s   | j tjdd d S r   )r   r@   log1prc   r   r   r   test_log1p_ufunc  s    zTestUFuncs.test_log1p_ufuncc                 C   s   | j tjdd d S r   )r   r@   sqrtrc   r   r   r   test_sqrt_ufunc  s    zTestUFuncs.test_sqrt_ufuncc                 C   s   |  tj d S r   )r   r@   Zsquarerc   r   r   r   test_square_ufunc  s    zTestUFuncs.test_square_ufuncc                 C   s   | j tjdd d S r   )r   r@   cbrtrc   r   r   r   test_cbrt_ufunc  s    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   r_   rX   rY   rZ   r[   r   r@   
reciprocalrd   Zto_skipr   r   r   test_reciprocal_ufunc  s       z TestUFuncs.test_reciprocal_ufuncc                 C   s   |  tj d S r   )r   r@   	conjugaterc   r   r   r   test_conjugate_ufunc  s    zTestUFuncs.test_conjugate_ufuncc                 C   s   | j tjdd d S r   )r   r@   sinrc   r   r   r   test_sin_ufunc  s    zTestUFuncs.test_sin_ufuncc                 C   s   | j tjdd d S r   )r   r@   cosrc   r   r   r   test_cos_ufunc  s    zTestUFuncs.test_cos_ufuncc                 C   s   | j tjdd d S r   )r   r@   tanrc   r   r   r   test_tan_ufunc  s    zTestUFuncs.test_tan_ufuncc                 C   s   | j tjdd d S r   )r   r@   arcsinrc   r   r   r   test_arcsin_ufunc  s    zTestUFuncs.test_arcsin_ufuncc                 C   s   | j tjdd d S r   )r   r@   arccosrc   r   r   r   test_arccos_ufunc  s    zTestUFuncs.test_arccos_ufuncc                 C   s   | j tjdd d S r   )r   r@   Zarctanrc   r   r   r   test_arctan_ufunc  s    zTestUFuncs.test_arctan_ufuncc                 C   s   | j tjdd d S r   )r   r@   Zarctan2rc   r   r   r   test_arctan2_ufunc  s    zTestUFuncs.test_arctan2_ufuncc                 C   s   | j tjdd d S r   )r   r@   hypotrc   r   r   r   test_hypot_ufunc  s    zTestUFuncs.test_hypot_ufuncc                 C   s   | j tjdd d S r   )r   r@   sinhrc   r   r   r   test_sinh_ufunc  s    zTestUFuncs.test_sinh_ufuncc                 C   s   | j tjdd d S r   )r   r@   coshrc   r   r   r   test_cosh_ufunc  s    zTestUFuncs.test_cosh_ufuncc                 C   s   | j tjdd d S r   )r   r@   tanhrc   r   r   r   test_tanh_ufunc  s    zTestUFuncs.test_tanh_ufuncc                 C   s   | j tjdd d S r   )r   r@   Zarcsinhrc   r   r   r   test_arcsinh_ufunc  s    zTestUFuncs.test_arcsinh_ufuncc                 C   s   | j tjdd d S r   )r   r@   Zarccoshrc   r   r   r   test_arccosh_ufunc  s    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 )NrI   rP   r   )r   r   )	r   r_   rX   rY   rZ   r[   r   r@   Zarctanhr   r   r   r   test_arctanh_ufunc  s    	   zTestUFuncs.test_arctanh_ufuncc                 C   s   | j tjdd d S r   )r   r@   Zdeg2radrc   r   r   r   test_deg2rad_ufunc  s    zTestUFuncs.test_deg2rad_ufuncc                 C   s   | j tjdd d S r   )r   r@   Zrad2degrc   r   r   r   test_rad2deg_ufunc  s    zTestUFuncs.test_rad2deg_ufuncc                 C   s   | j tjdd d S r   )r   r@   degreesrc   r   r   r   test_degrees_ufunc	  s    zTestUFuncs.test_degrees_ufuncc                 C   s   | j tjdd d S r   )r   r@   radiansrc   r   r   r   test_radians_ufunc  s    zTestUFuncs.test_radians_ufuncc                 C   s   |  tj d S r   )r   r@   Zbitwise_andrc   r   r   r   test_bitwise_and_ufunc  s    z!TestUFuncs.test_bitwise_and_ufuncc                 C   s   |  tj d S r   )r   r@   Z
bitwise_orrc   r   r   r   test_bitwise_or_ufunc  s    z TestUFuncs.test_bitwise_or_ufuncc                 C   s   |  tj d S r   )r   r@   Zbitwise_xorrc   r   r   r   test_bitwise_xor_ufunc  s    z!TestUFuncs.test_bitwise_xor_ufuncc                 C   s   |  tj d S r   )r   r@   invertrc   r   r   r   test_invert_ufunc  s    zTestUFuncs.test_invert_ufuncc                 C   s   |  tj d S r   )r   r@   Zbitwise_notrc   r   r   r   test_bitwise_not_ufunc  s    z!TestUFuncs.test_bitwise_not_ufuncc                 C   s   |  tj d S r   )r   r@   greaterrc   r   r   r   test_greater_ufunc-  s    zTestUFuncs.test_greater_ufuncc                 C   s   |  tj d S r   )r   r@   greater_equalrc   r   r   r   test_greater_equal_ufunc0  s    z#TestUFuncs.test_greater_equal_ufuncc                 C   s   |  tj d S r   )r   r@   lessrc   r   r   r   test_less_ufunc3  s    zTestUFuncs.test_less_ufuncc                 C   s   |  tj d S r   )r   r@   
less_equalrc   r   r   r   test_less_equal_ufunc6  s    z TestUFuncs.test_less_equal_ufuncc                 C   s   |  tj d S r   )r   r@   	not_equalrc   r   r   r   test_not_equal_ufunc9  s    zTestUFuncs.test_not_equal_ufuncc                 C   s   |  tj d S r   )r   r@   equalrc   r   r   r   test_equal_ufunc<  s    zTestUFuncs.test_equal_ufuncc                 C   s   |  tj d S r   )r   r@   logical_andrc   r   r   r   test_logical_and_ufunc?  s    z!TestUFuncs.test_logical_and_ufuncc                 C   s   |  tj d S r   )r   r@   
logical_orrc   r   r   r   test_logical_or_ufuncB  s    z TestUFuncs.test_logical_or_ufuncc                 C   s   |  tj d S r   )r   r@   logical_xorrc   r   r   r   test_logical_xor_ufuncE  s    z!TestUFuncs.test_logical_xor_ufuncc                 C   s   |  tj d S r   )r   r@   Zlogical_notrc   r   r   r   test_logical_not_ufuncH  s    z!TestUFuncs.test_logical_not_ufuncc                 C   s   |  tj d S r   )r   r@   maximumrc   r   r   r   test_maximum_ufuncK  s    zTestUFuncs.test_maximum_ufuncc                 C   s   |  tj d S r   )r   r@   minimumrc   r   r   r   test_minimum_ufuncN  s    zTestUFuncs.test_minimum_ufuncc                 C   s   |  tj d S r   )r   r@   Zfmaxrc   r   r   r   test_fmax_ufuncQ  s    zTestUFuncs.test_fmax_ufuncc                 C   s   |  tj d S r   )r   r@   Zfminrc   r   r   r   test_fmin_ufuncT  s    zTestUFuncs.test_fmin_ufuncc                 C   s&   t jddgt jdttjddfgS )NTFrO   rI   rP   )r@   r^   r   r   r_   rc   r   r   r   bool_additional_inputsZ  s    z!TestUFuncs.bool_additional_inputsc                 C   s   | j tjd|  d d S NZifcbr   )r   r@   isfiniter<  rc   r   r   r   test_isfinite_ufunc`  s
     zTestUFuncs.test_isfinite_ufuncc                 C   s   | j tjd|  d d S r=  )r   r@   isinfr<  rc   r   r   r   test_isinf_ufuncf  s
     zTestUFuncs.test_isinf_ufuncc                 C   s   | j tjd|  d d S r=  )r   r@   isnanr<  rc   r   r   r   test_isnan_ufuncl  s
     zTestUFuncs.test_isnan_ufuncc                 C   s   |  tj d S r   )r   r@   signbitrc   r   r   r   test_signbit_ufuncr  s    zTestUFuncs.test_signbit_ufuncc                 C   s   | j tjdd d S r   )r   r@   copysignrc   r   r   r   test_copysign_ufuncu  s    zTestUFuncs.test_copysign_ufuncc                 C   s   | j tjdd d S r   )r   r@   Z	nextafterrc   r   r   r   test_nextafter_ufuncx  s    zTestUFuncs.test_nextafter_ufuncc                 C   s   | j tjdd d S r   )r   r@   modfrc   r   r   r   test_modf_ufunc{  s    zTestUFuncs.test_modf_ufuncc                 C   s   | j tjdd d S r   )r   r@   frexprc   r   r   r   test_frexp_ufunc  s    zTestUFuncs.test_frexp_ufuncc                 C   s   | j tjdd d S r   )r   r@   floorrc   r   r   r   test_floor_ufunc  s    zTestUFuncs.test_floor_ufuncc                 C   s   | j tjdd d S r   )r   r@   ceilrc   r   r   r   test_ceil_ufunc  s    zTestUFuncs.test_ceil_ufuncc                 C   s   | j tjdd d S r   )r   r@   truncrc   r   r   r   test_trunc_ufunc  s    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 )NrO   rI   rP   r   r   )r@   r^   infr]   r   r_   r   spacing)rd   
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r&q|dkrf|ttjddkrf|tjkrfttjddrfq|dkr|ttjddkr|tjkrttjddrqt|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rXt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krdnd}| j|||d qd S )NrI   rJ   rM   r   rQ   rO   rP   rS   rK   rU   r   r   rA   singledouble)prec)r+   r0   r   rZ   r[   r]   r@   r^   r_   	itertoolsproductrX   r=   rj   r   ry   sizerA   r{   getattrr\   	complex64assertPreciseEqual)rd   r.   Z
ufunc_nameZinputs1Zinputs2r   rh   valsZinput1Zinput2ro   Zinput1_operandinput1_typeZinput2_operandinput2_typer   r   r   r   Zscalar_typerY  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 ]v\}}ttj	|j
d}ttj|j
d}||f}| ||}	tj|j|jd}
t||
 |	|| | ||
 q
t 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 ]\}}ttj	|j
d}ttj	|j
d}ttj	t|j
|j
d}|||f}| ||}	t||}
tj|
jdd}|	||| | ||
 qVd S )	N   rQ   rO   rI   	   rS      rP   )r0   r@   r   arangereshapery   rE   r   r_   rZ   rk   r[   rj   rz   rA   r_  r   rZ  r[  r   )rd   rh   Zinput_operandsZoutput_operandsr9   r   rl   ro   r   r   r   input1_operandsinput2_operandsr:   ra  rb  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 )NrI   rP   c                 S   s   t | |S r   r@   r   a0a1r   r   r   myadd2  s    z2TestUFuncs.test_implicit_output_npm.<locals>.myadd)r   r_   rZ   r   assertEqual	overloads	signaturereturn_type)rd   Zarr_tysigrp  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 ]h\}}ttj|jd	}ttj|jd	}||f}| j	||d
d}	t 
||}
|	||}t j|
| qd S )Nc                 S   s   t | |S r   rl  rm  r   r   r   rh   9  s    zATestUFuncs.test_broadcast_implicit_output_npm_nrt.<locals>.pyfuncrd  rQ   rO   re  rf  rI   rP   Tri   )r@   rg  rh  rZ  r[  r   r_   rZ   rk   rj   r   r   assert_array_equal)rd   rh   ri  rj  r9   r:   ra  rb  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rX|jd
ks\t	t|}|jj
rv|jdkszt	t|}|jdkst	|jjrt	|jj
rt	tt|||gd}|||fg7 }|||fg7 }|||fg7 }|D ]r\}	}
t|	t|
f}| j||dd}||	|
}||	|
}| |jj|jj | |jj
|jj
 t j|| qd S )Nc                 S   s   t | |S r   rl  rm  r   r   r   rh   V  s    z=TestUFuncs.test_implicit_output_layout_binary.<locals>.pyfuncr   rI      r   r   ForderrP   A   Trw  )r@   linspacerh  r^   Tr   flagsc_contiguouslayoutr   f_contiguousr   rZ  permutationsrj   rq  r   rx  )rd   rh   XYZXtyYtyZtyZ	testcasesarg0Zarg1r   r   r   r   r   r   r   "test_implicit_output_layout_binaryU  s8    



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rX|jd
ks\t	t|}|jj
rv|jdkszt	t|}|jdkst	|jjrt	|jj
rt	|||fD ]d}t|f}	| j||	dd}
||}|
|}| |jj|jj | |jj
|jj
 t j|| qd S )Nc                 S   s
   t | S r   r@   r   )rn  r   r   r   rh   {  s    z<TestUFuncs.test_implicit_output_layout_unary.<locals>.pyfuncr   rI   rz  r   r   r{  r|  rP   r~  Trw  )r@   r  rh  r^   r  r   r  r  r  r   r  rj   rq  r   rx  )rd   rh   r  r  r  r  r  r  r  r   r   r   r   r   r   r   !test_implicit_output_layout_unaryz  s0    


z,TestUFuncs.test_implicit_output_layout_unary)N)br+   rq   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r@   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"  r$  r&  r(  r*  r,  r.  r0  r2  r4  r5  r7  r9  r:  r;  r<  r?  rA  rC  rE  rG  rH  r    rJ  rL  rN  rP  rR  rV  rc  rk  rv  ry  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 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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   )rq  rA   r   r@   r   r   )rd   r   gotr   r   r   _check_results  s    z!TestArrayOperators._check_resultsTNc                 C   sz   t |}t| j}|| |}	|D ]P}
|
\}}||ks$t|tjsFq$| j|	|f|d}|	|}||}| || q$d S )Nrw  )	r6   r   rb   extendr=   r   r_   rj   r  )rd   operatorri   r   r   rm   rn   operator_funcrb   rh   r   r   rl   r   r   r  r   r   r   unary_op_test  s    


z TestArrayOperators.unary_op_testFc                 C   s  t |}t| j}	|	| |}
tjd}|	D ]}|\}}tt	|d|}|}||kr\q0|rrtj
d|dd }t|tjr|}|}|rt||k rq0n*|ddd|}t|}|r||k rq0||f}| j|
||d}|
||}|||}| || q0d S )NrI   rA   rO   r   d   
   rw  )r7   r   rb   r  r@   randomZRandomStater   Zas_dtyper]  ry   r=   r   r_   r   uniformZastyper   rj   r  )rd   r  ri   r   r   rm   rn   positive_rhsr  rb   rh   Zrandom_stater   Zinput_operand1rl   Zinput_dtypeZinput_type1zeroZinput_operand0Zinput_type0r   r   r   r  r   r   r   binary_op_test  s>    




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 )NTFrI   rP   )r   booleanr@   r^   r_   rc   r   r   r   bitwise_additional_inputs  s    z,TestArrayOperators.bitwise_additional_inputsc              	   O   sD   | dg }|tjtjttjddttjddg7 }| j||S )Nr   rI   rP   )
setdefaultr   r\   r]   r_   r  )rd   r   kwsr   r   r   r   binary_int_op_test  s     z%TestArrayOperators.binary_int_op_testc                 O   s$   | dg }||  7 }| j||S )Nr   )r  r  r  )rd   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 ]\\}}t|}t|}||f}| ||}| }||| | }||| | || qVd S )Nc                    s   g | ]}t j |d qS rO   r@   r^   r$   rA   )
lhs_valuesr   r   r&     s   z6TestArrayOperators.inplace_op_test.<locals>.<listcomp>c                    s   g | ]}t j |d qS r  r  r  )
rhs_valuesr   r   r&     s   c                    s   g | ]} D ]}||qqS r   r   )r$   vrA   )
rhs_dtypesr   r   r&     s       )r?   rZ  r[  r   rj   copyr_  )rd   r  r  r  Z
lhs_dtypesr  r  rh   Z
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  s(    



z"TestArrayOperators.inplace_op_testc              	   C   s&   |  |||tjtjftjtjtjfS r   )r  r@   r\   r]   r[   rd   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  r@   ra   rY   r[   rX   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  r@   r   r  r   r   r   inplace_bitwise_op_test  s
    
 
z*TestArrayOperators.inplace_bitwise_op_testc                 C   s   |  d d S N+r  rc   r   r   r   test_unary_positive_array_op#  s    z/TestArrayOperators.test_unary_positive_array_opc                 C   s   |  d d S N-r  rc   r   r   r   test_unary_negative_array_op&  s    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~rI   rP   )r   r   )r  r   r\   r]   r_   r  rc   r   r   r   test_unary_invert_array_op)  s    z-TestArrayOperators.test_unary_invert_array_opc                 C   s:   |  ddddgdddg |  tjdddgdddg d S )Nz+=rJ         ?rd  r         @)r  r  iaddrc   r   r   r   test_inplace_add3  s    z#TestArrayOperators.test_inplace_addc                 C   s:   |  ddddgdddg |  tjdddgdddg d S )Nz-=rJ   r  rd  r  r   r  )r  r  isubrc   r   r   r   test_inplace_sub7  s    z#TestArrayOperators.test_inplace_subc                 C   s:   |  ddddgdddg |  tjdddgdddg d S )Nz*=rJ   r  rd  r  r   r  )r  r  imulrc   r   r   r   test_inplace_mul;  s    z#TestArrayOperators.test_inplace_mulc                 C   s:   |  ddddgdddg |  tjdddgdddg d S )Nz//=rJ   r  rd  r        ?r  )r  r  	ifloordivrc   r   r   r   test_inplace_floordiv?  s    z(TestArrayOperators.test_inplace_floordivc                 C   s:   |  ddddgdddg |  tjdddgdddg d S )	Nz/=rJ   r  rd  r  r   r  r  )r  r  itruedivrc   r   r   r   test_inplace_divD  s    z#TestArrayOperators.test_inplace_divc                 C   s:   |  ddddgdddg |  tjdddgdddg d S )Nz%=rJ   r  rd  r  r  r  )r  r  imodrc   r   r   r   test_inplace_remainderI  s    z)TestArrayOperators.test_inplace_remainderc                 C   s:   |  ddddgdddg |  tjdddgdddg d S )Nz**=rJ   r  rd  r  r  r  )r  r  ipowrc   r   r   r   test_inplace_powM  s    z#TestArrayOperators.test_inplace_powc              	   C   sJ   |  ddddddgdddd	d
g |  tjdddddgdddd	d
g d S )Nz&=r   rI   r  rd  3      r   *      )r  r  iandrc   r   r   r   test_inplace_andQ  s    z#TestArrayOperators.test_inplace_andc              	   C   sJ   |  ddddddgdddd	d
g |  tjdddddgdddd	d
g d S )Nz|=r   rI   r  rd  r  r  r   r  r  )r  r  iorrc   r   r   r   test_inplace_orW  s    z"TestArrayOperators.test_inplace_orc              	   C   sJ   |  ddddddgdddd	d
g |  tjdddddgdddd	d
g d S )Nz^=r   rI   r  rd  r  r  r   r  r  )r  r  ixorrc   r   r   r   test_inplace_xor]  s    z#TestArrayOperators.test_inplace_xorc                 C   sB   |  dddddgddddg |  tjddddgddddg d S )	Nz<<=r   r   rI   r      )r  r  ilshiftrc   r   r   r   test_inplace_lshiftc  s    
z&TestArrayOperators.test_inplace_lshiftc                 C   sB   |  dddddgddddg |  tjddddgddddg d S )	Nz>>=r   r   r  r  rI   r   r  )r  r  irshiftrc   r   r   r   test_inplace_rshifth  s    
z&TestArrayOperators.test_inplace_rshiftc                 C   s   dd }t d}||}| |d |d ko<|d |d k t d}t||}| |d |d kox|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 )Nrd  r   r   rI   r   )ro  a2r   r   r   r   t  s    z<TestArrayOperators.test_unary_positive_array_op_2.<locals>.fr  r   rI   N)r@   ry   
assertTruer   r   rx  )rd   r   ro  r  a3Za4r   r   r   test_unary_positive_array_op_2m  s    
&
&z1TestArrayOperators.test_unary_positive_array_op_2c                 C   s   |  d d S r  r  rc   r   r   r   test_add_array_op  s    z$TestArrayOperators.test_add_array_opc                 C   s   |  d d S r  r  rc   r   r   r   test_subtract_array_op  s    z)TestArrayOperators.test_subtract_array_opc                 C   s   |  d d S )N*r  rc   r   r   r   test_multiply_array_op  s    z)TestArrayOperators.test_multiply_array_opc                 C   s   d }t j}| jd|d d S )N/r   )r   r]   r  r   r   r   r   test_divide_array_op  s    z'TestArrayOperators.test_divide_array_opc                 C   sd  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dddgddt	tjddft jd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| _
| d d S )NrI   r   r   r  rK   r  g      g      @r  rN   rO   rP   rd  rQ   rJ   r   rR      rS   rT   rU   z//)r@   rX   r   rY   rZ   r[   r\   r]   r^   r_   rb   r  rc   r   r   r   test_floor_divide_array_op  s,      ""z-TestArrayOperators.test_floor_divide_array_opc                 C   s   |  d d S )N%r  rc   r   r   r   test_remainder_array_op  s    z*TestArrayOperators.test_remainder_array_opc                 C   s   | j ddd d S )Nz**Tr  r  rc   r   r   r   test_power_array_op  s    z&TestArrayOperators.test_power_array_opc                 C   s   | j ddd d S )Nz<<Tr  r  rc   r   r   r   test_left_shift_array_op  s    z+TestArrayOperators.test_left_shift_array_opc                 C   s   | j ddd d S )Nz>>Tr  r  rc   r   r   r   test_right_shift_array_op  s    z,TestArrayOperators.test_right_shift_array_opc                 C   s   |  d d S )N&r  rc   r   r   r   test_bitwise_and_array_op  s    z,TestArrayOperators.test_bitwise_and_array_opc                 C   s   |  d d S )N|r  rc   r   r   r   test_bitwise_or_array_op  s    z+TestArrayOperators.test_bitwise_or_array_opc                 C   s   |  d d S )N^r  rc   r   r   r   test_bitwise_xor_array_op  s    z,TestArrayOperators.test_bitwise_xor_array_opc                 C   s   |  d d S )Nz==r  rc   r   r   r   test_equal_array_op  s    z&TestArrayOperators.test_equal_array_opc                 C   s   |  d d S )N>r  rc   r   r   r   test_greater_array_op  s    z(TestArrayOperators.test_greater_array_opc                 C   s   |  d d S )Nz>=r  rc   r   r   r   test_greater_equal_array_op  s    z.TestArrayOperators.test_greater_equal_array_opc                 C   s   |  d d S )N<r  rc   r   r   r   test_less_array_op  s    z%TestArrayOperators.test_less_array_opc                 C   s   |  d d S )Nz<=r  rc   r   r   r   test_less_equal_array_op  s    z+TestArrayOperators.test_less_equal_array_opc                 C   s   |  d d S )Nz!=r  rc   r   r   r   test_not_equal_array_op  s    z*TestArrayOperators.test_not_equal_array_op)/r+   rq   rr   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    sn     
  
*		
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   s2  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}
||
krt	|}nLt
|jt
jrt	|}n2t
|jt
jrt|}nt
|jt
jrt|}||j| jjf }tdd |D rd}ntdd |D rd}nd}| j|||	|d q
d S )	Nzfor args {0} typed {1}c                 S   s   g | ]}|t jkqS r   )r   r\   r$   tr   r   r   r&   
  s     z.TestScalarUFuncs.run_ufunc.<locals>.<listcomp>rW  c                 S   s   g | ]}|t jkqS r   )r   r]   r  r   r   r   r&     s     rX  exact)r   rY  )rE   r   rG   r"   setr   rY   rZ   r[   floatr@   Z
issubdtyperA   Zinexactintegerintr   boolrr  rs  rt  r   r_  )rd   rh   Z	arg_typesZ
arg_valuesrF   r   r   r  r   r   specialZalltypesrY  r   r   r   	run_ufunc  s4    




	

zTestScalarUFuncs.run_ufuncc                 C   sR   dd }ddddddg}t jft jft jft jft jft jfg}| ||| d S )Nc                 S   s
   t | S r   r  r9   r   r   r   _func  s    z7TestScalarUFuncs.test_scalar_unary_ufunc.<locals>._func)r  )rI   )皙?)皙?)r   rY   rX   r[   rZ   r\   r]   r  rd   r  r`  Ztysr   r   r   test_scalar_unary_ufunc  s      z(TestScalarUFuncs.test_scalar_unary_ufuncc                 C   sR   dd }ddddddg}t jt jt jt jt jt jg}| |t||t|| d S )Nc                 S   s   t | |S r   rl  r8   r   r   r   r    s    z@TestScalarUFuncs.test_scalar_binary_uniform_ufunc.<locals>._funcr  rI   r  r  )	r   rY   rX   r[   rZ   r\   r]   r  rE   r  r   r   r    test_scalar_binary_uniform_ufunc  s       z1TestScalarUFuncs.test_scalar_binary_uniform_ufuncc                 C   sV   dd }ddddddg}t jt jt jt jt jt jg}| |t	||t	|| d S )Nc                 S   s   t | |S r   rl  r8   r   r   r   r  '  s    z>TestScalarUFuncs.test_scalar_binary_mixed_ufunc.<locals>._funcr  rI   r  r  )
r   rY   rX   r[   rZ   r\   r]   r  rZ  r[  r  r   r   r   test_scalar_binary_mixed_ufunc&  s      
z/TestScalarUFuncs.test_scalar_binary_mixed_ufuncN)r+   rq   rr   __doc__r  r  r  r  r   r   r   r   r    s
   3
	r  c                   @   s   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   rl  )x1Zx2r   r   r   foo6  s    z+TestUfuncIssues.test_issue_651.<locals>.foor  rU   rO   )r   r@   rg  r_  )rd   r  r   r   r   r   r   test_issue_6514  s
    
zTestUfuncIssues.test_issue_651c                    s   dd }|t   fdd}tdddgtddd	gg}|D ]4}||d ||td ||tdddg qHd
S )zF
        <float32 ** int> should return float32, not float64.
        c                 S   s   t | |S r   )r@   r   r8   r   r   r   r  B  s    z,TestUfuncIssues.test_issue_2006.<locals>.fooc                    s2    | |}t j|| | |j| j d S r   )r@   r   r   rq  rA   )r9   r:   r  r   rh   rd   r   r   checkG  s    
z.TestUfuncIssues.test_issue_2006.<locals>.checkrI   r  rd                ?y      @      N)r   r@   r\   r^  rZ   r[   )rd   r  r  Zxsr9   r   r  r   test_issue_2006>  s     
zTestUfuncIssues.test_issue_2006N)r+   rq   rr   r  r   r   r   r   r   r  2  s   
r  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   r"  )r  r{  )r   d)r   r#  r   c                 C   s0  |dkrt jddddg|dS |dkr<t jddddg|dS |d	krZt jd
ddd
g|dS |d dkrt|dkrvd}t jddddg|dS |d dkrt|dkrd}t jddddg|dS |dkrt jdddtdg|dS |dkrtjdk rd}nd}t j|ddtd dg|dS td |f d!S )"z<return a suitable array argument for testing the letter typeZbhilqrI   r   r   r  rO   ZBHILQr  ?TFmzm8[D]ZNaTMzM8[D]ZNatr   fdr  g      rL   nanFDr   y             y              y      ?      ?r  y                ztype %r not understoodN)r@   r^   lenr
  r   platformRuntimeError)rd   a_letter_typeindexZnegzeror   r   r   _arg_for_typew  s4    
z_LoopTypesTester._arg_for_typec                    s   |d |j  ||j d    t| dg rHtfdd D rHd S t| dg tfdd D rnd S t| dg }|rt fdd|D sd S | ||  d S )NZ_supported_typesc                 3   s   | ]}| kV  qd S r   r   r$   l)supported_typesr   r   	<genexpr>  s     z/_LoopTypesTester._check_loop.<locals>.<genexpr>_skip_typesc                 3   s   | ]}| kV  qd S r   r   r1  )
skip_typesr   r   r4    s     _required_typesc                 3   s   | ]}| kV  qd S r   r   r1  )letter_typesr   r   r4    s   )r   r   r]  r   _check_ufunc_with_dtypes)rd   r'   r.   loopZrequired_typesr   )r8  r6  r3  r   _check_loop  s    z_LoopTypesTester._check_loopc                    sB  g }|D ]}|dkr|d }| | qdd |D }tdd |D }t||} fddt|D }	|	D ]}
 j|
 qndd |	D }||	  ||  t|||	D ]\}}} |||\}}|jj	} j
|j|fd}|d	krd
nd}|dkrdn|}dddddg}||j|	|||} j|||||d qd S )N)r%  r'  z8[D]c                 S   s   g | ]}t |qS r   )r@   rA   r  r   r   r   r&     s     z=_LoopTypesTester._check_ufunc_with_dtypes.<locals>.<listcomp>c                 S   s   g | ]}t t|d dqS )rI   rP   )r   r_   r   r  r   r   r   r&     s     c                    s$   g | ]\}} j ||d dqS )r/  r  )r0  repeat)r$   r/  r  rc   r   r   r&     s   c                 S   s   g | ]}|  qS r   )r  )r$   r   r   r   r   r&     s     rI   ZfFrW  r  ZdDrX  r   z ufunc '{0}' arrays differ ({1}):z	args: {2}zexpected {3}zgot {4})rY  r   ulps)appendr   r   	enumerater  shufflerE   _fixup_resultsrA   char_ulpsgetr+   r(   r"   r_  )rd   r'   r.   ZdtypesZdtypes_with_unitsr  Zarg_dtyZarg_nbtyr   Zc_argsZarrZpy_argsrA   py_argc_argZtypecharr>  rY  r   r   rc   r   r9    s>    
  z)_LoopTypesTester._check_ufunc_with_dtypesc                 C   s   ||fS r   r   )rd   rA   rF  rG  r   r   r   rB    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   )r0   r;  )rd   r'   r:  r.   r   r   test_template  s    z4_LoopTypesTester._inject_test.<locals>.test_templateztest_{0}_{1}z->_)setattrr"   r+   replace)rI  r.   r:  rL  r   rK  r   rH    s    
z_LoopTypesTester._inject_testc                 C   s   | j D ]}| | qd S r   )_ufuncsrJ  )rI  r.   r   r   r   autogenerate  s    
z_LoopTypesTester.autogenerateN)r   )r+   rq   rr   r  r5  rD  r0  r;  r9  rB  classmethodrJ  rH  rQ  r   r   r   r   r!  V  s(   	
'(

r!  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+   rq   rr   r   rP  remover@   r   r   
left_shiftright_shiftr   r   r7  r!  r5  r   r   r   r   rS    s   rS  c                   @   s*   e Zd ZejejgZdZdej	 d Z	dS ) TestLoopTypesSubtractAndNegativez?bBhHiIlLqQfdFDmMOr$  N)
r+   rq   rr   r@   r   r   rP  r7  r!  r5  r   r   r   r   rX    s   rX  c                       s4   e Zd ZejgZdZdej Zd fdd	Z	  Z
S )TestLoopTypesReciprocalbBhHiIlLqQfdFDrY  r   c                    s.   t | j| j||d}|dkr*d||dk< |S )Nr<  
bBhHiIlLqQr  r   rV   rf   r0  rd   r.  r/  resre   r   r   r0    s    z%TestLoopTypesReciprocal._arg_for_type)r   )r+   rq   rr   r@   r   rP  r7  r!  r5  r0  rt   r   r   re   r   rZ    s   
rZ  c                       s4   e Zd ZejgZdZdej Zd fdd	Z	  Z
S )TestLoopTypesPowerr[  rY  r   c                    s6   t | j| j||d}|dkr2|dkr2d||dk < |S )Nr<  r\  rI   rd  r   r]  r^  re   r   r   r0  &  s    z TestLoopTypesPower._arg_for_type)r   )r+   rq   rr   r@   r   rP  r7  r!  r5  r0  rt   r   r   re   r   r`  !  s   
r`  c                       s4   e Zd ZejgZdZdej Zd fdd	Z	  Z
S )TestLoopTypesIntLeftShiftr\  rT  r   c                    s@   t | j| j||d}|dkr<|jjd }t|d|d }|S Nr<  rI      r   )rV   rf   r0  rA   itemsizer@   cliprd   r.  r/  r_  Z	bit_countre   r   r   r0  9  s    z'TestLoopTypesIntLeftShift._arg_for_type)r   )r+   rq   rr   r@   rV  rP  r7  r!  r5  r0  rt   r   r   re   r   ra  4  s   
ra  c                       s4   e Zd ZejgZdZdej Zd fdd	Z	  Z
S )TestLoopTypesIntRightShiftr\  rT  r   c                    sR   t | j| j||d}|dkr<|jjd }t|d|d }|dkrNt|}|S rb  )rV   rf   r0  rA   rd  r@   re  r  rf  re   r   r   r0  P  s    

z(TestLoopTypesIntRightShift._arg_for_type)r   )r+   rq   rr   r@   rW  rP  r7  r!  r5  r0  rt   r   r   re   r   rg  K  s   
rg  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[  rY  c                 C   sF   |j dkr>t|t|@ }||dk|dk@ O }|| ||< ||fS )Nr   rL   )r   r@   r@  rB  )rd   rA   rF  rG  predr   r   r   rB  r  s
    
z'TestLoopTypesFloorDivide._fixup_resultsN)r+   rq   rr   r@   r   r   divmodrP  r7  r!  r5  rB  r   r   r   r   rh  m  s   
rh  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 )TestLoopTypesFloatNr(  ZFDmMO)r+   rq   rr   r   rP  	iswindowsrU  r@   rD  r   r   rj  r   r7  r!  r5  r   r   r   r   rk    s   rk  c                   @   s&   e Zd Zedd ZdZdej ZdS )TestLoopTypesComplexNr*  rY  )r+   rq   rr   r   rP  r7  r!  r5  r   r   r   r   rm    s   rm  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   s   t j}t|}| ||dddg | ||dddg | ||dddg | ||dddg | t | ||dddg W 5 Q R X d S )Nm8[s]m8[m]m8[ms])r@   r   r0   r9  assertRaisesr   rd   r.   r'   r   r   r   test_add  s    zTestLoopTypesDatetime.test_addc              	   C   s   t j}t|}| ||dddg | ||dddg | ||dddg | ||dddg | t | ||dddg W 5 Q R X d S )NM8[s]M8[m]ro  rq  rp  )r@   r   r0   r9  rr  r   rs  r   r   r   test_subtract  s    z#TestLoopTypesDatetime.test_subtractc              	   C   sd   t j}t|}| ||dddg | ||dddg | t | ||dddg W 5 Q R X d S )Nro  qzm8[us]rp  )r@   r   r0   r9  rr  r   rs  r   r   r   test_multiply  s    z#TestLoopTypesDatetime.test_multiplyc              	   C   s   t j}t|}| ||dddg | ||dddg | ||dddg | ||dddg | t | ||dddg W 5 Q R X d S )Nrp  ro  r#  rx  )r@   r   r0   r9  rr  r   rs  r   r   r   test_true_divide  s    z&TestLoopTypesDatetime.test_true_dividec              	   C   sd   t j}t|}| ||dddg | ||dddg | t | ||dddg W 5 Q R X d S )Nrp  rx  ro  r#  )r@   r   r0   r9  rr  r   rs  r   r   r   test_floor_divide  s    z'TestLoopTypesDatetime.test_floor_dividec                 C   s\   t |}| ||dddg | ||dddg | ||dddg | ||dddg d S )Nrp  ro  r$  rv  ru  )r0   r9  rs  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   )r@   r-  r+  r'  r)  r#  r%  r|  rv   r   r   r   test_comparisons  s
     z&TestLoopTypesDatetime.test_comparisons)r+   rq   rr   r   rP  rU  r@   rj  r7  rt  rw  ry  rz  r{  r|  r}  r   r   r   r   rn    s   


	rn  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestUFuncBadArgsc              	   C   s8   dd }|  t tttjg| W 5 Q R X d S )Nc                 S   s   t | }|S )zerror: np.add requires two argsrl  )r9   r   r   r   r   r     s    
z0TestUFuncBadArgs.test_missing_args.<locals>.funcrr  r	   r   r   r]   rd   r   r   r   r   test_missing_args  s    z"TestUFuncBadArgs.test_missing_argsc              	   C   sJ   dd }t t jdd}||||}| t t|| W 5 Q R X d S )Nc                 S   s   t | | ||}|S )zerror: too many argsrl  )r9   outZout2r   r   r   r   r     s    z1TestUFuncBadArgs.test_too_many_args.<locals>.funcrI   rP   )r   r_   r]   rr  r	   r   )rd   r   Z
array_typeru  r   r   r   test_too_many_args  s
    z#TestUFuncBadArgs.test_too_many_argsc              	   C   s8   dd }|  t tttjg| W 5 Q R X d S )Nc                 S   s   d}t | | | dS )z0error: scalar as a return value is not supportedr   Nrl  r8   r   r   r   r     s    zATestUFuncBadArgs.test_no_scalar_result_by_reference.<locals>.funcr  r  r   r   r   "test_no_scalar_result_by_reference  s    z3TestUFuncBadArgs.test_no_scalar_result_by_referenceN)r+   rq   rr   r  r  r  r   r   r   r   r~    s   	r~  c                   @   s   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 ]}|  q8|D ]}|  qJ|   dS )	z{
        Test that (lazy) compiling from several threads at once doesn't
        produce errors (see issue #2403).
        c                 S   s   | d S )NrI   r   r  r   r   r   r  %  s    z7TestUFuncCompilationThreadSafety.test_lock.<locals>.fooc               
      sl   z:t jdt jd} t jdt jdd }t j| | W n, tk
rf } z | W 5 d }~X Y nX d S )N)r  rO   g      ?)r@   Zonesr]   r   rx  	Exceptionr?  )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   r&   1  s     z>TestUFuncCompilationThreadSafety.test_lock.<locals>.<listcomp>r   N)r   r)   startr(   ZassertFalse)rd   threadsr  r   )r  r  r   r   	test_lock  s    


z*TestUFuncCompilationThreadSafety.test_lockN)r+   rq   rr   r  r   r   r   r   r    s   r  c                   @   s   e Zd Zdd Zdd ZdS )TestUfuncOnContextc              	   C   sr   t j}|tj}| |t ttj}| || t	 }| 
t}t| W 5 Q R X | |jj|f d S r   )r   Ztarget_contextget_ufunc_infor@   r   ZassertIsInstancedictr   rq  objectrr  KeyError	exceptionr   )rd   	targetctxZadd_infor   Zbadkeyraisesr   r   r   test_cpu_get_ufunc_info:  s    z*TestUfuncOnContext.test_cpu_get_ufunc_infoc              	   C   sD   t tjd}| t}|tj W 5 Q R X | t	|j
d d S )Ncpuz<<numba\..*\.BaseContext object at .*> does not support ufunc)r   r   Ztyping_contextrr  NotImplementedErrorr  r@   r   assertRegexr>   r  )rd   r  r  r   r   r   test_base_get_ufunc_infoJ  s    z+TestUfuncOnContext.test_base_get_ufunc_infoN)r+   rq   rr   r  r  r   r   r   r   r  9  s   r  c                   @   s   e Zd Zdd ZdS )TestUfuncWriteInputc                 C   sl   t dgddd }tjdd}tj|tjd}||| tjtjdd	d	d	dg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   rI   )r)   r\  )r9   r  r%   r   r   r   r   W  s    z6TestUfuncWriteInput.test_write_input_arg.<locals>.funcr  r   rO   TFr   )Zaxis)r   r@   r  Zrandr   r`   r   rx  r^   r   r   )rd   r   r9   r  r   r   r   test_write_input_argV  s    



z(TestUfuncWriteInput.test_write_input_argN)r+   rq   rr   r  r   r   r   r   r  U  s   r  __main__)Er   rZ  r   r   r  r  numpyr@   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is32bitsr,  r   rl  r    r0   r6   r7   r?   rG   rH   ru   r   r  r  r  r!  rS  rQ  rX  rZ  r`  ra  rg  rh  rk  rm  rn  r~  r  r  r  r+   mainr   r   r   r   <module>   s   

I     i  ?Z$ 	^ 
