
    (Th                        S SK Jr  SSKJr  SSKJr  Sr\\4S\R                  4S jj5       r\\4S\R                  4S jj5       r	\\4S\R                  4S	 jj5       r
\\4S\R                  4S
 jj5       r\S 5       r\\4S\R                  4S jj5       r\\4S\R                  4S jj5       r\S 5       r\\4S\R                  4S jj5       r\\4S\R                  4S jj5       rg)   )jit   )core)math
   n_roundsc                 *   U R                   [        R                  :X  a	  SnSnSn	Sn
O:[        R                  " U R                   [        R                  :H  S5        SnSnSn	S	n
[        R
                  " U5       H  nU	nU
nXp[        R                  " X5      U-  U-  n [        R                  " X5      U-  U-  n[        R                  " XS
S9n[        R                  " XS
S9n[        R                  " XGS
S9n[        R                  " XXS
S9nM     XX#4$ )zN
Run `n_rounds` rounds of Philox for state (c0, c1, c2, c3) and key (k0, k1).
l   yn< l   .v l   S$ l   W= z"dtype not supported in philox_impll   |~fq	 l   ;'	:=[ l   lB;: l   W$*	R F)sanitize_overflow)
dtypetluint32static_assertuint64static_ranger   umulhimuladd)c0c1c2c3k0k1r   PHILOX_KEY_APHILOX_KEY_BPHILOX_ROUND_APHILOX_ROUND_B_AB_c0_c2s                   N/var/www/auris/envauris/lib/python3.13/site-packages/triton/language/random.pyphilox_implr$      s    
 
xx299%/%/'1'1
RYY.0TU%7%7'9'9__X& S[[ 2%*[[ 2%*VVAe4VVAe4VVB>VVB> ' 2>    c           	         [         R                  " U 5      n [         R                  " U R                  R	                  5       5        U R                  [         R                  5      n [         R                  " U5      n[         R                  " U5      n[         R                  " U5      n[         R                  " U5      n[         R                  " UR                  R                  5      S:X  aX  [         R                  nU S-	  S-  R                  [         R                  5      nU S-  R                  [         R                  5      nOj[         R                  " [         R                  " UR                  R                  5      S:H  S5        [         R                  n[         R                  " SSUS9nU nUR                  USS	9nUR                  USS	9nUR                  USS	9nUR                  USS	9n[        XX4XU5      $ )
N    l    @   z bitwidth not supported in philox)r       )r   Tbitcast)r   	to_tensorr   r   is_inttor   	constexprprimitive_bitwidthr   fullr$   )	seedr   r   r   r   r   	int_dtypeseed_hiseed_los	            r#   philoxr6   -   sq   <<DTZZ&&()77299D	b	B	b	B	b	B	b	B	||BHH//0B6II	BJ*,00;*$((3
bhh&A&ABbHJlmII	''%)4	y$	'B	y$	'B	y$	'B	y$	'BrrwBBr%   c                 (    [        XU5      u  n    nU$ )aU  
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)r2   offsetr   retr   s        r#   randintr;   F   s     T84LCAqJr%   c                 &    US-  n[        XX3X25      $ )a9  
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)   )r6   )r2   r9   r   _0s       r#   r8   r8   V   s     
!B$55r%   c                    [         R                  " U R                  [         R                  :H  5      (       d6  [         R                  " U R                  [         R                  :H  5      (       a!  U R                  [         R                  SS9n SnO[         R                  " [         R                  " U R                  [         R                  :H  5      =(       d1    [         R                  " U R                  [         R                  :H  5      5        U R                  [         R                  SS9n Sn[         R                  " U S:  U * S-
  U 5      n X-  $ )zg
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.   r   r   int64where)xscales     r#   uint_to_uniform_floatrD   t   s     
||AGGryy())R\\!''RXX:M-N-NDD4D( 
agg&:;`r||AGGWYW_W_L_?`aDD4D(&
QQ"A9r%   c                 0    [        XU5      n[        U5      $ )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;   rD   )r2   r9   r   sources       r#   randrG      s     T8,F ((r%   c                     [        XU5      u  p4pV[        U5      n[        U5      n[        U5      n	[        U5      n
XxX4$ )z
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.
)r8   rD   )r2   offsetsr   i1i2i3i4u1u2u3u4s              r#   rand4xrR      sF     th7NBB	r	"B	r	"B	r	"B	r	"B2>r%   c                     [         R                  " SU 5      n SU-  n[        R                  " S[        R                  " U 5      -  5      nU[        R
                  " U5      -  U[        R                  " U5      -  4$ )zBox-Muller transformgHz>g-DT!@g       )r   maximumr   sqrtlogcossin)rN   rO   thrs       r#   pair_uniform_to_normalr[      s^     
FB	B	R	B		$"%&Atxx|Q"---r%   c                 l    [        XU5      u  p4  n[        U5      n[        U5      n[        Xg5      u  pU$ )z
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.
)r8   rD   r[   )	r2   r9   r   rJ   rK   r   rN   rO   n1s	            r#   randnr^      s;     T84LBAq	r	"B	r	"B"2*EBIr%   c                 \    [        XU5      u  p4pV[        X45      u  px[        XV5      u  pXxX4$ )z
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.
)rR   r[   )r2   r9   r   rN   rO   rP   rQ   r]   n2n3n4s              r#   randn4xrc      s6     D(3NBB#B+FB#B+FB2>r%   N)runtime.jitr    r   r   r   N_ROUNDS_DEFAULTr/   r$   r6   r;   r8   rD   rG   rR   r[   r^   rc    r%   r#   <module>rh      sP       AQ ",,  @ :J C2<< C C0 3C BLL   5E 6bll 6 6:  & 0@ 	) 	) 	) 3C BLL  * . . 1A ",,   3C BLL  r%   