o
    ,’×i˜  ã                   @   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 h d	£Z!ej"d
œdeej#ef deej$e	f f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                  C   s  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 jjjj d“t j!d“t"d“t#d“¥} 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Ú&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   ÚAbsr.   r/   ÚMinÚMaxr   Ú	functionsÚ
elementaryr4   ÚExprCondPairÚ	Piecewiser   r   Úgetattr)ÚHANDLERSÚname© rW   úW/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/torch/utils/_sympy/interp.pyÚhandlers+   sŒ   ÿþýüûúùø	÷
öõôóòñðïîíæåä à!ß"Þ#Ý$Ü%Û&Ú'Ù(Ø)×*Ö,rY   >   r(   r)   r   r   r1   r0   )Ú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 ur(ˆ  	||¡S t |tj
ƒr2ˆ| S t |tjƒrOt |jd tjjjƒrOˆ  tˆ ˆ|jd ƒ¡S t |tƒrbˆ  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 ur“tˆ |ƒg |¢|‘R Ž S t|jd	ƒrž|jj}nt ƒ |j }tˆ |ƒ}|t!v rÑt"|ƒdksµJ ‚||d |d ƒ}	t#d
t"|ƒƒD ]	}
||	||
 ƒ}	qÅ|	S ||Ž S )Nr   r   c                    s   g | ]}t ˆ ˆ|ƒ‘qS rW   )Úsympy_interp)Ú.0Úarg©Úanalysisr[   rW   rX   Ú
<listcomp>‡   s    z sympy_interp.<locals>.<listcomp>Útrunc_to_intÚfloor_to_intÚceil_to_intÚround_to_intÚ_torch_handler_nameé   )$Ú
isinstancer   ÚtorchÚboolr@   ÚIntegerÚint64ÚNumberÚdoubleÚconstantÚSymbolrL   ÚargsÚcoreÚnumbersÚHalfÚsqrtr]   r   Úto_dtypeÚfloat64r   ÚfloorÚceilingr   r   r   ÚgetÚfuncrT   Úhasattrrg   rY   ÚASSOCIATIVE_OPSÚlenÚrange)ra   r[   r\   rZ   Údtyperr   ÚINDEX_DTYPE_HANDLERSÚhandler_nameÚhandlerÚaccÚirW   r`   rX   r]   g   sP   
ÿ
ÿ
ú

r]   )&Ú__doc__Ú	functoolsÚtypingr   r   r   r@   Úsympy.logic.boolalgr   ÚSympyBooleanr   rj   rP   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Ú	lru_cacherY   r~   rm   rq   ÚExprr]   rW   rW   rW   rX   Ú<module>   s    	P
8ûþý