Author: Maciej Fijalkowski <fij...@gmail.com> Branch: numpy-multidim Changeset: r48502:21fa3eefa93b Date: 2011-10-27 12:40 +0200 http://bitbucket.org/pypy/pypy/changeset/21fa3eefa93b/
Log: few small fixes, start working on NDimSlice diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py --- a/pypy/module/micronumpy/interp_numarray.py +++ b/pypy/module/micronumpy/interp_numarray.py @@ -17,8 +17,9 @@ class BaseArray(Wrappable): _attrs_ = ["invalidates", "signature"] - def __init__(self): + def __init__(self, shape): self.invalidates = [] + self.shape = shape def invalidated(self): if self.invalidates: @@ -277,7 +278,6 @@ return space.wrap(res) def descr_setitem(self, space, w_idx, w_value): - # TODO: indexing by arrays and lists self.invalidated() if self._single_item_at_index(space, w_idx): item = self._single_item_at_index(space, w_idx) @@ -353,7 +353,7 @@ _attrs_ = ["dtype", "value"] def __init__(self, dtype, value): - BaseArray.__init__(self) + BaseArray.__init__(self, []) self.dtype = dtype self.value = value @@ -504,18 +504,19 @@ raise NotImplementedError def descr_len(self, space): + xxx # XXX find shape first return space.wrap(self.find_size()) def calc_index(self, item): raise NotImplementedError -class SingleDimSlice(ViewArray): +class NDimSlice(ViewArray): signature = signature.BaseSignature() def __init__(self, start, stop, step, slice_length, parent, signature): ViewArray.__init__(self, parent, signature) - if isinstance(parent, SingleDimSlice): + if isinstance(parent, NDimSlice): self.start = parent.calc_index(start) self.stop = parent.calc_index(stop) self.step = parent.step * step @@ -549,9 +550,8 @@ class NDimArray(BaseArray): def __init__(self, size, shape, dtype): - BaseArray.__init__(self) + BaseArray.__init__(self, shape) self.size = size - self.shape = shape self.dtype = dtype self.storage = dtype.malloc(size) self.signature = dtype.signature @@ -572,7 +572,10 @@ return self.dtype.getitem(self.storage, i) def descr_len(self, space): - return space.wrap(self.shape[0]) + if len(self.shape): + return space.wrap(self.shape[0]) + raise OperationError(space.w_TypeError, space.wrap( + "len() of unsized object")) def setitem_w(self, space, item, w_value): self.invalidated() diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -611,13 +611,14 @@ assert numpy.zeros((2, 2)).shape == (2,2) assert numpy.zeros((3, 1, 2)).shape == (3, 1, 2) assert len(numpy.zeros((3, 1, 2))) == 3 + raises(TypeError, len, numpy.zeros(())) def test_getsetitem(self): import numpy a = numpy.zeros((2, 3, 1)) - #raises(IndexError, a.__getitem__, (0, 0, 0, 0)) - #raises(IndexError, a.__getitem__, (3,)) - #raises(IndexError, a.__getitem__, (1, 3)) + raises(IndexError, a.__getitem__, (2, 0, 0)) + raises(IndexError, a.__getitem__, (0, 3, 0)) + raises(IndexError, a.__getitem__, (0, 0, 1)) assert a[1, 1, 0] == 0 a[1, 2, 0] = 3 assert a[1, 2, 0] == 3 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit