o
    i %                     @   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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 dS )    N)compile_isolatedDEFAULT_FLAGS)SerialMixin)typeofcudanjit)float64)MemoryLeakMixinoverride_env_config)configTc                 C      | d S N
    ar   r   k/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/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                   @   4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestBoundsCheckNoErrorc                 C      t j| _d t _d S Nr   BOUNDSCHECKold_boundscheckselfr   r   r   setUp$      
zTestBoundsCheckNoError.setUpc                 C   sf   t d}| t t| W d    n1 sw   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w   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   onesr0   r1   r   r   r   r   r   r2   BOUNDSCHECK_FLAGS	r)   r   br3   rtr4   r5   c_boundscheckboundscheckr   r   r   test_slice_array_boundscheck8   s*   


z3TestBoundsCheckNoError.test_slice_array_boundscheckc           	      C   s   t d}t d}| t t| W d    n1 sw   Y  t| t|}|jd d  }tt|g|td}|j	}tt|g|t
d}|j	}|| || || d S Nr      r9   )r   r/   r0   r1   r   r   dtyper   r   r2   r<   r=   r   r   r   test_fancy_indexing_boundscheckT   s*   


z6TestBoundsCheckNoError.test_fancy_indexing_boundscheckc                 C      | j t_d S r$   r'   r   r&   r(   r   r   r   tearDownq      zTestBoundsCheckNoError.tearDownN)__name__
__module____qualname__r*   r6   rB   rF   rI   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   r#   r$   r%   r(   r   r   r   r*   v   r+   zTestNoCudaBoundsCheck.setUpzNO CUDAc                 C   s   |  t tjdddd }W d    n1 sw   Y  tjdddd }tdd	, tjd
d }td}td}tj	sR|d || W d    d S W d    d S 1 s]w   Y  d S )NTrA   c                   S      d S r$   r   r   r   r   r   func}      z<TestNoCudaBoundsCheck.test_no_cuda_boundscheck.<locals>.funcFc                   S   rP   r$   r   r   r   r   r   func3   rR   z=TestNoCudaBoundsCheck.test_no_cuda_boundscheck.<locals>.func3NUMBA_BOUNDSCHECK1c                 S   s   | d |d< d S Nr   r   r   r   r   r   func2   r   z=TestNoCudaBoundsCheck.test_no_cuda_boundscheck.<locals>.func2)r   )r   r   )
r0   NotImplementedErrorr   Zjitr
   r   r;   Zzerosr   ZENABLE_CUDASIM)r)   rQ   rS   rW   r   r   r   r   r   test_no_cuda_boundscheckz   s    





	"z.TestNoCudaBoundsCheck.test_no_cuda_boundscheckc                 C   rG   r$   rH   r(   r   r   r   rI      rJ   zTestNoCudaBoundsCheck.tearDownN)
rK   rL   rM   r*   unittestZskipIfr   Zis_availablerY   rI   r   r   r   r   rN   u   s
    
rN   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestBoundsCheckErrorc                 C   r#   r$   r%   r(   r   r   r   r*      r+   zTestBoundsCheckError.setUpc                 C   s   t d}| t t| W d    n1 sw   Y  t|}tt|gtd}|j}| t || W d    d S 1 sBw   Y  d S r,   )	r   r/   r0   r1   r   r   r   r<   r2   )r)   r   r3   r@   rA   r   r   r   r6      s   


"z1TestBoundsCheckError.test_basic_array_boundscheckc                 C   s   t d}t d}| t t| W d    n1 sw   Y  t| t|}td d  }tt|g|td}|j	}| t || W d    d S 1 sRw   Y  d S r7   )
r   r;   r0   r1   r   r   r   r   r<   r2   r)   r   r>   r3   r?   r@   rA   r   r   r   rB      s    



"z1TestBoundsCheckError.test_slice_array_boundscheckc                 C      t d}t d}| t t| W d    n1 sw   Y  t| t|}|jd d  }tt|g|td}|j	}| t || W d    d S 1 sSw   Y  d S rC   )
r   r/   r0   r1   r   r   rE   r   r<   r2   r\   r   r   r   rF          



"z4TestBoundsCheckError.test_fancy_indexing_boundscheckc                 C   r]   rC   )
r   r/   r0   r1   r    r   rE   r   r<   r2   r\   r   r   r   1test_fancy_indexing_with_modification_boundscheck   r^   zFTestBoundsCheckError.test_fancy_indexing_with_modification_boundscheckc                 C   rG   r$   rH   r(   r   r   r   rI      rJ   zTestBoundsCheckError.tearDownN)	rK   rL   rM   r*   r6   rB   rF   r_   rI   r   r   r   r   r[      s    r[   c                   @   r!   )TestBoundsEnvironmentVariablec                 C   sT   t j| _d t _tdd }tdddd }tdddd	 }|| _|| _|| _d S )
Nc                 S   r   rV   r   r   r   r   r   default      z4TestBoundsEnvironmentVariable.setUp.<locals>.defaultFrO   c                 S   r   rV   r   ra   r   r   r   off   rc   z0TestBoundsEnvironmentVariable.setUp.<locals>.offTc                 S   r   rV   r   ra   r   r   r   on   rc   z/TestBoundsEnvironmentVariable.setUp.<locals>.on)r   r&   r'   r   rb   rd   re   )r)   rb   rd   re   r   r   r   r*      s   



z#TestBoundsEnvironmentVariable.setUpc              	   C   s   t dd; tdg}| | | | | t | | W d    n1 s+w   Y  W d    d S W d    d S 1 sCw   Y  d S )NrT    r   )r
   r   r   rb   rd   r0   r1   re   r)   r   r   r   r   test_boundscheck_unset  s   

"z4TestBoundsEnvironmentVariable.test_boundscheck_unsetc              	   C   s   t dd; tdg}| t | | | | | | W d    n1 s+w   Y  W d    d S W d    d S 1 sCw   Y  d S )NrT   rU   r   )r
   r   r   r0   r1   rb   rd   re   rg   r   r   r   test_boundscheck_enabled  s   

"z6TestBoundsEnvironmentVariable.test_boundscheck_enabledc                 C   sZ   t dd tdg}| | | | | | W d    d S 1 s&w   Y  d S )NrT   0r   )r
   r   r   rb   rd   re   rg   r   r   r   test_boundscheck_disabled  s   

"z7TestBoundsEnvironmentVariable.test_boundscheck_disabledc                 C   rG   r$   rH   r(   r   r   r   rI     rJ   z&TestBoundsEnvironmentVariable.tearDownN)rK   rL   rM   r*   rh   ri   rk   rI   r   r   r   r   r`      s    		r`   __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   rZ   copyr<   rA   r   r   r   r    ZTestCaser"   rN   r[   r`   rK   mainr   r   r   r   <module>   s*    R$T6