o
    kiCm                     @   sl   d dl Z d dlZd dlmZmZ d dlmZ dZdZdZ	G dd deZ
G d	d
 d
e
ZG dd de
ZdS )    N)
PRECEDENCE
precedence)
StrPrinterint64_tl             c                   @   s  e Zd ZdZdejdefddZdejdefddZd8dejd	edB defd
dZ	dejdefddZ
dejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefd d!Zdejdefd"d#Zdejdefd$d%Zdejdefd&d'Zdejdefd(d)Zdejdefd*d+Zdejdefd,d-Zdejdefd.d/Zdejdefd0d1Zdejdefd2d3Zdejdefd4d5Zdejdefd6d7ZdS )9ExprPrinter_torch_sympystrexprreturnc                 C      |  |jdt|S )N*	stringifyargsr   selfr	    r   e/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/utils/_sympy/printers.py
_print_Mul      zExprPrinter._print_Mulc                 C      d|  |jd  dS )Nznot (r   )_printr   r   r   r   r   
_print_Not      zExprPrinter._print_NotNorderc                 C   r   )Nz + r   )r   r	   r   r   r   r   
_print_Add   r   zExprPrinter._print_Addc                 C   s   |  |jd|j dt|S )N )r   r   rel_opr   r   r   r   r   _print_Relational   s   zExprPrinter._print_Relationalc                 C      |  |jdtd S )Nz & 
BitwiseAndr   r   r   r   r   r   r   _print_BitwiseFn_bitwise_and    r   z(ExprPrinter._print_BitwiseFn_bitwise_andc                 C   r!   )Nz | 	BitwiseOrr#   r   r   r   r   _print_BitwiseFn_bitwise_or#   r   z'ExprPrinter._print_BitwiseFn_bitwise_orc                 C   r!   )Nz ^ 
BitwiseXorr#   r   r   r   r   _print_BitwiseFn_bitwise_xor&   r   z(ExprPrinter._print_BitwiseFn_bitwise_xorc                 C      |  |jdtd d S N % Atom      ?r#   r   r   r   r   
_print_Mod+      zExprPrinter._print_Modc                 C   s$   |  |jdtd d }d| dS )N / r,   r-   (r   r#   )r   r	   sr   r   r   _print_FloatTrueDiv.   s   zExprPrinter._print_FloatTrueDivc                 C   s
   |  |S N)_print_FloorDivr   r   r   r   _print_CleanDiv2   s   
