Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2023

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