o
    wZh                     @   s  d Z ddlZddlZddl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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_Zint_truedivtruedivfloordivtruncwhereaddmulpowZpow_by_naturalmodabslogexpminimummaximumZmodular_indexingZexpr_cond_pair	piecewiseidentityZ&is_non_overlapping_and_dense_indicatorZround_decimallog2Zbitwise_andZ
bitwise_or)	cossintansinhcoshtanhasinacosatan))sympyOrAndEqZNeLtGtZLeZGeNotr   r   r   r
   r   r   AddZMulr   r   Powr   r   ZAbsr1   r2   r   r   r   	functionsZ
elementaryr5   ZExprCondPairZ	Piecewiser   r   r   r   r   r   getattr)ZHANDLERSname rM   H/var/www/auris/lib/python3.10/site-packages/torch/utils/_sympy/interp.pyhandlers6   s   	
 !"#$%&'()*+,5rO   >   r4   r-   r    r   r3   r,   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   Ztrunc_to_intZfloor_to_intZceil_to_intZround_to_intsym_sumzsym_sum(%s) -> %s_torch_handler_name   z%s(%s) -> %szfailed while executing %s(%s))#
isinstancerA   rI   argscorenumbersZHalfsqrtr   Zto_dtypetorchZfloat64r   floorZceilingr   r	   r   getfuncrK   rH   
is_integerhasattrrP   r1   debugrQ   rO   ASSOCIATIVE_OPSlenrangeNotImplementedError	Exceptionwarning)
analysisrT   exprindex_dtypeZINDEX_DTYPE_HANDLERShandler_namerhandleraccirM   rM   rN   _run_sympy_handler{   sP   




rm   rg   missing_handlerenvrf   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 )rn   )sympy_interp).0argre   rp   rg   ro   rM   rN   
<listcomp>   s    z sympy_interp.<locals>.<listcomp>)rg   )rS   r   rX   boolrA   Integerint64NumberdoubleZconstantSymbolrZ   _nilKeyErrorrm   rT   )re   rp   rf   rg   ro   Zdtyperi   rM   rt   rN   rq      s.   	

rq   )3__doc__	functoolsloggingtypingr   r   rA   Zsympy.logic.boolalgr   ZSympyBooleanr   rX   rJ   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__r1   	lru_cacherO   r_   rx   rm   objectr|   dictr{   Exprrq   rM   rM   rM   rN   <module>   s*   	h

A9