o
    1&i                      @   s   d dl 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dd Zd	d
 Zdd Zdd ZG dd deeZG dd deeZG dd deZG dd deZedkrhe  dS dS )    N)SerialMixin)typeofcudanjit)float64)TestCaseMemoryLeakMixin)configc                 C      | d S N
    ar   r   GC:\wamp64\www\opt\env\Lib\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      r   c                 C   s   t g d}| | S )N         nparrayxr   r   r   r   fancy_array_access   s   r   c                 C   s   t g d}d| |< | S )Nr   r   r   r   r   r   r   fancy_array_modify   s   r   c                   @   sT   e Zd Zejddiddd Zejddiddd Zejddiddd	 Zd
S )TestBoundsCheckNoErrorNUMBA_BOUNDSCHECK envvarsc                 C   sj   |  tj td}| t t| W d    n1 sw   Y  t|}t	|ft}|| d S )N   
assertIsNoner	   BOUNDSCHECKr   arangeassertRaises
IndexErrorr   r   r   )selfr   atnoboundscheckr   r   r   test_basic_array_boundscheck!   s   

z3TestBoundsCheckNoError.test_basic_array_boundscheckc                 C   s   |  tj td}td}| t t| W d    n1 s$w   Y  t| t|}t	d d  }t
||t}t
||ddt}|| || || d S N)r$   r$   )r$      Tboundscheckr&   r	   r'   r   onesr)   r*   r   r   r   r   r+   r   br,   rtr-   r2   r   r   r   test_slice_array_boundscheck2   s   


z3TestBoundsCheckNoError.test_slice_array_boundscheckc                 C   s   |  tj td}td}| t t| W d    n1 s$w   Y  t| t|}|j	d d  }t
||t}t
||ddt}|| || || d S Nr      Tr1   r&   r	   r'   r   r(   r)   r*   r   r   dtyper   r5   r   r   r   test_fancy_indexing_boundscheckK   s   


z6TestBoundsCheckNoError.test_fancy_indexing_boundscheckN)__name__
__module____qualname__r   run_test_in_subprocessr.   r8   r=   r   r   r   r   r      s    

r   c                   @   s6   e Zd Zee  dejddiddd Z	dS )TestNoCudaBoundsCheckzNO CUDAr    1r"   c                 C   s   |  tj | t tjdddd }W d    n1 s w   Y  tjdddd }tjdd	 }td
}t	d
}tj
sL|d || d S d S )NTr1   c                   S      d S Nr   r   r   r   r   funcl      z<TestNoCudaBoundsCheck.test_no_cuda_boundscheck.<locals>.funcFc                   S   rD   rE   r   r   r   r   r   func3r   rG   z=TestNoCudaBoundsCheck.test_no_cuda_boundscheck.<locals>.func3c                 S   s   | d |d< d S Nr   r   r   r   r   r   func2v   r   z=TestNoCudaBoundsCheck.test_no_cuda_boundscheck.<locals>.func2)r   )r   r   )
assertTruer	   r'   r)   NotImplementedErrorr   Zjitr   r4   ZzerosZENABLE_CUDASIM)r+   rF   rH   rJ   r   r   r   r   r   test_no_cuda_boundscheckg   s   





z.TestNoCudaBoundsCheck.test_no_cuda_boundscheckN)
r>   r?   r@   unittestZskipIfr   Zis_availabler   rA   rM   r   r   r   r   rB   f   s    rB   c                   @   sl   e Zd Zejddiddd Zejddiddd Zejddiddd	 Zejddidd
d ZdS )TestBoundsCheckErrorr    r!   r"   c                 C   s   |  tj td}| t t| W d    n1 sw   Y  t|}t	|fddt}| t || W d    d S 1 sFw   Y  d S )Nr$   Tr1   r%   )r+   r   r,   r2   r   r   r   r.      s   


"z1TestBoundsCheckError.test_basic_array_boundscheckc                 C   s   |  tj td}td}| t t| W d    n1 s$w   Y  t| t|}t	d d  }t
||ddt}| t || W d    d S 1 sVw   Y  d S r/   r3   r+   r   r6   r,   r7   r2   r   r   r   r8      s   



"z1TestBoundsCheckError.test_slice_array_boundscheckc                 C      |  tj td}td}| t t| W d    n1 s$w   Y  t| t|}|j	d d  }t
||ddt}| t || W d    d S 1 sWw   Y  d S r9   r;   rP   r   r   r   r=         



"z4TestBoundsCheckError.test_fancy_indexing_boundscheckc                 C   rQ   r9   )r&   r	   r'   r   r(   r)   r*   r   r   r<   r   rP   r   r   r   1test_fancy_indexing_with_modification_boundscheck   rR   zFTestBoundsCheckError.test_fancy_indexing_with_modification_boundscheckN)	r>   r?   r@   r   rA   r.   r8   r=   rS   r   r   r   r   rO      s    


rO   c                   @   s\   e Zd Zdd Zejddiddd Zejddidd	d
 Zejddiddd ZdS )TestBoundsEnvironmentVariablec                 C   sF   t dd }t dddd }t dddd	 }|| _|| _|| _d S )
Nc                 S   r
   rI   r   r   r   r   r   default      z4TestBoundsEnvironmentVariable.setUp.<locals>.defaultFr1   c                 S   r
   rI   r   rU   r   r   r   off   rW   z0TestBoundsEnvironmentVariable.setUp.<locals>.offTc                 S   r
   rI   r   rU   r   r   r   on   rW   z/TestBoundsEnvironmentVariable.setUp.<locals>.on)r   rV   rX   rY   )r+   rV   rX   rY   r   r   r   setUp   s   



z#TestBoundsEnvironmentVariable.setUpr    r!   r"   c                 C   sf   |  tj tdg}| | | | | t | 	| W d    d S 1 s,w   Y  d S rI   )
r&   r	   r'   r   r   rV   rX   r)   r*   rY   r+   r   r   r   r   test_boundscheck_unset   s   

"z4TestBoundsEnvironmentVariable.test_boundscheck_unsetrC   c                 C   sf   |  tj tdg}| t | | | | | 	| W d    d S 1 s,w   Y  d S rI   )
rK   r	   r'   r   r   r)   r*   rV   rX   rY   r[   r   r   r   test_boundscheck_enabled   s   

"z6TestBoundsEnvironmentVariable.test_boundscheck_enabled0c                 C   s:   |  tj tdg}| | | | | | d S rI   )ZassertFalser	   r'   r   r   rV   rX   rY   r[   r   r   r   test_boundscheck_disabled   s
   

z7TestBoundsEnvironmentVariable.test_boundscheck_disabledN)	r>   r?   r@   rZ   r   rA   r\   r]   r_   r   r   r   r   rT      s    


rT   __main__)numpyr   Znumba.cuda.testingr   Znumbar   r   r   Znumba.core.typesr   Znumba.tests.supportr   r   Z
numba.corer	   rN   r   r   r   r   r   rB   rO   rT   r>   mainr   r   r   r   <module>   s$    GQ6