K iddlmZddlmZddlmZej dZdeedefdZ d edejegeffd Z d edejegeffd Z d edejegeffd Z eje gd e dd4dZeje ddge dej d4dZeje ddge dej d4dZeje ddge dej d4dZeje ddge dej d4dZeje ddge dej d4dZeje ddge dej d4dZeje ddge d ej d4d!Zeje dge d"ej d4d#Zeje ddge d$ej d4d%Zej eje d&d4d'Zeje d(d5d)Zeje dge d*d4d+Zeje ddge d,ej d4d-Zeje ddge d.ej d4d/Zeje ddge d0ej d4d1Zeje d2d4d3Z y)6)corewraps)ListTdtypesreturncfd}|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. c2tfd}|S)Ncjt|t|jz}|Dcgc]}t|tjs|!c}D]S}|j j jvs&tdd|j j j|i|Scc}w)NzExpected dtype z but got ) listvalues isinstancertensortypescalarname ValueError)argskwargsall_argsaargr fns Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/triton/language/math.pycheckz,_check_dtype..wrapper..checksDzD$99H#+Jaz!T[[/IJ `88??''v5$vhiH\H\G]%^__ `t&v& &Ks B0 B0r)rrr s` rwrapperz_check_dtype..wrappers r '  ' )r rs` r _check_dtyper!s  Nrrc,dtdtffd }|S)Nfuncr c:d}|j|_|S)Nzk Computes the element-wise {name} of :code:`x`. :param x: the input values :type x: Block rformat__doc__r#docstrrs r _decoratorz)_add_math_1arg_docstr.._decorator#s# }}$}/  rrrr+s` r_add_math_1arg_docstrr.!sq rc,dtdtffd }|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 rr+z)_add_math_2arg_docstr.._decorator2s#}}$}/  rr,r-s` r_add_math_2arg_docstrr10s  q  rc,dtdtffd }|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 rr+z)_add_math_3arg_docstr.._decoratorCs# }}$}/  rr,r-s` r_add_math_3arg_docstrr4As  q  r)int32int64uint32uint64)r z-most significant N bits of the 2N-bit productNc|j|}|j|}tj|||\}}tj|jj |j |j |jSN) to_tensorrbinary_op_type_legalizationrbuilder create_umulhihandlerxy _semantics rumulhirDTsl AAAA  + +Aq) AA ;;y((33AHH=qvv FFrzexponential (base 2)c|j|}tj|jj |j |j Sr:)r;rrr= create_exp2r?rrJs rexp2rOg> AA ;;y((44QXX> GGrznatural logarithmc|j|}tj|jj |j |j Sr:)r;rrr= create_logr?rrJs rlogrSprLrzlogarithm (base 2)c|j|}tj|jj |j |j Sr:)r;rrr= create_log2r?rrJs rlog2rVyrPrcosinec|j|}tj|jj |j |j Sr:)r;rrr= create_cosr?rrJs rcosrZrLrsinec|j|}tj|jj |j |j Sr:)r;rrr= create_sinr?rrJs rsinr^rLrzfast square rootc|j|}tj|jj |j |j Sr:)r;rrr= create_sqrtr?rrJs rsqrtrarPrz?precise square root (rounding to nearest wrt the IEEE standard)c|j|}tj|jj |j |j Sr:)r;rrr=create_precise_sqrtr?rrJs rsqrt_rnrds> AA ;;y((< AA ;;y((55ahh? HHrzabsolute valuec|j|}|j}|jrtj|j dtj |}tj|jj|j|j|jS|jrCtj|jj|j|jS|jrCtj|jj|j|jS|j!r|SJd|)N)rCzUnexpected dtype )r;dtype is_fp8e4b15rfullshapeint8rr= create_andr?r is_floating create_fabs is_int_signed create_iabsis_int_unsigned)rArCrkmasks rabsrws AA GGE yy$ YG{{9,,77$++NPQPVPVWW    {{9,,88BAFFKK    {{9,,88BAFFKK    1)%11urz fast divisionctj|}|j|}|j|}|j|||Sr:)r_unwrap_if_constexprr;fdiv)rArB ieee_roundingrCs rrzrzsG--m>!Q ..rzrsDLLcq2   qc1f(=  qc1f(=" qc1f(=& ;<FGTH=T ff%&}%G&'G  ff%&-.H/'H  ff%&*+G,'G  ff%&+,H-'H  ff%&x G!'G  ff%&vG'G  ff%&)*H+'H  fXXYPZP  ff%&,-I.'I '( 2) 2 '/(/ fXUVZWZ ff%&'(G)'G  ff%&wI 'I  ff%&vH'H +,[-[r