Skip to content

BUG: random: Fix generation of nan by dirichlet.#24220

Merged
charris merged 1 commit intonumpy:mainfrom
WarrenWeckesser:dirichlet-zeros
Aug 3, 2023
Merged

BUG: random: Fix generation of nan by dirichlet.#24220
charris merged 1 commit intonumpy:mainfrom
WarrenWeckesser:dirichlet-zeros

Conversation

@WarrenWeckesser
Copy link
Member

@WarrenWeckesser WarrenWeckesser commented Jul 19, 2023

Don't call the C function random_beta() with both parameters a and b set to 0. In the case where this would occur, we know that the remaining values in the random vector being generated must be 0, so can break out of the loop early.

After this change, when alpha is all zero, the random variates will also be all zero.

Closes gh-24210.

Don't call the C function random_beta() with both parameters
`a` and `b` set to 0.  In the case where this would occur, we
know that the remaining values in the random vector being
generated must be 0, so can break out of the loop early.

After this change, when alpha is all zero, the random variates
will also be all zero.

Closes numpygh-24210.
@WarrenWeckesser
Copy link
Member Author

I updated the code so now, instead of generating an error, all zeros are returned when alpha is all zero.

@charris charris merged commit 09dac65 into numpy:main Aug 3, 2023
@charris
Copy link
Member

charris commented Aug 3, 2023

Let's give this a shot. Thanks Warren.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: random: dirichlet(alpha) can return nans in some cases.

2 participants