K iddlmZddlmZddlmZdZeefdejfdZeefdejfdZ eefdejfd Z eefdejfd Z ed Z eefdejfd Z eefdejfd ZedZeefdejfdZeefdejfdZy))jit)core)math n_roundsc@|jtjk(r d}d}d} d} n9tj|jtjk(dd}d}d} d } tj |D]} | } | } ||}}t j| ||z |z }t j| ||z |z }tj| |d }tj| |d }tj||d }tj||d }||||fS) zV Run `n_rounds` rounds of Philox for state (c0, c1, c2, c3) and key (k0, k1). lyn<l.vlS$lW =z"dtype not supported in philox_impll|~fq l;' :=[ llB;: lW$* R F)sanitize_overflow) dtypetluint32 static_assertuint64 static_rangerumulhimuladd)c0c1c2c3k0k1r PHILOX_KEY_A PHILOX_KEY_BPHILOX_ROUND_APHILOX_ROUND_B_AB_c0_c2s \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/triton/language/random.py philox_implr$ s  xx299%/ %/ '1'1 RYY.0TU%7 %7 '9'9 __X & ?  rS [[C 2 % * [[C 2 % * VVAse 4 VVAse 4 VVB  > VVB  > ? r2r>c tj|}tj|jj |j tj }tj|}tj|}tj|}tj|}tj|jjdk(rXtj}|dz dzj tj}|dzj tj}njtjtj|jjdk(dtj }tjdd|}|}|j |d }|j |d }|j |d }|j |d }t|||||||S) N l@z bitwidth not supported in philox)r)r Tbitcast) r to_tensorrr is_inttor constexprprimitive_bitwidthr fullr$) seedrrrrr int_dtypeseed_hiseed_los r#philoxr6-sw << DTZZ&&() 77299 D b B b B b B b B ||BHH//0B6II BJ*,00;*$((3 bhh&A&ABbHJlmII ''%)4 y$ 'B y$ 'B y$ 'B y$ 'B r2r2w BBr%c*t|||\}}}}|S)aq Given a :code:`seed` scalar and an :code:`offset` block, returns a single block of random :code:`int32`. If you need multiple streams of random numbers, using `randint4x` is likely to be faster than calling `randint` 4 times. :param seed: The seed for generating random numbers. :param offset: The offsets to generate random numbers for. ) randint4x)r2offsetrretrs r#randintr;HsT684LCAq Jr%c |jtj}|dz}tj|jj dkDr#|dz jtj}n|}t ||||||S)aU Given a :code:`seed` scalar and an :code:`offset` block, returns four blocks of random :code:`int32`. This is the maximally efficient entry point to Triton's Philox pseudo-random number generator. :param seed: The seed for generating random numbers. :param offsets: The offsets to generate random numbers for. r)r')r.r r r/r r0r6)r2r9r offset_lo_0 offset_his r#r8r8Xsl "))$I QB ||FLL334r9r\%%bii0  $ 9b"h ??r%ctj|jtjk(s0tj|jtjk(r$|j tjd}d}ntj tj|jtjk(xs0tj|jtjk(|j tjd}d}tj|dk| dz |}||zS)zo Numerically stable function to convert a random uint into a random float uniformly sampled in [0, 1). Tr*g=g;r)r) r r/r r int32r.rrint64where)xscales r#uint_to_uniform_floatrF~s ||AGGryy()R\\!''RXX:M-N DD4D (  agg&:;`r||AGGWYW_W_L_?`a DD4D (& QQ"A u9r%c2t|||}t|S)z Given a :code:`seed` scalar and an :code:`offset` block, returns a block of random :code:`float32` in :math:`U(0, 1)`. :param seed: The seed for generating random numbers. :param offsets: The offsets to generate random numbers for. )r;rF)r2r9rsources r#randrIsT68 ,F  ((r%ct|||\}}}}t|}t|}t|} t|} ||| | fS)a Given a :code:`seed` scalar and an :code:`offsets` block, returns 4 blocks of random :code:`float32` in :math:`U(0, 1)`. :param seed: The seed for generating random numbers. :param offsets: The offsets to generate random numbers for. )r8rF) r2offsetsri1i2i3i4u1u2u3u4s r#rand4xrTsPtWh7NBB r "B r "B r "B r "B r2r>r%ctjd|}d|z}tjdtj|z}|tj |z|tj |zfS)zBox-Muller transformgHz>g-DT!@g)r maximumrsqrtlogcossin)rPrQthrs r#pair_uniform_to_normalr]s^ FB B R B $"%&A txx| Q"- --r%ctt|||\}}}}t|}t|}t||\}}|S)a Given a :code:`seed` scalar and an :code:`offset` block, returns a block of random :code:`float32` in :math:`\mathcal{N}(0, 1)`. :param seed: The seed for generating random numbers. :param offsets: The offsets to generate random numbers for. )r8rFr]) r2r9rrLrMrrPrQn1s r#randnr`sCT684LBAq r "B r "B "2r *EB Ir%cnt|||\}}}}t||\}}t||\} } ||| | fS)a  Given a :code:`seed` scalar and an :code:`offset` block, returns 4 blocks of random :code:`float32` in :math:`\mathcal{N}(0, 1)`. :param seed: The seed for generating random numbers. :param offsets: The offsets to generate random numbers for. )rTr]) r2r9rrPrQrRrSr_n2n3n4s r#randn4xresHD&(3NBB #B +FB #B +FB r2r>r%N) runtime.jitrrr rN_ROUNDS_DEFAULTr/r$r6r;r8rFrIrTr]r`rer%r#rjsTAQ",,@:JC2<<CC43C BLL  5E@bll@@J&0@ ) ) )3C BLL  *..1A ",,  3C BLL  r%