
    x-jM-                       d dl mZ 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Zd dl	Z	d dl
mZmZmZ d dlZd dlmZ ddlmZmZmZmZmZ ddlmZ ddlmZmZmZ dd	lmZmZm Z m!Z! erd d
l"m#Z# g Z$ e            Z%d Z& e&            a'ddZ(ej)        dd            Z*ej)        dd            Z+d Z, G d d          Z-d Z.dS )    )annotationsN)TYPE_CHECKINGAnyCallable)Layer   )convert_enumerateconvert_lenconvert_printconvert_rangeconvert_zip)TranslatorLogger)StaticFunctionconvert_to_staticunwrap_decorators)TransformOptions
is_builtinis_paddle_funcpatch_method_guard)
ModuleTypec                     t           t          t          t          t          t
          t          t          g} 	 ddl}| 	                    |           n# t          $ r Y nw xY w| S )z!
    Return builtin modules.
    r   N)copycollectionsinspectloggingnumpyospdbresixappendImportError)modulesr    s     f/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/jit/dy2static/convert_call_func.pybuiltin_modulesr%   <   sm    
 	

	G


s    Ns   A 
AAr#   list[ModuleType]c                V    | D ]%}|t           vrt                               |           &dS )z0
    Adds modules that ignore transcription
    N)BUILTIN_LIKELY_MODULESr!   )r#   modules     r$   add_ignore_moduler*   W   s>    
  2 2///"))&1112 2    r)   r   returnlist[Callable[..., Any]]c                P    t                      ddfd |           S )Nr,   list[tuple[str, Any]]c                P    	 t          j        |           S # t          $ r g cY S w xY wN)r   
