
    9i                        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      S4S j5       5       5       r\R                  \	" SS/S9\" S5      \R                   S4S j5       5       5       5       r\R                  \	" SS/S9\" S5      \R                   S4S j5       5       5       5       r\R                  \	" SS/S9\" S5      \R                   S4S j5       5       5       5       r\R                  \	" SS/S9\" S5      \R                   S4S j5       5       5       5       r\R                  \	" SS/S9\" S5      \R                   S4S j5       5       5       5       r\R                  \	" SS/S9\" S5      \R                   S4S j5       5       5       5       r\R                  \	" SS/S9\" S 5      \R                   S4S! j5       5       5       5       r\R                  \	" S/S9\" S"5      \R                   S4S# j5       5       5       5       r\R                  \	" SS/S9\" S$5      \R                   S4S% j5       5       5       5       r\R                   \R                  \" S&5      S4S' j5       5       5       r\R                  \" S(5      S5S) j5       5       r\R                  \	" S/S9\" S*5      S4S+ j5       5       5       r\R                  \	" SS/S9\" S,5      \R                   S4S- j5       5       5       5       r\R                  \	" SS/S9\" S.5      \R                   S4S/ j5       5       5       5       r\R                  \	" SS/S9\" S05      \R                   S4S1 j5       5       5       5       r\R                  \" S25      S4S3 j5       5       r g)6   )core    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        T/var/www/html/land-doc-ocr/venv/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_docstrr1   !   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>._decorator2   s#     }}$}/r!   r/   r0   s   ` r   _add_math_2arg_docstrr5   0   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>._decoratorC   s#    	 }}$}/r!   r/   r0   s   ` r   _add_math_3arg_docstrr9   A   s     q  r!   )int32int64uint32uint64)r	   z-most significant N bits of the 2N-bit productNc                    UR                  U 5      n UR                  U5      n[        R                  " XU5      u  p[        R                  " UR                  R                  U R                  UR                  5      U R                  5      $ N)	to_tensorr   binary_op_type_legalizationr   buildercreate_umulhihandler   xy	_semantics      r   umulhirI   T   sh     	AAAA++A)<DA;;y((66qxxJAFFSSr!   fp32fp64exponentialc                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   
create_exprD   r   rF   rH   s     r   exprP   ^   >    
 	AA;;y((33AHH=qvvFFr!   zexponential (base 2)c                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   create_exp2rD   r   rO   s     r   exp2rT   g   >    
 	AA;;y((44QXX>GGr!   znatural logarithmc                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   
create_logrD   r   rO   s     r   logrX   p   rQ   r!   zlogarithm (base 2)c                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   create_log2rD   r   rO   s     r   log2r[   y   rU   r!   cosinec                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   
create_cosrD   r   rO   s     r   cosr_      rQ   r!   sinec                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   
create_sinrD   r   rO   s     r   sinrc      rQ   r!   zfast square rootc                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   create_sqrtrD   r   rO   s     r   sqrtrf      rU   r!   z?precise square root (rounding to nearest wrt the IEEE standard)c                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   create_precise_sqrtrD   r   rO   s     r   sqrt_rnri      s>    
 	AA;;y((<<QXXFOOr!   zinverse square rootc                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   create_rsqrtrD   r   rO   s     r   rsqrtrl      >    
 	AA;;y((55ahh?HHr!   zabsolute valuec                    UR                  U 5      n U R                  nUR                  5       (       a~  [        R                  " U R
                  S[        R                  US9n[        R                  " UR                  R                  U R                  UR                  5      U R                  5      $ UR                  5       (       aD  [        R                  " UR                  R                  U R                  5      U R                  5      $ UR                  5       (       aD  [        R                  " UR                  R                  U R                  5      U R                  5      $ UR!                  5       (       a  U $  SU 35       e)N   )rH   zUnexpected dtype )r@   dtypeis_fp8e4b15r   fullshapeint8r   rB   
create_andrD   r   is_floatingcreate_fabsis_int_signedcreate_iabsis_int_unsigned)rF   rH   rp   masks       r   absr|      s    	AAGGEyy$		YG{{9,,77$++NPQPVPVWW					{{9,,88BAFFKK					{{9,,88BAFFKK				 	 1)%11ur!   zfast divisionc                     [         R                  " U5      nUR                  U 5      n UR                  U5      nUR                  XU5      $ r?   )r   _unwrap_if_constexprr@   fdiv)rF   rG   ieee_roundingrH   s       r   r   r      sE     --m<MAAAA>>!..r!   z<precise division (rounding to nearest wrt the IEEE standard)c                    UR                  U 5      n UR                  U5      n[        R                  " XU5      u  p[        R                  " UR                  R                  U R                  UR                  5      U R                  5      $ r?   )r@   r   rA   r   rB   create_precise_divfrD   r   rE   s      r   div_rnr      sk     	AAAA++A)<DA;;y((<<QXXqxxPRSRXRXYYr!   zerror functionc                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   
create_erfrD   r   rO   s     r   erfr      rQ   r!   floorc                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   create_floorrD   r   rO   s     r   r   r      rm   r!   ceilc                     UR                  U 5      n [        R                  " UR                  R	                  U R
                  5      U R                  5      $ r?   )r@   r   r   rB   create_ceilrD   r   rO   s     r   r   r      rU   r!   zfused multiply-addc                    UR                  U 5      n UR                  U5      nUR                  U5      n[        R                  " XU5      u  p[        R                  " X U5      u  p [        R                  " X!U5      u  p![        R                  " UR                  R                  U R                  UR                  UR                  5      U R                  5      $ r?   )r@   r   rA   r   rB   
create_fmarD   r   )rF   rG   zrH   s       r   fmar      s     	AAAAAA++A)<DA++A)<DA++A)<DA;;y((33AHHahhQSTSYSYZZr!   r?   )FN)! r   	functoolsr   typingr   TypeVarr   strr#   Callabler1   r5   r9   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T H = T ff%&}%G  & ' G
 ff%&-.H  / ' H
 ff%&*+G  , ' G
 ff%&+,H  - ' H
 ff%&x G  ! ' G
 ff%&vG   ' G
 ff%&)*H  + ' H
 fXXYP  Z  P
 ff%&,-I  . ' I
 '(2 )  2  '/ ( / fXUVZ W  Z ff%&'(G  ) ' G
 ff%&wI    ' I
 ff%&vH   ' H
 +,[ - [r!   