
    rh                        d dl mZ ddlmZ ddlmZ  ej                  d      Zdee   defdZ	d	edej                  egef   fd
Zd	edej                  egef   fdZd	edej                  egef   fdZej                   e	g d       ed      d4d                     Zej                   e	ddg       ed      ej                   d4d                            Zej                   e	ddg       ed      ej                   d4d                            Zej                   e	ddg       ed      ej                   d4d                            Zej                   e	ddg       ed      ej                   d4d                            Zej                   e	ddg       ed      ej                   d4d                            Zej                   e	ddg       ed      ej                   d4d                            Zej                   e	ddg       ed       ej                   d4d!                            Zej                   e	dg       ed"      ej                   d4d#                            Zej                   e	ddg       ed$      ej                   d4d%                            Zej                   ej                   ed&      d4d'                     Zej                   ed(      d5d)              Zej                   e	dg       ed*      d4d+                     Zej                   e	ddg       ed,      ej                   d4d-                            Zej                   e	ddg       ed.      ej                   d4d/                            Zej                   e	ddg       ed0      ej                   d4d1                            Zej                   ed2      d4d3              Z y)6   )core    wraps)ListTdtypesreturnc                       fd}|S )al  
    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                 2     t                fd       }|S )Nc                  j   t        |       t        |j                               z   }|D cg c]  }t        |t        j                        s|! c}D ]S  }|j
                  j                  j                  vs&t        d d|j
                  j                  j                           | i |S c c}w )NzExpected dtype z	 but got )	listvalues
isinstancer   tensortypescalarname
ValueError)argskwargsall_argsaargr	   fns        g/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/triton/language/math.pycheckz,_check_dtype.<locals>.wrapper.<locals>.check   s     DzD$99H#+Jaz!T[[/IJ `88??''v5$vhiH\H\G]%^__` t&v&& Ks   B0B0r   )r   r   r	   s   ` r   wrapperz_check_dtype.<locals>.wrapper   s     	r	' 
	'      )r	   r   s   ` r   _check_dtyper!      s     Nr   r   c                 ,     dt         dt         f fd}|S )Nfuncr
   c                 :    d}|j                        | _        | S )Nzk
    Computes the element-wise {name} of :code:`x`.

    :param x: the input values
    :type x: Block
    r   format__doc__r#   docstrr   s     r   
_decoratorz)_add_math_1arg_docstr.<locals>._decorator#   s#     }}$}/r   r   r   r+   s   ` r   _add_math_1arg_docstrr.   !   s     q  r   c                 ,     dt         dt         f fd}|S )Nr#   r
   c                 :    d}|j                        | _        | S )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+   z)_add_math_2arg_docstr.<locals>._decorator2   s#     }}$}/r   r,   r-   s   ` r   _add_math_2arg_docstrr1   0   s    
 
q 
 r   c                 ,     dt         dt         f fd}|S )Nr#   r
   c                 :    d}|j                        | _        | S )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+   z)_add_math_3arg_docstr.<locals>._decoratorC   s#    	 }}$}/r   r,   r-   s   ` r   _add_math_3arg_docstrr4   A   s     q  r   )int32int64uint32uint64)r	   z-most significant N bits of the 2N-bit productNc                    |j                  |       } |j                  |      }t        j                  | ||      \  } }t        j                  |j                  j                  | j                  |j                        | j                        S N)	to_tensorr   binary_op_type_legalizationr   buildercreate_umulhihandler   xy	_semantics      r   umulhirD   T   sl     	AAAA++Aq)<DAq;;y((66qxxJAFFSSr   fp32fp64exponentialc                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   
create_expr?   r   rA   rC   s     r   exprK   ^   >    
 	AA;;y((33AHH=qvvFFr   zexponential (base 2)c                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   create_exp2r?   r   rJ   s     r   exp2rO   g   >    
 	AA;;y((44QXX>GGr   znatural logarithmc                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   
create_logr?   r   rJ   s     r   logrS   p   rL   r   zlogarithm (base 2)c                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   create_log2r?   r   rJ   s     r   log2rV   y   rP   r   cosinec                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   
create_cosr?   r   rJ   s     r   cosrZ      rL   r   sinec                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   
create_sinr?   r   rJ   s     r   sinr^      rL   r   zfast square rootc                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   create_sqrtr?   r   rJ   s     r   sqrtra      rP   r   z?precise square root (rounding to nearest wrt the IEEE standard)c                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   create_precise_sqrtr?   r   rJ   s     r   sqrt_rnrd      s>    
 	AA;;y((<<QXXFOOr   zinverse square rootc                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   create_rsqrtr?   r   rJ   s     r   rsqrtrg      >    
 	AA;;y((55ahh?HHr   zabsolute valuec                    |j                  |       } | j                  }|j                         rt        j                  | j
                  dt        j                  |      }t        j                  |j                  j                  | j                  |j                        | j                        S |j                         rCt        j                  |j                  j                  | j                        | j                        S |j                         rCt        j                  |j                  j                  | j                        | j                        S |j!                         r| S J d|        )N   )rC   zUnexpected dtype )r;   dtypeis_fp8e4b15r   fullshapeint8r   r=   
create_andr?   r   is_floatingcreate_fabsis_int_signedcreate_iabsis_int_unsigned)rA   rC   rk   masks       r   absrw      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                     t        j                  |      }|j                  |       } |j                  |      }|j                  | ||      S r:   )r   _unwrap_if_constexprr;   fdiv)rA   rB   ieee_roundingrC   s       r   rz   rz      sG     --m<MAAAA>>!Q..r   z<precise division (rounding to nearest wrt the IEEE standard)c                    |j                  |       } |j                  |      }t        j                  | ||      \  } }t        j                  |j                  j                  | j                  |j                        | j                        S r:   )r;   r   r<   r   r=   create_precise_divfr?   r   r@   s      r   div_rnr~      so     	AAAA++Aq)<DAq;;y((<<QXXqxxPRSRXRXYYr   zerror functionc                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   
create_erfr?   r   rJ   s     r   erfr      rL   r   floorc                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   create_floorr?   r   rJ   s     r   r   r      rh   r   ceilc                     |j                  |       } t        j                  |j                  j	                  | j
                        | j                        S r:   )r;   r   r   r=   create_ceilr?   r   rJ   s     r   r   r      rP   r   zfused multiply-addc                    |j                  |       } |j                  |      }|j                  |      }t        j                  | ||      \  } }t        j                  || |      \  }} t        j                  |||      \  }}t        j                  |j                  j                  | j                  |j                  |j                        | j                        S r:   )r;   r   r<   r   r=   
create_fmar?   r   )rA   rB   zrC   s       r   fmar      s     	AAAAAA++Aq)<DAq++Aq)<DAq++Aq)<DAq;;y((33AHHahhQSTSYSYZZr   r:   )FN)! r   	functoolsr   typingr   TypeVarr   strr!   Callabler.   r1   r4   builtinrD   _tensor_member_fnrK   rO   rS   rV   rZ   r^   ra   rd   rg   rw   rz   r~   r   r   r   r   r    r   r   <module>r      s     DLL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   