Commit b2658ad3 authored by Stefan Behnel's avatar Stefan Behnel

clean up some instances of suboffsets handling in memoryview code

parent 2799242d
...@@ -526,7 +526,7 @@ cdef class memoryview(object): ...@@ -526,7 +526,7 @@ cdef class memoryview(object):
@cname('__pyx_memoryview_get_suboffsets') @cname('__pyx_memoryview_get_suboffsets')
def __get__(self): def __get__(self):
if self.view.suboffsets == NULL: if self.view.suboffsets == NULL:
return [-1] * self.view.ndim return (-1,) * self.view.ndim
return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]])
...@@ -654,9 +654,8 @@ cdef tuple _unellipsify(object index, int ndim): ...@@ -654,9 +654,8 @@ cdef tuple _unellipsify(object index, int ndim):
return have_slices or nslices, tuple(result) return have_slices or nslices, tuple(result)
cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
cdef int i for suboffset in suboffsets[:ndim]:
for i in range(ndim): if suboffset >= 0:
if suboffsets[i] >= 0:
raise ValueError("Indirect dimensions not supported") raise ValueError("Indirect dimensions not supported")
# #
...@@ -1024,10 +1023,7 @@ cdef void slice_copy(memoryview memview, {{memviewslice_name}} *dst): ...@@ -1024,10 +1023,7 @@ cdef void slice_copy(memoryview memview, {{memviewslice_name}} *dst):
for dim in range(memview.view.ndim): for dim in range(memview.view.ndim):
dst.shape[dim] = shape[dim] dst.shape[dim] = shape[dim]
dst.strides[dim] = strides[dim] dst.strides[dim] = strides[dim]
if suboffsets == NULL: dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1
dst.suboffsets[dim] = -1
else:
dst.suboffsets[dim] = suboffsets[dim]
@cname('__pyx_memoryview_copy_object') @cname('__pyx_memoryview_copy_object')
cdef memoryview_copy(memoryview memview): cdef memoryview_copy(memoryview memview):
...@@ -1291,21 +1287,21 @@ cdef int memoryview_copy_contents({{memviewslice_name}} src, ...@@ -1291,21 +1287,21 @@ cdef int memoryview_copy_contents({{memviewslice_name}} src,
return 0 return 0
@cname('__pyx_memoryview_broadcast_leading') @cname('__pyx_memoryview_broadcast_leading')
cdef void broadcast_leading({{memviewslice_name}} *slice, cdef void broadcast_leading({{memviewslice_name}} *mslice,
int ndim, int ndim,
int ndim_other) nogil: int ndim_other) nogil:
cdef int i cdef int i
cdef int offset = ndim_other - ndim cdef int offset = ndim_other - ndim
for i in range(ndim - 1, -1, -1): for i in range(ndim - 1, -1, -1):
slice.shape[i + offset] = slice.shape[i] mslice.shape[i + offset] = mslice.shape[i]
slice.strides[i + offset] = slice.strides[i] mslice.strides[i + offset] = mslice.strides[i]
slice.suboffsets[i + offset] = slice.suboffsets[i] mslice.suboffsets[i + offset] = mslice.suboffsets[i]
for i in range(offset): for i in range(offset):
slice.shape[i] = 1 mslice.shape[i] = 1
slice.strides[i] = slice.strides[0] mslice.strides[i] = mslice.strides[0]
slice.suboffsets[i] = -1 mslice.suboffsets[i] = -1
# #
### Take care of refcounting the objects in slices. Do this seperately from any copying, ### Take care of refcounting the objects in slices. Do this seperately from any copying,
......
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