o
    "j`                     @   s   d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZ ddlmZ ddlmZ d	d
 ZdZdZdZdd Zdd Zdd Zdd Zdd ZG dd dZdd ZdS )    N)base)dygraphlayers)to_variable)gast   )ast_to_source_code)warnc                 C   s"   z|  |W S  ty   Y dS w )N)index
ValueError)Z
array_listitem r   b/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/jit/dy2static/utils_helper.pyindex_in_list   s
   r   zpaddle.zpaddle.jit.dy2staticzpaddle.base.dygraphc                 C   s   t | trdS t | tS )NF)is_api_in_moduleDYGRAPH_TO_STATIC_MODULE_PREFIXDYGRAPH_MODULE_PREFIXnoder   r   r   is_dygraph_api.   s   

r   c                 C   s   t | tjs
J d| j}t |tjr|j}t |tjstt| }zdd lm	  m
} ddlm} td| d| dW S  tyK   Y dS w )Nz&Input non-Call node for is_dygraph_apir   )	to_tensorz_is_api_in_module_helper(z, 'z')F)
isinstancer   Callfuncastor	to_sourcegast_to_aststripZpaddle.jit.dy2staticZjitZ	dy2staticpaddler   eval	Exception)r   module_prefixZ	func_nodefunc_strZ_jstr   r   r   r   r   8   s   r   c                 C   s   t | }|d uo|j|S N)inspect	getmodule__name__
startswith)objr"   mr   r   r   _is_api_in_module_helperK   s   
r+   c                 C   sf   t | tjs
J dtt| j}ztd|d}|p'|	dp'|	dW S  t
y2   Y dS w )Nz$Input non-Call node for is_numpy_apiz"_is_api_in_module_helper({}, '{}')numpyznumpy.znp.F)r   r   r   r   r   r   r   r    formatr(   r!   )r   r#   Zmodule_resultr   r   r   is_numpy_apiQ   s   
r.   c                 C   s
   t | tS r$   )r   PADDLE_MODULE_PREFIXr   r   r   r   is_paddle_apia   s   
r0   c                   @   s   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZeehZeee
ee	edZedd Zedd ZdS )NodeVarTypea  
    Enum class of python variable types. We have to know some variable types
    during compile time to transfer AST. For example, a string variable and a
    tensor variable in if clause may lead to different conversion from dygraph
    to static graph.
    r
   r   r      d   e   f   g   h   i   j            i,  i-  i.  i/  i0  )ZTensorzpaddle.Tensorintfloatboolstrc                 C   s   | |kr| S | t jkr|S |t jkr| S t jt jt jt jt jt jg}| |vr)t jS ||vr0t jS t jt jg}| |v rA||v rAt jS t| |S r$   )	r1   UNKNOWNBOOLEANINTFLOATNUMPY_NDARRAYTENSORPADDLE_RETURN_TYPESmax)Zin_type1Zin_type2Zsupported_typesZforbidden_typesr   r   r   binary_op_output_type   s*   

	
z!NodeVarType.binary_op_output_typec                 C   s2   t |  }|tjv rtj| S td|  tjS )Nz)Currently we don't support annotation: %s)r   r   r1   Annotation_mapr	   rA   )
annotationZannotation_strr   r   r   type_from_annotation   s
   

z NodeVarType.type_from_annotationN)r'   
__module____qualname____doc__ERRORrA   Z	STATEMENTZCALLABLENONErB   rC   rD   STRINGrF   rE   LISTZSETDICTZPADDLE_DYGRAPH_APIZPADDLE_CONTROL_IFZPADDLE_CONTROL_WHILEZPADDLE_CONTROL_FORrG   ZTENSOR_TYPESrJ   staticmethodrI   rL   r   r   r   r   r1   e   sB    	
r1   c                 C   s:   t jjj rt| t jjjsJ d| j| d S d S )Nz/In to_static mode, variable must be a Variable.)	r   r   r   Zin_to_static_moder   Z	frameworkVariabledesc	set_shape)variableZ
shape_listr   r   r   set_dynamic_shape   s   
rZ   )r%   r   r,   npr   r   Zpaddle.baser   r   Zpaddle.base.dygraphr   Zpaddle.utilsr   Z	ast_utilsr   Zlogging_utilsr	   r   r/   r   r   r   r   r+   r.   r0   r1   rZ   r   r   r   r   <module>   s*   

W