a
    
d(                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	Z	d dl
mZmZ d dlmZ ejdd ZG dd dee	jZdS )	    N)StringIO)SerialMixincreate_temp_module)
dispatcherc              	   c   s@   z.t  }t|}| | |V  W | | n| | 0 d S N)r   loggingStreamHandler
addHandlerremoveHandler)lbufferhandler r   d/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/numba/tests/test_jit_module.pycaptured_logs   s    

r   c                   @   sH   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d Z
dS )TestJitModulez
from numba import jit_module

def inc(x):
    return x + 1

def add(x, y):
    return x + y

def inc_add(x):
    y = inc(x)
    return add(x, y)

import numpy as np
mean = np.mean

class Foo(object):
    pass

jit_module({jit_options})
c                 C   s   t tj}ttj}t| jX}tj|j	}| 
|tjd  | 
tjdd  | | |jtjv  W d    n1 s|0    Y  | 
tj| | 
tj| d S )Nr      )listsyspathdictmodulesr   source_linesosdirname__file__assertEqual
assertTrue__name__)selfsys_path_originalsys_modules_originaltest_moduleZtemp_module_dirr   r   r   test_create_temp_jitted_module1   s    

0z,TestJitModule.test_create_temp_jitted_modulec                 C   s~   zJt tj}ttj}t| j tdW d    n1 s>0    Y  W n. tyx   | tj| | tj| Y n0 d S )NzSomething went wrong!)	r   r   r   r   r   r   r   
ValueErrorr   )r   r    r!   r   r   r   -test_create_temp_jitted_module_with_exception=   s    

*z;TestJitModule.test_create_temp_jitted_module_with_exceptionc                 C   s   t | j}| |jtj | |jtj | |jtj | |j	t
j	u  | t|j d\}}| |||j| | ||||j|| | |||j| W d    n1 s0    Y  d S )N)g333333?gffffff@)r   r   ZassertIsInstanceincr   Z
DispatcheraddZinc_addr   meannpinspectisclassZFoor   Zpy_func)r   r"   xyr   r   r   test_jit_moduleH   s     

zTestJitModule.test_jit_modulec                 C   sT   ddddd}t | jfi | }| |jj| W d    n1 sF0    Y  d S )NTFnumpy)nopythonnogilerror_modelboundscheck)r   r   r   r&   targetoptions)r   jit_optionsr"   r   r   r   test_jit_module_jit_optionsY   s    
z)TestJitModule.test_jit_module_jit_optionsc                 C   sn   d}dddd}t f d|i|8}| |jj| | |jjddd d W d    n1 s`0    Y  d S )Nz
from numba import jit, jit_module

@jit(nogil=True, forceobj=True)
def inc(x):
    return x + 1

def add(x, y):
    return x + y

jit_module({jit_options})
Tr/   F)r0   r2   r3   r   )r1   Zforceobjr3   )r   r   r'   r4   r&   )r   r   r5   r"   r   r   r   $test_jit_module_jit_options_overridec   s    

z2TestJitModule.test_jit_module_jit_options_overridec              	      s   t d}|t j ddd}t|~ t| jfi |L}   dd|j	d|g}| 
t fdd	|D  W d    n1 s0    Y  W d    n1 s0    Y  d S )
Nnumba.core.decoratorsTr/   )r0   r2   zAuto decorating functionzfrom module {}zwith jit and options: {}c                 3   s   | ]}| v V  qd S r   r   ).0ilogsr   r   	<genexpr>       z?TestJitModule.test_jit_module_logging_output.<locals>.<genexpr>)r   	getLoggersetLevelDEBUGr   r   r   getvalueformatr   r   all)r   loggerr5   r"   expectedr   r;   r   test_jit_module_logging_output|   s     



z,TestJitModule.test_jit_module_logging_outputc              	   C   s|   t d}|t j t|J}t| j  | | d W d    n1 sP0    Y  W d    n1 sn0    Y  d S )Nr8    )	r   r?   r@   INFOr   r   r   r   rB   )r   rE   r<   r   r   r   test_jit_module_logging_level   s
    

z+TestJitModule.test_jit_module_logging_levelN)r   
__module____qualname__r   r#   r%   r.   r6   r7   rG   rJ   r   r   r   r   r      s   
r   )r   r   r*   
contextlibr/   r)   r   ior   ZunittestZnumba.tests.supportr   r   Z
numba.corer   contextmanagerr   ZTestCaser   r   r   r   r   <module>   s   

