
    sg                        d Z ddlZddlZddlmZmZmZ ddlZddlm	Z
mZ ddlZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"  ejF                  e$      Z% ejL                  d      d        Z'h dZ(ejR                  fd	Z*ejR                  d
deejV                  ef   deejX                  e
f   fdZ-y)a  
This is a simple interpreter for Sympy expressions that dispatches to
classes following the torch._inductor.virtualized calling convention.
For directness, the interpreter takes the handler directly rather than
consulting the TLS.  It does not use most of the methods on the full
handler; only those with corresponding Sympy expressions.  To see an example
of a full handler, see torch.utils._sympy.value_ranges.ValueRangeAnalysis.
    N)AnyDictUnion)BooleanBooleanAtom   )	CeilToIntCleanDivFloatPowFloatTrueDivFloorDiv
FloorToIntIdentity
IntTrueDiv!IsNonOverlappingAndDenseIndicatorMaxMinModModularIndexingPowByNatural	PythonModRoundDecimal
RoundToIntToFloatTruncToFloat
TruncToIntWherec                     i t         j                  dt         j                  dt         j                  dt         j                  dt         j
                  dt         j                  dt         j                  dt         j                  dt         j                  d	t        d
t        dt        dt        dt        dt        dt         j                   dt         j"                  di t$        dt&        dt         j(                  dt*        dt,        dt         j*                  dt         j.                  dt         j0                  dt         j2                  dt         j4                  dt         j6                  dt4        dt6        dt8        dt         j:                  j<                  j>                  j@                  dt         jB                  dtD        dtF        dtH        di} dD ]  }|| tK        t         |      <    | S ) Nor_and_eqneltgtlegenot_int_truedivtruedivfloordivtruncwhereaddmulpowpow_by_naturalmodabslogexpminimummaximummodular_indexingexpr_cond_pair	piecewiseidentity&is_non_overlapping_and_dense_indicatorround_decimal)	cossintansinhcoshtanhasinacosatan)&sympyOrAndEqNeLtGtLeGeNotr   r   r   r
   r   r   AddMulr   r   Powr   r   Absr3   r4   r   r   r   	functions
elementaryr9   ExprCondPair	Piecewiser   r   r   getattr)HANDLERSnames     L/var/www/html/venv/lib/python3.12/site-packages/torch/utils/_sympy/interp.pyhandlersr\   3   sZ   .%.		6. 	$. 	$	.
 	$. 	$. 	$. 	$. 			6. 	M. 	i. 	*. 	*. 	g. 	w.  			5!." 			5#.$ 	%%.& 	&'.4 			#5.6 	U7.8 	59.@ 			5A.B 			5C.D 			5E.F 			5G.H 			9I.J 			9K.L 	YM.N 	YO.P 	+Q.R 	"",,99;KS.T 	U.V 	*W.X 	*+So[.H^ V .)-%&. O    >   r-   r.   r   r    r6   r5   c                    t        |t        j                        rOt        |j                  d   t        j                  j
                  j                        r| j                  |d         S t        |t              r#| j                  |d   t        j                        S t        dt        j                  dt        j                  dt        dt         dt"        di}|j%                  |j&                        x} t)        | |      g || S t+        |j&                  d      r|j&                  j,                  }nt/               |j&                     }t)        | |      }	 |t0        v r_t3        |      dkD  sJ  ||d   |d         }t5        dt3        |            D ]  } ||||         } t6        j9                  d	|||       |S  || }	t6        j9                  d	|||	       |	S # t:        $ r t6        j=                  d
||        w xY w)Nr   r   trunc_to_intfloor_to_intceil_to_intround_to_int_torch_handler_name   z%s(%s) -> %szfailed while executing %s(%s))
isinstancerF   rR   argscorenumbersHalfsqrtr   to_dtypetorchfloat64r   floorceilingr   r	   r   getfuncrX   hasattrrc   r\   ASSOCIATIVE_OPSlenranger3   debug	Exceptionwarning)
analysisrf   exprindex_dtypeINDEX_DTYPE_HANDLERShandler_namehandleraccirs
             r[   _run_sympy_handlerr   r   s   $		"z		!ejj((--( }}T!W%%$   a%--88 	N^}N=N -00;;H.wx.BBkBBtyy/0yy44z$)),h-G?*t9q= =$q'47+C1c$i( ,c47+,IInlD#>JAIInlD!<H 3\4Hs   A&G  G "Hr{   envrz   c                   d }t        |t              rt        j                  }nUt        |t        j
                        rt        j                  }n*t        |t        j                        rt        j                  }|| j                  ||      S t        |t        j                        r||   S t        | |j                  D cg c]  }t        | ||       c}||      S c c}w )Nr   )re   r   rl   boolrF   Integerint64NumberdoubleconstantSymbolr   rf   sympy_interp)ry   r   rz   r{   dtypeargs         r[   r   r      s     E$$

	D%--	(	D%,,	'  u--	D%,,	'4y 59YY?chS	)?	 ?s    C
).__doc__	functoolsloggingtypingr   r   r   rF   sympy.logic.boolalgr   SympyBooleanr   rl   rT   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	getLogger__name__r3   	lru_cacher\   rs   r   r   r   Exprr    r]   r[   <module>r      s      # #  D      2 g! T8 8v F :? .l 	ellC	  

L(
)r]   