o
    闦i                     @   s  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"m#Z#m$Z$m%Z% e&e'Z(e)ddd Z*h d	Z+ej,fd
dZ-e. Z/ej,dddeej0ef deej1e
f fd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DictUnion)BooleanBooleanAtom   )BitwiseFn_bitwise_andBitwiseFn_bitwise_or	CeilToIntCleanDivFloatPowFloatTrueDivFloorDiv
FloorToIntIdentity
IntTrueDiv!IsNonOverlappingAndDenseIndicatorMaxMinModModularIndexingOpaqueUnaryFn_log2PowByNatural	PythonModRoundDecimal
RoundToIntToFloatTruncToFloat
TruncToIntWherec                  C   s6  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tdtdtdt jjjj dt j!dt"dt#dt$dt%dt&d t'd!i} d"D ]	}|| t(t |< q| 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log2bitwise_and
bitwise_or)	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   Absr4   r5   r   r   r   	functions
elementaryr:   ExprCondPair	Piecewiser   r   r   r   r   r	   getattr)HANDLERSname r_   W/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/torch/utils/_sympy/interp.pyhandlers6   s   	
 !"#$%&'()*+,5ra   >   r.   r/   r    r!   r7   r6   c           
      C   s  t |tjrt |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 }d urLt| |g ||R  S |jtju rh|jrht| drh| |}td|| |S t|jd	rs|jj}nt |j }t| |}z@|tv rt|dksJ ||d |d }td
t|D ]	}	||||	 }qtd||| |W S || }td||| |W S  t y     t!y   t"d||  w )Nr   r   trunc_to_intfloor_to_intceil_to_intround_to_intsym_sumzsym_sum(%s) -> %s_torch_handler_name   z%s(%s) -> %szfailed while executing %s(%s))#
isinstancerJ   rV   argscorenumbersHalfsqrtr   to_dtypetorchfloat64r   floorceilingr   r
   r   getfuncr\   rT   
is_integerhasattrrf   r4   debugrg   ra   ASSOCIATIVE_OPSlenrangeNotImplementedError	Exceptionwarning)
analysisrj   exprindex_dtypeINDEX_DTYPE_HANDLERShandler_namerhandleraccir_   r_   r`   _run_sympy_handler{   sP   




r   r   missing_handlerenvr   c                   s   d }t |trtj}nt |tjrtj}n	t |tjrtj}|d ur( 	||S t |tj
rD|t }tur:|S r@|S t|t  fdd|jD |dS )Nc              	      s   g | ]}t  |d qS )r   )sympy_interp).0argr   r   r   r   r_   r`   
<listcomp>   s    z sympy_interp.<locals>.<listcomp>)r   )ri   r   rp   boolrJ   Integerint64NumberdoubleconstantSymbolrt   _nilKeyErrorr   rj   )r   r   r   r   r   dtyper   r_   r   r`   r      s.   	

r   )3__doc__	functoolsloggingtypingr   r   r   rJ   sympy.logic.boolalgr   SympyBooleanr   rp   rX   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__r4   	lru_cachera   ry   r   r   objectr   r   Exprr   r_   r_   r_   r`   <module>   s*   	h

A9