a
    
d %                     @   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re   dS )    N)compile_isolatedDEFAULT_FLAGS)SerialMixin)typeofcudanjit)float64)MemoryLeakMixinoverride_env_config)configTc                 C   s   | d S N
    ar   r   e/var/www/html/stable-diffusion-webui/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                 C   s   t g d}d| |< | S )Nr   r   r   r   r   r   r   fancy_array_modify   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/   r0   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<0    Y  t| t|}|jd d  }tt|g|td}|j	}tt|g|t
d}|j	}|| || || d S Nr      r4   )r   r*   r+   r,   r   r   dtyper   r   r-   r7   r8   r   r   r   test_fancy_indexing_boundscheckT   s(    

&z6TestBoundsCheckNoError.test_fancy_indexing_boundscheckc                 C   s   | j t_d S r    r#   r   r"   r$   r   r   r   tearDownq   s    zTestBoundsCheckNoError.tearDownN)__name__
__module____qualname__r&   r1   r=   rA   rC   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&   v   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 s0    Y  d S )NTr<   c                   S   s   d S r    r   r   r   r   r   func}   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   r6   zerosr   ZENABLE_CUDASIM)r%   rI   rJ   rN   r   r   r   r   r   test_no_cuda_boundscheckz   s    
(




z.TestNoCudaBoundsCheck.test_no_cuda_boundscheckc                 C   s   | j t_d S r    rB   r$   r   r   r   rC      s    zTestNoCudaBoundsCheck.tearDownN)
rD   rE   rF   r&   unittestZskipIfr   Zis_availablerQ   rC   r   r   r   r   rG   u   s   
rG   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   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 s0    Y  d S r'   )	r   r*   r+   r,   r   r   r   r7   r-   )r%   r   r.   r;   r<   r   r   r   r1      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 s0    Y  d S r2   )
r   r6   r+   r,   r   r   r   r   r7   r-   r%   r   r9   r.   r:   r;   r<   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 s0    Y  d S r>   )
r   r*   r+   r,   r   r   r@   r   r7   r-   rT   r   r   r   rA      s    

&z4TestBoundsCheckError.test_fancy_indexing_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 s0    Y  d S r>   )
r   r*   r+   r,   r   r   r@   r   r7   r-   rT   r   r   r   1test_fancy_indexing_with_modification_boundscheck   s    

&zFTestBoundsCheckError.test_fancy_indexing_with_modification_boundscheckc                 C   s   | j t_d S r    rB   r$   r   r   r   rC      s    zTestBoundsCheckError.tearDownN)	rD   rE   rF   r&   r1   r=   rA   rU   rC   r   r   r   r   rS      s   rS   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 rM   r   r   r   r   r   default   s    z4TestBoundsEnvironmentVariable.setUp.<locals>.defaultFrH   c                 S   s   | d S rM   r   rW   r   r   r   off   s    z0TestBoundsEnvironmentVariable.setUp.<locals>.offTc                 S   s   | d S rM   r   rW   r   r   r   on   s    z/TestBoundsEnvironmentVariable.setUp.<locals>.on)r   r"   r#   r   rX   rY   rZ   )r%   rX   rY   rZ   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 )NrK    r   )r
   r   r   rX   rY   r+   r,   rZ   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 )NrK   rL   r   )r
   r   r   r+   r,   rX   rY   rZ   r\   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 )NrK   0r   )r
   r   r   rX   rY   rZ   r\   r   r   r   test_boundscheck_disabled  s
    

z7TestBoundsEnvironmentVariable.test_boundscheck_disabledc                 C   s   | j t_d S r    rB   r$   r   r   r   rC     s    z&TestBoundsEnvironmentVariable.tearDownN)rD   rE   rF   r&   r]   r^   r`   rC   r   r   r   r   rV      s
   		rV   __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   rR   copyr7   r<   r   r   r   r   ZTestCaser   rG   rS   rV   rD   mainr   r   r   r   <module>   s&   R$T6