@@ -111,7 +111,7 @@ cdef extern from "distributions.h":
111
111
cdef void random_bounded_uint32_fill (aug_state * state , uint32_t off , uint32_t rng , intptr_t cnt ,uint32_t * out ) nogil
112
112
cdef void random_bounded_uint16_fill (aug_state * state , uint16_t off , uint16_t rng , intptr_t cnt , uint16_t * out ) nogil
113
113
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
115
115
cdef void random_uniform_fill (aug_state * state , intptr_t cnt , double * out ) nogil
116
116
cdef void random_standard_exponential_fill (aug_state * state , intptr_t count , double * out ) nogil
117
117
cdef void random_gauss_fill (aug_state * state , intptr_t count , double * out ) nogil
@@ -580,24 +580,28 @@ cdef class RandomState:
580
580
"""
581
581
cdef uint32_t [:] randoms32
582
582
cdef uint64_t [:] randoms64
583
+ cdef aug_state * rng_state
583
584
cdef Py_ssize_t i , n
585
+ rng_state = & self .rng_state
584
586
if bits == 64 :
585
587
if size is None :
586
- return random_uint64 (& self .rng_state )
588
+ with self .lock :
589
+ return random_uint64 (rng_state )
587
590
n = compute_numel (size )
588
591
randoms64 = np .empty (n , np .uint64 )
589
592
with self .lock , nogil :
590
593
for i in range (n ):
591
- randoms64 [i ] = random_uint64 (& self . rng_state )
594
+ randoms64 [i ] = random_uint64 (rng_state )
592
595
return np .asarray (randoms64 ).reshape (size )
593
596
elif bits == 32 :
594
597
if size is None :
595
- return random_uint32 (& self .rng_state )
598
+ with self .lock :
599
+ return random_uint32 (rng_state )
596
600
n = compute_numel (size )
597
601
randoms32 = np .empty (n , np .uint32 )
598
602
with self .lock , nogil :
599
603
for i in range (n ):
600
- randoms32 [i ] = random_uint32 (& self . rng_state )
604
+ randoms32 [i ] = random_uint32 (rng_state )
601
605
return np .asarray (randoms32 ).reshape (size )
602
606
else :
603
607
raise ValueError ('Unknown value of bits. Must be either 32 or 64.' )
@@ -631,17 +635,20 @@ cdef class RandomState:
631
635
cdef np .ndarray randoms
632
636
cdef uint64_t * randoms_data
633
637
cdef Py_ssize_t i , n
638
+ cdef aug_state * rng_state
639
+ rng_state = & self .rng_state
634
640
635
641
if size is None :
636
- return random_raw_values (& self .rng_state )
642
+ with self .lock :
643
+ return random_raw_values (rng_state )
637
644
638
645
randoms = < np .ndarray > np .empty (size , np .uint64 )
639
646
randoms_data = < uint64_t * > np .PyArray_DATA (randoms )
640
647
n = np .PyArray_SIZE (randoms )
641
648
642
649
with self .lock , nogil :
643
650
for i in range (n ):
644
- randoms_data [i ] = random_raw_values (& self . rng_state )
651
+ randoms_data [i ] = random_raw_values (rng_state )
645
652
return randoms
646
653
647
654
# Pickling support:
@@ -749,16 +756,20 @@ cdef class RandomState:
749
756
cdef np .npy_intp n
750
757
cdef np .ndarray randoms
751
758
cdef long * randoms_data
759
+ cdef aug_state * rng_state
760
+ rng_state = & self .rng_state
752
761
753
762
if size is None :
754
- return random_positive_int (& self .rng_state )
763
+ with self .lock :
764
+ return random_positive_int (rng_state )
755
765
756
766
randoms = < np .ndarray > np .empty (size , dtype = np .int )
757
767
randoms_data = < long * > np .PyArray_DATA (randoms )
758
768
n = np .PyArray_SIZE (randoms )
759
769
760
770
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 )
762
773
return randoms
763
774
764
775
def randint (self , low , high = None , size = None , dtype = int ):
@@ -4239,6 +4250,10 @@ cdef class RandomState:
4239
4250
4240
4251
Modify a sequence in-place by shuffling its contents.
4241
4252
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
+
4242
4257
Parameters
4243
4258
----------
4244
4259
x : array_like
@@ -4255,8 +4270,7 @@ cdef class RandomState:
4255
4270
>>> arr
4256
4271
[1 7 5 2 9 4 3 6 0 8]
4257
4272
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:
4260
4274
4261
4275
>>> arr = np.arange(9).reshape((3, 3))
4262
4276
>>> np.random.shuffle(arr)
0 commit comments