K ic>ddlmZddlmZmZddlmZddlmZedZedZ ejed Z ejeejd d Z ejeejd dDdZejedEdZedZedZedZedZedZedZedZejeej.ddddFdZejeej.dddGdZed Zed!Zed"Zed#Zejeej.d$dddFd%Zejeej.d&ddGd'Zed(Z ed)Z!ejeej.d*d+,dHdId-Z"ed.Z#ejeej.d/dJd0Z$ed1Z%ejeej.d2dEd3Z&ejeejNd4d+,dKdId5Z(ed6Z)ejeejNd7dLd8Z*edMd9Z+edNd:Z,edOd;Z-edPd<Z.ed d ej^fdQd=Z0ed ej^fdRd>Z1edSdTd?Z2ed ej^fdRd@Z3edAZ4ejedSdBZ5edCZ6y )U) annotations)jitconstexpr_function)core)mathc8d}|}|dkDr|dz}|dz }|dkDr|S)Nrr)ilog2ns ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/triton/language/standard.py_log2r s5 D A a% a   a% Kc&||dz zdk(xr|dk7SNrrr )r s r_is_power_of_twors QKA  (!q&(rc||zdz |zS)z Computes the ceiling division of :code:`x` by :code:`div` :param x: the input number :type x: Block :param div: the divisor :type div: Block rr )xdivs rcdivrs GaKC rsigmoidc:ddtj| zz S)Nr)r exp)rs rrr,s DHHaRL !!rsoftmaxNc|d}n|}|t|||z }tj|}t|||}tj|||S)Nr keep_dims)maxr rsumfdiv)rdimr ieee_rounding_dimznumdens rrr3sT { " C49 --A ((1+C c49 -C 99S#} --rcHtj||jg|S)zn Returns a contiguous flattened view of :code:`x`. :param x: the input tensor :type x: Block ) can_reorder)rreshapenumel)rr*s rravelr-As <<AGG9+ >>rc||z|z}||z}||z}||z}tj||z |}||z}|||zz} ||z} | | fS)a Transforms the indices of a row-major `size_i * size_j` matrix into the indices of a column-major matrix for each group of `size_g` rows. For example, for :code:`size_i = size_j = 4` and :code:`size_g = 2`, it will transform :: [[0 , 1 , 2 , 3 ], [4 , 5 , 6 , 7 ], [8 , 9 , 10, 11], [12, 13, 14, 15]] into :: [[0, 2, 4 , 6 ], [1, 3, 5 , 7 ], [8, 10, 12, 14], [9, 11, 13, 15]] rminimum) r jsize_isize_jsize_gijsize_gjgroup_idoff_inew_inew_js r swizzle2dr;Msm, VaBvoGW}H v E \\&5.& 1F gB BK E &LE %<rc0tj|d|S)a' Returns a tensor filled with the scalar value 0 for the given :code:`shape` and :code:`dtype`. :param shape: Shape of the new array, e.g., (8, 16) or (8, ) :type shape: tuple of ints :param dtype: Data-type of the new array, e.g., :code:`tl.float16` :type dtype: DType r)rfull)shapedtypes rzerosr@us 99UAu %%rcBt|j|jS)z Returns a tensor of zeros with the same shape and type as a given tensor. :param input: input tensor :type input: Tensor )r@r>r?)inputs r zeros_likerCs ekk **rc|r ||k(xr||k}nd}||kDxs|}tj|||}tj|||}||fSNFrwhere) value1index1value2index2tie_break_lefttiegtv_reti_rets r_argmax_combinerQsY26F? & CB JJr66 *E JJr66 *E %<rc t||||dSNTrQrHrIrJrKs r_argmax_combine_tie_break_leftrV 66664 @@rc t||||dSrErTrUs r_argmax_combine_tie_break_fastrY 66665 AArc.tj||SN)rmaximumabs r_elementwise_maxra <<1 rr]return_indicesreturn_indices_tie_break_left)return_indices_arg tie_break_argcztj|}|r<|rtj||t|Stj||t|Stj |j jtj dkrtj |j jr |jtj}n@|j jsJd|jtj}tj||t|SNr z"Expecting input to be integer type)r_promote_bfloat16_to_float32_reduce_with_indicesrVrY constexprr?primitive_bitwidth is_floatingtofloat32is_intint32reducerarBaxisrcrdrs rr r s  - -e 4E (,,UD:Xdmn n,,UD:Xdmn n >>%++88 9DNN2>%++88 9B >~~ekk5578.{{))+Q-QQ+,{{5$(8INNrz minimum indexc,t||d||\}}|Srw)rrxs rargminrs!TQ_kt uFAs Jrc ||zSr\r r^s r _sum_combiner q5Lrc||Sd}|jr%|jdkrtj}|Sd}|S|j r!|jdkrtj nd}|S)Nri) is_int_signed int_bitwidthrrris_int_unsigneduint32)in_dtyper? out_dtypes r_pick_sum_dtyper s{  I"*"7"7""s= uzz((//13Z[ ;;udK9 EErcumsumctj|}t|j|}||j |}tj ||t |Sr\)rrjrr?roassociative_scanr)rBrureverser?rs rrrIsO  - -e 4E / U CI#  lG DDrc ||zSr\r r^s r _prod_combiner[rrcumprodcdtj|}tj||t|Sr\)rrjrr)rBrurs rrr`s+  - -e 4E  mW EErctjdd}tj|dg||z dz zdgzdg|zz}|S)Nrrr)raranger+)n_dimsr1ars r _indicatorrlsH Q B b1#!a0A36!q@ AB Ircjt|j}tj|jj d}|j |d}|t||dz |z dz }|j |jd}t||}tj||kD||z k7||} | S)NTbitwidthsignedbitcastr) rr,r get_int_dtyper?rmrorrrG) rflipr ridtypeixiyris_rightrzs r_compare_and_swaprss#177^F  )C)CD QF fd #B gb&1*q.$/ /B aggt$A&!$H **a!e11a 8C Jrc|dk(r tt|j|}n|}tj|D]}t |||dz |z }|S)zb order_type 0 == ascending order_type 1 == descending order_type 2 == alternating rr)rrr,r static_ranger)rstageorderrr s r_bitonic_merge_hypercubersY z%.%0   u %6 auqy1} 56 Hrctj|dgt|jz}t |||}tj||j }|S)Nr)rr+rr,rr>)rrrrhs r_bitonic_mergersH QeAGGn,-A E51A Q A Hrc|t|jdz n|}tj|t|jdz k(dt |j|}||n t |}t |j }tj |dg|z}tjd|dzD]} t|| | |krdn|}tj|dz|dzD]d} |r&t|t |j dz |z n%t|t |j dz |z }t||| |krdn|}ftj ||jddd|zgz}|S)ai Sorts a tensor along a specified dimension. :param x: The input tensor to be sorted. :type x: Tensor :param dim: The dimension along which to sort the tensor. If None, the tensor is sorted along the last dimension. Currently, only sorting along the last dimension is supported. :type dim: int, optional :param k: the number of top elements to select. If none, assume k = x.shape[dim] :type k: int, optional :param descending: If set to True, the tensor is sorted in descending order. If set to False, the tensor is sorted in ascending order. :type descending: bool, optional Nr+only minor dimension is currently supportedr)ru) lenr>rrrr,r+rrr r) rkr# descendingr%log_nlog_krrr s r sort_implrsk03{3qwwrrrr)rr#rr%rs r bitonic_mergersb03{3qwws r _get_flip_dimrs. {%j1n Qw s5z Jrctjt|j |kxr|t|jkt ||j}tjt |j|t |j|}tj|jjd}tj|j|d|jd|dg|zz|j|dzdz}tj|D]}|t|||zdz }tj||jj|jd}|S)z Flips a tensor `x` along the dimension `dim`. :param x: the first input tensor :type x: Block :param dim: the dimension to flip along :type dim: int TrrNrr)rrrr>rrrrr?rmr+rorr)rr#r%stepsrrr s rrrs: AGG }+Bc!''l0BC(agg6D' 67!!''$-0E  )C)CD QF QTT&$T/$1#+1MPQPWPWX\_`X`XaPb1bcA   u %+ 4!8T* *+ Q ##AGGT#:A Hrctj||}t|jdk(r|Stj||jddd|jdzgzS)a7 Interleaves the values of two tensors along their last dimension. The two tensors must have the same shape. Equivalent to `tl.join(a, b).reshape(a.shape[:-1] + [2 * a.shape[-1]])` :param a: The first input tensor. :type a: Tensor :param b: The second input tensor. :type b: Tensor rNr)rjoinrr>r+)r_r`cs r interleaversY !QA 177|q ||Aqwws|q1772;.??@@r)NFF)F)NFTF)TF)NFN)r?core.constexprrE)rFN)rF)rrr1r)r r)rrrr)rrrrrr)rrr#rrr)r#rrrr\)rrr#r)7 __future__r runtime.jitrrrr rr_tensor_member_fnr_add_math_1arg_docstrrrr-r;r@rCrQrVrYra_add_reduction_docstrr r{rrrrrrrrr!rrrr_add_scan_docstrrrrrrrr CONSTEXPR_0rrrrrrrr rrrsb"1 ))    I&"'"I&.'.??$$N & &++AABBI:J*IKOKO"O;KLM  AABBI:J*IKOKO"O;KLM   EW5G6GI&G'GK(F)Fx73 E4 Ey!F"F $  *  %)dhdtdt% % P"&TEUEU8877+/dN^N^99  .AAr