o
    #j                     @   sp   d dl Z d dlZd dlmZ d dlmZ eeejddZG dd deZ	G dd	 d	Z
G d
d dZdd ZdS )    N)Enum)
get_loggerz&%(asctime)s-%(levelname)s: %(message)s)fmtc                   @   s   e Zd ZdZdZdS )FunctionTyper      N)__name__
__module____qualname__	FP16_ONLYCOMMON r   r   d/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/static/amp/function_overload.pyr      s    r   c                   @   s    e Zd ZdZdd Zdd ZdS )Functiona;  
    Function is a wrap over standard python function
    An instance of this Function class is also callable
    just like the python function that it wrapped.
    When the instance is "called" like a function it fetches
    the function to be invoked from the virtual namespace and then
    invokes the same.
    c                 C   s
   || _ d S Nfn)selfr   r   r   r   __init__,   s   
zFunction.__init__c                 O   s"   t  j|i |}||i |S )z]
        Overriding the __call__ function which makes the
        instance callable.
        )	Namespaceget_instanceget)r   argskwargsr   r   r   r   __call__/   s   zFunction.__call__N)r   r   r	   __doc__r   r   r   r   r   r   r   "   s    	r   c                   @   s8   e Zd ZdZdZdd Zedd Zdd Zd	d
 Z	dS )r   za
    Namespace is the singleton class that is responsible
    for holding all the functions.
    Nc                 C   s"   | j d u ri | _| t_ d S td)Nz#cannot instantiate Namespace again.)_Namespace__instancefunction_mapr   	Exception)r   r   r   r   r   C   s   

zNamespace.__init__c                   C   s   t jd u rt   t jS r   )r   r   r   r   r   r   r   J   s   
zNamespace.get_instancec                 C   s4   t |tsJ dt| dt|}|| j|< |S )a  
        Register the function in the virtual namespace and return
        an instance of callable Function that wraps the function fn.

        Args:
            fn (function): the native python function handle.
            key (FunctionType): the specified type.
        z>The type of  key is expected to be FunctionType, but recieved .)
isinstancer   typer   r   )r   r   keyfuncr   r   r   registerP   s   	
zNamespace.registerc              	   O   s:  t d| d|  t| j }t|t| }| j D ]V}||vr&q| j| }t|}t|t|t| k rNt d| d| d || qt|dkru|	 D ]\}}	||j
vrtt d| d| d ||  nqXqt|dkrt|d }
nt|dkrt|d	 trtj}
ntj}
| j|
S )
z
        Get the matching function from the virtual namespace according to the actual arguments.
        Return None if it did not find any matching function.
        zget function: args=z	, kwargs=zfn=z (key=z) is not satisfied and removed.r   r         )_loggerdebugsetr   keysleninspectgetfullargspecremoveitemsr   listr   floatr   r
   r   r   )r   r   r   Zsatisfied_function_keysZnum_actual_argsZfunc_keyr   specsZarg_namevaluer!   r   r   r   r   `   s<   




zNamespace.get)
r   r   r	   r   r   r   staticmethodr   r#   r   r   r   r   r   r   ;   s    
r   c                    s    fdd}|S )zjoverload is the decorator that wraps the function
    and returns a callable object of type Function.
    c                    s   t  |  S r   )r   r   r#   r   r!   r   r   	decorator   s   zoverload.<locals>.decoratorr   )r!   r5   r   r4   r   overload   s   r6   )r+   loggingenumr   Zpaddle.base.log_helperr   r   INFOr&   r   r   r   r6   r   r   r   r   <module>   s   K