GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — BUG: accept zeros on numpy.random dirichlet function by pcralmeida · Pull Request #23440 · numpy/numpy Conversation
Contributor
Changed
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
MatteoRaso
reviewed
Comment on lines
+61
to
+62
|
| 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
| 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') |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
| def test_dirichlet(): | ||
| dirichlet([5, 9, 0, 8]) |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the followup, looks good now. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| assert_raises(ValueError, random.dirichlet, alpha) | ||
|
|
||
| def test_dirichlet_zero_alpha(self): | ||
| y = random.default_rng().dirichlet([5, 9, 0, 8]) |
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.