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
MemoryView slicing contiguity bugfix #2961
Conversation
The change looks ok, but tests are missing. |
Hmm, hang on. Shouldn't we rather set |
Will add tests shortly.
It seemed that that the MemoryView slice itself doesn't have an |
I've added a couple of tests to the existing contiguous memview slice test code. |
tests/memoryview/memslice.pyx
Outdated
@@ -1,5 +1,5 @@ | |||
# mode: run | |||
|
|||
# tag: abcd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, that was quite careless. Removed (and rebased on top of current master).
Thanks! |
This addresses #2941. The MemoryView scalar assignment code currently generates a stride 1 (ie. contiguous) loop whenever the destination of the slice is contiguous, regardless of the slice. This isn't quite right, since slices of contiguous arrays of course aren't necessarily contiguous. This patch just adds a check: if any of the indices of the slice is not simply
:
, then do not assume contiguity (these slices are referred to as "ToughSlices" elsewhere in the code).One can do better than this, ie. if for a C-contiguous array the slice
a[1][:]
is contiguous, so the old generated code is correct and the new generated code is a little slower. Not ideal, and maybe is worth adding logic to detect these cases, but this seems a reasonable first-pass fix.