U
    ‰dC  ã                   @   s¼   U d Z ddlZddlZddlZG dd„ dƒZeƒ Zdd„ Zdd„ Zej 	¡ Z
i Zi Zd	d
„ Zdd„ Zdd„ Zdd„ Ze ¡ Zejed< e ¡ Zejed< dd„ Zdd„ Zdd„ Zdd„ ZdS )zÃJIT-related state

This module stores various pieces of Python-global state relating to the JIT.

This is not intended to be imported directly; please the exposed
functionalities in `torch.jit`.
é    Nc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚEnabledProxyzyStores whether the JIT is enabled or not.

    This is just a wrapper for a bool, so that we get reference semantics
    c                 C   s   |   dddd¡| _d S )NZPYTORCH_JITTz> Using PyTorch JITz> PyTorch JIT DISABLED)Ú	parse_envÚenabled©Úself© r   ú4/tmp/pip-unpacked-wheel-ua33x9lu/torch/jit/_state.pyÚ__init__   s       ÿzEnabledProxy.__init__c                 C   sr   t j |¡}|d kr|S | ¡ dkr(dS | ¡ dkr8dS |dkrLt|ƒ dS |dkr`t|ƒ dS td |¡ƒ‚d S )N>   ÚyesÚ1ÚtrueT>   ÚfalseÚ0ÚnoFZ1vZ0vz(Unknown setting of {}. Try using 0 or 1.)ÚosÚenvironÚgetÚlowerÚprintÚ
ValueErrorÚformat)r   ÚnameÚdefaultZtrue_messageZfalse_messageÚvaluer   r   r   r      s    zEnabledProxy.parse_envc                 C   s   | j S ©N)r   r   r   r   r   Ú__bool__'   s    zEnabledProxy.__bool__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r   r   r      s   r   c                   C   s
   dt _d S )NF©Ú_enabledr   r   r   r   r   Údisable.   s    r"   c                   C   s
   dt _d S )NTr    r   r   r   r   Úenable2   s    r#   c                 C   s   |t | < | t| ¡ < d S r   )Ú_script_classesÚ_name_to_pyclassÚqualified_name)Úpython_classZscript_classr   r   r   Ú_add_script_classA   s    r(   c                 C   s(   t | dd ƒ}|d k	rt|ƒ} t | d ¡S )NZ_jit_override_qualname)ÚgetattrÚ_get_python_classr$   r   )r'   Úoverrider   r   r   Ú_get_script_classF   s    r,   c                 C   s   t  | d ¡S r   )r%   r   ©r&   r   r   r   r*   M   s    r*   c                   C   s   t  ¡  t ¡  d S r   )r$   Úclearr%   r   r   r   r   Ú_clear_class_stateQ   s    r/   Ú_jit_caching_layerÚ_jit_function_overload_cachingc                 C   s&   t  | d ¡}|rdd„ |D ƒS d S d S )Nc                 S   s   g | ]}t  |¡‘qS r   )Ú
_python_cuÚfind_function)Ú.0Ú	qual_namer   r   r   Ú
<listcomp>d   s     z1_try_get_jit_cached_overloads.<locals>.<listcomp>)r1   r   )ÚkeyZ
qual_namesr   r   r   Ú_try_get_jit_cached_overloadsa   s    r8   c                 C   s   dd„ |D ƒt | < d S )Nc                 S   s   g | ]
}|j ‘qS r   r-   )r4   Úfnr   r   r   r6   i   s     z+_set_jit_overload_cache.<locals>.<listcomp>)r1   )r7   Zcompiled_fnsr   r   r   Ú_set_jit_overload_cacheh   s    r:   c                 C   s6   t | ddƒdkrd S t | d ¡}|r.t |¡S d S d S )NZ __disable_jit_function_caching__FT)r)   r0   r   r2   r3   )r7   r5   r   r   r   Ú_try_get_jit_cached_functionk   s    
r;   c                 C   s    t |tjjƒst‚|jt| < d S r   )Ú
isinstanceÚtorchZjitZScriptFunctionÚAssertionErrorr&   r0   )r7   r   r   r   r   Ú_set_jit_function_cachet   s    r?   )r   r=   r   Úweakrefr   r!   r"   r#   Z_CZCompilationUnitr2   r$   r%   r(   r,   r*   r/   ÚWeakKeyDictionaryr0   Ú__annotations__r1   r8   r:   r;   r?   r   r   r   r   Ú<module>   s(   
	