zExprPrinter._print_CleanDivc                 C      |  |jd S Nr   r   r   r   r   r   _print_Identity5   s   zExprPrinter._print_Identityc                 C   s$   |j dkrttj|ddS t|S )N5      )dps)_precstrsympyFloatr   r   r   r   _print_Float9   s   
zExprPrinter._print_Floatc                 C   s`   |j \}}|t|krt|t|}|dk rtd| |dkr.| |g| dtd S dS )Nr   z#exponent must be non-negative, got r   Mul1)r   intAssertionErrorr   r   r   r	   baseexpr   r   r   
_print_PowJ   s   
zExprPrinter._print_Powc                 C      t dt|  )Nz#_print_ToFloat not implemented for NotImplementedErrortyper   r   r   r   _print_ToFloatZ      zExprPrinter._print_ToFloatc                 C   rJ   )Nz$_print_Infinity not implemented for rK   r   r   r   r   _print_Infinity]   rO   zExprPrinter._print_Infinityc                 C   rJ   )Nz,_print_NegativeInfinity not implemented for rK   r   r   r   r   _print_NegativeInfinity`      z#ExprPrinter._print_NegativeInfinityc                 C   rJ   )Nz$_print_FloorDiv not implemented for rK   r   r   r   r   r5   e   rO   zExprPrinter._print_FloorDivc                 C   rJ   )Nz%_print_PythonMod not implemented for rK   r   r   r   r   _print_PythonModh   rO   zExprPrinter._print_PythonModc                 C   rJ   )Nz&_print_IntTrueDiv not implemented for rK   r   r   r   r   _print_IntTrueDivk   rO   zExprPrinter._print_IntTrueDivc                 C   rJ   )N(_print_PowByNatural not implemented for rK   r   r   r   r   _print_PowByNaturaln   rR   zExprPrinter._print_PowByNaturalc                 C   rJ   )Nz$_print_FloatPow not implemented for rK   r   r   r   r   _print_FloatPows   rO   zExprPrinter._print_FloatPowc                 C   rJ   )Nz&_print_TruncToInt not implemented for rK   r   r   r   r   _print_TruncToIntv   rO   zExprPrinter._print_TruncToIntc                 C   rJ   )Nz&_print_RoundToInt not implemented for rK   r   r   r   r   _print_RoundToInty   rO   zExprPrinter._print_RoundToIntc                 C   rJ   )Nz(_print_RoundDecimal not implemented for rK   r   r   r   r   _print_RoundDecimal|   rR   zExprPrinter._print_RoundDecimalc                 C   rJ   )Nz(_print_TruncToFloat not implemented for rK   r   r   r   r   _print_TruncToFloat   rR   zExprPrinter._print_TruncToFloatr4   ) __name__
__module____qualname__printmethodr?   Exprr>   r   r   r   r    r$   r&   r(   r.   r3   r6   r9   rA   rI   rN   rP   rQ   r5   rS   rT   rV   rW   rX   rY   rZ   r[   r   r   r   r   r      s6    
r   c                   @   s  e Zd ZdejdefddZdejdefddZdejdefddZdejdefd	d
Z	dejdefddZ
dejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefdd Zdejdefd!d"Zdejdefd#d$Zdejdefd%d&Zdejdefd'd(Zdejdefd)d*Zdejdefd+d,Zdejdefd-d.Zdejdefd/d0Zdejdefd1d2Zdejdefd3d4Zdejdefd5d6Zdejdefd7d8Z dejdefd9d:Z!dejdefd;d<Z"dejdefd=d>Z#dejdefd?d@Z$dejdefdAdBZ%dejdefdCdDZ&dejdefdEdFZ'dGS )HPythonPrinterr	   r
   c                 C   .   t |jdkrtdd| |jd  dS )N   $ToFloat expects exactly one argumentztorch.sym_float(r   r   lenr   rE   r   r   r   r   r   rN      s   zPythonPrinter._print_ToFloatc                 C   r   )Nz and r   r   r   r   r   
_print_And   r   zPythonPrinter._print_Andc                 C   r   )Nz or r   r   r   r   r   	_print_Or   r   zPythonPrinter._print_Orc                    sF    fdd|j D \}}}|dkrd| d| d}d| d| dS )Nc                 3   $    | ]}  |td  d V  qdS r,   r-   Nparenthesizer   .0argr   r   r   	<genexpr>       
z7PythonPrinter._print_ModularIndexing.<locals>.<genexpr>rC   r1    // r   r+   r   r   r	   xdivmodr   rp   r   _print_ModularIndexing   s   
z$PythonPrinter._print_ModularIndexingc                 C      dS )Nzmath.infr   r   r   r   r   rP         zPythonPrinter._print_Infinityc                 C   rz   )Nz	-math.infr   r   r   r   r   rQ      r{   z%PythonPrinter._print_NegativeInfinityc                 C   r)   r*   r#   r   r   r   r   rS      r/   zPythonPrinter._print_PythonModc                    s&    fdd|j D \}}| d| S )Nc                 3   ri   rj   rk   rm   rp   r   r   rq      s   " z0PythonPrinter._print_FloorDiv.<locals>.<genexpr>rs   rt   r   r	   rv   rw   r   rp   r   r5      s   zPythonPrinter._print_FloorDivc                 C   r)   )Nr0   r,   r-   r#   r   r   r   r   rT      r/   zPythonPrinter._print_IntTrueDivc                 C   s   d|  | dS )Nz
math.sqrt(r   r   r   r   r   r   _helper_sqrt   s   zPythonPrinter._helper_sqrtc                 C   r7   r8   )r~   r   r   r   r   r   _print_OpaqueUnaryFn_sqrt      z'PythonPrinter._print_OpaqueUnaryFn_sqrtc                 C   r!   Nz ** Powr#   r   r   r   r   rW      r   zPythonPrinter._print_FloatPowc                 C   r!   r   r#   r   r   r   r   rV      r   z!PythonPrinter._print_PowByNaturalc                 C   rb   )Nrc   "floor expects exactly one argumentmath.floor(r   r   re   r   r   r   r   _print_floor      zPythonPrinter._print_floorc                 C   rb   )Nrc   'FloorToInt expects exactly one argumentr   r   r   re   r   r   r   r   _print_FloorToInt   r   zPythonPrinter._print_FloorToIntc                 C   rb   )Nrc   'TruncToInt expects exactly one argumentzmath.trunc(r   r   re   r   r   r   r   rX         zPythonPrinter._print_TruncToIntc                 C   rb   )Nrc   $ceiling expects exactly one argument
math.ceil(r   r   re   r   r   r   r   _print_ceiling   r   zPythonPrinter._print_ceilingc                 C   rb   )Nrc   &CeilToInt expects exactly one argumentr   r   r   re   r   r   r   r   _print_CeilToInt   r   zPythonPrinter._print_CeilToIntc                 C   rb   )Nrc    Abs expects exactly one argumentzabs(r   r   re   r   r   r   r   
_print_Abs   r   zPythonPrinter._print_Absc                 C   2   t |jdk rtdddt| j|j dS )N   z"Max expects at least two argumentszmax(, r   rf   r   rE   joinmapr   r   r   r   r   
_print_Max      zPythonPrinter._print_Maxc                 C   r   )Nr   z"Min expects at least two argumentszmin(r   r   r   r   r   r   r   
_print_Min   r   zPythonPrinter._print_Minc                 C   rb   )Nrc    cos expects exactly one argumentz	math.cos(r   r   re   r   r   r   r   _print_OpaqueUnaryFn_cos  r   z&PythonPrinter._print_OpaqueUnaryFn_cosc                 C   rb   )Nrc   !cosh expects exactly one argumentz
math.cosh(r   r   re   r   r   r   r   _print_OpaqueUnaryFn_cosh
  r   z'PythonPrinter._print_OpaqueUnaryFn_coshc                 C   rb   )Nrc   !acos expects exactly one argumentz
math.acos(r   r   re   r   r   r   r   _print_OpaqueUnaryFn_acos  r   z'PythonPrinter._print_OpaqueUnaryFn_acosc                 C   rb   Nrc   z sin expects exactly one argumentz	math.sin(r   r   re   r   r   r   r   _print_OpaqueUnaryFn_sin  r   z&PythonPrinter._print_OpaqueUnaryFn_sinc                 C   rb   )Nrc   !sinh expects exactly one argumentz
math.sinh(r   r   re   r   r   r   r   _print_OpaqueUnaryFn_sinh  r   z'PythonPrinter._print_OpaqueUnaryFn_sinhc                 C   rb   )Nrc   !asin expects exactly one argumentz
math.asin(r   r   re   r   r   r   r   _print_OpaqueUnaryFn_asin"  r   z'PythonPrinter._print_OpaqueUnaryFn_asinc                 C   rb   )Nrc    tan expects exactly one argumentz	math.tan(r   r   re   r   r   r   r   _print_OpaqueUnaryFn_tan(  r   z&PythonPrinter._print_OpaqueUnaryFn_tanc                 C   rb   )Nrc   !tanh expects exactly one argumentz
math.tanh(r   r   re   r   r   r   r   _print_OpaqueUnaryFn_tanh.  r   z'PythonPrinter._print_OpaqueUnaryFn_tanhc                 C   rb   )Nrc   !atan expects exactly one argumentz
math.atan(r   r   re   r   r   r   r   _print_OpaqueUnaryFn_atan4  r   z'PythonPrinter._print_OpaqueUnaryFn_atanc                 C   rb   )Nrc   z!log2 expects exactly one argumentz
math.log2(r   r   re   r   r   r   r   _print_OpaqueUnaryFn_log2:  r   z'PythonPrinter._print_OpaqueUnaryFn_log2c                 C   rb   )Nrc   'RoundToInt expects exactly one argumentround(r   r   re   r   r   r   r   rY   @  r   zPythonPrinter._print_RoundToIntc                 C   sL   t |jdkrtd|j\}}t|tjstdd| | d| dS )Nr   *RoundDecimal expects exactly two argumentsz,ndigits must be an instance of sympy.Integerr   r   r   )rf   r   rE   
isinstancer?   Integer	TypeErrorr   )r   r	   numberndigitsr   r   r   rZ   F  s   
z!PythonPrinter._print_RoundDecimalc                 C   sl   d }t |jD ](\}}| |}|dkr|}q| |}|d u r#|}qd| d| d| d}q|r4|S dS )NTr1   z if z else r   0)reversedr   r   r   r	   resultexpr_icond_iexpr_strcond_strr   r   r   _print_PiecewiseO  s   

