Commit dc0769a8 authored by Stefan Behnel's avatar Stefan Behnel

Refactor step handling in slice_memviewslice() utility code to make it more...

Refactor step handling in slice_memviewslice() utility code to make it more obvious what is happening in which case.
Closes GH-3568.
parent f3394797
......@@ -832,10 +832,13 @@ cdef int slice_memviewslice(
_err_dim(PyExc_IndexError, "Index out of bounds (axis %d)", dim)
else:
# index is a slice
negative_step = have_step != 0 and step < 0
if have_step and step == 0:
if have_step:
negative_step = step < 0
if step == 0:
_err_dim(PyExc_ValueError, "Step may not be zero (axis %d)", dim)
else:
negative_step = False
step = 1
# check our bounds and set defaults
if have_start:
......@@ -867,9 +870,6 @@ cdef int slice_memviewslice(
else:
stop = shape
if not have_step:
step = 1
# len = ceil( (stop - start) / step )
with cython.cdivision(True):
new_shape = (stop - start) // step
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment