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.
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.