
    i"7                     ,   d dl Z d dlZd dlmZ d dl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  G d d      Z G d de      Z G d d	e      Zd
ej<                  dej>                  dej<                  fdZ  G d d      Z!y)    N)NoReturn)_keep_floatBitwiseFn_bitwise_andBitwiseFn_bitwise_orBitwiseFn_bitwise_xorFloatPowFloatTrueDivFloorDiv
IntTrueDivMaxMinModOpaqueUnaryFn_expOpaqueUnaryFn_logOpaqueUnaryFn_log2OpaqueUnaryFn_sqrtPowByNaturalRoundDecimal
RoundToIntToFloat
TruncToIntc                      e Zd Zed        Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed        Zed	        Zed
        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zedefd       Zed        Zed        Z ed        Z!ed        Z"ed        Z#ed         Z$ed!        Z%ed"        Z&ed#        Z'ed$        Z(ed%        Z)ed&        Z*ed'        Z+ed(        Z,ed)        Z-ed*        Z.ed+        Z/y,)-ReferenceAnalysisc                 ,    t        j                  |       S N)sympysympifycdtypes     V/var/www/html/engine/venv/lib/python3.12/site-packages/torch/utils/_sympy/reference.pyconstantzReferenceAnalysis.constant(       }}Q    c                     | |z  S r    abs     r!   or_zReferenceAnalysis.or_,       1ur$   c                     | |z  S r   r&   r'   s     r!   and_zReferenceAnalysis.and_0   r+   r$   c                     t        | t        j                        st        |t        j                        rt        j                  | |      S | |k(  S r   )
isinstancer   ExprEqr'   s     r!   eqzReferenceAnalysis.eq4   s6    a$
1ejj(A88Aq>!Avr$   c                 D    | j                  | j                  ||            S r   )not_r2   clsr(   r)   s      r!   nezReferenceAnalysis.ne:   s    xxq!%%r$   c                     | |k  S r   r&   r'   s     r!   ltzReferenceAnalysis.lt>   r+   r$   c                     | |kD  S r   r&   r'   s     r!   gtzReferenceAnalysis.gtB   r+   r$   c                     | |k  S r   r&   r'   s     r!   lezReferenceAnalysis.leF       Avr$   c                     | |k\  S r   r&   r'   s     r!   gezReferenceAnalysis.geJ   r>   r$   c                 >    t        | t              rt        d      |  S )Nznot_ needs sympy expr)r/   boolAssertionErrorr(   s    r!   r4   zReferenceAnalysis.not_N   s    a !899r	r$   c                     t        d|       S )Ng      ?r	   xs    r!   
reciprocalzReferenceAnalysis.reciprocalT   s    C##r$   c                     t        | d      S )N   r   rG   s    r!   squarezReferenceAnalysis.squareX       Aq!!r$   c                     t        |       S r   )r   rH   r    s     r!   trunc_to_intzReferenceAnalysis.trunc_to_int\       !}r$   c                 ,    t        j                  |       S r   )r   ceilingrP   s     r!   ceil_to_intzReferenceAnalysis.ceil_to_int`   r#   r$   c                 ,    t        j                  |       S r   )r   floorrP   s     r!   floor_to_intzReferenceAnalysis.floor_to_intd   s    {{1~r$   c                 @     t        t        j                        |       S r   )r   r   rW   rG   s    r!   rW   zReferenceAnalysis.floorh   s    '{5;;'**r$   c                 @     t        t        j                        |       S r   )r   r   rT   rG   s    r!   ceilzReferenceAnalysis.ceill   s    ){5==)!,,r$   c                 \    |t         j                  k(  rt        |       S t        d| d      Nz	to_dtype z NYI)torchfloat64r   NotImplementedErrorrP   s     r!   to_dtypezReferenceAnalysis.to_dtypep   s,    EMM!1:!IeWD"9::r$   c                     t        | |      S r   )r   rH   ys     r!   modzReferenceAnalysis.modv       1ayr$   c                     t        |       S r   )absrG   s    r!   rh   zReferenceAnalysis.absz   s    1vr$   c                     |  S r   r&   rG   s    r!   negzReferenceAnalysis.neg~   s	    r	r$   c                     t        | |      S r   rF   r'   s     r!   truedivzReferenceAnalysis.truediv   rN   r$   c                     t        | |      S r   )r   r'   s     r!   int_truedivzReferenceAnalysis.int_truediv   s    !Qr$   c                     t        | |      S r   )r
   r'   s     r!   floordivzReferenceAnalysis.floordiv   s    1~r$   returnc                     t        d      )NzTODO: truncdivr`   r'   s     r!   truncdivzReferenceAnalysis.truncdiv   s    !"233r$   c                 B     t        t        j                        | |      S r   )r   operatoraddr'   s     r!   rw   zReferenceAnalysis.add       ({8<<(A..r$   c                 &    t        j                  | S r   )r   Add)r6   argss     r!   sym_sumzReferenceAnalysis.sym_sum   s    yy$r$   c                 B     t        t        j                        | |      S r   )r   rv   mulr'   s     r!   r~   zReferenceAnalysis.mul   rx   r$   c                 B     t        t        j                        | |      S r   )r   rv   subr'   s     r!   r   zReferenceAnalysis.sub   rx   r$   c                     t        |       S r   )r   rG   s    r!   expzReferenceAnalysis.exp        ##r$   c                     t        |       S r   )r   rG   s    r!   logzReferenceAnalysis.log   r   r$   c                     t        |       S r   )r   rG   s    r!   log2zReferenceAnalysis.log2       !!$$r$   c                     t        |       S r   )r   rG   s    r!   sqrtzReferenceAnalysis.sqrt   r   r$   c                 .     t        t              | |      S r   )r   r   r'   s     r!   powzReferenceAnalysis.pow   s     %{8$Q**r$   c                     t        | |      S r   rL   r'   s     r!   pow_by_naturalz ReferenceAnalysis.pow_by_natural   rN   r$   c                     t        | |      S r   )r   r'   s     r!   minimumzReferenceAnalysis.minimum   rf   r$   c                     t        | |      S r   )r   r'   s     r!   maximumzReferenceAnalysis.maximum   rf   r$   c                     t        |       S r   )r   r(   r    s     r!   round_to_intzReferenceAnalysis.round_to_int   rR   r$   c                     t        | |      S r   )r   r'   s     r!   round_decimalzReferenceAnalysis.round_decimal   rN   r$   c                     t        | |      S r   )r   r'   s     r!   bitwise_andzReferenceAnalysis.bitwise_and       $Q**r$   c                     t        | |      S r   )r   r'   s     r!   
bitwise_orzReferenceAnalysis.bitwise_or   s    #Aq))r$   c                     t        | |      S r   )r   r'   s     r!   bitwise_xorzReferenceAnalysis.bitwise_xor   r   r$   N)0__name__
__module____qualname__staticmethodr"   r*   r-   r2   classmethodr7   r9   r;   r=   r@   r4   rI   rM   rQ   rU   rX   rW   r[   ra   re   rh   rj   rl   rn   rp   r   rt   rw   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&   r$   r!   r   r   '   sO            
 & &          
 $ $ " "         + + - - ; ;
       " "       4( 4 4 / /     / / / / $ $ $ $ % % % % + + " "       " " + + * * + +r$   r   c                      e Zd Zed        Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed        Zed	efd
       Zed	efd       Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zy)PythonReferenceAnalysisc                     |t         j                  u rt        |       S |t         j                  u rt	        |       S |t         j
                  u rt        |       S t        d|       )Nunrecognized dtype )r^   int64intdoublefloatrB   rC   r   s     r!   r"   z PythonReferenceAnalysis.constant   sT    EKKq6Mell"8Oejj 7N #6ug!>??r$   c                 ,    t        j                  |       S r   )r^   sym_notrD   s    r!   r4   zPythonReferenceAnalysis.not_   r#   r$   c                     t        |      dk(  ryt        |      dk(  r|d   S | j                  |d   |d         }t        dt        |            D ]  }| j                  |||         } |S )Nr      rK   )lenrw   range)r6   r{   accis       r!   r|   zPythonReferenceAnalysis.sym_sum   so    t9>t9>7Nggd1gtAw'q#d)$ 	(A''#tAw'C	(
