U
    Mh                     @   s   d 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 eddd Z d	d
ddddhZ!ej"deej#ef eej$e	f dd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
IntTrueDiv!IsNonOverlappingAndDenseIndicatorModModularIndexingPowByNatural	PythonModRoundDecimal
RoundToIntToFloatTruncToFloat
TruncToIntWherec               B   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 jjjj dt j!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	piecewiseZ&is_non_overlapping_and_dense_indicatorZround_decimal)	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Absr,   r-   ZMinZMaxr   	functionsZ
elementaryr0   ZExprCondPairZ	Piecewiser   r   getattr)ZHANDLERSname rF   K/var/www/html/venv/lib/python3.8/site-packages/torch/utils/_sympy/interp.pyhandlers+   s                                 
    ,rH   r.   r/   r(   r'   r   r   )index_dtype)envexprc                   s  d }t |trtj}n&t |tjr*tj}nt |tjr<tj}|d k	rP 	||S t |tj
rd| S t |tjrt |jd tjjjr t |jd S t |trĈ t |jd tjS  fdd|jD }tdtjdtjdtdtdtdi}||j }d k	r$t |||f S t|jd	r<|jj}nt  |j }t |}|t!krt"|dksnt#||d |d }	t$d
t"|D ]}
||	||
 }	q|	S || S d S )Nr   r   c                    s   g | ]}t  |qS rF   )sympy_interp).0arganalysisrJ   rF   rG   
<listcomp>   s     z sympy_interp.<locals>.<listcomp>Ztrunc_to_intZfloor_to_intZceil_to_intZround_to_int_torch_handler_name   )%
isinstancer   torchboolr:   Integerint64NumberdoubleZconstantSymbolrB   argscorenumbersZHalfsqrtrL   r   Zto_dtypeZfloat64r   floorZceilingr   r   r   getfuncrD   hasattrrR   rH   ASSOCIATIVE_OPSlenAssertionErrorrange)rP   rJ   rK   rI   Zdtyper\   ZINDEX_DTYPE_HANDLERShandler_namehandleraccirF   rO   rG   rL   g   s`    
 
 
      


rL   )&__doc__	functoolstypingr   r   r   r:   Zsympy.logic.boolalgr   ZSympyBooleanr   rU   rC   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	lru_cacherH   rd   rX   r[   ExprrL   rF   rF   rF   rG   <module>   s   	P
8