
    ёi                         S SK r S SKrS SKJr  S SKJr  \" \\R                  SS9r " S S\5      r	 " S S	5      r
 " S
 S5      rS rg)    N)Enum)
get_loggerz&%(asctime)s-%(levelname)s: %(message)s)fmtc                       \ rS rSrSrSrSrg)FunctionType   r       N)__name__
__module____qualname____firstlineno__	FP16_ONLYCOMMON__static_attributes__r
       c/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/static/amp/function_overload.pyr   r      s    IFr   r   c                   $    \ rS rSrSrS rS rSrg)Function"   a  
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                     Xl         g Nfn)selfr   s     r   __init__Function.__init__,   s    r   c                 Z    [         R                  5       R                  " U0 UD6nU" U0 UD6$ )zE
Overriding the __call__ function which makes the
instance callable.
)	Namespaceget_instanceget)r   argskwargsr   s       r   __call__Function.__call__/   s2     ##%))4:6:4"6""r   r   N)r   r   r   r   __doc__r   r$   r   r
   r   r   r   r   "   s    	#r   r   c                   >    \ rS rSrSrSrS r\S 5       rS r	S r
Srg)	r   ;   zU
Namespace is the singleton class that is responsible
for holding all the functions.
Nc                 X    U R                   c  0 U l        U [        l         g [        S5      e)Nz#cannot instantiate Namespace again.)_Namespace__instancefunction_mapr   	Exception)r   s    r   r   Namespace.__init__C   s(    ??" "D#'I ABBr   c                  X    [         R                  c
  [        5         [         R                  $ r   )r   r*   r
   r   r   r    Namespace.get_instanceJ   s    'K###r   c                     [        U[        5      (       d   S[        U5       S35       e[        U5      nXR                  U'   U$ )z
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   registerNamespace.registerP   sN     #|,, 	
LTRUYKWXY	
, |!##r   c           	         [         R                  SU SU 35        [        U R                  R	                  5       5      n[        U5      [        U5      -   nU R                  R	                  5        H  nXS;  a  M
  U R                  U   n[        R                  " U5      n[        U5      [        U5      [        U5      -   :  a/  [         R                  SU SU S35        UR                  U5        M  [        U5      S:  d  M  UR                  5        HD  u  pXR                  ;  d  M  [         R                  SU SU S35        UR                  U5          M     M     [        U5      S:X  a  [        [        U5      5      n
OH[        U5      S:  a)  [        US	   [        5      (       a  [        R                   n
O[        R"                  n
U R                  R%                  U
5      $ )
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iterr2   floatr   r   r   r!   )r   r"   r#   satisfied_function_keysnum_actual_argsfunc_keyr   specsarg_namevaluer4   s              r   r!   Namespace.get`   s   
 	+D66(CD"%d&7&7&<&<&>"?d)c&k1))..0H6""8,B**2.E5zCIF33"VH:-LM (..x86{Q'-||~OHzz1!"VH:5TU 066x@ (6 1* &'1,t345CY!^
47E : :((C%%C  $$S))r   )r+   )r   r   r   r   r&   r*   r   staticmethodr    r6   r!   r   r
   r   r   r   r   ;   s2    
 JC $ $
 #*r   r   c                    ^  U 4S jnU$ )zboverload is the decorator that wraps the function
and returns a callable object of type Function.
c                 L   > [         R                  5       R                  U T5      $ r   )r   r    r6   )r   r4   s    r   	decoratoroverload.<locals>.decorator   s    %%'00S99r   r
   )r4   rQ   s   ` r   overloadrS      s    
: r   )r@   loggingenumr   paddle.base.log_helperr   r   INFOr;   r   r   r   rS   r
   r   r   <module>rX      sQ   $    -
gll H
4 
# #2H* H*Vr   