
    (Th                        S SK Jr  S SK Jr  SSKJr  SSKJr  \R                  " S5      rS\\	   S\4S	 jr
S
\	S\R                  \/\4   4S jrS
\	S\R                  \/\4   4S jrS
\	S\R                  \/\4   4S jr\R                  \
" / SQS9\" S5      S5S j5       5       5       r\R                  \
" SS/S9\" S5      \R"                  S5S j5       5       5       5       r\R                  \
" SS/S9\" S5      \R"                  S5S j5       5       5       5       r\R                  \
" SS/S9\" S5      \R"                  S5S j5       5       5       5       r\R                  \
" SS/S9\" S5      \R"                  S5S j5       5       5       5       r\R                  \
" SS/S9\" S5      \R"                  S5S j5       5       5       5       r\R                  \
" SS/S9\" S5      \R"                  S5S  j5       5       5       5       r\R                  \
" SS/S9\" S!5      \R"                  S5S" j5       5       5       5       r\R                  \
" S/S9\" S#5      \R"                  S5S$ j5       5       5       5       r\R                  \
" SS/S9\" S%5      \R"                  S5S& j5       5       5       5       r\R"                  \R                  \" S'5      S5S( j5       5       5       r\R                  \" S)5      S6S* j5       5       r\R                  \
" S/S9\" S+5      S5S, j5       5       5       r\R                  \
" SS/S9\" S-5      \R"                  S5S. j5       5       5       5       r\R                  \
" SS/S9\" S/5      \R"                  S5S0 j5       5       5       5       r\R                  \
" SS/S9\" S15      \R"                  S5S2 j5       5       5       5       r \R                  \" S35      S5S4 j5       5       r!g)7   )core)semantic    wraps)ListTdtypesreturnc                    ^  U 4S jnU$ )aT  
We're following libdevice's convention to check accepted data types for math functions.
It is not a good practice to support all data types as accelerators/GPUs don't support
many float16 and bfloat16 math operations.
We should let the users know that they are using and invoke explicit cast to convert
the data type to the supported one.
c                 4   >^  [        T 5      UU 4S j5       nU$ )Nc                    > [        U 5      [        UR                  5       5      -   nU Vs/ s H&  n[        U[        R                  5      (       d  M$  UPM(     sn HV  nUR
                  R                  R                  T;  d  M)  [        ST SUR
                  R                  R                   35      e   T" U 0 UD6$ s  snf )NzExpected dtype z	 but got )	listvalues
isinstancer   tensortypescalarname
ValueError)argskwargsall_argsaargr
   fns        L/var/www/auris/envauris/lib/python3.13/site-packages/triton/language/math.pycheck,_check_dtype.<locals>.wrapper.<locals>.check   s     DzD$99H#+J8az!T[[/I8J88??''v5$vhiH\H\G]%^__ K t&v&& Ks   #B=B=r   )r   r   r
   s   ` r   wrapper_check_dtype.<locals>.wrapper   s     	r	' 
	'      )r
   r    s   ` r   _check_dtyper$   	   s     Nr"   r   c                 0   ^  S[         S[         4U 4S jjnU$ )Nfuncr   c                 4   > SnUR                  TS9U l        U $ )Nzk
    Computes the element-wise {name} of :code:`x`.

    :param x: the input values
    :type x: Block
    r   format__doc__r&   docstrr   s     r   
_decorator)_add_math_1arg_docstr.<locals>._decorator$   s#     }}$}/r"   r	   r   r.   s   ` r   _add_math_1arg_docstrr2   "   s     q  r"   c                 0   ^  S[         S[         4U 4S jjnU$ )Nr&   r   c                 4   > SnUR                  TS9U l        U $ )Nz
    Computes the element-wise {name} of :code:`x` and :code:`y`.

    :param x: the input values
    :type x: Block
    :param y: the input values
    :type y: Block
    r(   r)   r,   s     r   r.   )_add_math_2arg_docstr.<locals>._decorator3   s#     }}$}/r"   r0   r1   s   ` r   _add_math_2arg_docstrr6   1   s    
 
q 
 r"   c                 0   ^  S[         S[         4U 4S jjnU$ )Nr&   r   c                 4   > SnUR                  TS9U l        U $ )Nz
    Computes the element-wise {name} of :code:`x`, :code:`y`, and :code:`z`.

    :param x: the input values
    :type x: Block
    :param y: the input values
    :type y: Block
    :param z: the input values
    :type z: Block
    r(   r)   r,   s     r   r.   )_add_math_3arg_docstr.<locals>._decoratorD   s#    	 }}$}/r"   r0   r1   s   ` r   _add_math_3arg_docstrr:   B   s     q  r"   )int32int64uint32uint64)r
   z-most significant N bits of the 2N-bit productNc                    [         R                  " X5      n [         R                  " X5      n[        R                  " XU5      u  p[        R                  " UR                  U R                  UR                  5      U R                  5      $ N)r   	to_tensorr   binary_op_type_legalizationr   create_umulhihandler   xy_builders      r   umulhirI   U   sb     	1'A1'A++A(;DA;;x--ahhA166JJr"   fp32fp64exponentialc                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   
create_exprD   r   rF   rH   s     r   exprP   _   8    
 	1'A;;x**1884aff==r"   zexponential (base 2)c                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   create_exp2rD   r   rO   s     r   exp2rT   h   8    
 	1'A;;x++AHH5qvv>>r"   znatural logarithmc                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   
create_logrD   r   rO   s     r   logrX   q   rQ   r"   zlogarithm (base 2)c                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   create_log2rD   r   rO   s     r   log2r[   z   rU   r"   cosinec                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   
create_cosrD   r   rO   s     r   cosr_      rQ   r"   sinec                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   
create_sinrD   r   rO   s     r   sinrc      rQ   r"   zfast square rootc                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   create_sqrtrD   r   rO   s     r   sqrtrf      rU   r"   z?precise square root (rounding to nearest wrt the IEEE standard)c                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   create_precise_sqrtrD   r   rO   s     r   sqrt_rnri      s8    
 	1'A;;x33AHH=qvvFFr"   zinverse square rootc                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   create_rsqrtrD   r   rO   s     r   rsqrtrl      8    
 	1'A;;x,,QXX6??r"   zabsolute valuec                    [         R                  " X5      n U R                  nUR                  5       (       at  [        R
                  " U R                  S[        R                  US9n[        R                  " UR                  U R                  UR                  5      U R                  5      $ UR                  5       (       a:  [        R                  " UR                  U R                  5      U R                  5      $ UR                  5       (       a:  [        R                  " UR                  U R                  5      U R                  5      $ UR!                  5       (       a  U $  SU 35       e)N   )rH   zUnexpected dtype )r   rA   dtypeis_fp8e4b15r   fullshapeint8r   
create_andrD   r   is_floatingcreate_fabsis_int_signedcreate_iabsis_int_unsigned)rF   rH   rp   masks       r   absr|      s     	1'AGGEyy$		HE{{8..qxxEqvvNN					{{8//9166BB					{{8//9166BB				 	 1)%11ur"   zfast divisionc                     [         R                  " U5      n[        R                  " X5      n [        R                  " X5      n[        R                  " XX#5      $ r@   )r   _constexpr_to_valuer   rA   fdiv)rF   rG   ieee_roundingrH   s       r   r   r      sE     ,,];M1'A1'A==}77r"   z<precise division (rounding to nearest wrt the IEEE standard)c                    [         R                  " X5      n [         R                  " X5      n[        R                  " XU5      u  p[        R                  " UR                  U R                  UR                  5      U R                  5      $ r@   )r   rA   r   rB   r   create_precise_divfrD   r   rE   s      r   div_rnr      sb     	1'A1'A++A(;DA;;x33AHHahhGPPr"   zerror functionc                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   
create_erfrD   r   rO   s     r   erfr      rQ   r"   floorc                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   create_floorrD   r   rO   s     r   r   r      rm   r"   ceilc                     [         R                  " X5      n [        R                  " UR	                  U R
                  5      U R                  5      $ r@   )r   rA   r   r   create_ceilrD   r   rO   s     r   r   r      rU   r"   zfused multiply-addc                    [         R                  " X5      n [         R                  " X5      n[         R                  " X#5      n[        R                  " XU5      u  p[        R                  " X U5      u  p [        R                  " X!U5      u  p![        R                  " UR                  U R                  UR                  UR                  5      U R                  5      $ r@   )r   rA   r   rB   r   
create_fmarD   r   )rF   rG   zrH   s       r   fmar      s     	1'A1'A1'A++A(;DA++A(;DA++A(;DA;;x**188QXXqxxH!&&QQr"   r@   )FN)" r   r   	functoolsr   typingr   TypeVarr	   strr$   Callabler2   r6   r:   builtinrI   _tensor_member_fnrP   rT   rX   r[   r_   rc   rf   ri   rl   r|   r   r   r   r   r   r   r#   r"   r   <module>r      s      LLc q 2 qc1f(=  qc1f(= " qc1f(= & ;<FGK H = K ff%&}%>  & ' >
 ff%&-.?  / ' ?
 ff%&*+>  , ' >
 ff%&+,?  - ' ?
 ff%&x >  ! ' >
 ff%&v>   ' >
 ff%&)*?  + ' ?
 fXXYG  Z  G
 ff%&,-@  . ' @
 '(2 )  2  '8 ( 8 fXUVQ W  Q ff%&'(>  ) ' >
 ff%&w@    ' @
 ff%&v?   ' ?
 +,R - Rr"   