r$   c                     | |z  S r   r&   r'   s     r!   rp   z PythonReferenceAnalysis.floordiv   r>   r$   c                     | |z  S r   r&   rc   s     r!   re   zPythonReferenceAnalysis.mod   r+   r$   c                     | |z  S r   r&   rc   s     r!   
python_modz"PythonReferenceAnalysis.python_mod   r+   r$   c                     | |z  S r   r&   r'   s     r!   rt   z PythonReferenceAnalysis.truncdiv  r+   r$   c                 p    |t         j                  k(  rt        j                  |       S t        d| d      r]   )r^   r_   	sym_floatr`   rP   s     r!   ra   z PythonReferenceAnalysis.to_dtype  s1    EMM!??1%%!IeWD"9::r$   rq   c                     t        d      )Nz!exp is not valid shape sympy exprrC   rG   s    r!   r   zPythonReferenceAnalysis.exp      @AAr$   c                     t        d      )Nz!log is not valid shape sympy exprr   rG   s    r!   r   zPythonReferenceAnalysis.log  r   r$   c                 ,    t        j                  |       S r   )r^   	_sym_log2rG   s    r!   r   zPythonReferenceAnalysis.log2      q!!r$   c                 ,    t        j                  |       S r   )r^   	_sym_sqrtrG   s    r!   r   zPythonReferenceAnalysis.sqrt  r   r$   c                 .    t        j                  | |      S r   )r^   sym_minr'   s     r!   r   zPythonReferenceAnalysis.minimum      }}Q""r$   c                 .    t        j                  | |      S r   )r^   sym_maxr'   s     r!   r   zPythonReferenceAnalysis.maximum   r   r$   c                 ,    t        j                  |       S r   )mathrW   rP   s     r!   rX   z$PythonReferenceAnalysis.floor_to_int$  s    zz!}r$   c                 ,    t        j                  |       S r   )r   r[   rP   s     r!   rU   z#PythonReferenceAnalysis.ceil_to_int(  s    yy|r$   c                 >    t        t        j                  |             S r   )r   r   rW   rG   s    r!   rW   zPythonReferenceAnalysis.floor,  s    TZZ]##r$   c                 >    t        t        j                  |             S r   )r   r   r[   rG   s    r!   r[   zPythonReferenceAnalysis.ceil0  s    TYYq\""r$   c                     | |z  S r   r&   r'   s     r!   rl   zPythonReferenceAnalysis.truediv4  r+   r$   c                     | |z  S r   r&   r'   s     r!   r   zPythonReferenceAnalysis.pow8  s    !tr$   c                     | |z  S r   r&   r'   s     r!   r   z&PythonReferenceAnalysis.pow_by_natural<  s    
 !tr$   c                     t        |       S r   roundr   s     r!   r   z$PythonReferenceAnalysis.round_to_intC  s    Qxr$   c                     t        | |      S )N)ndigitsr   r'   s     r!   r   z%PythonReferenceAnalysis.round_decimalG  s    Q""r$   c                     | |z  S r   r&   r'   s     r!   r   z#PythonReferenceAnalysis.bitwise_andK  r+   r$   c                     | |z  S r   r&   r'   s     r!   r   z"PythonReferenceAnalysis.bitwise_orO  r+   r$   c                     | |z  S r   r&   r'   s     r!   r   z#PythonReferenceAnalysis.bitwise_xorS  r+   r$   N) r   r   r   r   r"   r4   r   r|   rp   re   r   rt   ra   r   r   r   r   r   r   r   rX   rU   rW   r[   rl   r   r   r   r   r   r   r   r&   r$   r!   r   r      s   @ @               ; ;
 B( B B B( B B " " " " # # # #     $ $ # #         # #      r$   r   c                       e Zd Zed        Zy) OptimizedPythonReferenceAnalysisc                 ,    t        j                  |       S r   )r^   r|   )r{   s    r!   r|   z(OptimizedPythonReferenceAnalysis.sym_sum[  s    }}T""r$   N)r   r   r   r   r|   r&   r$   r!   r   r   Z  s    # #r$   r   rH   r    rq   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   opsprimsconvert_element_typedefaultrP   s     r!   	_to_dtyper   `  s#    99??//775AAr$   c                   >   e Zd Zed        Zed        Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zedefd       Zed        Zed        Zed        Zed        Zed        Z edefd       Z!ed        Z"ed        Z#ed         Z$ed!        Z%ed"        Z&ed#        Z'ed$        Z(ed%        Z)ed&        Z*ed'        Z+ed(        Z,ed)        Z-ed*        Z.ed+        Z/ed,        Z0ed-        Z1ed.        Z2ed/        Z3ed0        Z4ed1        Z5ed2        Z6edefd3       Z7y4)5TensorReferenceAnalysisc                 <   |t         j                  u rt        |       }nJ|t         j                  u rt	        |       }n,|t         j
                  u rt        |       }nt        d|       t         j                  j                  j                  j                  ||      S )Nr   )r    )r^   r   r   r   r   rB   rC   r   atenscalar_tensorr   )r   r    ds      r!   r"   z TensorReferenceAnalysis.constantu  sz     EKKAAell"aAejj QA #6ug!>??yy~~++33AU3CCr$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   
