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: accept zeros on numpy.random dirichlet function by pcralmeida · Pull Request #23440 · numpy/numpy

Conversation

@pcralmeida

@pcralmeida pcralmeida commented Mar 23, 2023

Copy link
Copy Markdown
Contributor

Changed alpha value error to pass a null value. This way, dirichlet function wont raise a value exception at 0. Also added new test_dirichlet function on numpy.tests.test_matlib.py.

Sorry, something went wrong.

Uh oh!

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

All reactions
pcralmeida added 2 commits March 21, 2023 18:06
@pcralmeida
fix(mtrand): change dirichlet alpha value error
28e1bb4
@pcralmeida
fix(test_matlib): add spaces on test
cd8f481
@github-actions github-actions Bot added the 00 - Bug label Mar 23, 2023
@MatteoRaso

MatteoRaso commented Mar 24, 2023

Copy link
Copy Markdown
Contributor

Thanks for the PR. Just to let everybody know, this is in reference to #22547.

All reactions

Sorry, something went wrong.

Uh oh!

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

MatteoRaso
MatteoRaso reviewed Mar 24, 2023
View reviewed changes
Comment thread numpy/tests/test_matlib.py Outdated
Comment on lines +61 to +62
def test_dirichlet():
dirichlet([5, 9, 0, 8])

@MatteoRaso MatteoRaso Mar 24, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_dirichlet():
dirichlet([5, 9, 0, 8])
def test_dirichlet():
y = dirichlet([5, 9, 0, 8])
assert y[2] == 0

We don't just want to show that the function doesn't throw an error, we also want to show that the function returns the right result when 0 is given as input.

Sorry, something went wrong.

Uh oh!

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

seberg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@seberg seberg Mar 24, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matteo is right, we should check this, thanks. However, this isn't the right file. The correct tests are in the numpy/random submodule.

Sorry, something went wrong.

Uh oh!

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

All reactions
seberg
seberg requested changes Mar 24, 2023
View reviewed changes

@seberg seberg left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but all changes here need to be moved around, they should be OK changes, but they are at the wrong spot.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread numpy/random/mtrand.pyx Outdated
if np.any(np.less_equal(alpha_arr, 0)):
raise ValueError('alpha <= 0')
if np.any(np.less(alpha_arr, 0)):
raise ValueError('alpha < 0')

@seberg seberg Mar 24, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please limit this change to generator.pyx. I am not sure I mind this much (since it is an error being thrown), but the backward compat guarantees on RandomState this file are very strong.

So, the change here is not correct, but the identical change on the generator would be.

Sorry, something went wrong.

Uh oh!

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

All reactions

@pcralmeida pcralmeida Mar 25, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the changes to generator.pyx as intended, and also passed the test to the numpy/random submodule. However, the test would raise the alpha = 0 value error from mtrand.pyx, so I maintained the changes that were made. The changes now seem OK, but I will wait for your feedback.

Sorry, something went wrong.

Uh oh!

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

All reactions

@seberg seberg Mar 26, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value-error is desired in mtrand (strict compatibility). The tests just need to be different. We should make sure that generator is tested, not mtrand (i.e. not np.random.diriclet but np.random.default_rng().dirichlet. Those tests live in a different file.

In a sense, we want to nudge users towards preferring np.random.default_rng() anyway, so there is probably not much reason to improve mtrand.

Sorry, something went wrong.

Uh oh!

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

All reactions

@pcralmeida pcralmeida Apr 6, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry for the long wait. I've read your comment and I've reverted the changes in mtrand. Also fixed the test having np.random.default_rng() in account. Hope these changes are good now.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread numpy/tests/test_matlib.py Outdated
Comment on lines +61 to +62
def test_dirichlet():
dirichlet([5, 9, 0, 8])

@seberg seberg Mar 24, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matteo is right, we should check this, thanks. However, this isn't the right file. The correct tests are in the numpy/random submodule.

Sorry, something went wrong.

Uh oh!

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

All reactions
@pcralmeida
fix(dirichlet): add verification on generator.pyx
195874c
@pcralmeida
pcralmeida requested a review from seberg March 25, 2023 22:18
pcralmeida added 2 commits April 6, 2023 22:16
@pcralmeida
feat(mtrand.pyx): revert changes
72a5647
@pcralmeida
fix(test_randomstate): alter method tocrng
4497e43
@pcralmeida
pcralmeida requested a review from MatteoRaso April 9, 2023 15:51
MatteoRaso
MatteoRaso approved these changes Apr 9, 2023
View reviewed changes

@MatteoRaso MatteoRaso left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sorry, something went wrong.

Uh oh!

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

All reactions
seberg
seberg approved these changes Apr 11, 2023
View reviewed changes
@seberg
seberg merged commit fe89374 into numpy:main Apr 11, 2023
@seberg

seberg commented Apr 11, 2023

Copy link
Copy Markdown
Member

Thanks for the followup, looks good now.

All reactions

Sorry, something went wrong.

Uh oh!

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

@WarrenWeckesser WarrenWeckesser mentioned this pull request Jul 18, 2023
BUG: random: dirichlet(alpha) can return nans in some cases. #24210
Closed
WarrenWeckesser
WarrenWeckesser reviewed Jul 19, 2023
View reviewed changes
Comment thread numpy/random/tests/test_randomstate.py
assert_raises(ValueError, random.dirichlet, alpha)

def test_dirichlet_zero_alpha(self):
y = random.default_rng().dirichlet([5, 9, 0, 8])

@WarrenWeckesser WarrenWeckesser Jul 19, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using the result of default_rng(), which is a Generator instance (not RandomState), so this test should not be in this file. I'll fix this in the pull request I am working on for #24210.

Sorry, something went wrong.

Uh oh!

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

All reactions
@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

@WarrenWeckesser WarrenWeckesser WarrenWeckesser left review comments
@seberg seberg seberg approved these changes
+1 more reviewer
@MatteoRaso MatteoRaso MatteoRaso approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

00 - Bug

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@pcralmeida @MatteoRaso @seberg @WarrenWeckesser
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.