-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Bug: Adding a transposed array to itself #5241
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
There is similar discussion at #2705. |
So across at least two machines running 1.9.1 this bug occurs for 91x91 arrays but not for 90x90 arrays. I'm not sure what significance that holds. https://gist.github.com/PhilReinhold/5327001ac17f923942ad#file-test_transpose-py |
The default buffer size is 8192 items, 90x90 is 8100, 91x91 is 8281. You should actually see that the first wrong value is the third entry of the last row, I.e. the 8193rd entry. |
@PhilReinhold This is a design issue, not really a bug that is realistically fixable as far as I understand. At best, some warning could be added, and I'm not sure how difficult that would be. Python allows |
In order to detect this case and issue a warning or whatever, we would need
|
Would it be reasonable to back off from |
Numpy's general philosophy is to provide as much safety as possible without
|
Should this issue be closed as 'not a bug' or 'wont fix' or something to that effect? |
I doubt there's very much code in existence that's both safe and efficient here, given that this depends on Numpy implementation details that we change without notice. For example:
I would say the behavior is undefined. The cases where the traversal order is simple enough to analyze to write correct code for are probably mostly 1D. I do not remember seeing many proposed use cases. Whether this should be a generic ufunc thing or just for binary operations and assignment, just a warning that things look dangerous or something more is then a more hairy question. The previous suggestion (gh-1683) was to make copies of RHS when it's not clear the operation is safe. |
The problem is that even trivial safe cases like 'arr[:, 0] += arr[:, 1]'
|
Remember when gcc reversed the traversal order of memcpy? |
But that wouldn't affect this example in which |
duplicate gh-1683 |
Something very strange happens when you try adding a transposed array to itself:
arr = arr + arr.T
works fine of course.It looks like because arr.T is a view of arr, while reading values out of arr.T it reads elements of arr that have already been written to. This could lead to some really sneaky bugs. Even just detecting the situation and raising an exception would be an acceptable solution.
The text was updated successfully, but these errors were encountered: