-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
sum
method returns array with invalid C/F-contiguous flags
#387
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
The first bad commit over here is aed9925, but don't have enough knowledge about the code base to tell more (Just took this issue as an opportunity to start digging in...). |
@stefanv, would you know how to fix this? |
Hey, I think this might all come down to 0 stride arrays (it seems to me the code added in the commit tomspurs linked uses 0-strides). Maybe it is an idea to fix it by flagsobject.c, something along the lines of (same for Fortranconigouos of course) --- a/numpy/core/src/multiarray/flagsobject.c
+++ b/numpy/core/src/multiarray/flagsobject.c
@@ -134,10 +134,12 @@ _IsContiguous(PyArrayObject *ap)
if (dim == 0) {
return 1;
}
- if (PyArray_STRIDES(ap)[i] != sd) {
- return 0;
+ if (dim != 1) {
+ if (PyArray_STRIDES(ap)[i] != sd) {
+ return 0;
+ }
+ sd *= dim;
}
- sd *= dim;
}
return 1;
} However I wonder if this may create troubles at some other places. The thing is that size 1 dimensions do not really matter when it comes to C-Contiguousity. Alternatively, maybe these strides in size 1-dimensions should maybe be silently replaced with something other then 0? I remember seeing a 0-stride reshape bug too in the Tracker, comeing down to a similar issue (though at another place I guess). |
Actually, the thing above is what it comes down too. However, UpdateFlags assumes that for multi dimensional arrays it cannot be true that both C and F-contiguous is true. So either PyArray_RemoveAxesInPlace (shape.c) must update the flags, or here as said above 1 sized dimensions be generally allowed to have any stride (and UpdateFlags would need this assumption of mutual exclusiveness removed too). |
Thanks @seberg for the investigation. Well, we can try the above fix and run tests. That should reveal if it breaks something. |
Fixed by #420. |
This still works in 1.5.1. Broken on the latest Git HEAD.
It affects all reductions of ndarray objects.
The text was updated successfully, but these errors were encountered: