@@ -111,7 +111,7 @@ cdef extern from "distributions.h":
111111 cdef void random_bounded_uint32_fill (aug_state * state , uint32_t off , uint32_t rng , intptr_t cnt ,uint32_t * out ) nogil
112112 cdef void random_bounded_uint16_fill (aug_state * state , uint16_t off , uint16_t rng , intptr_t cnt , uint16_t * out ) nogil
113113 cdef void random_bounded_uint8_fill (aug_state * state , uint8_t off , uint8_t rng , intptr_t cnt , uint8_t * out ) nogil
114- cdef void random_bool_fill (aug_state * state , int8_t off , int8_t rng , intptr_t cnt , int8_t * out ) nogil
114+ cdef void random_bool_fill (aug_state * state , np . npy_bool off , np . npy_bool rng , intptr_t cnt , np . npy_bool * out ) nogil
115115 cdef void random_uniform_fill (aug_state * state , intptr_t cnt , double * out ) nogil
116116 cdef void random_standard_exponential_fill (aug_state * state , intptr_t count , double * out ) nogil
117117 cdef void random_gauss_fill (aug_state * state , intptr_t count , double * out ) nogil
@@ -580,24 +580,28 @@ cdef class RandomState:
580580 """
581581 cdef uint32_t [:] randoms32
582582 cdef uint64_t [:] randoms64
583+ cdef aug_state * rng_state
583584 cdef Py_ssize_t i , n
585+ rng_state = & self .rng_state
584586 if bits == 64 :
585587 if size is None :
586- return random_uint64 (& self .rng_state )
588+ with self .lock :
589+ return random_uint64 (rng_state )
587590 n = compute_numel (size )
588591 randoms64 = np .empty (n , np .uint64 )
589592 with self .lock , nogil :
590593 for i in range (n ):
591- randoms64 [i ] = random_uint64 (& self . rng_state )
594+ randoms64 [i ] = random_uint64 (rng_state )
592595 return np .asarray (randoms64 ).reshape (size )
593596 elif bits == 32 :
594597 if size is None :
595- return random_uint32 (& self .rng_state )
598+ with self .lock :
599+ return random_uint32 (rng_state )
596600 n = compute_numel (size )
597601 randoms32 = np .empty (n , np .uint32 )
598602 with self .lock , nogil :
599603 for i in range (n ):
600- randoms32 [i ] = random_uint32 (& self . rng_state )
604+ randoms32 [i ] = random_uint32 (rng_state )
601605 return np .asarray (randoms32 ).reshape (size )
602606 else :
603607 raise ValueError ('Unknown value of bits. Must be either 32 or 64.' )
@@ -631,17 +635,20 @@ cdef class RandomState:
631635 cdef np .ndarray randoms
632636 cdef uint64_t * randoms_data
633637 cdef Py_ssize_t i , n
638+ cdef aug_state * rng_state
639+ rng_state = & self .rng_state
634640
635641 if size is None :
636- return random_raw_values (& self .rng_state )
642+ with self .lock :
643+ return random_raw_values (rng_state )
637644
638645 randoms = < np .ndarray > np .empty (size , np .uint64 )
639646 randoms_data = < uint64_t * > np .PyArray_DATA (randoms )
640647 n = np .PyArray_SIZE (randoms )
641648
642649 with self .lock , nogil :
643650 for i in range (n ):
644- randoms_data [i ] = random_raw_values (& self . rng_state )
651+ randoms_data [i ] = random_raw_values (rng_state )
645652 return randoms
646653
647654 # Pickling support:
@@ -749,16 +756,20 @@ cdef class RandomState:
749756 cdef np .npy_intp n
750757 cdef np .ndarray randoms
751758 cdef long * randoms_data
759+ cdef aug_state * rng_state
760+ rng_state = & self .rng_state
752761
753762 if size is None :
754- return random_positive_int (& self .rng_state )
763+ with self .lock :
764+ return random_positive_int (rng_state )
755765
756766 randoms = < np .ndarray > np .empty (size , dtype = np .int )
757767 randoms_data = < long * > np .PyArray_DATA (randoms )
758768 n = np .PyArray_SIZE (randoms )
759769
760770 for i in range (n ):
761- randoms_data [i ] = random_positive_int (& self .rng_state )
771+ with self .lock , nogil :
772+ randoms_data [i ] = random_positive_int (rng_state )
762773 return randoms
763774
764775 def randint (self , low , high = None , size = None , dtype = int ):
@@ -4239,6 +4250,10 @@ cdef class RandomState:
42394250
42404251 Modify a sequence in-place by shuffling its contents.
42414252
4253+ This function only shuffles the array along the first axis of a
4254+ multi-dimensional array. The order of sub-arrays is changed but
4255+ their contents remains the same.
4256+
42424257 Parameters
42434258 ----------
42444259 x : array_like
@@ -4255,8 +4270,7 @@ cdef class RandomState:
42554270 >>> arr
42564271 [1 7 5 2 9 4 3 6 0 8]
42574272
4258- This function only shuffles the array along the first index of a
4259- multi-dimensional array:
4273+ Multi-dimensional arrays are only shuffled along the first axis:
42604274
42614275 >>> arr = np.arange(9).reshape((3, 3))
42624276 >>> np.random.shuffle(arr)
0 commit comments