Improve `randint` compatibility
@@ -611,11 +611,9 @@ class RandomState(object):
a ``numpy.uint32`` array is returned.
""" # NOQA
if size is None:
- return self._interval(mx, 1).reshape(())
- elif size == 0:
- return cupy.array(())
+ size = ()
elif isinstance(size, int):
- size = (size, )
+ size = size,
if mx == 0:
return cupy.zeros(size, dtype=numpy.int32)
@@ -637,7 +635,7 @@ class RandomState(object):
n = functools.reduce(operator.mul, size, 1)
if n == 0:
- return cupy.array(())
+ return cupy.empty(size, dtype=dtype)
sample = cupy.empty((n,), dtype=dtype)
n_rem = n # The number of remaining elements to sample
@@ -1103,21 +1101,21 @@ class RandomState(object):
"""
if high is None:
lo = 0
- hi = low
+ hi1 = int(low) - 1
else:
- lo = low
- hi = high
+ lo = int(low)
+ hi1 = int(high) - 1
- if lo >= hi:
+ if lo > hi1:
raise ValueError('low >= high')
if lo < cupy.iinfo(dtype).min:
raise ValueError(
'low is out of bounds for {}'.format(cupy.dtype(dtype).name))
- if hi > cupy.iinfo(dtype).max + 1:
+ if hi1 > cupy.iinfo(dtype).max:
raise ValueError(
'high is out of bounds for {}'.format(cupy.dtype(dtype).name))
- diff = hi - lo - 1
+ diff = hi1 - lo
if diff > cupy.iinfo(cupy.int32).max - cupy.iinfo(cupy.int32).min + 1:
raise NotImplementedError(
'Sampling from a range whose extent is larger than int32 '
