o
    h                     @   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h d	Z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   )CleanDivFloorDivModModularIndexingWherec                  C   s   ddl m} m} 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|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maximummodular_indexing)%torch.fx.experimental.symbolic_shapesr   r   sympyOrAndEqNeLtGtLeGeNotr	   r   r   AddMulr
   Absr!   r"   r#   ceilingMinMaxr   )r   r   HANDLERS r:   O/var/www/html/ai/venv/lib/python3.10/site-packages/torch/utils/_sympy/interp.pyhandlers   s`   	
r<   >   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 ur( 	||S t |tj
r2| S t |tjrOt |jd tjjjrO t |jd S  fdd|jD }t |j }t |}|tv rt|dksqJ ||d |d }tdt|D ]	}|||| }q|S || S )Nr   r   c                    s   g | ]}t  |qS r:   )sympy_interp).0arganalysisr=   r:   r;   
<listcomp>[   s    z sympy_interp.<locals>.<listcomp>   )
isinstancer   torchboolr)   Integerint64NumberdoubleconstantSymbolr   argscorenumbersHalfsqrtr?   r<   funcgetattrASSOCIATIVE_OPSlenrange)	rC   r=   r>   dtyperO   handler_namehandleraccir:   rB   r;   r?   C   s2   

r?   )__doc__	functoolstypingr   r   r   r)   sympy.logic.boolalgr   SympyBooleanr   rG   	functionsr   r	   r
   r   r   	lru_cacher<   rV   rN   Exprr?   r:   r:   r:   r;   <module>   s    	
(