
     Ti	                        S SK Jr  S SKJrJrJr  S SKrS SKJ	s  J
r  S SKJrJr  S SKJrJr  \\\R&                  4   rS	S jrS
S jrSS jrg)    )annotations)CallableSequenceUnionN)MatchFailureErrorMatchingTracer)RewriteRuleRewriteRuleSetc                    UR                   c  gUR                   R                  5       [        U5      :w  a  g[        UR                   U5       H  u  p4X@;  a  X0U'   M  X0U   :w  d  M    g   g)NFT)shaperanklenzip)bindingsvalr   actualexpecteds        `/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnxscript/rewriter/_fusion_utils.pycheck_shape_boolr      sb    
yy
yy~~3u:%		51#!'X))	 2
     c                   UR                   c  [        SU S3U5      eUR                   R                  5       [        U5      :w  a7  [        SU SUR                   R                  5        S[        U5       S3U5      e[	        [        UR                   U5      5       H6  u  nu  pEXP;  a  X@U'   M  X@U   :w  d  M  [        SU SU SU S	X    S
3	U5      e   g )NzThe shape of z is unknown.zThe rank of z (z" does not match the expected rank .z
Dimension z of z) does not have expected size (z).)r   r   r   r   	enumerater   )r   r   r   ir   r   s         r   check_shaper      s    
yy-uL A3GG
yy~~3u:%3%r#)).."2!33UVYZ_V`Uaabc
 	
 "+3syy%+@!AF#!'X))#QCtC56(2QRZRdQeegh 	 "Br   c                ,   ^   S       SU 4S jjjnU$ )a  
Apply the given fusion rules to the model and return the number of fusions applied.

model: The input ONNX model represented as an `ir.Model`.
debug: If debug is True, enable pattern matching tracer for debugging.
apply_shape_inference: If True, apply shape inference after fusions.
c                   > TR                   " U 40 UD6nU(       a  [        R                  " 5       " U 5        US:X  a6  U(       a/  [        5       nTR                   " U 4SU0UD6  UR	                  5         U$ )Nr   tracer)apply_to_modelcommon_passesShapeInferencePassr   report)modeldebugapply_shape_inferencekwargscountr   ruless         r   apply_to$apply_fusion_rules.<locals>.apply_to8   se     $$U5f5 ,,.u5A:%#%F  @v@@MMOr   )FF)r#   zir.Modelr$   boolr%   r+   returnint )r(   r)   s   ` r   apply_fusion_rulesr/   /   s;     MR

 $
EI
	
 
 Or   )r   dict[str, Dim]r   ir.Valuer   Sequence[str]r,   r+   )r   r0   r   r1   r   r2   )r(   zRewriteRule | RewriteRuleSetr,   r   )
__future__r   typingr   r   r   onnx_irironnx_ir.passes.commonpassescommonr    onnxscript.rewriter._basicsr   r   !onnxscript.rewriter._rewrite_ruler	   r
   r-   SymbolicDimDimr   r   r/   r.   r   r   <module>r>      sA    # , ,  - - I IC 
$r   