o
    ki                      @   s  d Z ddlZddlZddl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#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de/ej0ef dej1eB f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)BooleanBooleanAtom   )BitwiseFn_bitwise_andBitwiseFn_bitwise_orBitwiseFn_bitwise_xor	CeilToIntCleanDivFloatPowFloatTrueDivFloorDiv
FloorToIntIdentity
IntTrueDiv!IsNonOverlappingAndDenseIndicatorMaxMinModModularIndexingOpaqueUnaryFn_log2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dtdt jjjj dt j!dt"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_int_truedivtruedivfloordivtruncwhereaddmulpowpow_by_naturalmod
python_modabslogexpminimummaximummodular_indexingexpr_cond_pair	piecewiseidentity&is_non_overlapping_and_dense_indicatorround_decimallog2bitwise_and
bitwise_orbitwise_xor)	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   Absr4   r5   r   r   r   	functions
elementaryr:   ExprCondPair	Piecewiser   r   r   r   r   r   r   getattr)HANDLERSname r`   c/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/utils/_sympy/interp.pyhandlers7   s   	
 !"#$%&'()*+,6rb   >   r-   r.   r   r    r7   r6   c           
      C   s  t |tjrt |jd tjjjr| |d S t |tr&| 	|d t
jS tdtjdtjdtdtdtdi}||j }d urLt| |g ||R  S |jtju rh|jrht| drh| |}td|| |S t|jd	rs|jj}nt |j }t| |}zB|tv rt|dkrtd
||d |d }t dt|D ]	}	||||	 }qtd||| |W S || }td||| |W S  t!y     t"y   t#d||  w )Nr   r   trunc_to_intfloor_to_intceil_to_intround_to_intsym_sumzsym_sum(%s) -> %s_torch_handler_namezassociative op needs >1 args   z%s(%s) -> %szfailed while executing %s(%s))$
isinstancerK   rW   argscorenumbersHalfsqrtr   to_dtypetorchfloat64r   floorceilingr   r	   r   getfuncr]   rU   
is_integerhasattrrg   r4   debugrh   rb   ASSOCIATIVE_OPSlenAssertionErrorrangeNotImplementedError	Exceptionwarning)
analysisrk   exprindex_dtypeINDEX_DTYPE_HANDLERShandler_namerhandleraccir`   r`   ra   _run_sympy_handler}   sR   




r   r   missing_handlerenvr   c                   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
rD|t }tur:|S r@|S t|t  fdd|jD |dS )Nc              	      s   g | ]}t  |d qS )r   )sympy_interp).0argr   r   r   r   r`   ra   
<listcomp>   s    z sympy_interp.<locals>.<listcomp>)r   )rj   r   rq   boolrK   Integerint64NumberdoubleconstantSymbolru   _nilKeyErrorr   rk   )r   r   r   r   r   dtyper   r`   r   ra   r      s.   	

r   )3__doc__	functoolsloggingtypingr   rK   sympy.logic.boolalgr   SympyBooleanr   rq   rY   r   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__r4   cacherb   rz   r   r   objectr   dictr   Exprr   r`   r`   r`   ra   <module>   s*   	l

B: