-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
FIX: Do not rely on strides for contiguous arrays #1458
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
When an array is contiguous in memory but has `shape[dim] == 1`, then its `strides[dim]` is not really used, so it can be considered arbitrary even if the array is contiguous. This is generally true for 0-sized arrays. If there is no chance of 0-sized (or 1-sized and 1-dimensioal) arrays, then this code is perfectly correct in current numpy. But its a dangerous design choice and it would be nice to be able to change numpy at some point.
There shouldn't be any casts, only memory views ;)
|
I don't see any of this... |
@larsman It actually seems likely that memoryviews only use the buffer interface, and I think for those numpy should probably allow you to rely on strides, but cython currently uses something in between buffers and arrays for |
@seberg: thanks a lot for pitching in. I haven't had time to look at this |
Ah, that's what you mean. Yes, a lot of our code uses |
@larsmans I don't think this was intentional - just a lack of expertise (at least on my side) - if there is a safety risk in our current codebase we should fix that. you propose that we use |
@pprett for everything to do with indexing. Also normal indexing, strides, shape/size too, I believe you need to use |
Thanks for the hints! We should indeed use Regarding this PR, this looks good to me. +1 |
We should create a ticket with the 'EasyFix' label. |
Isn't there a release coming up? If so, we should (IMHO) merge this, then do the release, then merge in new features. |
I wasn't clear: +1 on merging this; -1 for doing the refactoring before 2012/12/11 Lars Buitinck notifications@github.com
Peter Prettenhofer |
Am 11.12.2012 14:42, schrieb Lars Buitinck:
|
I won't be really able to help before beginning of January. Sorry. |
I am merging this, since both @pprett and I are fine with it. I'll edit the what's new myself and open an issue regarding the use of |
FIX: Do not rely on strides for contiguous arrays
When an array is contiguous in memory but has
shape[dim] == 1
, thenits
strides[dim]
is not really used, so it can be considered arbitraryeven if the array is contiguous. This is generally true for 0-sized arrays.
If there is no chance of 0-sized (or 1-sized and 1-dimensioal) arrays, then
this code is perfectly correct in current numpy. But its a dangerous
design choice and it would be nice to be able to change numpy at some point.
This fixes gh-1406 (without a numpy change, which I am sure will come soon, but there is no reason to change it here anyway). Using
.itemsize
is much clearer anyway, so the only reason to not do it is to do some premature optimization because Cython doesn't compile it away.(Recreated the c files with cython 0.17.1)
Btw. all over this file
<int>
casts seem to be used for memory pointers. Is this really correct? Since it should benpy_intp
from a numpy perspective.