cupy.random.uniform(low=low, high=high) returns high
See original GitHub issueimport cupy as cp
cp.random.seed(seed=13)
high = 2**32 - 1
low = 2**32 - 3
size = 100000000
(cp.random.uniform(low=low, high=high, size=size) == high).sum()
returns array(11)
, while array(0)
is expected, as “Samples are drawn from a uniform distribution over the half-open interval [low, high)”.
Interestingly, the documentation of standard random.uniform
says “The end-point value b may or may not be included in the range depending on floating-point rounding in the equation a + (b-a) * random()
”. RandomState._scale_kernel
seems to do the same thing, so it might be a documentation problem.
BTW, the behavior looks like it is consistent with numpy
.
- Conditions
CuPy Version : 6.0.0
CUDA Root : /usr/local/cuda
CUDA Build Version : 10000
CUDA Driver Version : 10010
CUDA Runtime Version : 10000
cuDNN Build Version : 7301
cuDNN Version : 7605
NCCL Build Version : 1000
NCCL Runtime Version : (unknown)
Linux 4.4.180-102-default
Intel(R) Xeon(R) Gold 5118 CPU @ 2.30GHz
Tesla P100
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (9 by maintainers)
Top Results From Across the Web
cupy.random.uniform — CuPy 11.4.0 documentation
Returns an array of uniformly-distributed samples over an interval. Samples are drawn from a uniform distribution over the half-open interval [low, high) ....
Read more >cupy.random.uniform — CuPy 7.8.0 documentation
Returns an array of uniformly-distributed samples over an interval. Samples are drawn from a uniform distribution over the half-open interval [low, high) ....
Read more >Random sampling (cupy.random) — CuPy 11.4.0 ...
Functions in cupy.random # ; uniform ([low, high, size, dtype]). Returns an array of uniformly-distributed samples over an interval. ; vonmises (mu, kappa[,...
Read more >Random Sampling (cupy.random) — CuPy 4.5.0 documentation
cupy.random.rand, Returns an array of uniform random values over the interval [0, 1) . ... Returns a scalar or an array of integer...
Read more >cupy.random.random_integers — CuPy 11.3.0 documentation
Return a scalar or an array of integer values over [low, high] ... are independently sampled from uniform distribution over closed interval [low,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@toslunar We’re dealing with the expression
round(low+round(r*round(high-low)))
. LetD
denote the largest distance between the two consecutive floats in the interval[low, high]
. The change of the rounding policy will shift the value ofround(high-low)
by at mostD
. As long as|r|<=1
, the valuer*round(high-low)
will be also shifted by at mostD
. Hence,round(r*round(high-low))
shall not be shifted by more than2D
andround(low+round(r*round(high-low)))
– by3D
. Clearly, the mean will not be shifted by more than3D
either. And it doesn’t strike me as a significant change.Why, is it
low
on RHS? Why not smth likestd::nextafter(high, 0.0)
?Thank you for referencing the numpy issue. Looks like they found it possible to just change the rounding mode, but lest they break the others’ code, they just edited the docs.
Ah, I think I finally figured out what you’re saying is the issue. In numpy.random.uniform, "The high limit may be included in the returned array of floats due to floating-point rounding in the equation low + (high-low) * random_sample(). ". You’re saying that the problem is that there is no such an explanation in the cupy.random.uniform document?