
    [i                      n   d Z ddlZddlZddl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 m!Z!m"Z"m#Z#m$Z$  ej%        e&          Z'ej(        d             Z)h dZ*e
j+        fd	Z, e-            Z.e
j+        dd
de/ej0        ef         dej1        ez  fdZ2dS )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)BooleanBooleanAtom   )BitwiseFn_bitwise_andBitwiseFn_bitwise_orBitwiseFn_bitwise_xor	CeilToIntCleanDivFloatPowFloatTrueDivFloorDiv
FloorToIntIdentity
IntTrueDiv!IsNonOverlappingAndDenseIndicatorMaxMinModModularIndexingOpaqueUnaryFn_log2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           j        dt           j        dt           j        dt           j        dt4          dt6          dt8          dt           j        j        j        j         dt           j!        dtD          dtF          dtH          dtJ          d tL          d!tN          d"tP          d#i} d$D ]}|| tS          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
python_modabslogexpminimummaximummodular_indexingexpr_cond_pair	piecewiseidentity&is_non_overlapping_and_dense_indicatorround_decimallog2bitwise_and
bitwise_orbitwise_xor)	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   Absr6   r7   r   r   r   	functions
elementaryr<   ExprCondPair	Piecewiser   r   r   r   r   r   r	   getattr)HANDLERSnames     L/var/www/icac/venv/lib/python3.11/site-packages/torch/utils/_sympy/interp.pyhandlersrc   7   sP   3%3	63 	$3 	$	3
 	$3 	$3 	$3 	$3 		63 	M3 	i3 	*3 	*3 	g3 	w3  		5!3" 		5#3 3$ 	%%3& 	&'34 		#536 	U738 	<93@ 		5A3B 		5C3D 		5E3F 		5G3H 		9I3J 		9K3L 	YM3N 	YO3P 	+Q3R 	",9;KS3T 	U3V 	*W3 3X 	*+SoF}l}e3 3Hl V . .)-%%&&O    >   r/   r0   r!   r"   r9   r8   c                 @   t          |t          j                  rJt          |j        d         t          j        j        j                  r|                     |d                   S t          |t                    r&| 	                    |d         t          j                  S t          dt          j        dt          j        dt          dt           dt"          di}|                    |j                  x} t)          | |          g ||R  S |j        t          j        u rJ|j        rCt/          | d          r3|                     |          }t2                              d||           |S t/          |j        d	          r|j        j        }nt9                      |j                 }t)          | |          }	 |t:          v rt=          |          dk    rt?          d
           ||d         |d                   }tA          dt=          |                    D ]}	 ||||	                   }t2                              d|||           |S  || }t2                              d|||           |S # tB          $ r  tD          $ r t2          #                    d||            w xY w)Nr   r   trunc_to_intfloor_to_intceil_to_intround_to_intsym_sumzsym_sum(%s) -> %s_torch_handler_namezassociative op needs >1 args   z%s(%s) -> %szfailed while executing %s(%s))$
isinstancerM   rY   argscorenumbersHalfsqrtr   to_dtypetorchfloat64r   floorceilingr   r
   r   getfuncr_   rW   
is_integerhasattrrj   r6   debugrk   rc   ASSOCIATIVE_OPSlenAssertionErrorrangeNotImplementedError	Exceptionwarning)
analysisrn   exprindex_dtypeINDEX_DTYPE_HANDLERShandler_namerhandleraccis
             rb   _run_sympy_handlerr   }   s   $	"" &z	!ej(-( ( & }}T!W%%%$   9  a%-888 	N^}N=N -00;;;H.wx..BBkBBBB yEI$/gh	6R6RT""		%tQ///ty/00 -y4zz$),h--G?**4yyA~~$%CDDD'$q'47++C1c$ii(( , ,gc47++IInlD#>>>JAIInlD!<<<H      3\4HHHs   3BI+ #I+ +2Jr   missing_handlerenvr   c                "    d }t          |t                    rt          j        }nMt          |t          j                  rt          j        }n&t          |t          j                  rt          j        }| 	                    ||          S t          |t          j
                  rB                    |t                    x}t          ur|S r |          S t          |          t            fd|j        D             |          S )Nc           	      8    g | ]}t          |           S )r   )sympy_interp).0argr   r   r   r   s     rb   
<listcomp>z sympy_interp.<locals>.<listcomp>   sI     		
 		
 		
  ' /  		
 		
 		
rd   )r   )rm   r   rt   boolrM   Integerint64NumberdoubleconstantSymbolrx   _nilKeyErrorr   rn   )r   r   r   r   r   dtyper   s   `` ``  rb   r   r      s4    E$$$ 
	D%-	(	( 	D%,	'	'   u---	D%,	'	' !t$$$AT11H 	!"?4(((4..  		
 		
 		
 		
 		
 		
 		
 y		
 		
 		
 	   rd   )3__doc__	functoolsloggingtypingr   rM   sympy.logic.boolalgr   SympyBooleanr   rt   r[   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	getLogger__name__r6   cacherc   r}   r   r   objectr   dictr   Exprr    rd   rb   <module>r      s0                D D D D D D D D                                                      : g!! ? ? ?D FEE :? 7 7 7 7t vxx * * *	elC	 * *|
#* * * * * *rd   