o
    * i                     @   s\   d dl Z d dlZd dlZG dd dZG dd dZe ZG dd dZdd	 Zd
d Z	dS )    Nc                   @   s   e Zd ZdS )
HookAPIMapN)__name__
__module____qualname__ r   r   h/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/paddle/api_tracer/api_tracer.pyr      s    r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )

ConfigDumpc                 C   s   d S Nr   )selfr   r   r   __init__   s   zConfigDump.__init__c                 C   s   t |d| _d S )Nza+)openfile)r
   pathr   r   r   	open_file   s   zConfigDump.open_filec           	      C   s   |d }|D ]}|  ||}|dkr d S || d }q| D ]\}}|  ||}|dkr1 d S || d | d }q |d }| j| | jd | j  d S )N( z, =)
)dump_item_stritemsr   writeflush)	r
   apiZ
input_argsZinput_kwargsZoutputsresultvaluetmpkeyr   r   r   dump_config    s   zConfigDump.dump_configc                 C   s  dd l }tjttjttjttjttjttj	ttj
ttjttjttjttjttjti}| D ]\}}t||r=||} nq.t||jrXdt|j d t|jdd   d S t||jjjrldt|dd   d S t||jjjjrdt|dd   d S t|trd	}|D ]}| ||}	|	d
kr d
S ||	 d }q|d }|S t|t rd}|D ]}| ||}	|	d
kr d
S ||	 d }q|d }|S t|t!rt|j"|jrtt|j"# nt|j"}
t|j$|jrtt|j$# nt|j$}t|j%|jrtt|j%# nt|j%}d|
 d | d | d S t|tr9d| ||j& d | ||j' d S |d u r@dS t||jj(|jj)j*j+frPd
S |t,j-krXdS |t,j- kradS |t,j.kridS |t,j. krrdS t|tttfrt|S t|trd| d S t|t/rdt|t|0dd t|1d  d S t|tj2rt|dd S t|tjrdt| d S |t3krdS t4d|d|dt/| d
S )Nr   zTensor(z,"   z")zDtype(r   zVarType(zlist[r   ,]ztuple(zslice(zcomplex(Nonezmath.infz	-math.infzmath.nanz	-math.nan"ztype('   Ellipsisz#[api_tracer error] : dump_item_str z	, item = z, type(item) = )5paddlenpZint16intZint32Zint64Zfloat16floatZfloat32Zfloat64integerZfloatingZbool_boolZcomplexfloatingcomplexZstr_strbytes_bytesr   
isinstanceZTensorshapeZdtypebasecoreZDataTypeZVarDescZVarTypelistr   tupleslicestartnumpystopsteprealimagVariableZ	libpaddleZpirValuemathinfnantypeindexrindexZndarrayr'   print)r
   r   itemr(   Ztype_mappingZ
numpy_typeZbuiltin_typer   Zsub_itemr   Z	start_strZstop_strZstep_strr   r   r   r   9   s   
&


&
zConfigDump.dump_item_strN)r   r   r   r   r   r   r   r   r   r   r   r      s
    r   c                   @   s   e Zd Zdd Zdd ZdS )APITemplatec                 C   s
   || _ d S r	   api_name)r
   rK   r   r   r   r      s   
zAPITemplate.__init__c              
   O   sh   t t| j|i |}zt| j||| W |S  ty3 } ztd| jt| W Y d }~|S d }~ww )Nz-[api_tracer error] : config_dump.dump_config )getattrr   rK   config_dumpr   	ExceptionrG   r/   )r
   argskwargsoutputerrr   r   r   __call__   s   zAPITemplate.__call__N)r   r   r   r   rS   r   r   r   r   rI      s    rI   c                    s    fdd}|S )Nc                     s   t  | i |S r	   )rI   )rO   rP   rJ   r   r   api_template   s   z!wrapped_api.<locals>.api_templater   )rK   rT   r   rJ   r   wrapped_api   s   rU   c           
      C   s   dd l }t|j t| d}t|}|d}|  W d    n1 s'w   Y  |D ]<}|jddd\}}zt	t
|tt|| t	t||t| W q. tyj }	 ztd|t|	 W Y d }	~	q.d }	~	ww t| d S )Nr   rapis.r%   )maxsplitz&[api_tracer error] : start_api_tracer )r(   rG   __version__r   yamlZ	safe_loadgetclosersplitsetattrr   rL   evalrU   rN   r/   rM   r   )
Zapi_pathZsave_config_pathr(   frW   Zsample_apisr   parent_packagemethod_namerR   r   r   r   start_api_tracer   s"   



rd   )
rA   r:   r)   r[   r   r   rM   rI   rU   rd   r   r   r   r   <module>   s    