-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
numpy.linalg.norm() broken for multidimensional integer arrays #5626
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
Oh, that's not good. The problem seems to be |
The |
Some examples
|
Is it not a bug that |
A related issue #5018 with the appropriate reference to http://xkcd.com/1172/. If numpy wants to break spacebar heating, what if all functions in |
@argriffing I'm thinking of converting everything to floats or objects for linalg.norm. |
It seems like you have to convert to a float before doing any operations on it, if you want it to work as expected. In the first one, I think the 2nd example isn't actually a bug, but the behavior is very unintuitive if you don't see what's going on. Although the 1st example (the linalg.norm) call makes sense once you think about it, I'd prefer the float casting solution, having the expected behavior of the standard library match expectations is worth the possible slowdowns. |
Great! (I assume you would also allow complex numbers) |
Converting to floats sounds good. That should help the L0 case, as well.
|
OK, this change should be made. Still time for 1.11 if someone wants to step up... |
Sure, I'll give it a try. Should be straightforward. All we want to do is cast to float if it is not floating point. Should we raise a warning that we did so too? If so, what kind of warning? Should I PR |
I don't think a warning is needed, we should just return floats. I'll add a mention in the release notes when it goes in. |
Interesting fact, it states it will return |
Interesting. IIRC, the current behavior is actually a regression. |
I added a PR ( #7088 ) for the simple fix to see if that goes ok. Then we probably should go back and clean up the examples. For now, I have allowed other types of floats that are not 64-bit. This way we aren't forcing people to cast up or down. However, if it isn't a kind of float we are always casting to 64-bit floats. |
It should be pointed out that the OP has also demonstrated that |
@jakirkham How so? There are no overflow guarantees for dot... |
Oh ok, if there are no guarantees, I guess it is fine. |
The text was updated successfully, but these errors were encountered: