Commit 54f2970b authored by mattip's avatar mattip

fix translation, code cleanup needed

parent 3e8b0e26
......@@ -449,7 +449,7 @@ class SliceArray(BaseConcreteArray):
strides.reverse()
backstrides.reverse()
new_shape.reverse()
return type(self)(self.start, strides, backstrides, new_shape,
return self.__class__(self.start, strides, backstrides, new_shape,
self, orig_array)
new_strides = calc_new_strides(new_shape, self.get_shape(),
self.get_strides(),
......@@ -460,7 +460,7 @@ class SliceArray(BaseConcreteArray):
new_backstrides = [0] * len(new_shape)
for nd in range(len(new_shape)):
new_backstrides[nd] = (new_shape[nd] - 1) * new_strides[nd]
return type(self)(self.start, new_strides, new_backstrides, new_shape,
return self.__class__(self.start, new_strides, new_backstrides, new_shape,
self, orig_array)
......
......@@ -99,7 +99,7 @@ class IterState(object):
class ArrayIter(object):
_immutable_fields_ = ['contiguous', 'array', 'size', 'ndim_m1', 'shape_m1[*]',
'strides[*]', 'backstrides[*]', 'factors[*]',
'track_index', 'operand_type']
'track_index', 'operand_type', 'slice_operand_type']
track_index = True
......@@ -116,6 +116,7 @@ class ArrayIter(object):
self.shape_m1 = [s - 1 for s in shape]
self.strides = strides
self.backstrides = backstrides
self.slice_operand_type = concrete.SliceArray
ndim = len(shape)
factors = [0] * ndim
......@@ -243,39 +244,36 @@ class SliceIter(ArrayIter):
used with external loops, getitem and setitem return a SliceArray
view into the original array
'''
_immutable_fields_ = ['base', 'slice_shape[*]', 'slice_stride[*]', 'slice_backstride[*]']
def __init__(self, array, size, shape, strides, backstrides, slice_shape,
slice_stride, slice_backstride, op_flags, base):
from pypy.module.micronumpy import concrete
ArrayIter.__init__(self, array, size, shape, strides, backstrides, op_flags)
self.shape = shape[:]
self.slice_shape = slice_shape
self.slice_stride = slice_stride
self.slice_backstride = slice_backstride
self.base = base
if op_flags.rw == 'r':
self.operand_type = concrete.NonWritableSliceArray
self.slice_operand_type = concrete.NonWritableSliceArray
else:
self.operand_type = concrete.SliceArray
self.slice_operand_type = concrete.SliceArray
def getitem(self, state):
assert state.iterator is self
impl = self.operand_type
arr = impl(state.offset, [self.slice_stride], [self.slice_backstride],
[self.slice_shape], self.array, self.base)
return arr
# XXX cannot be called - must return a boxed value
assert False
def getitem_bool(self, state):
# XXX cannot be called
# XXX cannot be called - must return a boxed value
assert False
def setitem(self, state, elem):
assert state.iterator is self
impl = self.operand_type
slice = impl(state.offset, [self.slice_stride], [self.slice_backstride],
[self.shape], self.array, self.base)
# TODO: implement
# XXX cannot be called - must return a boxed value
assert False
def getoperand(self, state, base):
return self.getitem(state)
assert state.iterator is self
impl = self.slice_operand_type
arr = impl(state.offset, [self.slice_stride], [self.slice_backstride],
[self.slice_shape], self.array, self.base)
return arr
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