getmembers	Exception)r)   s    r$   _try_get_membersz.get_module_functions.<locals>._try_get_memberse   s<    	%f--- 	 	 	III	s    %%c                   | v rg S                      |            g } |           D ][\  }}t          |          r|                    |           t          j        |          r|                     |                     \|S r1   )addcallabler!   r   ismoduleextend)r)   results_member_namemember_get_module_functionsr4   visiteds       r$   r=   z3get_module_functions.<locals>._get_module_functionsk   s    WIF$4$4V$<$< 	> 	> L& 'v&&&'' >44V<<===r+   )r,   r/   )set)r)   r=   r4   r>   s    @@@r$   get_module_functionsr@   a   sX    eeG   
 
 
 
 
 
 
 ! (((r+   
str | Nonec                \    dd}t          | d          r| j        d S  || j                  S )N	file_pathstrr,   c                .    t          j        dd|           S )Nz__init__.py$ )r   sub)rC   s    r$   _remove_module_init_suffixz<get_module_defining_path.<locals>._remove_module_init_suffix|   s    vor9555r+   __file__)rC   rD   r,   rD   )hasattrrI   )r)   rH   s     r$   get_module_defining_pathrK   z   sI    6 6 6 6 6:&& &/*At%%fo666r+   c                   fdt           D             }t          | d          rQ| j        j        rE| j        j        t	          fd|D                       rt
                              dd|            dS d t           D             }|D ]%}| |u rt
                              dd|             dS &t          |           rt
                              dd|            dS d	S )
zJ
    Checks whether the func is supported by dygraph to static graph.
    c                6    g | ]}t          |          xS r1   )rK   ).0r)   module_paths     r$   
<listcomp>z"is_unsupported.<locals>.<listcomp>   s6       3F;;;KH 	HHHr+   __code__c              3  B   K   | ]}                     |          V  d S r1   )
startswith)rN   rO   	func_paths     r$   	<genexpr>z!is_unsupported.<locals>.<genexpr>   sE       
 
   --
 
 
 
 
 
r+      zMWhitelist: %s is part of built-in module and does not have to be transformed.Tc                6    g | ]}t          |          D ]}|S  )r@   )rN   r)   funcs      r$   rP   z"is_unsupported.<locals>.<listcomp>   sG       (00   	   r+   zKWhitelist: %s is part of Paddle module and does not have to be transformed.F)r(   rJ   rQ   co_filenameanytranslator_loggerlogr   )rY   builtin_module_pathsbuiltin_functions
builtin_fnrT   rO   s       @@r$   is_unsupportedra      sb   
   ,   tZ   T]%> M-	 
 
 
 
3
 
 
 
 
 		 !!_  
 4 ,   (  
:!!_  
 44  d Y	
 	
 	

 t5r+   c                      e Zd Zd Zd ZdS )StaticLayerWrapperc                    || _         d S r1   )layer)selfre   s     r$   __init__zStaticLayerWrapper.__init__   s    


r+   c                    t          | j        dt          | j        j                            5   | j        |i |cd d d            S # 1 swxY w Y   d S )Nforward)r   re   convert_callri   )rf   argskwargss      r$   __call__zStaticLayerWrapper.__call__   s    J	<
0B#C#C
 
 	/ 	/ 4:t.v..	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   AAAN)__name__
__module____qualname__rg   rm   rX   r+   r$   rc   rc      s2          / / / / /r+   rc   c                   t                               dd|            d}d}t          |           \  }} t          j        | t          j        j                  st                               dd|            | S t          | d          rt          S t          | d          rt          S t          | d          rt          S t          | d	          rt          S t          | d
          rt          S t          |           st          |           r| S t          j        |           r<d}t                               dd|z  z   d| j         dz   dz   d|z  z   dz              | S t          j        |           rs| j        dk    r| S 	 t          j        |           }t)                      }|j                                        D ]}t          j        |          r|                    |           ,t1          |t2                    r(t          |          \  }}|                    |           it          j        |          rHt1          |j                            | j        d          t:                    r|                    |            | |v r!t=          |           }t?          | dd          }nt                               d|            | }n# t@          $ r d}Y n tB          $ r d}Y nw xY wt          j"        |           r4	 t=          |           }t?          | dd          }n# tB          $ r d}Y nw xY wtG          | d          rtI          | j%                  rptG          | d          r$t1          | tL                    rtO          |           S 	 | j%        j(        }t=          |          }| }n0# tB          tR          f$ r	 |rdn|}Y nw xY wtU          d|  d          |t                               d|            | S |tW          j,        ||          }|S )a9  
    Converts a function call which needs to be transformed to static function.

    Args:
        func (callable): A callable function or method to convert.

    Returns:
        Callable: A converted function.

    Examples:
        .. code-block:: python

            >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest')
            >>> import paddle
            >>> from paddle.jit.dy2static import Call

            >>> paddle.enable_static()
            >>> def dyfunc(x):
            ...     if paddle.mean(x) < 0:
            ...         x_v = x - 1
            ...     else:
            ...         x_v = x + 1
            ...     return x_v
            ...
            >>> new_func = Call(dyfunc)
            >>> x = paddle.tensor.manipulation.fill_constant(shape=[3, 3], value=0, dtype='float64')
            >>> x_v = new_func(x)

            >>> exe = paddle.static.Executor(paddle.CPUPlace())
            >>> out = exe.run(fetch_list=[x_v])
            >>> print(out[0])
            [[1. 1. 1.]
             [1. 1. 1.]
             [1. 1. 1.]]

    r   z$Convert callable object: convert %s.NrV   zG%s is not converted when it is decorated by 'paddle.jit.not_to_static'.lenziprange	enumerateprint   z

*z
Your function:`zk` doesn't support to transform to static function because it is a generator function, it will be run as-is.
z<lambda>__self__zr%s doesn't have to be transformed to static function because it has been transformed before, it will be run as-is.	__class__ri   z	Callable z# can not be transformed at present.zO%s doesn't have to be transformed to static function, and it will be run as-is.)-r\   r]   r   r   check_fn_need_transformToStaticModeASTr   r
   r   r   r	   r   ra   r   isgeneratorfunctionwarnrn   
isfunctionunwrapr?   __globals__valuesr6   
isinstancer   isclass__dict__getstaticmethodr   getattrAttributeErrorOSErrorismethodrJ   r7   r{   r   rc   rm   	TypeErrorNotImplementedError	functoolspartial)	rY   	func_selfconverted_call_number_of_stars	_origfuncglobal_functionsfn	call_funcs	            r$   rj   rj      s   J !CTJJJIN  %%GAt3+/   	U	
 	
 	

 $ $ $   $$$ !  $   $ >$// "4((  O#$ ]$-  ]  ]  ]]  O#	$
 	
 	
 	
 $ O
=J&&K2	"  t,,I"uu+2244  %b)) $((,,,,N33 	-b11EAr$((,,,,_R(( !t<<l   ),,    '''!24!8!8#D*d;;		
 "&& I   "& 	" 	" 	" "NNN 	" 	" 	" "NNN		"
 
	$		 
	".t44Nj$77II 	" 	" 	"!NNN	" 
{	#	# 
(@(@ 
4## 	=
4(?(? 	=%d+++= N3	!29!=!= 		Y' = = = %.<DD9				= "AAAA
 
 	
 ]	
 	
 	
 "*>9EEs=   ;EK   KKK5 L L%$L%N N98N9)r#   r&   )r)   r   r,   r-   )r)   r   r,   rA   )/
__future__r   r   r   r   r   r   r   r   r   typingr   r   r   r   	paddle.nnr   convert_operatorsr	   r
   r   r   r   logging_utilsr   program_translatorr   r   r   utilsr   r   r   r   typesr   __all__r\   r%   r(   r*   	lru_cacher@   rK   ra   rc   rj   rX   r+   r$   <module>r      sk   # " " " " "            				 



 				 / / / / / / / / / /                     , + + + + +         
             !      
 %$&&   0 )** 2 2 2 2 ) ) ) )0 7 7 7 71 1 1h/ / / / / / / /r r r r rr+   