logical_orr   r'   s     r!   r*   zTensorReferenceAnalysis.or_  s#    yy~~((00A66r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   logical_andr   r'   s     r!   r-   zTensorReferenceAnalysis.and_  s#    yy~~))11!Q77r$   c                 V    t         j                  j                  j                  | |      S r   )r^   r   r   r   r'   s     r!   r   z#TensorReferenceAnalysis.bitwise_and      yy~~))!Q//r$   c                 V    t         j                  j                  j                  | |      S r   )r^   r   r   r   r'   s     r!   r   z"TensorReferenceAnalysis.bitwise_or  s    yy~~((A..r$   c                 V    t         j                  j                  j                  | |      S r   )r^   r   r   r   r'   s     r!   r   z#TensorReferenceAnalysis.bitwise_xor  r   r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   r2   Tensorr'   s     r!   r2   zTensorReferenceAnalysis.eq  #    yy~~  ''1--r$   c                 j    t         j                  j                  j                  j	                  ||      S r   )r^   r   r   r7   r   r5   s      r!   r7   zTensorReferenceAnalysis.ne  r   r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   r9   r   r'   s     r!   r9   zTensorReferenceAnalysis.lt  r   r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   r;   r   r'   s     r!   r;   zTensorReferenceAnalysis.gt  r   r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   r=   r   r'   s     r!   r=   zTensorReferenceAnalysis.le  r   r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   r@   r   r'   s     r!   r@   zTensorReferenceAnalysis.ge  r   r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   logical_notr   rD   s    r!   r4   zTensorReferenceAnalysis.not_  s!    yy~~))11!44r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   rI   r   rG   s    r!   rI   z"TensorReferenceAnalysis.reciprocal  s!    yy~~((0033r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   rM   r   rG   s    r!   rM   zTensorReferenceAnalysis.square  s#     yy~~$$,,Q//r$   c                 |    t        t        j                  j                  j                  j                  |       |      S r   )r   r^   r   r   truncr   rP   s     r!   rQ   z$TensorReferenceAnalysis.trunc_to_int  (    --55a8%@@r$   c                 |    t        t        j                  j                  j                  j                  |       |      S r   )r   r^   r   r   r[   r   rP   s     r!   rU   z#TensorReferenceAnalysis.ceil_to_int  s(    ,,44Q7??r$   c                 |    t        t        j                  j                  j                  j                  |       |      S r   )r   r^   r   r   rW   r   rP   s     r!   rX   z$TensorReferenceAnalysis.floor_to_int  r   r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   rW   r   rG   s    r!   rW   zTensorReferenceAnalysis.floor  !    yy~~##++A..r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   r[   r   rG   s    r!   r[   zTensorReferenceAnalysis.ceil  !    yy~~""**1--r$   c                     t        | |      S r   )r   rP   s     r!   ra   z TensorReferenceAnalysis.to_dtype  s    E""r$   rq   c                     t        d      )Nz8no C-style modulus operation available from frontend atmrs   rc   s     r!   re   zTensorReferenceAnalysis.mod  s     "F
 	
r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   rh   r   rG   s    r!   rh   zTensorReferenceAnalysis.abs  !    yy~~!!))!,,r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   rj   r   rG   s    r!   rj   zTensorReferenceAnalysis.neg  r  r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   true_divider   r'   s     r!   rl   zTensorReferenceAnalysis.truediv  s#    yy~~))00A66r$   c                     t        d      )Nz8Python int truediv difficult to implement in PyTorch atm)r`   r^   r   r   r  r   r   r_   r'   s     r!   rn   z#TensorReferenceAnalysis.int_truediv      !F
 	
r$   c                 n    t         j                  j                  j                  j	                  | |d      S )NrW   )rounding_mode)r^   r   r   divTensor_moder'   s     r!   rp   z TensorReferenceAnalysis.floordiv  s(    yy~~!!--a'-JJr$   c                     t        d      )Nz9no C-style truncdiv operation available from frontend atmrs   r'   s     r!   rt   z TensorReferenceAnalysis.truncdiv  s    !G
 	
r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   rw   r   r'   s     r!   rw   zTensorReferenceAnalysis.add  #    yy~~!!((A..r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   r~   r   r'   s     r!   r~   zTensorReferenceAnalysis.mul  r  r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   r   r   r'   s     r!   r   zTensorReferenceAnalysis.sub  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   r   r   rG   s    r!   r   zTensorReferenceAnalysis.exp	  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   r   r   rG   s    r!   r   zTensorReferenceAnalysis.log  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   r   r   rG   s    r!   r   zTensorReferenceAnalysis.log2  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   r   r   rG   s    r!   r   zTensorReferenceAnalysis.sqrt  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   sinr   rG   s    r!   r  zTensorReferenceAnalysis.sin  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   cosr   rG   s    r!   r  zTensorReferenceAnalysis.cos  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   tanhr   rG   s    r!   r   zTensorReferenceAnalysis.tanh!  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   sinhr   rG   s    r!   r"  zTensorReferenceAnalysis.sinh%  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   coshr   rG   s    r!   r$  zTensorReferenceAnalysis.cosh)  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   tanr   rG   s    r!   r&  zTensorReferenceAnalysis.tan-  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   acosr   rG   s    r!   r(  zTensorReferenceAnalysis.acos1  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   atanr   rG   s    r!   r*  zTensorReferenceAnalysis.atan5  r  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   asinr   rG   s    r!   r,  zTensorReferenceAnalysis.asin9  r  r$   c                 j    t         j                  j                  j                  j	                  | |      S r   r^   r   r   r   Tensor_Tensorr'   s     r!   r   zTensorReferenceAnalysis.pow=  s#    yy~~!!//155r$   c                 j    t         j                  j                  j                  j	                  | |      S r   r.  r'   s     r!   r   z&TensorReferenceAnalysis.pow_by_naturalA  s%     yy~~!!//155r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   r   r   r'   s     r!   r   zTensorReferenceAnalysis.minimumF  #    yy~~%%--a33r$   c                 j    t         j                  j                  j                  j	                  | |      S r   )r^   r   r   r   r   r'   s     r!   r   zTensorReferenceAnalysis.maximumJ  r2  r$   c                 h    t         j                  j                  j                  j	                  |       S r   )r^   r   r   r   r   r   s     r!   r   z$TensorReferenceAnalysis.round_to_intN  r  r$   c                     t        d      )Nz8round decimal doesn't support Tensor second argument atmrs   r'   s     r!   r   z%TensorReferenceAnalysis.round_decimalR  r  r$   N)8r   r   r   r   r"   r*   r-   r   r   r   r2   r   r7   r9   r;   r=   r@   r4   rI   rM   rQ   rU   rX   rW   r[   ra   r   re   rh   rj   rl   rn   rp   rt   rw   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   r   r  s	    
D 
D 7 7 8 8 0 0 / / 0 0 . . . . . . . . . . . . 5 5 4 4 0 0 A A @ @ A A / / . . # # 
X 
 
 - - - - 7 7 

 

 K K 
( 
 

 / / / / / / - - - - . . . . - - - - . . . . . . - - . . . . . . 6 6 6 6 4 4 4 4 / / 
x 
 
r$   r   )"r   rv   typingr   r   r^   torch.utils._sympy.functionsr   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   r   r&   r$   r!   <module>r8     s             <n+ n+hz/ z~#'> #B Bekk Bell B$d
 d
r$   