a
    –§»a·!  ã                   @   sî   d dl Zd dlmZmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZ d dlZe ¡ Zde_d	d
„ Zdd„ Zdd„ ZG dd„ deejƒZG dd„ deejƒZG dd„ dejƒZG dd„ dejƒZedkrêe ¡  dS )é    N)Úcompile_isolatedÚDEFAULT_FLAGS)ÚSerialMixin)ÚtypeofÚcudaÚnjit)Úfloat64)ÚMemoryLeakMixinÚoverride_env_config)ÚconfigTc                 C   s   | d S ©Né
   © ©Úar   r   úV/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/numba/tests/test_boundscheck.pyÚbasic_array_access   s    r   c                 C   s   | dd …df S r   r   r   r   r   r   Úslice_array_access   s    r   c                 C   s   t  g d¢¡}| | S )N)é   é   é   )ÚnpÚarray©Úxr   r   r   r   Úfancy_array_access   s    r   c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestBoundsCheckNoErrorc                 C   s   t j| _d t _d S ©N©r   ÚBOUNDSCHECKÚold_boundscheck©Úselfr   r   r   ÚsetUp   s    zTestBoundsCheckNoError.setUpc                 C   sf   t  d¡}|  t¡� t|ƒ W d   ƒ n1 s20    Y  t|ƒ}tt|gtd�}|j}||ƒ d S ©Né   )Úflags)	r   ÚarangeÚassertRaisesÚ
IndexErrorr   r   r   r   Úentry_point)r"   r   ÚatÚc_noboundscheckÚnoboundscheckr   r   r   Útest_basic_array_boundscheck"   s    
&ÿz3TestBoundsCheckNoError.test_basic_array_boundscheckc           	      C   s®   t  d¡}t  d¡}|  t¡� t|ƒ W d   ƒ n1 s<0    Y  t|ƒ t|ƒ}td d … }tt|g|td�}|j	}tt|g|t
d�}|j	}||ƒ ||ƒ ||ƒ d S ©N)r%   r%   )r%   é   ©Úreturn_typer&   )r   Úonesr(   r)   r   r   r   r   r   r*   ÚBOUNDSCHECK_FLAGS©	r"   r   Úbr+   Úrtr,   r-   Úc_boundscheckÚboundscheckr   r   r   Útest_slice_array_boundscheck2   s(    

&þþz3TestBoundsCheckNoError.test_slice_array_boundscheckc           	      C   s°   t  d¡}t  d¡}|  t¡� t|ƒ W d   ƒ n1 s<0    Y  t|ƒ t|ƒ}|jd d … }tt|g|td�}|j	}tt|g|t
d�}|j	}||ƒ ||ƒ ||ƒ d S ©Nr   é   r1   )r   r'   r(   r)   r   r   Údtyper   r   r*   r4   r5   r   r   r   Útest_fancy_indexing_boundscheckN   s(    

&þþz6TestBoundsCheckNoError.test_fancy_indexing_boundscheckc                 C   s   | j t_d S r   ©r    r   r   r!   r   r   r   ÚtearDownk   s    zTestBoundsCheckNoError.tearDownN©Ú__name__Ú
__module__Ú__qualname__r#   r.   r:   r>   r@   r   r   r   r   r      s
   r   c                   @   s6   e Zd Zdd„ Ze e ¡  d¡dd„ ƒZdd„ Z	dS )	ÚTestNoCudaBoundsCheckc                 C   s   t j| _d t _d S r   r   r!   r   r   r   r#   p   s    zTestNoCudaBoundsCheck.setUpzNO CUDAc                 C   s¶   |   t¡�$ tjdd�dd„ ƒ}W d   ƒ n1 s40    Y  tjdd�dd„ ƒ}tdd	ƒ�F tjd
d„ ƒ}t d¡}t d¡}tj	s”|d ||ƒ W d   ƒ n1 s¨0    Y  d S )NT©r9   c                   S   s   d S r   r   r   r   r   r   Úfuncw   s    z<TestNoCudaBoundsCheck.test_no_cuda_boundscheck.<locals>.funcFc                   S   s   d S r   r   r   r   r   r   Úfunc3}   s    z=TestNoCudaBoundsCheck.test_no_cuda_boundscheck.<locals>.func3ÚNUMBA_BOUNDSCHECKÚ1c                 S   s   | d |d< d S ©Nr   r   r   r   r   r   Úfunc2‚   s    z=TestNoCudaBoundsCheck.test_no_cuda_boundscheck.<locals>.func2)r   )r   r   )
r(   ÚNotImplementedErrorr   Zjitr
   r   r3   Úzerosr   ZENABLE_CUDASIM)r"   rG   rH   rL   r   r   r   r   r   Útest_no_cuda_boundscheckt   s    
