σ
\K]c           @@ s¬  d  d l  m Z m Z d  d l Z d  d l 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 e Z e e  Z e d    Z e d    Z e d	    Z e
 d
  e
 d  f Z e d    Z e d    Z e d    Z e d    Z e d    Z e j d e j  Z e j d e j  Z e d    Z e d    Z  e d    Z! d  d  d  Z" d  d  d  Z# d S(   i    (   t   print_functiont   absolute_importN(   t   cudat   float32t   float64t   uint32t   int64t   uint64t
   from_dtypet   jitt   s0t   s1t   alignc         C@ s   t  |  } t |  } | t d  } | | t d  ?At d  } | | t d  ?At d  } | | t d  ?A} | |  | d <| |  | d <d	 S(
   sΑ  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   |~εf»q	 i   l   ΉeΙ9΄Βz i   l   λb&μ&&	 i   R
   R   N(   R   R   R   (   t   statest   indext   seedt   z(    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   init_xoroshiro128p_state%   s    c         C@ s2   t  |   }  t |  } |  | >|  t d |  ?BS(   s   Left rotate x by k bits.i@   (   R   R   (   t   xt   k(    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   rotl?   s    c         C@ s   t  |  } |  | d } |  | d } | | } | | N} t t | t d    | A| t d  >A|  | d <t t | t d    |  | d <| S(   sύ   Return 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   i7   i   i$   (   R   R   R   R   (   R   R   R
   R   t   result(    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   xoroshiro128p_nextG   s    


5#l   ΛzKW`u l   "U.XC c         C@ sΔ   t  |  } t d  } t d  } x} t d  D]o } xf t d  D]X } t | t d  t |  >@r | |  | d N} | |  | d N} n  t |  |  qD Wq1 W| |  | d <| |  | d <d S(   sΫ   Advance 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
    i    i   i@   i   R
   R   N(   R   R   t   ranget   XOROSHIRO128P_JUMPR   R   (   R   R   R
   R   t   it   b(    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   xoroshiro128p_jump`   s    	c         C@ s8   t  |   }  |  t d  ?t d  t  d  t d  >S(   s7   Convert uint64 to float64 value in the range [0.0, 1.0)i   i   i5   (   R   R   R   (   R   (    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   uint64_to_unit_float64y   s    c         C@ s   t  |   }  t t |    S(   s7   Convert uint64 to float32 value in the range [0.0, 1.0)(   R   R   R   (   R   (    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   uint64_to_unit_float32   s    c         C@ s   t  |  } t t |  |   S(   sώ   Return 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   R   R   (   R   R   (    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   xoroshiro128p_uniform_float32   s    
c         C@ s   t  |  } t t |  |   S(   sώ   Return 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   R   R   (   R   R   (    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   xoroshiro128p_uniform_float64   s    
i   c         C@ sb   t  |  } t |  |  } t |  |  } t j t d  t j |   t j t |  } | S(   s  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
    g       @(   R   R   t   matht   sqrtR   t   logt   cost   TWO_PI_FLOAT32(   R   R   t   u1t   u2t   z0(    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   xoroshiro128p_normal_float32§   s
    4c         C@ sb   t  |  } t |  |  } t |  |  } t j t d  t j |   t j t |  } | S(   s  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
    g       @(   R   R   R    R!   R   R"   R#   t   TWO_PI_FLOAT64(   R   R   R%   R&   R'   (    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   xoroshiro128p_normal_float64Ώ   s
    4c         C@ s₯   |  j  d } t |  } t |  } | d k r‘ t |  d |  x! t |  D] } t |  d  qN Wx9 t d |  D]% } |  | d |  | <t |  |  qu Wn  d  S(   Ni    i   (   t   shapeR   R   R   R   (   R   R   t   subsequence_startt   nt   _R   (    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   init_xoroshiro128p_states_cpuΧ   s    c         C@ sB   t  j d |  j d t  } t | | |  |  j | d | d S(   s΄  Initialize RNG states on the GPU for parallel generators.

    This intializes 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
    R+   t   dtypet   streamN(   t   npt   emptyR+   t   xoroshiro128p_dtypeR/   t   copy_to_device(   R   R   R,   R1   t
   states_cpu(    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   init_xoroshiro128p_statesκ   s    c         C@ s2   t  j |  d t d | } t | | | |  | S(   s4  Returns a new device array initialized for n random number generators.

    This intializes 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
    R0   R1   (   R   t   device_arrayR4   R7   (   R-   R   R,   R1   R   (    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   create_xoroshiro128p_states  s    ($   t
   __future__R    R   R    t   numbaR   R   R   R   R   R   R   R	   t   numpyR2   R0   t   TrueR4   t   xoroshiro128p_typeR   R   R   R   R   R   R   R   R   t   piR$   R)   R(   R*   R/   R7   R9   (    (    (    s0   lib/python2.7/site-packages/numba/cuda/random.pyt   <module>   s*   :-