question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some cupy.random distribution does not support `size=None`

See original GitHub issue

size=None is different from size=().

>>> np.random.uniform([2], [[3]])
array([[2.63150331]])
>>> np.random.uniform([2], [[3]], size=())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mtrand.pyx", line 1317, in mtrand.RandomState.uniform
  File "mtrand.pyx", line 267, in mtrand.cont2_array
ValueError: size is not compatible with inputs
>>> 
>>> cupy.random.uniform([2], [[3]])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kataoka/cupy/cupy/random/distributions.py", line 454, in uniform
    return rs.uniform(low, high, size=size, dtype=dtype)
  File "/home/kataoka/cupy/cupy/random/generator.py", line 484, in uniform
    return RandomState._scale_kernel(low, high, rand)
  File "cupy/core/_kernel.pyx", line 532, in cupy.core._kernel.ElementwiseKernel.__call__
    out_args = _get_out_args_with_params(
  File "cupy/core/_kernel.pyx", line 368, in cupy.core._kernel._get_out_args_with_params
    raise ValueError('Out shape is mismatched')
ValueError: Out shape is mismatched

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
andfoycommented, Sep 26, 2022

After a little bit of inspection using the following script, the status regarding the broadcasting support when size=None. Checked means that the generator supports array broadcasting on its parameters, otherwise not. Manual inspection was done over triangular and zipf, since they have some restrictions on the input values, where it was determined that they support broadcasting.

Valid generators

  • beta
  • binomial
  • chisquare
  • dirichlet
  • exponential
  • f
  • gamma
  • geometric
  • gumbel
  • hypergeometric
  • laplace
  • logistic
  • lognormal
  • logseries
  • negative_binomial
  • noncentral_chisquare
  • noncentral_f
  • normal
  • pareto
  • poisson
  • power
  • rayleigh
  • standard_gamma
  • standard_t
  • triangular
  • uniform
  • vonmises
  • wald
  • zipf

Potentially invalid or restricted generators

  • multinomial → Both CuPy and NumPy documentation state that it operates over 1D values only.
  • multivariate_normal → All arguments need to be 2D
  • randint → CuPy only supports int as parameters for low and high, whereas NumPy allows for arrays. https://github.com/cupy/cupy/pull/7051
  • random_integers → Deprecated in NumPy, CuPy only supports int ranges, it depends on randint . https://github.com/cupy/cupy/pull/7051
  • weibull → Does not support array input
2reactions
kmaehashicommented, Aug 10, 2022

I guess not all fixed yet? @asi1024

Read more comments on GitHub >

github_iconTop Results From Across the Web

cupy.random.Generator — CuPy 11.4.0 documentation
Generator exposes a number of methods for generating random numbers drawn from a variety of probability distributions. · None . · None ,...
Read more >
cupy.random.RandomState — CuPy 11.3.0 documentation
Returns an array of samples drawn from the binomial distribution. ... cuSOLVER routine(s) which may yield invalid results if input conditions are not...
Read more >
cupy.random.choice — CuPy 11.4.0 documentation
Returns an array of random values from a given 1-D array. Each element of the returned array is independently sampled from a according...
Read more >
cupy.random.multinomial — CuPy 11.4.0 documentation
cupy.random.multinomial# ... Returns an array from multinomial distribution. ... It does not support sum(pvals) < 1 case. ... Created using Sphinx 5.0.2.
Read more >
cupy.random.random_integers — CuPy 11.3.0 documentation
low (int) – If high is not None , it is the lower bound of the interval. ... size (None or int or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found