(




z.TestNoCudaBoundsCheck.test_no_cuda_boundscheckc                 C   s   | j t_d S r   r?   r!   r   r   r   r@   �   s    zTestNoCudaBoundsCheck.tearDownN)
rB   rC   rD   r#   ÚunittestZskipIfr   Zis_availablerO   r@   r   r   r   r   rE   o   s   
rE   c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestBoundsCheckErrorc                 C   s   t j| _d t _d S r   r   r!   r   r   r   r#   ”   s    zTestBoundsCheckError.setUpc                 C   s�   t  d¡}|  t¡� t|ƒ W d   ƒ n1 s20    Y  t|ƒ}tt|gtd�}|j}|  t¡� ||ƒ W d   ƒ n1 s‚0    Y  d S r$   )	r   r'   r(   r)   r   r   r   r4   r*   )r"   r   r+   r8   r9   r   r   r   r.   ˜   s    
&ÿz1TestBoundsCheckError.test_basic_array_boundscheckc                 C   s°   t  d¡}t  d¡}|  t¡� t|ƒ W d   ƒ n1 s<0    Y  t|ƒ t|ƒ}td d … }tt|g|td�}|j	}|  t¡� ||ƒ W d   ƒ n1 s¢0    Y  d S r/   )
r   r3   r(   r)   r   r   r   r   r4   r*   ©r"   r   r6   r+   r7   r8   r9   r   r   r   r:   ¨   s    

&þz1TestBoundsCheckError.test_slice_array_boundscheckc                 C   s²   t  d¡}t  d¡}|  t¡� t|ƒ W d   ƒ n1 s<0    Y  t|ƒ t|ƒ}|jd d … }tt|g|td�}|j	}|  t¡� ||ƒ W d   ƒ n1 s¤0    Y  d S r;   )
r   r'   r(   r)   r   r   r=   r   r4   r*   rR   r   r   r   r>   »   s    

&þz4TestBoundsCheckError.test_fancy_indexing_boundscheckc                 C   s   | j t_d S r   r?   r!   r   r   r   r@   Ï   s    zTestBoundsCheckError.tearDownNrA   r   r   r   r   rQ   “   s
   rQ   c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestBoundsEnvironmentVariablec                 C   sT   t j| _d t _tdd„ ƒ}tdd�dd„ ƒ}tdd�dd	„ ƒ}|| _|| _|| _d S )
Nc                 S   s   | d S rK   r   ©r   r   r   r   ÚdefaultØ   s    z4TestBoundsEnvironmentVariable.setUp.<locals>.defaultFrF   c                 S   s   | d S rK   r   rT   r   r   r   ÚoffÜ   s    z0TestBoundsEnvironmentVariable.setUp.<locals>.offTc                 S   s   | d S rK   r   rT   r   r   r   Úonà   s    z/TestBoundsEnvironmentVariable.setUp.<locals>.on)r   r   r    r   rU   rV   rW   )r"   rU   rV   rW   r   r   r   r#   Ô   s    


z#TestBoundsEnvironmentVariable.setUpc              	   C   s‚   t ddƒ�d t dg¡}|  |¡ |  |¡ |  t¡� |  |¡ W d   ƒ n1 sV0    Y  W d   ƒ n1 st0    Y  d S )NrI   Ú r   )r
   r   r   rU   rV   r(   r)   rW   ©r"   r   r   r   r   Útest_boundscheck_unsetè   s    

z4TestBoundsEnvironmentVariable.test_boundscheck_unsetc              	   C   s‚   t ddƒ�d t dg¡}|  t¡�. |  |¡ |  |¡ |  |¡ W d   ƒ n1 sV0    Y  W d   ƒ n1 st0    Y  d S )NrI   rJ   r   )r
   r   r   r(   r)   rU   rV   rW   rY   r   r   r   Útest_boundscheck_enabledó   s    

z6TestBoundsEnvironmentVariable.test_boundscheck_enabledc                 C   sX   t ddƒ�: t dg¡}|  |¡ |  |¡ |  |¡ W d   ƒ n1 sJ0    Y  d S )NrI   Ú0r   )r
   r   r   rU   rV   rW   rY   r   r   r   Útest_boundscheck_disabledü   s
    

z7TestBoundsEnvironmentVariable.test_boundscheck_disabledc                 C   s   | j t_d S r   r?   r!   r   r   r   r@     s    z&TestBoundsEnvironmentVariable.tearDownN)rB   rC   rD   r#   rZ   r[   r]   r@   r   r   r   r   rS   Ó   s
   		rS   Ú__main__) Únumpyr   Znumba.core.compilerr   r   Znumba.cuda.testingr   Znumbar   r   r   Znumba.core.typesr   Znumba.tests.supportr	   r
   Z
numba.corer   rP   Úcopyr4   r9   r   r   r   ZTestCaser   rE   rQ   rS   rB   Úmainr   r   r   r   Ú<module>   s$   R$@6