o
    MeN
  ã                   @   sd   d Z ddlmZ ddlZddlZe ¡ Zg d¢Zdd„ Z	dd„ Z
d	d
„ Zdd„ Zdd„ Zdd„ ZdS )aÎ  
Default scope function.

`Paddle` manages Scope as programming language's scope.  It just a
thread-local stack of Scope. Top of that stack is current scope, the bottom
of that stack is all scopes' parent.

Invoking `var/find_var`  can `new/find` variable in current scope.
Invoking `enter_local_scope/leave_local_scope` can create or destroy local
scope.

A `scoped_function` will take a `function` as input. That function will be
invoked in a new local scope.
é    )Úprint_functionN)Úget_cur_scopeÚenter_local_scopeÚleave_local_scopeÚvarÚfind_varÚscoped_functionc                  C   sH   t tddƒ} | du rtƒ t_ttjƒdkrtj tjj 	¡ ¡ tjd S )z@
    Get current scope.
    :rtype: paddle.fluid.core.Scope
    Ú	cur_scopeNr   éÿÿÿÿ)
ÚgetattrÚ__tl_scope__Úlistr	   ÚlenÚappendÚpaddleZfluidÚcoreZScope)Zcur_scope_stack© r   úPD:\Projects\ConvertPro\env\Lib\site-packages\paddle/fluid/default_scope_funcs.pyr   .   s   
r   c                  C   s   t ƒ } |  ¡ }tj |¡ dS )z!
    Enter a new local scope
    N)r   Ú	new_scoper   r	   r   )r	   r   r   r   r   r   ;   s   r   c                   C   s   t j ¡  tƒ  ¡  dS )z
    Leave local scope
    N)r   r	   Úpopr   Z	drop_kidsr   r   r   r   r   D   s   
r   c                 C   ó   t ƒ  | ¡S )z+
    create variable in current scope.
    )r   r   ©Únamer   r   r   r   L   ó   r   c                 C   r   )z(
    get variable in current scope.
    )r   r   r   r   r   r   r   S   r   r   c                 C   s0   t ƒ  zz| ƒ  W n   ‚ W tƒ  dS tƒ  w )zƒ
    invoke `func` in new scope.

    :param func: a callable function that will be run in new scope.
    :type func: callable
    N)r   r   )Úfuncr   r   r   r   Z   s   
þr   )Ú__doc__Ú
__future__r   Zpaddle.fluid.corer   Ú	threadingÚlocalr   Ú__all__r   r   r   r   r   r   r   r   r   r   Ú<module>   s   
	