
    {-j                         d dl Z d dlZd dlmZ d dlmZ  eeej        d          Z G d de          Z	 G d d	          Z
 G d
 d          Zd ZdS )    N)Enum)
get_loggerz&%(asctime)s-%(levelname)s: %(message)s)fmtc                       e Zd ZdZdZdS )FunctionTyper      N)__name__
__module____qualname__	FP16_ONLYCOMMON     c/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/static/amp/function_overload.pyr   r      s        IFFFr   r   c                       e Zd ZdZd Z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                     || _         d S N)fn)selfr   s     r   __init__zFunction.__init__,   s    r   c                 X    t                                          j        |i |} ||i |S )z]
        Overriding the __call__ function which makes the
        instance callable.
        )	Namespaceget_instanceget)r   argskwargsr   s       r   __call__zFunction.__call__/   s:     ##%%)4:6::r4"6"""r   N)r	   r
   r   __doc__r   r   r   r   r   r   r   "   s<           	# 	# 	# 	# 	#r   r   c                   >    e Zd ZdZdZd Zed             Zd Zd Z	dS )r   za
    Namespace is the singleton class that is responsible
    for holding all the functions.
    Nc                 X    | j         i | _        | t          _         d S t          d          )Nz#cannot instantiate Namespace again.)_Namespace__instancefunction_mapr   	Exception)r   s    r   r   zNamespace.__init__C   s/    ?" "D#'I   ABBBr   c                  N    t           j        t                       t           j        S r   )r   r"   r   r   r   r   zNamespace.get_instanceJ   s    'KKK##r   c                     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 received .)
isinstancer   typer   r#   )r   r   keyfuncs       r   registerzNamespace.registerP   s\     #|,, 	
 	
YTRUYYYYY	
 	
, ||!##r   c           	         t                               d| d|            t          | j                                                  }t          |          t          |          z   }| j                                        D ]}||vr| j        |         }t          j        |          }t          |          t          |          t          |          z   k     r7t                               d| d| d           |                    |           t          |          dk    r[|	                                D ]F\  }}	||j
        vr8t                               d| d| d           |                    |            nGt          |          dk    rt          t          |                    }
nGt          |          dk    r(t          |d	         t                    rt          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   nextiterr(   floatr   r   r   r   )r   r   r   satisfied_function_keysnum_actual_argsfunc_keyr   specsarg_namevaluer*   s              r   r   zNamespace.get`   s   
 	CDCC6CCDDD"%d&7&<&<&>&>"?"?d))c&kk1)..00 	 	H666"8,B*2..E5zzCIIF333M"MMHMMM   (..x8886{{Q'-||~~  OHeuz11U"UUHUUU   066x@@@ 2 &''1,,t34455CCYY!^^
47E : :^(CC%C $$S)))r   )
r	   r
   r   r   r"   r   staticmethodr   r,   r   r   r   r   r   r   ;   sp         
 JC C C $ $ \$
   #* #* #* #* #*r   r   c                       fd}|S )zjoverload is the decorator that wraps the function
    and returns a callable object of type Function.
    c                 ^    t                                                               |           S r   )r   r   r,   )r   r*   s    r   	decoratorzoverload.<locals>.decorator   s%    %%''00S999r   r   )r*   rE   s   ` r   overloadrF      s$    
: : : : : r   )r5   loggingenumr   paddle.base.log_helperr   r	   INFOr0   r   r   r   rF   r   r   r   <module>rK      s   $         - - - - - -
*gl H  
    4   
# # # # # # # #2H* H* H* H* H* H* H* H*V    r   