a
    h                     @   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j(dd Z)h d	Z*ej+fd
dZ,e- Z.ej+dde/ej0ef eej1e	f d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               N   C   s   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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   G/var/www/auris/lib/python3.9/site-packages/torch/utils/_sympy/interp.pyhandlers6   sV    5rO   >   r4   r   r    r3   r,   r-   c           
      C   s  t |tjr0t |jd tjjjr0| |d S t |trL| 	|d t
jS tdtjdtjdtdtdtdi}||j }d urt| |g ||R  S |jtju r|jrt| dr| |}td|| |S t|jd	r|jj}nt |j }t| |}z|tv rft|dksJ ||d |d }td
t|D ]}	||||	 }q:td||| |W S || }td||| |W S W n8 t y    Y n$ t!y   t"d||  Y n0 d S )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coreZnumbersZHalfsqrtr   Zto_dtypetorch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_HANDLERSZhandler_namerhandleraccirM   rM   rN   _run_sympy_handler{   sN    






rl   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rP 	||S t |tj
r|t }turt|S r|S t|t  fdd|jD |dS )Nc              	      s   g | ]}t  |d qS )rm   )sympy_interp).0argre   ro   rg   rn   rM   rN   
<listcomp>   s   z sympy_interp.<locals>.<listcomp>)rg   )rS   r   rW   boolrA   ZIntegerint64NumberdoubleZconstantSymbolrZ   _nilKeyErrorrl   rT   )re   ro   rf   rg   rn   Zdtyperh   rM   rs   rN   rp      s.    	

rp   )3__doc__	functoolsloggingtypingr   r   rA   Zsympy.logic.boolalgr   ZSympyBooleanr   rW   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   cacherO   r_   rv   rl   objectrz   dictry   Exprrp   rM   rM   rM   rN   <module>   s&   	h

A9