-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
np.power(0, -1) behaviour #7510
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
Comments
I'll open a PR to fix the |
Reopening, just in case we need to revisit the |
Just for completeness |
So for 8 and 16 bit signed integers we returned 0. For all other integer types we returned the minimum value. I guess we'd like to make this consistently return the minimum value then? AFAICT these return values where just happy accidents in the past since there wasn't any code that explicitly chose these values. |
Those return values mostly came from how I doubt there is a simple clear "right" here, except maybe that it could be nice to give a warning. |
Just for completeness in master Reusing the same snippet as posted by @ewmoore: import numpy as np
inttypes = ['i1', 'i2', 'i4', 'i8', 'u1', 'u2', 'u4', 'u8']
for dt in inttypes:
a = np.array([0,0,0], dt)
b = np.array([0, -1, -2], dt)
c = a**b
print(repr(c)) Output:
|
Why not raise an error? I understand the idea that errors are not so nice because they interrupt vectorised calculation flows, but surely silently returning nonsense is worse, and with ints there is no nan available so those are our only two options. |
Surely then calling
I think we should 1) ensure that the appropriate |
Yeah, we don't really have any coherent policy for how to handle exceptional conditions in integer calculations right now. Sometimes we check for overflow, sometimes not... It's a mess. We can split this into the short term and long term discussions: If current master is causing regressions then fine, that's some argument for at least reverting to the same odd behavior as 1.11-and-earlier while continuing the ongoing discussion about integer error conditions. But in that longer discussion, if the best answer to "why shouldn't we raise an error?" is "well this other operation also returns nonsensical results" then I don't find that very compelling :-). |
Just to clarify, in the present 'master' branch in the forked repository, Upd : |
This issue is still in master. The consensus seems to be to raise an error for integer type arrays. I updated the title to make it more clear that only the |
I want to take this up as this seems to be an easy fix and could be my first open source contribution. Could I get some help as to what files to look into to fix this? |
Look at numpy/core/src/umath/loops.c.src. You'll need to use the |
This gives 1 as expected in numpy 1.11 but 0 in master. The problem happens only for ints. For floats it works fine, for example
np.power(0.0, 0)
is 1 in master.git bisect tells me this is the commit e7ddb39 where things started to go wrong.
ping @ewmoore, @jaimefrio.
The text was updated successfully, but these errors were encountered: