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