-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Allow many distributions to have a scale of 0. #5822
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
Conversation
if np.any(np.less_equal(oshape, 0.0)): | ||
raise ValueError("shape <= 0") | ||
if np.any(np.less(oshape, 0.0)): | ||
raise ValueError("shape < 0") | ||
return cont1_array(self.internal_state, rk_standard_gamma, size, |
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 calling rk_standard_gamma
with shape = 0
. If you go to the source code of that function in distributions.c
, you will find that, with shape = 0
, you are computing things like X = pow(U, 1./shape))
. I think we should handle that particular case directly there, not rely on the behavior of pow
for corner cases.
Please, double check what the Another thing to consider is whether we want to handle the |
Arguably the right way to handle a lot of those cases is to fix the rk_*
|
|
There are to sources of unease for me here:
I don't know the answer to 1, but for 2, if you take a look at
where
Now if
which I am guessing will return a big fat From a quick look it seems that |
374ab22
to
c4ff5f6
Compare
I apologize for The case of negative zero is more interesting; as it is at least some of the generators ( |
I think treating negative zero like zero would be better? In general they Regarding special value handling in general: NumPy certainly requires
|
Everything in Most of the changes we made to |
Heh. |
Actually -0.+-0. = -0. but that' not the point there :-) I can certainly switch the checks to "normalize -0. to +0.", I don't care much. |
I would like to see this going into 1.10. Kindly bumping the issue, now that 1.10 is being branched out. I know that Pillow is starting to use Appveyor for Windows testing, perhaps that could be useful for numpy too? |
☔ The latest upstream changes (presumably #6831) made this pull request unmergeable. Please resolve the merge conflicts. |
@anntzer Oops, needs rebase after spelling fix went in... |
Any news as to testing on Windows (which is all that blocks this issue)? Even though I gave in and finally installed MSVC for other purposes, I still can't manage to build numpy (this fails with an unresolved external symbol, |
(in which case a stream of 0's is usually returned (or 1's)). See numpy#5818.
26f0e39
to
5bc4624
Compare
Kindly bumping the issue. The remaining blocker was the lack of tests on Windows (wrt. MSVC compliance with the annex F of the C standard), but now we can check that the tests pass on Appveyor. |
@@ -799,6 +835,9 @@ def test_weibull(self): | |||
[0.67057783752390987, 1.39494046635066793]]) | |||
assert_array_almost_equal(actual, desired, decimal=15) | |||
|
|||
def test_weibull_0(self): | |||
assert_equal(np.random.weibull(a=0), 0) | |||
|
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.
Real nitpick, but for completeness might as well test for the exception being raise on -0.
here as well.
This does look all OK otherwise.
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.
Force edited.
At least the gamma generator doesn't support it.
5bc4624
to
0319d0c
Compare
Sorry for how long this has been sitting, and thanks for being stubborn about pinging. Indeed the windows tests seem to be passing, I don't see any complaints, and from a quick read through the changes it LGTM, so merging! |
(in which case a stream of 0's is usually returned (or 1's)).
See #5818.