
    sh(                        S SK r S SKJrJrJrJrJrJrJrJ	r	J
r
  S SKr\R                  " S\R                  4S\R                  4/SS9r\	" \5      r\R                   =rr\R                   (       + r\
" \\\S9S 5       r\
" \\\S9S	 5       r\
" \\\S9S
 5       r\
" \\\S9S 5       r\
" \\\S9S 5       r\
" \\\S9S 5       r\
" \\\S9S 5       r\
" \\\S9S 5       r\R                  " S\ R8                  -  5      r\R
                  " S\ R8                  -  5      r\
" \\\S9S 5       r\
" \\\S9S 5       r \
" \\\S9S 5       r!SS jr"SS jr#g)    N)	configcudafloat32float64uint32int64uint64
from_dtypejits0s1T)align)forceobjloopliftnopythonc                     [        U5      n[        U5      nU[        S5      -   nX3[        S5      -	  -  [        S5      -  nX3[        S5      -	  -  [        S5      -  nX3[        S5      -	  -  nX0U   S'   X0U   S'   g	)
a  Use SplitMix64 to generate an xoroshiro128p state from 64-bit seed.

This ensures that manually set small seeds don't result in a predictable
initial sequence from the random number generator.

:type states: 1D array, dtype=xoroshiro128p_dtype
:param states: array of RNG states
:type index: uint64
:param index: offset in states to update
:type seed: int64
:param seed: seed value to use when initializing state
l   |~fq	    l   e9z    l   b&&&	    r   r   N)r   r	   r   )statesindexseedzs       e/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/cuda/random.pyinit_xoroshiro128p_stater   .   s     %LE$<Dv())A	
6":o	&);"<<A	
6":o	&);"<<A	&*_A5M$5M$    c                 Z    [        U 5      n [        U5      nX-  U [        SU-
  5      -	  -  $ )zLeft rotate x by k bits.@   )r	   r   )xks     r   rotlr!   H   s0     	q	Aq	AFqF26N*++r   c                     [        U5      nX   S   nX   S   nX#-   nX2-  n[        [        U[        S5      5      5      U-  U[        S5      -  -  X   S'   [        [        U[        S5      5      5      X   S'   U$ )zReturn the next random uint64 and advance the RNG in states[index].

:type states: 1D array, dtype=xoroshiro128p_dtype
:param states: array of RNG states
:type index: int64
:param index: offset in states to update
:rtype: uint64
r   r   7      $   )r   r	   r!   r   )r   r   r   r   results        r   xoroshiro128p_nextr'   P   s     %LE	t	B	t	BWFHB b&*!56;rVBZ?OPFM$ b&*!56FM$Mr   c                 V   [        U5      n[        S5      [        S5      4n[        S5      n[        S5      n[        S5       HU  n[        S5       HC  nX%   [        S5      [        U5      -  -  (       a  X0U   S   -  nX@U   S   -  n[	        X5        ME     MW     X0U   S'   X@U   S'   g	)
zAdvance the RNG in ``states[index]`` by 2**64 steps.

:type states: 1D array, dtype=xoroshiro128p_dtype
:param states: array of RNG states
:type index: int64
:param index: offset in states to update
l   zKW`u l   "U.XC r      r      r   r   N)r   r	   ranger   r'   )r   r   jumpr   r   ibs          r   xoroshiro128p_jumpr/   f   s     %LE%&/A(BCD	B	B1XrAw&)vay01UmD))UmD))v-	   5M$5M$r   c                 |    [        U 5      n U [        S5      -	  [        S5      [        S5      [        S5      -  -  -  $ )z7Convert uint64 to float64 value in the range [0.0, 1.0)   r*   5   )r	   r   r   r   s    r   uint64_to_unit_float64r4      s6     	q	AO
fQi6":.E FGGr   c                 @    [        U 5      n [        [        U 5      5      $ )z7Convert uint64 to float32 value in the range [0.0, 1.0))r	   r   r4   r3   s    r   uint64_to_unit_float32r6      s     	q	A)!,--r   c                 @    [        U5      n[        [        X5      5      $ )zReturn a float32 in range [0.0, 1.0) and advance ``states[index]``.

:type states: 1D array, dtype=xoroshiro128p_dtype
:param states: array of RNG states
:type index: int64
:param index: offset in states to update
:rtype: float32
)r   r6   r'   r   r   s     r   xoroshiro128p_uniform_float32r9           %LE!"4V"CDDr   c                 @    [        U5      n[        [        X5      5      $ )zReturn a float64 in range [0.0, 1.0) and advance ``states[index]``.

:type states: 1D array, dtype=xoroshiro128p_dtype
:param states: array of RNG states
:type index: int64
:param index: offset in states to update
:rtype: float64
)r   r4   r'   r8   s     r   xoroshiro128p_uniform_float64r<      r:   r   r)   c                     [        U5      n[        X5      n[        X5      n[        R                  " [	        S5      * [        R
                  " U5      -  5      [        R                  " [        U-  5      -  nU$ )av  Return a normally distributed float32 and advance ``states[index]``.

The return value is drawn from a Gaussian of mean=0 and sigma=1 using the
Box-Muller transform.  This advances the RNG sequence by two steps.

:type states: 1D array, dtype=xoroshiro128p_dtype
:param states: array of RNG states
:type index: int64
:param index: offset in states to update
:rtype: float32
       @)r   r9   mathsqrtr   logcosTWO_PI_FLOAT32r   r   u1u2z0s        r   xoroshiro128p_normal_float32rH      \     %LE	&v	5B	&v	5B	GCL=488B</	0488NR<O3P	PB Ir   c                     [        U5      n[        X5      n[        X5      n[        R                  " [	        S5      * [        R
                  " U5      -  5      [        R                  " [        U-  5      -  nU$ )av  Return a normally distributed float32 and advance ``states[index]``.

The return value is drawn from a Gaussian of mean=0 and sigma=1 using the
Box-Muller transform.  This advances the RNG sequence by two steps.

:type states: 1D array, dtype=xoroshiro128p_dtype
:param states: array of RNG states
:type index: int64
:param index: offset in states to update
:rtype: float64
r>   )r   r9   r?   r@   r   rA   rB   TWO_PI_FLOAT64rD   s        r   xoroshiro128p_normal_float64rL      rI   r   c                     U R                   S   n[        U5      n[        U5      nUS:  aS  [        U SU5        [        U5       H  n[	        U S5        M     [        SU5       H  nXS-
     X'   [	        X5        M     g g )Nr   r*   )shaper	   r   r+   r/   )r   r   subsequence_startn_r-   s         r   init_xoroshiro128p_states_cpurR      s    QA$<D01Av D1 ()Avq) * q!A1uFIv)  r   c                     [         R                  " U R                  [        S9n[	        XAU5        U R                  XCS9  g)a  Initialize RNG states on the GPU for parallel generators.

This initializes the RNG states so that each state in the array corresponds
subsequences in the separated by 2**64 steps from each other in the main
sequence.  Therefore, as long no CUDA thread requests more than 2**64
random numbers, all of the RNG states produced by this function are
guaranteed to be independent.

The subsequence_start parameter can be used to advance the first RNG state
by a multiple of 2**64 steps.

:type states: 1D DeviceNDArray, dtype=xoroshiro128p_dtype
:param states: array of RNG states
:type seed: uint64
:param seed: starting seed for list of generators
)rN   dtype)streamN)npemptyrN   xoroshiro128p_dtyperR   copy_to_device)r   r   rO   rU   
states_cpus        r   init_xoroshiro128p_statesr[      s5    & 4GHJ!*4EF
*4r   c                 R    [         R                  " U [        US9n[        XAX#5        U$ )a  Returns a new device array initialized for n random number generators.

This initializes the RNG states so that each state in the array corresponds
subsequences in the separated by 2**64 steps from each other in the main
sequence.  Therefore, as long no CUDA thread requests more than 2**64
random numbers, all of the RNG states produced by this function are
guaranteed to be independent.

The subsequence_start parameter can be used to advance the first RNG state
by a multiple of 2**64 steps.

:type n: int
:param n: number of RNG states to create
:type seed: uint64
:param seed: starting seed for list of generators
:type subsequence_start: uint64
:param subsequence_start:
:type stream: CUDA stream
:param stream: stream to run initialization kernel on
)rT   rU   )r   device_arrayrX   r[   )rP   r   rO   rU   r   s        r   create_xoroshiro128p_statesr^     s)    * q(;FKFf,=FMr   )r   r   )$r?   numbar   r   r   r   r   r   r	   r
   r   numpyrV   rT   rX   xoroshiro128p_typeENABLE_CUDASIM	_forceobj	_looplift	_nopythonr   r!   r'   r/   r4   r6   r9   r<   pirC   rK   rH   rL   rR   r[   r^    r   r   <module>rh      s   $ $ $ 4 hhryy 1D"))3DE%)+  34  -- -	I%%%	 i)i@ A2 i)i@, A, i)i@ A* i)i@ A4 i)i@H AH i)i@. A. i)i@
E A
E i)i@
E A
E AK(AK( i)i@ A0 i)i@ A0 i)i@* A*$52r   