Commit f0d60728 authored by Stefan Behnel's avatar Stefan Behnel

clean up and simplify some code

parent 2700e637
...@@ -296,12 +296,7 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry): ...@@ -296,12 +296,7 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry):
name, "MemoryView_C.c", context=context_dict) name, "MemoryView_C.c", context=context_dict)
return impl return impl
all_dimensions_direct = True all_dimensions_direct = all(access == 'direct' for access, packing in self.type.axes)
for access, packing in self.type.axes:
if access != 'direct':
all_dimensions_direct = False
break
no_suboffset_dim = all_dimensions_direct and not have_slices no_suboffset_dim = all_dimensions_direct and not have_slices
if not no_suboffset_dim: if not no_suboffset_dim:
suboffset_dim = code.funcstate.allocate_temp(PyrexTypes.c_int_type, manage_ref=False) suboffset_dim = code.funcstate.allocate_temp(PyrexTypes.c_int_type, manage_ref=False)
...@@ -313,10 +308,17 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry): ...@@ -313,10 +308,17 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry):
dim = -1 dim = -1
for index in indices: for index in indices:
error_goto = code.error_goto(index.pos) if index.is_none:
if not index.is_none: # newaxis
for attrib, value in [('shape', 1), ('strides', 0), ('suboffsets', -1)]:
code.putln("%s.%s[%d] = %d;" % (dst, attrib, new_ndim, value))
new_ndim += 1
continue
dim += 1 dim += 1
access, packing = self.type.axes[dim] access, packing = self.type.axes[dim]
error_goto = code.error_goto(index.pos)
if isinstance(index, ExprNodes.SliceNode): if isinstance(index, ExprNodes.SliceNode):
# slice, unspecified dimension, or part of ellipsis # slice, unspecified dimension, or part of ellipsis
...@@ -324,14 +326,9 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry): ...@@ -324,14 +326,9 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry):
for s in "start stop step".split(): for s in "start stop step".split():
idx = getattr(index, s) idx = getattr(index, s)
have_idx = d['have_' + s] = not idx.is_none have_idx = d['have_' + s] = not idx.is_none
if have_idx: d[s] = idx.result() if have_idx else "0"
d[s] = idx.result()
else:
d[s] = "0"
if (not d['have_start'] and if not (d['have_start'] or d['have_stop'] or d['have_step']):
not d['have_stop'] and
not d['have_step']):
# full slice (:), simply copy over the extent, stride # full slice (:), simply copy over the extent, stride
# and suboffset. Also update suboffset_dim if needed # and suboffset. Also update suboffset_dim if needed
d['access'] = access d['access'] = access
...@@ -340,32 +337,23 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry): ...@@ -340,32 +337,23 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry):
code.put(load_slice_util("ToughSlice", d)) code.put(load_slice_util("ToughSlice", d))
new_ndim += 1 new_ndim += 1
elif index.is_none:
# newaxis
attribs = [('shape', 1), ('strides', 0), ('suboffsets', -1)]
for attrib, value in attribs:
code.putln("%s.%s[%d] = %d;" % (dst, attrib, new_ndim, value))
new_ndim += 1
else: else:
# normal index # normal index
idx = index.result() idx = index.result()
if access == 'direct': indirect = access != 'direct'
indirect = False if indirect:
else: generic = access == 'full'
indirect = True
generic = (access == 'full')
if new_ndim != 0: if new_ndim != 0:
return error(index.pos, return error(index.pos,
"All preceding dimensions must be " "All preceding dimensions must be "
"indexed and not sliced") "indexed and not sliced")
wraparound = int(directives['wraparound']) d = dict(
boundscheck = int(directives['boundscheck']) locals(),
d = locals() wraparound=int(directives['wraparound']),
boundscheck=int(directives['boundscheck'])
)
code.put(load_slice_util("SliceIndex", d)) code.put(load_slice_util("SliceIndex", d))
if not no_suboffset_dim: if not no_suboffset_dim:
......
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