Ë
    �…j]  ã                   óà  — d dl Z d dlZd dlZej                  j	                  e«      Zej                  j                  ej                  j                  ed«      «      r6ej                  j                  ej                  j                  ed«      «       n5ej                  j                  ej                  j                  ed«      «       d dl
mZmZmZ  e j                  e«      Z G d„ de«      Zy)é    Nz ../tools/symbolic_shape_infer.pyz../toolsz..)ÚSymbolicShapeInferenceÚget_shape_from_type_protoÚsympyc                   óN   ‡ — e Zd Zdˆ fd„	Zd	deeef   defd„Zd„ Zd„ Z	d„ Z
ˆ xZS )
ÚSymbolicShapeInferenceHelperc                 ób   •— t         ‰| �  ||||«       || _        d| _        d| _        i | _        y )NF)ÚsuperÚ__init__Úmodel_Úall_shapes_inferred_Úis_inferred_Údynamic_axis_mapping_)ÚselfÚmodelÚverboseÚint_maxÚ
auto_mergeÚguess_output_rankÚ	__class__s         €úl/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/onnxruntime/transformers/shape_infer_helper.pyr
   z%SymbolicShapeInferenceHelper.__init__   s6   ø€ Ü‰Ñ˜ *Ð.?ÀÔIØˆŒØ*/ˆÔ!Ø"'ˆÔØ57ˆÕ"ó    Údynamic_axis_mappingÚmax_runsc                 ór  — |€J ‚| j                   r| j                  |k(  r| j                  S || _        | j                  | j                  «       d}| j
                  rJt        j                  d|› �«       | j                  «       | _        |dz  }|dkD  r||k\  rn| j
                  rŒJd| _         | j                  S )a©  Run shape inference, and try replace dynamic axis from string to integer when mapping is provided.

        Args:
            dynamic_axis_mapping (_type_): a dictionary with name of dynamic axis as key, like {"batch_size" : 4}
            max_runs (int, optional): limit maximum number of runs to avoid infinite loop. Defaults to 200.

        Returns:
            bool: whether all shapes has been inferred or not.
        r   zshape infer run é   T)	r   r   r   Ú_preprocessr   Úrun_ÚloggerÚdebugÚ_infer_impl)r   r   r   Úcounts       r   Úinferz"SymbolicShapeInferenceHelper.infer   s·   € ð $Ð/Ð/Ð/à×Ò ×!;Ñ!;Ð?SÒ!SØ×,Ñ,Ð,à%9ˆÔ"à×Ñ˜Ÿ™Ô%àˆØ�iŠiÜ�L‰LÐ+¨E¨7Ð3Ô4Ø(,×(8Ñ(8Ó(:ˆDÔ%Ø�Q‰JˆEØ˜!Š| ¨Ò 1Øð �i‹ið !ˆÔØ×(Ñ(Ð(r   c                 óŒ  — g }| j                  ||«      }|r­|D ]¨  }t        |t        «      r�|| j                  v r|j	                  | j                  |   «       Œ@|| j
                  v r|j	                  | j
                  |   «       Œm|j	                  t        j                  |d¬«      «       Œ”|€J ‚|j	                  |«       Œª |S )zQOverride it to ensure shape inference by giving the actual value of dynamic axis.T)Úinteger)Ú
_get_shapeÚ
isinstanceÚstrr   ÚappendÚsymbolic_dims_r   ÚSymbol)r   ÚnodeÚidxÚsympy_shapeÚshapeÚdims         r   Ú_get_sympy_shapez-SymbolicShapeInferenceHelper._get_sympy_shape<   sº   € àˆà—‘  cÓ*ˆÙØò 
,�Ü˜c¤3Ô'Ø˜d×8Ñ8Ñ8Ø#×*Ñ*¨4×+EÑ+EÀcÑ+JÕKØ × 3Ñ 3Ñ3Ø#×*Ñ*¨4×+>Ñ+>¸sÑ+CÕDà#×*Ñ*¬5¯<©<¸ÀTÔ+JÕKà˜?Ð*˜?Ø×&Ñ& sÕ+ð
,ð Ðr   c                 óD  — | j                   sJ ‚|| j                  vrt        dt        |«      z   «       y| j                  |   j                  }t        |«      }|�Et        |«      D ]7  \  }}t        |t        «      sŒ|| j                  v sŒ&| j                  |   ||<   Œ9 |S )z¬Get shape of an edge.

        Args:
            edge (str): name of edge

        Returns:
            Optional[List[int]]: the shape, or None if shape is unknown
        zCannot retrieve the shape of N)	r   Ú	known_vi_Úprintr'   Útyper   Ú	enumerater&   r   )r   ÚedgeÚ
type_protor.   Úir/   s         r   Úget_edge_shapez+SymbolicShapeInferenceHelper.get_edge_shapeO   s¢   € ð ×(Ò(Ð(Ð(Ø�t—~‘~Ñ%ÜÐ1´C¸³IÑ=Ô>Øà—^‘^ DÑ)×.Ñ.ˆ
Ü)¨*Ó5ˆàÐÜ# EÓ*ò ?‘��3Ü˜c¤3Õ'¨C°4×3MÑ3MÒ,MØ#×9Ñ9¸#Ñ>�E˜!’Hð?ð ˆr   c                 óŠ   — | j                   sJ ‚| j                  |«      }| j                  |«      }|�|€t        d«      ‚||k(  S )a*  Compare shape of two edges.

        Args:
            edge (str): name of edge
            edge_other (str): name of another edge

        Raises:
            Exception: At least one shape is missed for edges to compare

        Returns:
            bool: whether the shape is same or not
        z1At least one shape is missed for edges to compare)r   r9   Ú	Exception)r   r6   Ú
edge_otherr.   Úshape_others        r   Úcompare_shapez*SymbolicShapeInferenceHelper.compare_shapeg   sT   € ð ×(Ò(Ð(Ð(Ø×#Ñ# DÓ)ˆØ×)Ñ)¨*Ó5ˆØˆ=˜KÐ/ÜÐOÓPÐPØ˜Ñ#Ð#r   )r   iÿÿÿTF)éÈ   )Ú__name__Ú
__module__Ú__qualname__r
   Údictr'   Úintr"   r0   r9   r>   Ú__classcell__)r   s   @r   r   r      s2   ø„ õ8ñ)¨$¨s°C¨x©.ð )ÀCó )ò<ò&ö0$r   r   )ÚloggingÚosÚsysÚpathÚdirnameÚ__file__Ú	file_pathÚexistsÚjoinr(   Úsymbolic_shape_inferr   r   r   Ú	getLoggerr@   r   r   © r   r   ú<module>rR      s©   ðó Û 	Û 
ð �G‰G�O‰O˜HÓ%€	Ø‡7�7‡>�>�"—'‘'—,‘,˜yÐ*LÓMÔNØ‡H�H‡O�O�B—G‘G—L‘L ¨JÓ7Õ8à‡H�H‡O�O�B—G‘G—L‘L ¨DÓ1Ô2ç YÑ Yà	ˆ×	Ñ	˜8Ó	$€ôc$Ð#9õ c$r   