o
    Z۷iy                     @   s   d dl Z d dlZd dlZd dlmZmZ d dlmZm	Z	m
Z
 d dl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e	ZedkrUe  dS dS )    N)	vectorizeguvectorize)TestCaseCheckWarningsMixinskip_macos_fenv_errorsc                 C   s   | dk rt d| d S )N        Value must be positiveg      ?)
ValueError)val r   V/home/ubuntu/vllm_env/lib/python3.10/site-packages/numba/tests/npyufunc/test_errors.pysqrt   s   r   c                 C   s@   t | jd D ]}| | dk rtd| | |d  ||< qd S )Nr   r   )rangeshaper	   )inpnoutir   r   r   
gufunc_foo   s
   r   c                 C   s   | | S Nr   abr   r   r   truediv      r   c                 C   s   | | S r   r   r   r   r   r   floordiv   r   r   c                 C   s   | | S r   r   r   r   r   r   	remainder   r   r   c                 C   s   | | S r   r   r   r   r   r   power"   r   r   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )TestExceptionsz0
    Test raising exceptions inside ufuncs.
    c                 K   s   t dgfi |t}tjg dtjd}t|}| t}||| W d    n1 s/w   Y  | dt	|j
 | t|g d d S )Nzfloat64(float64))      	      dtyper   )r      r      r   r    )r   r   nparrayfloat64
zeros_likeassertRaisesr	   assertInstr	exceptionassertEquallistselfvectorize_argsfarrr   cmr   r   r   check_ufunc_raise+   s   
z TestExceptions.check_ufunc_raisec                 C      | j dd d S NTnopythonr9   r4   r   r   r   test_ufunc_raise5      zTestExceptions.test_ufunc_raisec                 C   r:   NT)forceobjr>   r?   r   r   r   test_ufunc_raise_objmode8   rA   z'TestExceptions.test_ufunc_raise_objmodec                 K   s   t dgdfi |t}tjg dtjd}t|}| t}||d| W d    n1 s1w   Y  | t	|g d d S )Nzint32[:], int32[:], int32[:]z(n),()->(n))r   r'   r    r%   r'   )r'   r    r   r   )
r   r   r)   r*   int32r,   r-   r	   r1   r2   r3   r   r   r   check_gufunc_raise;   s   
z!TestExceptions.check_gufunc_raisec                 C   r:   r;   rG   r?   r   r   r   test_gufunc_raiseE   rA   z TestExceptions.test_gufunc_raisec                 C   r:   rB   rH   r?   r   r   r   test_gufunc_raise_objmodeH   rA   z(TestExceptions.test_gufunc_raise_objmodeN)
__name__
__module____qualname____doc__r9   r@   rD   rG   rI   rJ   r   r   r   r   r   &   s    

r   c                   @   sl   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dd Z
dd Zdd Zdd Zdd Zdd ZdS )TestFloatingPointExceptionsz{
    Test floating-point exceptions inside ufuncs.

    Note the warnings emitted by Numpy reflect IEEE-754 semantics.
    c                 C   s   t ddt}tjg d|d}tjg d|d}tdtdtdd	g}| d
dg |||}| || W d   dS 1 sDw   Y  dS )z'
        Test 1 / 0 and 0 / 0.
        Tr<   )      @      @r          @r%         ?r   r         @rP   infnan       @divide by zero encounteredinvalid value encounteredN)r   r   r)   r*   floatcheck_warningsassertPreciseEqualr4   r&   r6   r   r   expectedresr   r   r   check_truediv_realR   s   
"z.TestFloatingPointExceptions.check_truediv_realc                 C      |  tj d S r   )ra   r)   r+   r?   r   r   r   test_truediv_float_   rA   z.TestFloatingPointExceptions.test_truediv_floatc                 C   rb   r   )ra   r)   rF   r?   r   r   r   test_truediv_integerb   rA   z0TestFloatingPointExceptions.test_truediv_integerc           	      C   sz   t dd|}tg d}tg d}t|}| | |||}| || W d   dS 1 s6w   Y  dS )z)
        Test 1 // 0 and 0 // 0.
        Tr<   )rP   rQ   r   g      "@rS   Nr   r)   r*   r\   r]   )	r4   pyfuncvaluesmessagesr6   r   r   r_   r`   r   r   r   check_divmod_floate   s   

"z.TestFloatingPointExceptions.check_divmod_floatc                 C   s&   |  tdtdtddgddg d S )NrP   rV   rW   rX   rY   rZ   )ri   r   r[   r?   r   r   r   test_floordiv_floatq   s   z/TestFloatingPointExceptions.test_floordiv_floatc                 C   s$   |  tdtdtddgdg d S )Nr   rW   rT   rZ   )ri   r   r[   r?   r   r   r   test_remainder_floatw   s   z0TestFloatingPointExceptions.test_remainder_floatc                 C   sz   t dd|}tg d}tg d}t|}| g  |||}| || W d   dS 1 s6w   Y  dS )z'
        Test 1 % 0 and 0 % 0.
        Tr<   )      r   r"   )r   r   r   r    Nre   )r4   rf   rg   r6   r   r   r_   r`   r   r   r   check_divmod_int}   s   

"z,TestFloatingPointExceptions.check_divmod_intc                 C      |  tg d d S )N)rl   r   r   r'   )rn   r   r?   r   r   r   test_floordiv_int      z-TestFloatingPointExceptions.test_floordiv_intc                 C   ro   )N)r   r   r   r   )rn   r   r?   r   r   r   test_remainder_int   rq   z.TestFloatingPointExceptions.test_remainder_intc                 C   s   t ddt}tg d}tg d}tdtdtddg}| dd	g |||}| || W d
   d
S 1 s@w   Y  d
S )z5
        Test 0 ** -1 and 2 ** <big number>.
        Tr<   )rP   r   rX   rR   )rT   g      g@xDrU   rP   rV   g      @rY   zoverflow encounteredN)r   r   r)   r*   r[   r\   r]   )r4   r6   r   r   r_   r`   r   r   r   test_power_float   s   
"z,TestFloatingPointExceptions.test_power_floatc                 C   s   t j}tdgddt}t jg d|d}t jg d|d}t jg d|d}| g  |||}| || W d   dS 1 sCw   Y  dS )	z
        Test 0 ** -1.
        Note 2 ** <big number> returns an undefined value (depending
        on the algorithm).
        zint64(int64, int64)Tr<   )rl   r   rm   r%   )r   r#   r'   )rl   l         $   N)r)   int64r   r   r*   r\   r]   r^   r   r   r   test_power_integer   s   
"z.TestFloatingPointExceptions.test_power_integerN)rK   rL   rM   rN   ra   rc   rd   ri   rj   r   rk   rn   rp   rr   rs   rv   r   r   r   r   rO   K   s    
rO   __main__)
contextlibsysnumpyr)   numbar   r   numba.tests.supportr   r   r   unittestr   r   r   r   r   r   r   rO   rK   mainr   r   r   r   <module>   s"    %b