o
    8ήc                     @   s  d dl Z d dlZd dlmZmZmZmZmZm	Z	 d dl
mZmZ d dlZe jZdd Zdd Zdd	 ZG d
d deZG dd dejeZG dd dejeZG dd dejeZG dd dejeZG dd deZG dd dejeZG dd deZedkre  dS dS )    N)int32uint32float32float64jit	vectorize)tagCheckWarningsMixinc                 C   s"   | dkrdS t | t t|   S )N        g      ?mathsinpi)x r   P/tmp/pip-target-vg8gfxp4/lib/python/numba/tests/npyufunc/test_vectorize_decor.pysinc   s   r   c                 C   s&   | dkr|S |t | t t|    S )Nr
   r   )r   scaler   r   r   scaled_sinc   s   r   c                 C   s   | | S )Nr   )abr   r   r   
vector_add   s   r   c                   @   sL   e Zd ZdZdZeeedZe	dd Z
dd Zdd Zd	d
 Zdd ZdS )BaseVectorizeDecorN)func1func2func3c           
      O   sj   | j d ur
|  |}t|| jd|}t|}||g|R  }||g|R  }	tjj||	fi | d S )N)target)wrapperr   r   nptestingassert_allclose)
clsfuncsigAargskwargs
numba_func
numpy_funcresultgoldr   r   r   _run_and_compare&   s   


z#BaseVectorizeDecor._run_and_comparec                 C   s4   ddg}| j d }tjdtjd}| ||| d S )Nzfloat64(float64)zfloat32(float32)r   d   dtype)funcsr   aranger   r+   selfr#   r"   r$   r   r   r   test_10   s   
zBaseVectorizeDecor.test_1c                 C   s<   t t ttg}| jd }tjdtj d}| ||| d S )Nr   r,   r-   )r   r   r/   r   r0   r+   r1   r   r   r   test_26   s   
zBaseVectorizeDecor.test_2c                 C   sB   dg}| j d }tjdtjd}td}| j||||dd d S )Nzfloat64(float64, uint32)r   r,   r-      g:0yE>)atol)r/   r   r0   r   r   r+   )r2   r#   r"   r$   r   r   r   r   test_3<   s
   

zBaseVectorizeDecor.test_3c                 C   s   t t t tttttttttg}| jd }tjdtjd}| |||| |tj}| |||| |tj }| |||| |tj}| |||| d S )Nr   r,   r-   )	r   r   r   r   r/   r   r0   r+   astyper1   r   r   r   test_4C   s   
zBaseVectorizeDecor.test_4)__name__
__module____qualname__r   r   r   r   r   r/   classmethodr+   r3   r4   r7   r9   r   r   r   r   r      s    
	r   c                   @   s   e Zd ZdZdS )TestCPUVectorizeDecorcpuN)r:   r;   r<   r   r   r   r   r   r>   U   s    r>   c                   @   s   e Zd ZdZdZdS )TestParallelVectorizeDecorFparallelN)r:   r;   r<   _numba_parallel_test_r   r   r   r   r   r@   Y       r@   c                   @   s   e Zd ZdZeZdS )TestCPUVectorizeJittedr?   N)r:   r;   r<   r   r   r   r   r   r   r   rD   ^   rC   rD   c                   @      e Zd ZdZdddZdS )BaseVectorizeNopythonArgzH
    Test passing the nopython argument to the vectorize decorator.
    Tc           	      C   s   t jdgt jd}t jdgt jd}tttg}|r|gpg }| | t||ddt}||| W d    d S 1 s?w   Y  d S )N       @r-         @T)r   nopython)r   arrayr   check_warningsr   r   )	r2   r   warningswith_sigr   r   r#   r%   fr   r   r   _test_target_nopythong   s   "z.BaseVectorizeNopythonArg._test_target_nopythonNT)r:   r;   r<   __doc__rO   r   r   r   r   rF   c       rF   c                   @   $   e Zd Zdd Zdd Zdd ZdS )TestVectorizeNopythonArgc                 C      |  dg  d S Nr?   rO   r2   r   r   r   test_target_cpu_nopythonq      z1TestVectorizeNopythonArg.test_target_cpu_nopythonc                 C   s   |  dg d d S Nr?   FrW   rX   r   r   r   test_target_cpu_nopython_no_sigt   s   z8TestVectorizeNopythonArg.test_target_cpu_nopython_no_sigc                 C   rU   NrA   rW   rX   r   r   r   test_target_parallel_nopythonw   rZ   z6TestVectorizeNopythonArg.test_target_parallel_nopythonN)r:   r;   r<   rY   r\   r^   r   r   r   r   rT   p       rT   c                   @   rE   )BaseVectorizeUnrecognizedArgzK
    Test passing an unrecognized argument to the vectorize decorator.
    Tc           	      C   s   t jdgt jd}t jdgt jd}tttg}|r|gpg }| t}t||ddt}||| W d    n1 s>w   Y  | dt|j	 d S )NrG   r-   rH      )r   nonexistentzUnrecognized options)
r   rJ   r   assertRaisesKeyErrorr   r   assertInstr	exception)	r2   r   rM   r   r   r#   r%   raisesrN   r   r   r   _test_target_unrecognized_arg   s   z:BaseVectorizeUnrecognizedArg._test_target_unrecognized_argNrP   )r:   r;   r<   rQ   ri   r   r   r   r   r`   {   rR   r`   c                   @   rS   )TestVectorizeUnrecognizedArgc                 C      |  d d S rV   ri   rX   r   r   r    test_target_cpu_unrecognized_arg      z=TestVectorizeUnrecognizedArg.test_target_cpu_unrecognized_argc                 C   s   |  dd d S r[   rl   rX   r   r   r   'test_target_cpu_unrecognized_arg_no_sig   rZ   zDTestVectorizeUnrecognizedArg.test_target_cpu_unrecognized_arg_no_sigc                 C   rk   r]   rl   rX   r   r   r   %test_target_parallel_unrecognized_arg   rn   zBTestVectorizeUnrecognizedArg.test_target_parallel_unrecognized_argN)r:   r;   r<   rm   ro   rp   r   r   r   r   rj      r_   rj   __main__)r   numpyr   numbar   r   r   r   r   r   numba.tests.supportr   r	   unittestr   r   r   r   objectr   TestCaser>   r@   rD   rF   rT   r`   rj   r:   mainr   r   r   r   <module>   s(     8