GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: random: Fix generation of nan by dirichlet. by WarrenWeckesser · Pull Request #24220 · numpy/numpy

Conversation

@WarrenWeckesser

@WarrenWeckesser WarrenWeckesser commented Jul 19, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@WarrenWeckesser WarrenWeckesser added 00 - Bug component: numpy.random labels Jul 19, 2023
@WarrenWeckesser WarrenWeckesser mentioned this pull request Jul 19, 2023
BUG: random: dirichlet(alpha) can return nans in some cases. #24210
Closed
@WarrenWeckesser
BUG: random: Fix generation of nan by dirichlet.
c27678e
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
WarrenWeckesser force-pushed the dirichlet-zeros branch from 0b1d70e to c27678e Compare July 21, 2023 17:43
@WarrenWeckesser

WarrenWeckesser commented Jul 21, 2023

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

charris commented Aug 3, 2023

Copy link
Copy Markdown
Member

Let's give this a shot. Thanks Warren.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@WarrenWeckesser
WarrenWeckesser deleted the dirichlet-zeros branch August 3, 2023 23:18
@charris charris mentioned this pull request Aug 4, 2023
BUG: random: Fix generation of nan by dirichlet. #24338
Merged
@WarrenWeckesser WarrenWeckesser mentioned this pull request Aug 14, 2023
BUG: numpy.random.Generator.dirichlet should accept zeros. #22547
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

00 - Bug component: numpy.random

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@WarrenWeckesser @charris
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.