B
     \Y                @   s0  d dl m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 d dlmZmZmZmZmZmZ d dlmZmZ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!m"Z" d	d
l#m$Z$m%Z%m&Z&m'Z' d dl(m)Z) d dl*m+Z+m,Z, e-j.dkZ/ej01dZ2edkZ3e Z4e45d e45d e Z6e65d e Z7e75d e75d dd Z8dd Z9d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@e$ZAG d'd( d(e@e$ZBG d)d* d*e$ZCG d+d, d,eCZDG d-d. d.e$ZEG d/d0 d0e$ZFG d1d2 d2eFZGeGH  G d3d4 d4eFZIeIH  G d5d6 d6eFZJeJH  G d7d8 d8eFZKeKH  G d9d: d:eFZLeLH  G d;d< d<eFZMeMH  G d=d> d>eFZNeNH  G d?d@ d@eFZOeOH  G dAdB dBeFZPePH  G dCdD dDeFZQeQH  G dEdF dFe$ZRG dGdH dHe$ZSeTdIkr,eU  dS )J    )print_functionN)typestypingutilstypeofnumpy_supportnjit)compile_isolatedFlagsDEFAULT_FLAGS)
from_dtypeversion)jit	vectorize)	PYVERSION)LoweringErrorTypingError   )TestCaseCompilationCacheMemoryLeakMixintag)exec_)supported_ufuncs
all_ufuncs   win32)r      Zenable_pyobjectZno_rewritesZnrtc                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<   y | | 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 6lib/python3.7/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>7   s    z'_make_ufunc_usecase.<locals>.<listcomp>zdef fn({0}):
    np.{1}({0})fnz{0}_usecase)joinrangenargsr+   __name__r   globals)ufuncldictZarg_strZfunc_strr/   r$   r$   r%   _make_ufunc_usecase5   s    r7   c             C   s6   | j }i }td|t | |d }d||_ |S )Nz def fn(x,out):
    np.{0}(x,out)r/   z{0}_usecase)r3   r   r+   r4   )r5   
ufunc_namer6   r/   r$   r$   r%   _make_unary_ufunc_usecase?   s    r9   c             C   s4   i }t d| t | |d }dt| |_|S )Nzdef fn(x):
    return {0}(x)r/   zusecase_{0})r   r+   r4   hashr3   )ufunc_opr6   r/   r$   r$   r%   _make_unary_ufunc_op_usecaseH   s
    r<   c             C   s6   | j }i }td|t | |d }d||_ |S )Nz$def fn(x,y,out):
    np.{0}(x,y,out)r/   z{0}_usecase)r3   r   r+   r4   )r5   r8   r6   r/   r$   r$   r%   _make_binary_ufunc_usecaseP   s    r=   c             C   s4   i }t d| t | |d }dt| |_|S )Nzdef fn(x,y):
    return x{0}yr/   zusecase_{0})r   r+   r4   r:   r3   )r;   r6   r/   r$   r$   r%   _make_binary_ufunc_op_usecaseY   s
    r>   c             C   s4   i }t d| t | |d }dt| |_|S )Nzdef fn(x,y):
    x{0}yr/   zusecase_{0})r   r+   r4   r:   r3   )r;   r6   r/   r$   r$   r%   _make_inplace_ufunc_op_usecasea   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dtypestrtype)r,   tyvalr$   r$   r%   r.   l   s    z#_as_dtype_value.<locals>.<listcomp>)zip)tyargsr!   r$   r$   r%   _as_dtype_valuei   s    rH   c                   s&   e Zd Z fddZdddZ  ZS )BaseUFuncTestc                s  t t|   tdtjftdtjftdtjftdtjftdtjftdtjftdtjftdtjftdtjftdtjft	dtj	ft	dtj	ft	dtj	ft
