
    i                     d   S SK JrJrJrJrJr  S SKrS SKrS SKJ	r	J
r
  S\\\R                  4   S\\   4S jrS\\\R                  4   S\4S jrS	\\\\R                  4      4S
 jrS	\\\\R                  4      S\\   4S jrS	\\\\R                  4      S\\R"                     4S jrg)    )IterableListOptionalSetUnionN)bound_sympyValueRangessymintreturnc                 "   [        U [        5      (       a  U $ U R                  nUR                  nUR                  n UR                  U5      n[        U5      $ ! [        R                  R                  R                  R                   a     gf = f)z
Evaluate a symint to int. Returns None if symint's symoblic expr
can not be evaluated to valid integer according to the hints.
N)
isinstanceintnode	shape_envexpr	size_hinttorchfxexperimentalsymbolic_shapesGuardOnDataDependentSymNode)r
   r   r   r   outputs        W/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/exir/sym_util.py	eval_exprr      s|    
 &#;;DI99D$$T* v; 88  00LL s   A 2BBmaybe_symintc                    [        U [        5      (       a  U $ U R                  nUR                  nUR                  n[        X2R                  5      nUR                  n SSKJ	n  [        U[        R                  5      (       a6  [        UR                  5      n[        U[        5      (       d
   SU 35       eU$ Ub  XVL a  U$ [        SU 35      e! [         a    Sn Nzf = f)z
Evaluate a symint to its uppper bound value. Returns None if symint's symoblic expr's
upper bound can not be evaluated to valid integer according to the constraints in shape_env.
r   )int_ooNz0Expect upper bound to be a concrete int but got z:Expect upper bound to be sympy.Integer or int_oo. but got )r   r   r   r   r   r   var_to_rangeuppertorch.utils._sympy.numbersr   ImportErrorsympyIntegerRuntimeError)r   r   r   r   	var_rangeupper_boundr   concrete_uppers           r   eval_upper_boundr(   "   s    
 ,$$DI99D($$I //K5 +u}}--Y__-C
 
 	O=n=MN	O 
 		 5HV
 	
  s   C CCshapec                 f    / n[        U 5       H  u  p#UR                  [        U5      5        M!     U$ )z
Shape maybe immutable so we return a new shape. Return None for
dimensions that are unbacked e.g. first dimension of nonzero's output.
)	enumerateappendr   r)   	new_shape_ss       r   
eval_shaper1   E   s2    
 I% 1& !    c                 f    / n[        U 5       H  u  p#UR                  [        U5      5        M!     U$ N)r+   r,   r(   r-   s       r   eval_shape_upper_boundr5   P   s2    I% )!,- !r2   c                     [        5       nU  HS  n[        U[        R                  5      (       d  M$  UR	                  UR
                  R                  R                  5        MU     U$ r4   )setr   r   SymIntupdater   r   free_symbols)r)   symsetszs      r   collect_free_symbolsr=   W   sJ     UF"ell++bggll//0  Mr2   )typingr   r   r   r   r   r"   r   torch.utils._sympy.value_rangesr   r	   r   r8   r   r(   r1   r5   Symbolr=    r2   r   <module>rB      s    8 7   DeC-. 8C= " 
5ell):#;  
  
FhuS%,,%678 (5ell1B+C"D c E#u||+,-r2   