U
    •Ê¹j¸  ã                   @   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 e d¡dd„ ƒZd	d
ddddhZ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é   )ÚCleanDivÚFloorDivÚModÚModularIndexingÚWherec               6   C   s¬   ddl m} m} 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|dtdtdtdtjdtjd| dtjdt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i}|S )Nr   )ÚPowÚTrueDivÚor_Úand_ÚeqÚneÚltÚgtÚleÚgeÚnot_ÚtruedivÚfloordivÚdivÚwhereÚaddÚmulÚpowÚmodÚabsÚlogÚexpÚfloorÚceilÚminimumÚmaximumZmodular_indexing)Z%torch.fx.experimental.symbolic_shapesr   r   ÚsympyÚOrÚAndÚEqZNeÚLtÚGtZLeZGeÚNotr	   r   r   ÚAddZMulr
   ZAbsr!   r"   r#   ZceilingZMinZMaxr   )r   r   ZHANDLERS© r/   úX/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torch/utils/_sympy/interp.pyÚhandlers   sr                               år1   r%   r&   r   r   r   r   )Ú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ƒržt |jd tjjjƒržˆ  tˆ ˆ|jd ƒ¡S ‡ ‡fdd„|jD ƒ}tƒ |j }tˆ |ƒ}|tk�rt|ƒdksät‚||d |d ƒ}tdt|ƒƒD ]}|||| ƒ}�q|S ||Ž S d S )Nr   r   c                    s   g | ]}t ˆ ˆ|ƒ‘qS r/   )Úsympy_interp)Ú.0Úarg©Úanalysisr2   r/   r0   Ú
<listcomp>[   s     z sympy_interp.<locals>.<listcomp>é   )Ú
isinstancer   ÚtorchÚboolr'   ÚIntegerZint64ÚNumberÚdoubleZconstantÚSymbolr   ÚargsÚcoreÚnumbersZHalfÚsqrtr4   r1   ÚfuncÚgetattrÚASSOCIATIVE_OPSÚlenÚAssertionErrorÚrange)	r8   r2   r3   ZdtyperB   Úhandler_nameÚhandlerÚaccÚir/   r7   r0   r4   C   s4    
 ÿ

r4   )Ú__doc__Ú	functoolsÚtypingr   r   r   r'   Zsympy.logic.boolalgr   ZSympyBooleanr   r<   Z	functionsr   r	   r
   r   r   Ú	lru_cacher1   rH   rA   ÚExprr4   r/   r/   r/   r0   Ú<module>   s   	
( ÿ