zPythonPrinter._print_PiecewiseN)(r\   r]   r^   r?   r`   r>   rN   rg   rh   ry   rP   rQ   rS   r5   rT   r~   r   rW   rV   r   r   rX   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rY   rZ   r   r   r   r   r   ra      sF    		ra   c                   @   s  e Zd ZdejdefddZdejdefddZdejdefddZdejdefd	d
Z	dejdefddZ
dejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefddZdejdefdd Zdejdefd!d"Zdejdefd#d$Zdejdefd%d&Zdejdefd'd(Zdejdefd)d*Zdejdefd+d,Zdejdefd-d.Zdejdefd/d0Zdejdefd1d2Zdejdefd3d4Zdejdefd5d6Zdejdefd7d8Z dejdefd9d:Z!dejdefd;d<Z"dejdefd=d>Z#dejdefd?d@Z$dejdefdAdBZ%dejdefdCdDZ&dejdefdEdFZ'dejdefdGdHZ(dejdefdIdJZ)dejdefdKdLZ*dejdefdMdNZ+dOS )P
CppPrinterr	   r
   c                 C   sl   t jdv rdnd}t|}|tks|tk rt| dt |tkr0|dkr*tdd| dS | | S )	N)darwinwin32LLLz too big to convert to r   z#unexpected minimum index type valuez(-1z << 63))sysplatformrD   INDEX_TYPE_MAXINDEX_TYPE_MINOverflowError
INDEX_TYPErE   )r   r	   suffixir   r   r   _print_Integere  s   zCppPrinter._print_Integerc                    s.    fdd|j D \}}}| d| d| S )Nc                 3   ri   rj   rk   rm   rp   r   r   rq   s  rr   z*CppPrinter._print_Where.<locals>.<genexpr> ?  : rt   )r   r	   cpqr   rp   r   _print_Wherer  s   
zCppPrinter._print_Wherec                 C   s   d }t |jD ]0\}}| |td d }|dkr|}q| |td d }|d u r-|}q| d| d| }q|r@d| dS dS )	Nr,   r-   Tr   r   r1   r   r   )r   r   rl   r   r   r   r   r   r   x  s   zCppPrinter._print_Piecewisec              	   C   s|   |j \}}}| |}|dkr*| |}|jr!d| d| d}n	d| d| d}| |}dt d| d	t d| d	S )
Nrc   ,c10::div_floor_integer(static_cast<int64_t>(), static_cast<int64_t>()),c10::div_floor_floating(static_cast<double>(), static_cast<double>(z(static_cast<>(z) % static_cast<)r   doprint
is_integerr   ru   r   r   r   ry     s   


z!CppPrinter._print_ModularIndexingc                 C   sH   |j \}}| |}| |}|jrd| d| dS d| d| dS )Nr   r   r   r   r   )r   r   r   r|   r   r   r   r5     s   


zCppPrinter._print_FloorDivc                 C   J   t |jdkrtdd| |jd  d}|jr#dt d| dS |S )Nrc   r   std::floor(r   r   static_cast<r   rf   r   rE   r   r   r   r   r	   rr   r   r   r        zCppPrinter._print_floorc                 C   r   )Nrc   r   r   r   r   r   r   r   r   r   r   r   r     r   zCppPrinter._print_FloorToIntc                 C   s@   t |jdkrtdd| |jd  d}dt d| dS )Nrc   r   std::trunc(r   r   r   r   )rf   r   rE   r   r   r   r   r   r   rX     s   zCppPrinter._print_TruncToIntc                 C   rb   )Nrc   z)TruncToFloat expects exactly one argumentr   r   r   re   r   r   r   r   r[     r   zCppPrinter._print_TruncToFloatc                 C   rb   )Nrc   rd   static_cast<double>(r   r   re   r   r   r   r   rN     r   zCppPrinter._print_ToFloatc                 C   s0   |j \}}| |}| |}d| d| dS )Nzc10::div_mod(r   r   )r   r   r|   r   r   r   rS     s   


zCppPrinter._print_PythonModc                 C   (   |j \}}d| | d| | dS )Nr   z) / static_cast<double>(r   r   r   )r   r	   lhsrhsr   r   r   rT     s   
zCppPrinter._print_IntTrueDivc                 C   s6   |j \}}|dkrd| | dS tdt|  )Nr   z(1 << (r   rU   )r   r   rL   rM   rF   r   r   r   rV     s   
zCppPrinter._print_PowByNaturalc                 C   r   )N	std::pow(r   r   r   rF   r   r   r   rW     s   
zCppPrinter._print_FloatPowc                 C   s   |j \}}|dks|dkr"| |}|dkrd| dS d| dS |jrmt|}|dkr:| |g| dtd }n%|d	k rQd
| |gt| dtd  d }n|d	kr]d| | }nd}|jrkdt d| dS |S d| dt| dS )Nr-   g      
std::sqrt(r   z1.0/std::sqrt(r   r   rB   z1.0/(z1.0/z1.0r   r   r   r   )	r   r   r   rD   r   r   absr   float)r   r	   rG   rH   r   r   r   r   rI     s(   

 zCppPrinter._print_Powc                 C   sD   |j dkr
|j }n
|j d|j  d}|jr dt d| dS |S )Nrc   z.0/z.0r   r   r   )r   r   r   r   r   r   r   r   _print_Rational  s   

zCppPrinter._print_Rationalc                 C   r   )Nrc   r   
std::ceil(r   r   r   r   r   r   r   r   r   r     r   zCppPrinter._print_ceilingc                 C   r   )Nrc   r   r   r   r   r   r   r   r   r   r   r   r     r   zCppPrinter._print_CeilToIntc              	      j    fdd|j D }t|dkr#dt d|d  dt d|d  d		S d
d| d }dt d| dS )Nc                       g | ]}  |qS r   r}   rn   arp   r   r   
<listcomp>      z)CppPrinter._print_Min.<locals>.<listcomp>r   zstd::min(static_cast<r   r   ), static_cast<rc   r   {r   }z	std::min<r   r   rf   r   r   r   r	   r   ilr   rp   r   r     
   &zCppPrinter._print_Minc              	      r   )Nc                    r   r   r}   r   rp   r   r   r     r   z)CppPrinter._print_Max.<locals>.<listcomp>r   zstd::max(static_cast<r   r   r   rc   r   r   r   r   z	std::max<r   r   r   r   rp   r   r     r   zCppPrinter._print_Maxc                 C   rb   )Nrc   r   z	std::abs(r   r   re   r   r   r   r   r   #  r   zCppPrinter._print_Absc                 C   rb   )Nrc   r   z	std::cos(r   r   re   r   r   r   r   r   )  r   z#CppPrinter._print_OpaqueUnaryFn_cosc                 C   rb   )Nrc   r   z
std::cosh(r   r   re   r   r   r   r   r   /  r   z$CppPrinter._print_OpaqueUnaryFn_coshc                 C   rb   )Nrc   r   z
std::acos(r   r   re   r   r   r   r   r   5  r   z$CppPrinter._print_OpaqueUnaryFn_acosc                 C   rb   r   re   r   r   r   r   r   ;  r   z#CppPrinter._print_OpaqueUnaryFn_sinc                 C   rb   )Nrc   r   z
std::sinh(r   r   re   r   r   r   r   r   A  r   z$CppPrinter._print_OpaqueUnaryFn_sinhc                 C   rb   )Nrc   r   z
std::asin(r   r   re   r   r   r   r   r   G  r   z$CppPrinter._print_OpaqueUnaryFn_asinc                 C   rb   )Nrc   r   z	std::tan(r   r   re   r   r   r   r   r   M  r   z#CppPrinter._print_OpaqueUnaryFn_tanc                 C   rb   )Nrc   r   z
std::tanh(r   r   re   r   r   r   r   r   S  r   z$CppPrinter._print_OpaqueUnaryFn_tanhc                 C   rb   )Nrc   r   z
std::atan(r   r   re   r   r   r   r   r   Y  r   z$CppPrinter._print_OpaqueUnaryFn_atanc                 C   r   )Nr   r   r   r   r   r   r   r   r   _  r   z$CppPrinter._print_OpaqueUnaryFn_sqrtc                 C   r   )Nz
std::log2(r   r   r   r   r   r   r   r   c  r   z$CppPrinter._print_OpaqueUnaryFn_log2c                 C   rb   )Nrc   r   zstd::lrint(r   r   re   r   r   r   r   rY   g  r   zCppPrinter._print_RoundToIntc                 C   sp   t |jdkrtd|j\}}|jr#|dkrtdtd| d| |td }d| d	| d
|  dS )Nr   r   r   z+ndigits must be negative for integer inputszOFor integer inputs, only non-negative ndigits are currently supported, but got .rB   z%static_cast<double>(std::nearbyint(1ez * z) * 1er   )rf   r   rE   r   
ValueErrorrl   r   )r   r	   r   r   
number_strr   r   r   rZ   n  s   

zCppPrinter._print_RoundDecimalc                 C   rz   )Ntruer   r   r   r   r   _print_BooleanTrue|  r{   zCppPrinter._print_BooleanTruec                 C   rz   )Nfalser   r   r   r   r   _print_BooleanFalse  r{   zCppPrinter._print_BooleanFalsec                 C   rz   )Nz'std::numeric_limits<double>::infinity()r   r   r   r   r   rP     r{   zCppPrinter._print_Infinityc                 C   s   d|  | S )N-)rP   r   r   r   r   rQ     r   z"CppPrinter._print_NegativeInfinityN),r\   r]   r^   r?   r`   r>   r   r   r   ry   r5   r   r   rX   r[   rN   rS   rT   rV   rW   rI   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rY   rZ   r   r  rP   rQ   r   r   r   r   r   d  sN    


r   )r   r?   sympy.printing.precedencer   r   sympy.printing.strr   r   r   r   r   ra   r   r   r   r   r   <module>   s    } Y