o
    ®Ÿ?e}  ã                   @   sŽ   d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	l	mZ G d
d„ deƒZG dd„ dejƒZdd„ ZdS )zJConverts function definitions and lambdas by adding necessary boilerplate.é    N)Ú	converter)Úanno)Úparser)Ú
qual_names)Ú	templates)Úactivity)Úannosc                   @   s   e Zd Zdd„ ZdS )Ú	_Functionc                 C   s
   d | _ d S ©N)Úcontext_name)Úself© r   úq/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/autograph/converters/functions.pyÚ__init__   s   
z_Function.__init__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r	      s    r	   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚFunctionTransformerz<Wraps function bodies around autograph-specific boilerplate.c                 C   s"   |j dkr
| jjjS | jjj ¡ S )z9Returns the options with which to create function scopes.é   )ÚlevelÚctxÚuserÚoptionsZcall_options)r   Úfn_scoper   r   r   Ú_function_scope_options%   s   

z+FunctionTransformer._function_scope_optionsc              	   C   sÈ   | j t U}|  |¡}|jdkrtjd|dW  d   ƒ S t |tjj	¡}| j
j d|j¡}||_t |d|¡ d}tj||  |¡ ¡ |tj|d d|jd|_|W  d   ƒ S 1 s]w   Y  d S )	Nr   zag__.autograph_artifact(l))ÚlZlscopeÚfunction_context_namezt
        ag__.with_function_scope(
            lambda function_context: body, function_context_name, options)
      ©Úkind)r   Úfunction_contextr   Úbody)Ústater	   Úgeneric_visitr   r   Zreplace_as_expressionr   ÚgetannoZStaticZSCOPEr   ÚnamerÚ
new_symbolÚ
referencedr   Úsetannor   Úto_astÚgastÚConstantr    )r   Únoder   Úscoper   Útemplater   r   r   Úvisit_Lambda1   s.   

ÿû
ÿû$çz FunctionTransformer.visit_Lambdac           	   	   C   s,  | j t ‡}t |tjj¡}| jj 	d|j
¡}||_t |d|¡ |  |¡}|jdkr/g |_n	|j t d¡¡ d }|jrY|jd }t|tjƒrYt|jtjƒrY|}|jdd … |_d}tj|tj|jd dtj|d d|  |¡ ¡ ||jd	}|d ur€|g| }||_|W  d   ƒ S 1 sw   Y  d S )
NZfscoper   r   zag__.autograph_artifactr   é   z~
        with ag__.FunctionScope(
            function_name, context_name, options) as function_context:
          body
      r   )Zfunction_namer   r   r   r    )r!   r	   r   r#   r   ZNodeAnnoZ
BODY_SCOPEr   r$   r%   r&   r   r'   r"   r   Údecorator_listÚappendr   Zparse_expressionr    Ú
isinstancer)   ÚExprÚvaluer*   r   ÚreplaceÚnamer   r(   )	r   r+   r   r,   r   Zdocstring_nodeZfirst_statementr-   Zwrapped_bodyr   r   r   Úvisit_FunctionDefM   sF   
ÿ

ÿ
ÿú
$Ïz%FunctionTransformer.visit_FunctionDefN)r   r   r   Ú__doc__r   r.   r7   r   r   r   r   r   "   s
    r   c                 C   s&   t  | ¡} t | |d ¡} t|ƒ | ¡S r
   )r   Úresolver   r   Úvisit)r+   r   r   r   r   Ú	transform‚   s   
r;   )r8   r)   Z tensorflow.python.autograph.corer   Z tensorflow.python.autograph.pyctr   r   r   r   Z0tensorflow.python.autograph.pyct.static_analysisr   r   Úobjectr	   ZBaser   r;   r   r   r   r   Ú<module>   s   `