
    J/Ph(                     (   d dl Z d dlmZmZmZmZmZmZmZm	Z	m
Z
 d dlZ ej        dej        fdej        fgd          Z e	e          Zej        xZZej         Z e
eee          d             Z e
eee          d	             Z e
eee          d
             Z e
eee          d             Z e
eee          d             Z e
eee          d             Z e
eee          d             Z e
eee          d             Z ej        de j        z            Z ej        de j        z            Z e
eee          d             Z e
eee          d             Z  e
eee          d             Z!ddZ"ddZ#dS )    N)	configcudafloat32float64uint32int64uint64
from_dtypejits0s1T)align)forceobjloopliftnopythonc                 P   t          |          }t          |          }|t          d          z   }||t          d          z	  z  t          d          z  }||t          d          z	  z  t          d          z  }||t          d          z	  z  }|| |         d<   || |         d<   d	S )
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       Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/cuda/random.pyinit_xoroshiro128p_stater   .   s     %LLE$<<Dv()))A	
a6"::o	&);"<"<<A	
a6"::o	&);"<"<<A	Q&**_AF5M$F5M$    c                 t    t          |           } t          |          }| |z  | t          d|z
            z	  z  S )zLeft rotate x by k bits.@   )r	   r   )xks     r   rotlr!   H   s8     	q		Aq		AFqF26NN*++r   c                 h   t          |          }| |         d         }| |         d         }||z   }||z  }t          t          |t          d                              |z  |t          d          z  z  | |         d<   t          t          |t          d                              | |         d<   |S )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     %LLE	t	B	t	B"WF"HB b&**!5!566;rVBZZ?OPF5M$ b&**!5!566F5M$Mr   c                    t          |          }t          d          t          d          f}t          d          }t          d          }t          d          D ]n}t          d          D ]\}||         t          d          t          |          z  z  r"|| |         d         z  }|| |         d         z  }t	          | |           ]o|| |         d<   || |         d<   d	S )
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     %LLE%&&/A(B(BCD	B	B1XX . .r 	. 	.AAw&))vayy01 *fUmD))fUmD))vu----		. F5M$F5M$r   c                     t          |           } | t          d          z	  t          d          t          d          t          d          z  z  z  S )z7Convert uint64 to float64 value in the range [0.0, 1.0)   r*   5   )r	   r   r   r   s    r   uint64_to_unit_float64r4      s@     	q		AO

fQii6"::.E FGGr   c                 X    t          |           } t          t          |                     S )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                 Z    t          |          }t          t          | |                    S )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      (     %LLE!"4VU"C"CDDDr   c                 Z    t          |          }t          t          | |                    S )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                    t          |          }t          | |          }t          | |          }t          j        t	          d           t          j        |          z            t          j        t          |z            z  }|S )a  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      l     %LLE	&vu	5	5B	&vu	5	5B	GCLL=48B<</	0	048NR<O3P3P	PB Ir   c                    t          |          }t          | |          }t          | |          }t          j        t	          d           t          j        |          z            t          j        t          |z            z  }|S )a  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                 4   | j         d         }t          |          }t          |          }|dk    rdt          | d|           t          |          D ]}t	          | d           t          d|          D ]"}| |dz
           | |<   t	          | |           !d S d S )Nr   r*   )shaper	   r   r+   r/   )r   r   subsequence_startn_r-   s         r   init_xoroshiro128p_states_cpurR      s    QA$<<D011Avv D111 ()) 	* 	*Avq)))) q! 	* 	*Aq1uF1Ivq)))) v	* 	*r   c                     t          j        | j        t                    }t	          |||           |                     ||           dS )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[      sM    & 4GHHHJ!*d4EFFF
*V44444r   c                 b    t          j        | t          |          }t          ||||           |S )a5  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^     s6    * q(;FKKKFfd,=vF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      sM   $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $    4 bhry 1D")3DE%)+ + + Z 344  - -	I%%	 i)i@@@  A@2 i)i@@@, , A@, i)i@@@  A@* i)i@@@  A@4 i)i@@@H H A@H i)i@@@. . A@. i)i@@@
E 
E A@
E i)i@@@
E 
E A@
E AK((AK(( i)i@@@  A@0 i)i@@@  A@0 i)i@@@* * A@*$5 5 5 52     r   