@@ -949,33 +949,42 @@ cdef class RandomState:
949
949
key = np .dtype (dtype ).name
950
950
if not key in _randint_type :
951
951
raise TypeError ('Unsupported dtype "%s" for randint' % key )
952
+
952
953
lowbnd , highbnd = _randint_type [key ]
953
954
954
- if low < lowbnd :
955
+ # TODO: Do not cast these inputs to Python int
956
+ #
957
+ # This is a workaround until gh-8851 is resolved (bug in NumPy
958
+ # integer comparison and subtraction involving uint64 and non-
959
+ # uint64). Afterwards, remove these two lines.
960
+ ilow = int (low )
961
+ ihigh = int (high )
962
+
963
+ if ilow < lowbnd :
955
964
raise ValueError ("low is out of bounds for %s" % (key ,))
956
- if high > highbnd :
965
+ if ihigh > highbnd :
957
966
raise ValueError ("high is out of bounds for %s" % (key ,))
958
- if low >= high :
967
+ if ilow >= ihigh :
959
968
raise ValueError ("low >= high" )
960
969
961
970
if key == 'int32' :
962
- ret = _rand_int32 (low , high - 1 , size , & self .rng_state , self .lock )
971
+ ret = _rand_int32 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
963
972
elif key == 'int64' :
964
- ret = _rand_int64 (low , high - 1 , size , & self .rng_state , self .lock )
973
+ ret = _rand_int64 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
965
974
elif key == 'int16' :
966
- ret = _rand_int16 (low , high - 1 , size , & self .rng_state , self .lock )
975
+ ret = _rand_int16 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
967
976
elif key == 'int8' :
968
- ret = _rand_int8 (low , high - 1 , size , & self .rng_state , self .lock )
977
+ ret = _rand_int8 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
969
978
elif key == 'uint64' :
970
- ret = _rand_uint64 (low , high - 1 , size , & self .rng_state , self .lock )
979
+ ret = _rand_uint64 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
971
980
elif key == 'uint32' :
972
- ret = _rand_uint32 (low , high - 1 , size , & self .rng_state , self .lock )
981
+ ret = _rand_uint32 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
973
982
elif key == 'uint16' :
974
- ret = _rand_uint16 (low , high - 1 , size , & self .rng_state , self .lock )
983
+ ret = _rand_uint16 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
975
984
elif key == 'uint8' :
976
- ret = _rand_uint8 (low , high - 1 , size , & self .rng_state , self .lock )
985
+ ret = _rand_uint8 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
977
986
elif key == 'bool' :
978
- ret = _rand_bool (low , high - 1 , size , & self .rng_state , self .lock )
987
+ ret = _rand_bool (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
979
988
980
989
if size is None :
981
990
if dtype in (np .bool , np .int , np .long ):
@@ -1021,7 +1030,7 @@ cdef class RandomState:
1021
1030
----------
1022
1031
a : 1-D array-like or int
1023
1032
If an ndarray, a random sample is generated from its elements.
1024
- If an int, the random sample is generated as if a was np.arange(n )
1033
+ If an int, the random sample is generated as if a were np.arange(a )
1025
1034
size : int or tuple of ints, optional
1026
1035
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
1027
1036
``m * n * k`` samples are drawn. Default is None, in which case a
@@ -1035,7 +1044,7 @@ cdef class RandomState:
1035
1044
1036
1045
Returns
1037
1046
-------
1038
- samples : 1-D ndarray, shape (size,)
1047
+ samples : single item or ndarray
1039
1048
The generated random samples
1040
1049
1041
1050
Raises
@@ -4094,8 +4103,8 @@ cdef class RandomState:
4094
4103
Instead of specifying the full covariance matrix, popular
4095
4104
approximations include:
4096
4105
4097
- - Spherical covariance (* cov* is a multiple of the identity matrix)
4098
- - Diagonal covariance (* cov* has non-negative elements, and only on
4106
+ - Spherical covariance (` cov` is a multiple of the identity matrix)
4107
+ - Diagonal covariance (` cov` has non-negative elements, and only on
4099
4108
the diagonal)
4100
4109
4101
4110
This geometrical property can be seen in two dimensions by plotting
@@ -4507,6 +4516,7 @@ cdef class RandomState:
4507
4516
with self .lock :
4508
4517
for i in reversed (range (1 , n )):
4509
4518
j = random_interval (& self .rng_state , i )
4519
+ if i == j : continue # i == j is not needed and memcpy is undefined.
4510
4520
buf [...] = x [j ]
4511
4521
x [j ] = x [i ]
4512
4522
x [i ] = buf
0 commit comments