dtj
ft
dtj
ft
dtj
ftjddgddttjdd	ftjddgd
dttjdd	ftj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g| _t | _d S )Nr   r   g      g        g      ?u4)rA   Cu8i4i8f4f8)superrI   setUpr@   uint32r   int32uint64int64float32float64arrayArrayinputsr   cache)self)	__class__r$   r%   rS   r   s0      """(zBaseUFuncTest.setUpNc             C   s   |}t |tjr|j}|tjkrD|r4t|dd}qt|dd}nP|tjkrr|rbt|dd}qt|dd}n"|rt|dd}nt|dd}|S )Nr   rL   )
isinstancer   r[   rA   Zsigned_domainZunsigned_domain)r^   
input_typeint_output_typefloat_output_typerD   output_typer$   r$   r%   _determine_output_type   s    

z$BaseUFuncTest._determine_output_type)NN)r3   
__module____qualname__rS   re   __classcell__r$   r$   )r_   r%   rI   p   s    rI   c               @   s  e Zd Zeg g dddfddZeg g ddddfddZdefdd	Zdefd
dZedefddZ	edefddZ
edefddZedefddZdd Zdd ZedefddZeddd ZedefddZedefdd Zedefd!d"Zedefd#d$Zedefd%d&Zedeejfd'd(Zedefd)d*Zedefd+d,Zedefd-d.Zedefd/d0Zedefd1d2Zedefd3d4Zedefd5d6Zedefd7d8Z edefd9d:Z!edefd;d<Z"edefd=d>Z#edefd?d@Z$edefdAdBZ%edefdCdDZ&edefdEdFZ'edefdGdHZ(edefdIdJZ)edefdKdLZ*edefdMdNZ+efdOdPZ,efdQdRZ-efdSdTZ.efdUdVZ/efdWdXZ0edefdYdZZ1edefd[d\Z2edefd]d^Z3efd_d`Z4efdadbZ5efdcddZ6efdedfZ7efdgdhZ8efdidjZ9efdkdlZ:efdmdnZ;efdodpZ<efdqdrZ=efdsdtZ>efdudvZ?edefdwdxZ@edefdydzZAedefd{d|ZBedefd}d~ZCedefddZDedefddZEefddZFefddZGefddZHefddZIedefddZJedefddZKefddZLefddZMedefddZNedefddZOedefddZPedefddZQedefddZRefddZSeTefddZUeTefddZVedefddZWedefddZXedefddZYefddZZefddZ[dd Z\eddd Z]dd Z^dd Z_dd Z`dd ZadS )
TestUFuncsNZifcc          
   C   s  |  t t|}t| j}|| |}	x|D ]}
|
d }|
d }||krRq2tjrf|jj	|krfq2| 
|||}| jj|	||f|d}|j}t|tjrtj|j|jjd}tj|j|jjd}n$tjd|jjd}tjd|jjd}d}tjddR}td |	|| d	}x2|D ]*}t|jtrt|j|rd}qW W d Q R X ||| d
dddddddg|j|||||j|}ytjj ||d|d W q2 t!k
r   |rt"d|
|| n Y q2X q2W d S )Nr   r   )flags)rA   FT)recordalwayszinvalid value encountered
zufunc '{0}' failedzinputs ({1}):z{2}zgot({3})z{4}zexpected ({5}):z{6}   )ZdecimalZerr_msgz!Output mismatch for invalid input)#Zreset_module_warningsr3   r9   listr\   extendr   strict_ufunc_typingrA   kindre   r]   compileentry_pointr`   r@   ndarrayzerossizenamewarningscatch_warningssimplefilter
issubclasscategoryRuntimeWarningrB   message
startswithr0   r+   testingassert_array_almost_equalAssertionErrorprint)r^   r5   rj   skip_inputsadditional_inputsrb   rc   kindsr\   pyfuncinput_tupleinput_operandra   rd   crcfuncresultexpectedZinvalid_flagZwarnlistZwarnmsgZthiswarnmsgr$   r$   r%   unary_ufunc_test   sh    










zTestUFuncs.unary_ufunc_testFc	             C   s  t |}t| j| }	|}
x|	D ]}|d }|d }||kr>q |rRt|dk rRq tjrf|jj|krfq | 	|||}| j
j|
|||f|d}|j}t|tjrt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j|| q W d S )Nr   r   )rj   )rA   )r=   ro   r\   r@   anyr   rq   rA   rr   re   r]   rs   rt   r`   ru   rv   rw   rx   r   r   )r^   r5   rj   r   r   rb   rc   r   positive_onlyr\   r   r   r   ra   rd   r   r   r   r   r$   r$   r%   binary_ufunc_test   s8    

zTestUFuncs.binary_ufunc_testc             C   s8   | j ||tjtjttjddttjddgd d S )Nr   rL   )rj   r   )r   r   rX   rY   r[   )r^   rx   rj   r$   r$   r%   unary_int_ufunc_test%  s    zTestUFuncs.unary_int_ufunc_testc             C   s8   | j ||tjtjttjddttjddgd d S )Nr   rL   )rj   r   )r   r   rX   rY   r[   )r^   rx   rj   r$   r$   r%   binary_int_ufunc_test+  s    z TestUFuncs.binary_int_ufunc_test	importantc             C   s   | j tj|d d S )N)rj   )r   r@   add)r^   rj   r$   r$   r%   test_add_ufunc5  s    zTestUFuncs.test_add_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   subtract)r^   rj   r$   r$   r%   test_subtract_ufunc9  s    zTestUFuncs.test_subtract_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   multiply)r^   rj   r$   r$   r%   test_multiply_ufunc=  s    zTestUFuncs.test_multiply_ufuncc             C   s(   d }t dkrtj}| jtj||d d S )N)   r   )rj   rb   )r   r   rY   r   r@   divide)r^   rj   int_out_typer$   r$   r%   test_divide_ufuncA  s    zTestUFuncs.test_divide_ufuncc             C   s   | j tjdd d S )Nf)r   )r   r@   Z	logaddexp)r^   r$   r$   r%   test_logaddexp_ufuncK  s    zTestUFuncs.test_logaddexp_ufuncc             C   s   | j tjdd d S )Nr   )r   )r   r@   Z
logaddexp2)r^   r$   r$   r%   test_logaddexp2_ufuncN  s    z TestUFuncs.test_logaddexp2_ufuncc             C   s   | j tj|tjd d S )N)rj   rb   )r   r@   true_divider   rY   )r^   rj   r$   r$   r%   test_true_divide_ufuncQ  s    z!TestUFuncs.test_true_divide_ufuncc             C   s   |  tj d S )N)r   r@   floor_divide)r^   r$   r$   r%   test_floor_divide_ufuncU  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   rL   )rb   r   rj   )r   r@   negativer   rW   r[   rT   )r^   rj   r$   r$   r%   test_negative_ufuncY  s    zTestUFuncs.test_negative_ufuncc             C   s   | j tj|td d S )N)rj   r   )r   r@   powerafter_numpy_112)r^   rj   r$   r$   r%   test_power_ufunca  s    
zTestUFuncs.test_power_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   	remainder)r^   rj   r$   r$   r%   test_remainder_ufuncf  s    zTestUFuncs.test_remainder_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   mod)r^   rj   r$   r$   r%   test_mod_ufuncj  s    zTestUFuncs.test_mod_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zfmod)r^   rj   r$   r$   r%   test_fmod_ufuncn  s    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)rj   r   )r   r@   rT   Ziinfomaxr   rV   rX   ZfinfominrY   )r^   rj   r5   r$   r$   r%   test_abs_ufuncr  s
    zTestUFuncs.test_abs_ufuncc             C   s   | j |tjd d S )N)rj   r5   )r   r@   Zabsolute)r^   rj   r$   r$   r%   test_absolute_ufunc|  s    zTestUFuncs.test_absolute_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zfabs)r^   rj   r$   r$   r%   test_fabs_ufunc  s    zTestUFuncs.test_fabs_ufuncc             C   s   | j tj|dd d S )Ncf)rj   r   )r   r@   Zrint)r^   rj   r$   r$   r%   test_rint_ufunc  s    zTestUFuncs.test_rint_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zsign)r^   rj   r$   r$   r%   test_sign_ufunc  s    zTestUFuncs.test_sign_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zconj)r^   rj   r$   r$   r%   test_conj_ufunc  s    zTestUFuncs.test_conj_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zexp)r^   rj   r$   r$   r%   test_exp_ufunc  s    zTestUFuncs.test_exp_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zexp2)r^   rj   r$   r$   r%   test_exp2_ufunc  s    zTestUFuncs.test_exp2_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   log)r^   rj   r$   r$   r%   test_log_ufunc  s    zTestUFuncs.test_log_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zlog2)r^   rj   r$   r$   r%   test_log2_ufunc  s    zTestUFuncs.test_log2_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   log10)r^   rj   r$   r$   r%   test_log10_ufunc  s    zTestUFuncs.test_log10_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zexpm1)r^   rj   r$   r$   r%   test_expm1_ufunc  s    zTestUFuncs.test_expm1_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zlog1p)r^   rj   r$   r$   r%   test_log1p_ufunc  s    zTestUFuncs.test_log1p_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   sqrt)r^   rj   r$   r$   r%   test_sqrt_ufunc  s    zTestUFuncs.test_sqrt_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zsquare)r^   rj   r$   r$   r%   test_square_ufunc  s    zTestUFuncs.test_square_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   rL   )r   rj   )	r   r[   rT   rU   rV   rW   r   r@   
reciprocal)r^   rj   to_skipr$   r$   r%   test_reciprocal_ufunc  s
    z TestUFuncs.test_reciprocal_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   	conjugate)r^   rj   r$   r$   r%   test_conjugate_ufunc  s    zTestUFuncs.test_conjugate_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zsin)r^   rj   r$   r$   r%   test_sin_ufunc  s    zTestUFuncs.test_sin_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zcos)r^   rj   r$   r$   r%   test_cos_ufunc  s    zTestUFuncs.test_cos_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Ztan)r^   rj   r$   r$   r%   test_tan_ufunc  s    zTestUFuncs.test_tan_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   arcsin)r^   rj   r$   r$   r%   test_arcsin_ufunc  s    zTestUFuncs.test_arcsin_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   arccos)r^   rj   r$   r$   r%   test_arccos_ufunc  s    zTestUFuncs.test_arccos_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zarctan)r^   rj   r$   r$   r%   test_arctan_ufunc  s    zTestUFuncs.test_arctan_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zarctan2)r^   rj   r$   r$   r%   test_arctan2_ufunc  s    zTestUFuncs.test_arctan2_ufuncc             C   s   | j tjdd d S )Nr   )r   )r   r@   Zhypot)r^   rj   r$   r$   r%   test_hypot_ufunc  s    zTestUFuncs.test_hypot_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zsinh)r^   rj   r$   r$   r%   test_sinh_ufunc  s    zTestUFuncs.test_sinh_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zcosh)r^   rj   r$   r$   r%   test_cosh_ufunc  s    zTestUFuncs.test_cosh_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   tanh)r^   rj   r$   r$   r%   test_tanh_ufunc  s    zTestUFuncs.test_tanh_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zarcsinh)r^   rj   r$   r$   r%   test_arcsinh_ufunc  s    zTestUFuncs.test_arcsinh_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zarccosh)r^   rj   r$   r$   r%   test_arccosh_ufunc  s    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   rL   r   )r   rj   r   )	r   r[   rT   rU   rV   rW   r   r@   Zarctanh)r^   rj   r   r$   r$   r%   test_arctanh_ufunc  s    	zTestUFuncs.test_arctanh_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zdeg2rad)r^   rj   r$   r$   r%   test_deg2rad_ufunc  s    zTestUFuncs.test_deg2rad_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zrad2deg)r^   rj   r$   r$   r%   test_rad2deg_ufunc  s    zTestUFuncs.test_rad2deg_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zdegrees)r^   rj   r$   r$   r%   test_degrees_ufunc  s    zTestUFuncs.test_degrees_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zradians)r^   rj   r$   r$   r%   test_radians_ufunc  s    zTestUFuncs.test_radians_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zbitwise_and)r^   rj   r$   r$   r%   test_bitwise_and_ufunc  s    z!TestUFuncs.test_bitwise_and_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Z
bitwise_or)r^   rj   r$   r$   r%   test_bitwise_or_ufunc  s    z TestUFuncs.test_bitwise_or_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zbitwise_xor)r^   rj   r$   r$   r%   test_bitwise_xor_ufunc  s    z!TestUFuncs.test_bitwise_xor_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   invert)r^   rj   r$   r$   r%   test_invert_ufunc  s    zTestUFuncs.test_invert_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zbitwise_not)r^   rj   r$   r$   r%   test_bitwise_not_ufunc   s    z!TestUFuncs.test_bitwise_not_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   greater)r^   rj   r$   r$   r%   test_greater_ufunc/  s    zTestUFuncs.test_greater_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   greater_equal)r^   rj   r$   r$   r%   test_greater_equal_ufunc3  s    z#TestUFuncs.test_greater_equal_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   less)r^   rj   r$   r$   r%   test_less_ufunc7  s    zTestUFuncs.test_less_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   
less_equal)r^   rj   r$   r$   r%   test_less_equal_ufunc;  s    z TestUFuncs.test_less_equal_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   	not_equal)r^   rj   r$   r$   r%   test_not_equal_ufunc?  s    zTestUFuncs.test_not_equal_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   equal)r^   rj   r$   r$   r%   test_equal_ufuncC  s    zTestUFuncs.test_equal_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zlogical_and)r^   rj   r$   r$   r%   test_logical_and_ufuncG  s    z!TestUFuncs.test_logical_and_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Z
logical_or)r^   rj   r$   r$   r%   test_logical_or_ufuncJ  s    z TestUFuncs.test_logical_or_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zlogical_xor)r^   rj   r$   r$   r%   test_logical_xor_ufuncM  s    z!TestUFuncs.test_logical_xor_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zlogical_not)r^   rj   r$   r$   r%   test_logical_not_ufuncP  s    z!TestUFuncs.test_logical_not_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zmaximum)r^   rj   r$   r$   r%   test_maximum_ufuncS  s    zTestUFuncs.test_maximum_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zminimum)r^   rj   r$   r$   r%   test_minimum_ufuncW  s    zTestUFuncs.test_minimum_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zfmax)r^   rj   r$   r$   r%   test_fmax_ufunc[  s    zTestUFuncs.test_fmax_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zfmin)r^   rj   r$   r$   r%   test_fmin_ufunc^  s    zTestUFuncs.test_fmin_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   Zisfinite)r^   rj   r$   r$   r%   test_isfinite_ufuncd  s    zTestUFuncs.test_isfinite_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   isinf)r^   rj   r$   r$   r%   test_isinf_ufunch  s    zTestUFuncs.test_isinf_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   isnan)r^   rj   r$   r$   r%   test_isnan_ufuncl  s    zTestUFuncs.test_isnan_ufuncc             C   s   | j tj|d d S )N)rj   )r   r@   signbit)r^   rj   r$   r$   r%   test_signbit_ufuncp  s    zTestUFuncs.test_signbit_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zcopysign)r^   rj   r$   r$   r%   test_copysign_ufunct  s    zTestUFuncs.test_copysign_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Z	nextafter)r^   rj   r$   r$   r%   test_nextafter_ufuncx  s    zTestUFuncs.test_nextafter_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zmodf)r^   rj   r$   r$   r%   test_modf_ufunc{  s    zTestUFuncs.test_modf_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zfrexp)r^   rj   r$   r$   r%   test_frexp_ufunc  s    zTestUFuncs.test_frexp_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zfloor)r^   rj   r$   r$   r%   test_floor_ufunc  s    zTestUFuncs.test_floor_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zceil)r^   rj   r$   r$   r%   test_ceil_ufunc  s    zTestUFuncs.test_ceil_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Ztrunc)r^   rj   r$   r$   r%   test_trunc_ufunc  s    zTestUFuncs.test_trunc_ufuncc             C   s   | j tj|dd d S )Nr   )rj   r   )r   r@   Zspacing)r^   rj   r$   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}|}x 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| 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krdnd}| j|||d qW d S )Nr   rJ   g      ?r   rM   )rA   rL   rO   g      rQ   r   r   )rj   rA   singledouble)prec)r3   r=   r   rV   rW   rY   r@   rZ   r[   	itertoolsproductrT   r`   r]   rs   rt   ru   rv   rw   rA   rx   getattrrX   	complex64assertPreciseEqual)r^   r5   rj   r8   Zinputs1Zinputs2Zoutput_typesr   Zinput1Zinput2rd   Zinput1_operandinput1_typeZinput2_operandinput2_typer   r   r   r   Zscalar_typer  r$   r$   r%   binary_ufunc_mixed_types_test  sh      $  z(TestUFuncs.binary_ufunc_mixed_types_testc             C   s   t js| jtjtd d S )N)rj   )r   rq   r  r@   r   no_pyobj_flags)r^   r$   r$   r%   test_mixed_types  s    zTestUFuncs.test_mixed_typesc             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}xt||D ]~\}}ttj	|j
d}ttj|j
d}| jj|||ftd}|j}	tj|j|jd}
t||
 |	|| | ||
 qW 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	}|}xt||D ]\}}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}|	||| | ||
 qdW d S )
Nr   rO   )rA   r   	      rL   )rj   rM   )r9   r@   r   arangereshaperv   rF   r   r[   rV   ndimrW   r]   rs   r  rt   shaperA   r  r=   r   r  r  r   )r^   r   Zinput_operandsZoutput_operandsxr   ra   rd   r   r   r   input1_operandsinput2_operandsyr  r  r$   r$   r%   test_broadcasting  sZ    


zTestUFuncs.test_broadcastingc          	   C   sD   |  t0 dd }ttjdd}t|||ftd}W d Q R X d S )Nc             S   s   t | |S )N)r@   r   )a0a1r$   r$   r%   myadd-  s    z2TestUFuncs.test_implicit_output_npm.<locals>.myaddr   rL   )rj   )assertRaises	TypeErrorr   r[   rV   r	   r  )r^   r$  Zarr_tyr   r$   r$   r%   test_implicit_output_npm+  s
    
z#TestUFuncs.test_implicit_output_npmc             C   sH  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	}|}x|t||D ]l\}}ttj|jd	}ttj|jd	}| j	j
|||ftd
}|j}	t ||}
|	||}t j|
| qW d S )Nc             S   s   t | |S )N)r@   r   )r"  r#  r$   r$   r%   r   4  s    zATestUFuncs.test_broadcast_implicit_output_npm_nrt.<locals>.pyfuncr   rM   )rA   r  r  r   rL   )rj   )r@   r  r  r  r  r   r[   rV   r  r]   rs   enable_nrt_flagsrt   r   r   assert_array_equal)r^   r   r  r  r  r   r  r  r   r   r   r   r$   r$   r%   &test_broadcast_implicit_output_npm_nrt3  s(    
z1TestUFuncs.test_broadcast_implicit_output_npm_nrtc             C   sh  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 }xz|D ]r\}	}
| jj|t|	t|
ftd}||	|
}||	|
}| |jj|jj | |jj
|jj
 t j|| qW d S )Nc             S   s   t | |S )N)r@   r   )r"  r#  r$   r$   r%   r   R  s    z=TestUFuncs.test_implicit_output_layout_binary.<locals>.pyfuncr   r      r   rn   F)orderrL   A   )rj   )r@   linspacer  rZ   Tr   rj   c_contiguouslayoutr   f_contiguousro   r  permutationsr]   rs   r(  rt   assertEqualr   r)  )r^   r   XYZXtyYtyZtyZ	testcasesarg0Zarg1r   r   r   r$   r$   r%   "test_implicit_output_layout_binaryQ  s4    




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	xr|||gD ]d}| jj|t|ftd}	||}
|	|}| |
jj|jj | |
jj
|jj
 t j|
| qW d S )Nc             S   s
   t | S )N)r@   r   )r"  r$   r$   r%   r   w  s    z<TestUFuncs.test_implicit_output_layout_unary.<locals>.pyfuncr   r   r+  r   rn   r,  )r-  rL   r.  )rj   )r@   r0  r  rZ   r1  r   rj   r2  r3  r   r4  r]   rs   r(  rt   r6  r   r)  )r^   r   r7  r8  r9  r:  r;  r<  r=  r   r   r   r$   r$   r%   !test_implicit_output_layout_unaryv  s,    




z,TestUFuncs.test_implicit_output_layout_unary)br3   rf   rg   r  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   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%   ri      s&  K)
		
IE%ri   c               @   sF  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eddd Zdd Zeddd Zedd d! Zedd"d# Zd$d% Zd&d' Zd(d) Zedd*d+ Zd,d- Zd.d/ Zd0d1 Zedd2d3 Zd4d5 Zd6d Zedd7d8 Zedd9d: Zedd;d< Z edd=d> Z!edd?d@ Z"eddAdB Z#eddCdD Z$eddEdF Z%eddGdH Z&eddIdJ Z'eddKdL Z(eddMdN Z)eddOdP Z*eddQdR Z+eddSdT Z,eddUdV Z-eddWdX Z.eddYdZ Z/dS )[TestArrayOperatorsc             C   s&   |  |jj|jj tj|| d S )N)r6  rA   rr   r@   r   r   )r^   r   gotr$   r$   r%   _check_results  s    z!TestArrayOperators._check_resultsNc             C   s   t |}t| j}|| |}	x`|D ]X}
|
\}}||ks&t|tjsHq&| jj|	|f|d}|j	}|	|}||}| 
|| q&W d S )N)rj   )r<   ro   r\   rp   r`   r   r[   r]   rs   rt   rC  )r^   operatorrj   r   r   rb   rc   operator_funcr\   r   r   r   ra   r   r   r   rB  r$   r$   r%   unary_op_test  s    


z TestArrayOperators.unary_op_testFc             C   s  t |}t| j}	|	| |}
x|	D ]}|\}}tt|d|}|}||krRq&|rhtjd|dd }t	|t
jr|}|}|rt||k rq&n,tjdd |}t|}|r||k rq&| jj|
||f|d}|j}|
||}|||}| || q&W d S )NrA   r   )rA   r   
   d   )rj   )r>   ro   r\   rp   r   Zas_dtyper  r@   rv   r`   r   r[   r   randomZastyper   r]   rs   rt   rC  )r^   rD  rj   r   r   rb   rc   positive_rhsrE  r\   r   r   Zinput_operand1ra   Zinput_dtypeZinput_type1ZzeroZinput_operand0Zinput_type0r   r   r   rB  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 )NTFr   rL   )r   Zbooleanr@   rZ   r[   )r^   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   r   rL   )
setdefaultr   rX   rY   r[   rK  )r^   r!   kwsr   r$   r$   r%   binary_int_op_test  s    z%TestArrayOperators.binary_int_op_testc             O   s$   | dg }||  7 }| j||S )Nr   )rM  rL  rO  )r^   r!   rN  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 }
|	|
 }xtt||D ]d\}}t|}t|}| jj|||ftd}|j}| }||| | }||| | 	|| qXW d S )Nc                s   g | ]}t j |d qS ))rA   )r@   rZ   )r,   rA   )
lhs_valuesr$   r%   r.     s   z6TestArrayOperators.inplace_op_test.<locals>.<listcomp>c                s   g | ]}t j |d qS ))rA   )r@   rZ   )r,   rA   )
rhs_valuesr$   r%   r.     s   c                s   g | ]} D ]}||qqS r$   r$   )r,   vrA   )
rhs_dtypesr$   r%   r.     s    )rj   )
r?   r  r  r   r]   rs   r  rt   copyr  )r^   rD  rQ  rR  Z
lhs_dtypesrT  rE  r   Z
lhs_inputsZ
rhs_arraysZrhs_scalarsZ
rhs_inputsZlhsZrhsZlhs_typeZrhs_typer   r   r   rB  r$   )rQ  rT  rR  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 )N)rV  r@   rX   rY   rW   )r^   rD  rQ  rR  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 )N)rV  r@   Zint16rU   rW   rT   )r^   rD  rQ  rR  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 )N)rX  rV  r@   Zbool_)r^   rD  rQ  rR  r$   r$   r%   inplace_bitwise_op_test  s    
z*TestArrayOperators.inplace_bitwise_op_testc             C   s   |  d d S )N+)rF  )r^   r$   r$   r%   test_unary_positive_array_op!  s    z/TestArrayOperators.test_unary_positive_array_opr   c             C   s   |  d d S )N-)rF  )r^   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~r   rL   )r   r   )rF  r   rX   rY   r[   rL  )r^   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 d S )Nz+=rJ   g      ?r   r   g      @)rW  )r^   r$   r$   r%   test_inplace_add2  s    z#TestArrayOperators.test_inplace_addc             C   s   |  ddddgdddg d S )Nz-=rJ   g      ?r   r`  r   g      @)rW  )r^   r$   r$   r%   test_inplace_sub6  s    z#TestArrayOperators.test_inplace_subc             C   s   |  ddddgdddg d S )Nz*=rJ   g      ?r   r`  r   g      @)rW  )r^   r$   r$   r%   test_inplace_mul:  s    z#TestArrayOperators.test_inplace_mulc             C   s   |  ddddgdddg d S )Nz//=rJ   g      ?r   r`  g      ?g      @)rW  )r^   r$   r$   r%   test_inplace_floordiv>  s    z(TestArrayOperators.test_inplace_floordivc             C   s   |  ddddgdddg d S )Nz/=rJ   g      ?r   r`  r   g      @)rW  )r^   r$   r$   r%   test_inplace_divA  s    z#TestArrayOperators.test_inplace_divc             C   s   |  ddddgdddg d S )Nz%=rJ   g      ?r   r`  r/  g      @)rW  )r^   r$   r$   r%   test_inplace_remainderD  s    z)TestArrayOperators.test_inplace_remainderc             C   s   |  ddddgdddg d S )Nz**=rJ   g      ?r   r`  r/  g      @)rW  )r^   r$   r$   r%   test_inplace_powG  s    z#TestArrayOperators.test_inplace_powc          	   C   s&   |  ddddddgdddd	d
g d S )Nz&=r   r   r/  r   3         *      )rY  )r^   r$   r$   r%   test_inplace_andK  s    z#TestArrayOperators.test_inplace_andc          	   C   s&   |  ddddddgdddd	d
g d S )Nz|=r   r   r/  r   rh  ri  rj  rk  rl  )rY  )r^   r$   r$   r%   test_inplace_orN  s    z"TestArrayOperators.test_inplace_orc          	   C   s&   |  ddddddgdddd	d
g d S )Nz^=r   r   r/  r   rh  ri  rj  rk  rl  )rY  )r^   r$   r$   r%   test_inplace_xorQ  s    z#TestArrayOperators.test_inplace_xorc             C   s"   |  dddddgddddg d S )	Nz<<=r   rn   iir   r      )rX  )r^   r$   r$   r%   test_inplace_lshiftT  s    z&TestArrayOperators.test_inplace_lshiftc             C   s"   |  dddddgddddg d S )	Nz>>=r   rn   iir   r   rp  )rX  )r^   r$   r$   r%   test_inplace_rshiftX  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 )Nr   r   r   r   r$   )r#  a2r$   r$   r%   r   b  s    z:TestArrayOperators.test_unary_positive_array_op.<locals>.frG  r   r   N)r@   rv   Z
assertTruer   r   r)  )r^   r   r#  rs  Za3Za4r$   r$   r%   r[  [  s    
&
&c             C   s   |  d d S )NrZ  )rK  )r^   r$   r$   r%   test_add_array_opt  s    z$TestArrayOperators.test_add_array_opc             C   s   |  d d S )Nr\  )rK  )r^   r$   r$   r%   test_subtract_array_opx  s    z)TestArrayOperators.test_subtract_array_opc             C   s   |  d d S )N*)rK  )r^   r$   r$   r%   test_multiply_array_op|  s    z)TestArrayOperators.test_multiply_array_opc             C   s$   d }t dkrtj}| jd|d d S )N)r   r   /)rb   )r   r   rY   rK  )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 )Nr   r   r   r`  g      g      ?g      g      @r/  rK   )rA   rL   r   rM   rJ   rn   rN      rO   rP   rQ   z//)r@   rT   r   rU   rV   rW   rX   rY   rZ   r[   r\   rK  )r^   r$   r$   r%   test_floor_divide_array_op  s"      "" &z-TestArrayOperators.test_floor_divide_array_opc             C   s   |  d d S )N%)rK  )r^   r$   r$   r%   test_remainder_array_op  s    z*TestArrayOperators.test_remainder_array_opc             C   s   | j dtd d S )Nz**)rJ  )rK  r   )r^   r$   r$   r%   test_power_array_op  s    z&TestArrayOperators.test_power_array_opc             C   s   | j ddd d S )Nz<<T)rJ  )rO  )r^   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>>T)rJ  )rO  )r^   r$   r$   r%   test_right_shift_array_op  s    z,TestArrayOperators.test_right_shift_array_opc             C   s   |  d d S )N&)rP  )r^   r$   r$   r%   test_bitwise_and_array_op  s    z,TestArrayOperators.test_bitwise_and_array_opc             C   s   |  d d S )N|)rP  )r^   r$   r$   r%   test_bitwise_or_array_op  s    z+TestArrayOperators.test_bitwise_or_array_opc             C   s   |  d d S )N^)rP  )r^   r$   r$   r%   test_bitwise_xor_array_op  s    z,TestArrayOperators.test_bitwise_xor_array_opc             C   s   |  d d S )Nz==)rK  )r^   r$   r$   r%   test_equal_array_op  s    z&TestArrayOperators.test_equal_array_opc             C   s   |  d d S )N>)rK  )r^   r$   r$   r%   test_greater_array_op  s    z(TestArrayOperators.test_greater_array_opc             C   s   |  d d S )Nz>=)rK  )r^   r$   r$   r%   test_greater_equal_array_op  s    z.TestArrayOperators.test_greater_equal_array_opc             C   s   |  d d S )N<)rK  )r^   r$   r$   r%   test_less_array_op  s    z%TestArrayOperators.test_less_array_opc             C   s   |  d d S )Nz<=)rK  )r^   r$   r$   r%   test_less_equal_array_op  s    z+TestArrayOperators.test_less_equal_array_opc             C   s   |  d d S )Nz!=)rK  )r^   r$   r$   r%   test_not_equal_array_op  s    z*TestArrayOperators.test_not_equal_array_op)0r3   rf   rg   rC  r(  rF  rK  rL  rO  rP  rV  rW  rX  rY  r[  r   r]  r_  ra  rb  rc  rd  re  rf  rg  rm  rn  ro  rq  rr  rt  ru  rw  ry  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r$   r$   r$   r%   rA    sb   %		
rA  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   sB  x: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}||krt|	}	nLt|	jtjrt|	}	n2t|	jtjrt|	}	nt|	jtjrt|	}	|jj|jjf }tdd |D r
d}ntdd |D r$d}nd}| j||	|
|d	 qW d S )
N)rj   zfor args {0} typed {1}c             S   s   g | ]}|t jkqS r$   )r   rX   )r,   tr$   r$   r%   r.     s    z.TestScalarUFuncs.run_ufunc.<locals>.<listcomp>r
  c             S   s   g | ]}|t jkqS r$   )r   rY   )r,   r  r$   r$   r%   r.   
  s    r  exact)r   r  )rF   r	   _compile_flagsrt   rH   r+   setr   rU   rV   rW   floatr@   Z
issubdtyperA   ZinexactZintegerintboolZ	signaturer!   return_typer   r  )r^   r   Z	arg_typesZ
arg_valuesrG   r!   r   r   rB  r   r   ZspecialZalltypesr  r$   r$   r%   	run_ufunc  s.    


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 )N)r@   r   )r  r$   r$   r%   _func  s    z7TestScalarUFuncs.test_scalar_unary_ufunc.<locals>._func)r/  )r   )g?)g?)r   rU   rT   rW   rV   rX   rY   r  )r^   r  vals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 )N)r@   r   )r  r   r$   r$   r%   r    s    z@TestScalarUFuncs.test_scalar_binary_uniform_ufunc.<locals>._funcr/  r   g?g?)	r   rU   rT   rW   rV   rX   rY   r  rF   )r^   r  r  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 )N)r@   r   )r  r   r$   r$   r%   r  (  s    z>TestScalarUFuncs.test_scalar_binary_mixed_ufunc.<locals>._funcr/  r   g?g?)
r   rU   rT   rW   rV   rX   rY   r  r  r  )r^   rj   r  r  r  r$   r$   r%   test_scalar_binary_mixed_ufunc'  s    z/TestScalarUFuncs.test_scalar_binary_mixed_ufuncN)
r3   rf   rg   __doc__enable_pyobj_flagsr  r  r  r  r  r$   r$   r$   r%   r    s   /
r  c               @   s   e Zd ZdZeZdS )TestScalarUFuncsNoPythonz:Same tests as TestScalarUFuncs, but forcing no python modeN)r3   rf   rg   r  r  r  r$   r$   r$   r%   r  3  s   r  c               @   s$   e Zd Zd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 )N)r@   r   )Zx1Zx2r$   r$   r%   foo<  s    z+TestUfuncIssues.test_issue_651.<locals>.foorG  rQ   )rA   )r   r@   r  r  )r^   r  abr$   r$   r%   test_issue_651:  s    zTestUfuncIssues.test_issue_651c             C   s8   dd }t |tjtjg}| |dd|dd d S )Nc             S   s   t | |S )N)r@   r   )r  r   r$   r$   r%   r  E  s    z+TestUfuncIssues.test_issue_713.<locals>.fooy              ?)r	   r   Z
complex128r6  rt   )r^   r  r   r$   r$   r%   test_issue_713D  s    zTestUfuncIssues.test_issue_713c                s   dd }|t dd  fdd}tddd	gtd
ddgg}x<|D ]4}||d	 ||td	 ||tddd	g qPW dS )zF
        <float32 ** int> should return float32, not float64.
        c             S   s   t | |S )N)r@   r   )r  r   r$   r$   r%   r  O  s    z,TestUfuncIssues.test_issue_2006.<locals>.fooT)Znopythonc                s2    | |}t j|| | |j| j d S )N)r@   r   r   r6  rA   )r  r   rB  )r   r   r^   r$   r%   checkT  s    
z.TestUfuncIssues.test_issue_2006.<locals>.checkr   r/  r   y              ?y      @      N)r   r@   rX   r  rV   rW   )r^   r  r  Zxsr  r$   )r   r   r^   r%   test_issue_2006K  s     

zTestUfuncIssues.test_issue_2006N)r3   rf   rg   r  r  r  r$   r$   r$   r%   r  8  s   
r  c               @   sj   e Zd ZdZdZ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'.
    ZOegGr/  r   rn   ))r   r,  )r   D)r   r,  )r   r  )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bhilqr   r   r   rz  )rA   ZBHILQr/  ?TFmzm8[D]ZNaTMzM8[D]ZNat   fdg      ?g      g        nanFDr   y             y              y      ?      ?y              ?y                ztype %r not understoodN)r@   rZ   lenr  r   platformRuntimeError)r^   a_letter_typeindexZnegzeror$   r$   r%   _arg_for_type  s0    
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 )Nr$   )r,   l)supported_typesr$   r%   	<genexpr>  s    z/_LoopTypesTester._check_loop.<locals>.<genexpr>_skip_typesc             3   s   | ]}| kV  qd S )Nr$   )r,   r  )
skip_typesr$   r%   r    s    _required_typesc             3   s   | ]}| kV  qd S )Nr$   )r,   r  )letter_typesr$   r%   r    s   )ZninZnoutr  r   _check_ufunc_with_dtypes)r^   r/   r5   loopZrequired_typesr$   )r  r  r  r%   _check_loop  s    
z_LoopTypesTester._check_loopc                s$  dd |D }dd |D }t || jd} fddt|D }x|D ]} j| qHW dd |D }	|j|  ||	  xt||	|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 qW d S )Nc             S   s   g | ]}t |qS r$   )r@   rA   )r,   r  r$   r$   r%   r.     s    z=_LoopTypesTester._check_ufunc_with_dtypes.<locals>.<listcomp>c             S   s   g | ]}t t|d dqS )r   rL   )r   r[   r   )r,   r  r$   r$   r%   r.     s    )rj   c                s$   g | ]\}} j ||d dqS ))r  r/  )r  repeat)r,   r  r  )r^   r$   r%   r.     s   c             S   s   g | ]}|  qS r$   )rU  )r,   r  r$   r$   r%   r.     s    r   ZfFr
  r  ZdDr  rm   z ufunc '{0}' arrays differ ({1}):z	args: {2}zexpected {3}zgot {4})r  r   ulps)r	   r  	enumeraterI  Zshufflert   rF   _fixup_resultsrA   char_ulpsgetr3   r0   r+   r  )r^   r/   r5   ZdtypesZarg_dtyZarg_nbtyr   Zc_argsZarrZpy_argsrA   py_argc_argZtypecharr  r  r   r$   )r^   r%   r    s*    


z)_LoopTypesTester._check_ufunc_with_dtypesc             C   s   ||fS )Nr$   )r^   rA   r  r  r$   r$   r%   r    s    z_LoopTypesTester._fixup_resultsc             C   s    x|j D ]}| || qW d S )N)r   _inject_test)clsr5   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 )N)r7   r  )r^   r/   )r  r5   r$   r%   test_template  s    z4_LoopTypesTester._inject_test.<locals>.test_templateztest_{0}_{1}z->_)setattrr+   r3   replace)r  r5   r  r  r$   )r  r5   r%   r    s    z_LoopTypesTester._inject_testc             C   s   x| j D ]}| | qW d S )N)_ufuncsr  )r  r5   r$   r$   r%   autogenerate  s    z_LoopTypesTester.autogenerateN)r   )r3   rf   rg   r  r  r  r  r  r  r  classmethodr  r  r  r$   r$   r$   r%   r  c  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)r3   rf   rg   r  r  r   r  remover@   r   r   
left_shiftright_shiftr   r   r  r  r  r$   r$   r$   r%   r    s   r  c               @   s6   e Zd ZeZejejgZdZ	de
j Zer2ed7 ZdS )(TestLoopTypesSubtractAndNegativeNoPythonz?bBhHiIlLqQfdFDmMOr  N)r3   rf   rg   r  r  r@   r   r   r  r  r  r  r   r$   r$   r$   r%   r    s   
r  c                   s8   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kr*d||dk< |S )N)r  
bBhHiIlLqQrk  r   )rR   r_   r  )r^   r  r  res)r_   r$   r%   r    s
    z-TestLoopTypesReciprocalNoPython._arg_for_type)r   )r3   rf   rg   r  r  r@   r   r  r  r  r  r  rh   r$   r$   )r_   r%   r    s
   
r  c                   s8   e Zd ZeZejgZdZde	j
 Z
d fdd	Z  ZS )TestLoopTypesPowerNoPythonr  r  r   c                s6   t | j| j||d}|dkr2|dkr2d||dk < |S )N)r  r  r   r   r   )rR   r_   r  )r^   r  r  r  )r_   r$   r%   r  +  s
    z(TestLoopTypesPowerNoPython._arg_for_type)r   )r3   rf   rg   r  r  r@   r   r  r  r  r  r  rh   r$   r$   )r_   r%   r  %  s
   
r  c                   s8   e Zd ZeZejgZdZde	j
 Z
d fdd	Z  ZS )!TestLoopTypesIntLeftShiftNoPythonr  r  r   c                s@   t | j| j||d}|dkr<|jjd }t|d|d }|S )N)r  r      r   )rR   r_   r  rA   itemsizer@   clip)r^   r  r  r  	bit_count)r_   r$   r%   r  >  s    z/TestLoopTypesIntLeftShiftNoPython._arg_for_type)r   )r3   rf   rg   r  r  r@   r  r  r  r  r  r  rh   r$   r$   )r_   r%   r  8  s
   
r  c                   s8   e Zd ZeZejgZdZde	j
 Z
d fdd	Z  ZS )"TestLoopTypesIntRightShiftNoPythonr  r  r   c                sR   t | j| j||d}|dkr<|jjd }t|d|d }|dkrNt|}|S )N)r  r   r  r   )rR   r_   r  rA   r  r@   r  r@  )r^   r  r  r  r  )r_   r$   r%   r  U  s    

z0TestLoopTypesIntRightShiftNoPython._arg_for_type)r   )r3   rf   rg   r  r  r@   r  r  r  r  r  r  rh   r$   r$   )r_   r%   r  O  s
   
r  c               @   s2   e Zd ZeZ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   g        )rr   r@   r   r   )r^   rA   r  r  Zpredr$   r$   r%   r  w  s
    
z/TestLoopTypesFloorDivideNoPython._fixup_resultsN)r3   rf   rg   r  r  r@   r   r   r  r  r  r  r  r$   r$   r$   r%   r  q  s
   
r  c               @   s^   e Zd ZeZedd Zer(ee	j
 ee	j ee	j ee	j dZdej ZdS )TestLoopTypesFloatNoPythonNr  ZFDmMO)r3   rf   rg   r  r  r   r  	iswindowsr  r@   r   r   r   r   r  r  r  r$   r$   r$   r%   r    s   r  c               @   s*   e Zd ZeZedd ZdZdej	 Z	dS )TestLoopTypesComplexNoPythonNr  r  )
r3   rf   rg   r  r  r   r  r  r  r  r$   r$   r$   r%   r    s   r  c               @   sX   e Zd ZeZedd ZdZdd Zdd Z	dd Z
d	d
 Zdd Zdd Zdd ZdS )TestLoopTypesDatetimeNoPythonNZmMc          	   C   s   t j}t|}| ||dddg | ||dddg tjsd| ||dddg | ||dddg | ||dddg | ||dddg | t | ||dddg W d Q R X d S )Nzm8[s]zm8[m]m8zm8[ms])r@   r   r7   r  r   rq   r%  r   )r^   r5   r/   r$   r$   r%   test_add  s    z&TestLoopTypesDatetimeNoPython.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 d Q R X d S )NzM8[s]zM8[m]zm8[s]zm8[ms]zm8[m])r@   r   r7   r  r%  r   )r^   r5   r/   r$   r$   r%   test_subtract  s    z+TestLoopTypesDatetimeNoPython.test_subtractc          	   C   sd   t j}t|}| ||dddg | ||dddg | t | ||dddg W d Q R X d S )Nzm8[s]qzm8[us]zm8[m])r@   r   r7   r  r%  r   )r^   r5   r/   r$   r$   r%   test_multiply  s    z+TestLoopTypesDatetimeNoPython.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 d Q R X d S )Nzm8[m]zm8[s]dr  )r@   r   r7   r  r%  r   )r^   r5   r/   r$   r$   r%   test_true_divide  s    z.TestLoopTypesDatetimeNoPython.test_true_dividec          	   C   sd   t j}t|}| ||dddg | ||dddg | t | ||dddg W d Q R X d S )Nzm8[m]r  zm8[s]r  )r@   r   r7   r  r%  r   )r^   r5   r/   r$   r$   r%   test_floor_divide  s    z/TestLoopTypesDatetimeNoPython.test_floor_dividec             C   s   t |}| ||dddg | ||dddg tjs^| ||dddg | ||dddg | ||dddg | ||dddg d S )Nzm8[m]zm8[s]r  r  zM8[m]zM8[s])r7   r  r   rq   )r^   r5   r/   r$   r$   r%   _check_comparison  s    z/TestLoopTypesDatetimeNoPython._check_comparisonc             C   s4   x.t jt jt jt jt jt jgD ]}| | qW d S )N)r@   r   r   r   r   r   r   r  )r^   r5   r$   r$   r%   test_comparisons  s    z.TestLoopTypesDatetimeNoPython.test_comparisons)r3   rf   rg   r  r  r   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   s*   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 args)r@   r   )r  r   r$   r$   r%   r#     s    
z8TestUFuncBadArgsNoPython.test_missing_args.<locals>.func)r  rj   )r%  r   r	   r   rY   r  )r^   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 args)r@   r   )r  outZout2r   r$   r$   r%   r#     s    z9TestUFuncBadArgsNoPython.test_too_many_args.<locals>.funcr   rL   r   )r  rj   )r   r[   rY   r%  r   r	   r  )r^   r#   Z
array_typer$   r$   r%   test_too_many_args  s    z+TestUFuncBadArgsNoPython.test_too_many_argsc             C   s*   dd }| j tt|tjgtj| jd d S )Nc             S   s   d}t | | | dS )z0error: scalar as a return value is not supportedr   N)r@   r   )r  r   r$   r$   r%   r#     s    zITestUFuncBadArgsNoPython.test_no_scalar_result_by_reference.<locals>.func)r  rj   )r%  r   r	   r   rY   r  )r^   r#   r$   r$   r%   "test_no_scalar_result_by_reference  s    z;TestUFuncBadArgsNoPython.test_no_scalar_result_by_referenceN)r3   rf   rg   r  r  r  r  r  r$   r$   r$   r%   r    s   

r  c               @   s   e Zd Zdd ZdS ) TestUFuncCompilationThreadSafetyc                sn   g  t dd  fddfddtdD }x|D ]}|  q:W x|D ]}|  qPW |   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           
      sl   y:t jdt jd} t jdt jdd }t j| | W n, tk
rf } z | W d d }~X Y nX d S )N)rG  )rA   g      ?)r@   ZonesrY   r   r)  BaseExceptionappend)r  r   e)errorsr  r$   r%   r&   -  s    z;TestUFuncCompilationThreadSafety.test_lock.<locals>.wrapperc                s   g | ]}t j d qS ))target)	threadingZThread)r,   r-   )r&   r$   r%   r.   5  s    z>TestUFuncCompilationThreadSafety.test_lock.<locals>.<listcomp>rj  N)r   r1   startr0   ZassertFalse)r^   Zthreadsr  r$   )r  r  r&   r%   	test_lock"  s    

z*TestUFuncCompilationThreadSafety.test_lockN)r3   rf   rg   r  r$   r$   r$   r%   r     s   r  __main__)VZ
__future__r   r'   r  rer   ry   r  Znumpyr@   Znumba.unittest_supportZunittest_supportr   Znumbar   r   r   r   r   r   Znumba.compilerr	   r
   r   Znumba.numpy_supportr   r   Znumpy_versionr   r   Znumba.configr   Znumba.errorsr   r   Zsupportr   r   r   r   Z	numba.sixr   Znumba.typing.npydeclr   r   tuple__itemsize__Zis32bitsr  r   r  r   r  r  r  r(  r)   r7   r9   r<   r=   r>   r?   rH   rI   ri   rA  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r3   mainr$   r$   r$   r%   <module>   s    






		9     t  A\+ 	`
