
    Χg                     l   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j#        e$          Z% ej&        d          d             Z'h dZ(ej)        fd	Z*ej)        d
deej+        ef         deej,        e
f         fdZ-d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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                  n   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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     U/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/utils/_sympy/interp.pyhandlersr\   3   s<   .%.	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;KS.T 	U.V 	*W. .X 	*+So[. .H^ V . .)-%%&&O    >   r-   r.   r   r    r6   r5   c                 X   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 t+          |j        d          r|j        j        }nt/                      |j                 }t)          | |          }	 |t0          v r~t3          |          dk    sJ  ||d         |d                   }t5          dt3          |                    D ]} ||||                   }t6                              d	|||           |S  || }	t6                              d	|||	           |	S # t:          $ r t6                              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	!ej(-( ( & }}T!W%%%$   9  a%-888 	N^}N=N -00;;;H.wx..BBkBBBBty/00 -y4zz$),h--G?**t99q===='$q'47++C1c$ii(( , ,gc47++IInlD#>>>JAIInlD!<<<H   3\4HHHs   BH #H (H)r{   envrz   c                    d }t          |t                    rt          j        }nMt          |t          j                  rt          j        }n&t          |t          j                  rt          j        }| 	                    ||          S t          |t          j
                  r|         S t            fd|j        D             ||          S )Nc                 2    g | ]}t          |          S  )sympy_interp).0argry   r   s     r[   
<listcomp>z sympy_interp.<locals>.<listcomp>   s%    ???chS	)	)???r]   r   )re   r   rl   boolrF   Integerint64NumberdoubleconstantSymbolr   rf   )ry   r   rz   r{   dtypes   ``   r[   r   r      s     E$$$ 
	D%-	(	( 	D%,	'	'   u---	D%,	'	' 4y ?????TY???	   r]   ).__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]   r[   <module>r      s         # # # # # # # # # #  D D D D D D D D                                              2 g!! T8 8 8v FEE :? . . . .l   	elC	  
L(
)     r]   