Author: mattip <matti.pi...@gmail.com> Branch: missing-ndarray-attributes Changeset: r60214:beb9be493502 Date: 2013-01-19 22:11 +0200 http://bitbucket.org/pypy/pypy/changeset/beb9be493502/
Log: implement arg_gettitem_slice diff --git a/pypy/module/micronumpy/arrayimpl/sort.py b/pypy/module/micronumpy/arrayimpl/sort.py --- a/pypy/module/micronumpy/arrayimpl/sort.py +++ b/pypy/module/micronumpy/arrayimpl/sort.py @@ -6,8 +6,8 @@ from pypy.rpython.lltypesystem import rffi, lltype from pypy.rlib.listsort import make_timsort_class from pypy.rlib.objectmodel import specialize -from pypy.rlib.rawstorage import raw_storage_getitem, raw_storage_setitem - +from pypy.rlib.rawstorage import raw_storage_getitem, raw_storage_setitem, \ + free_raw_storage, alloc_raw_storage from pypy.interpreter.error import OperationError from pypy.module.micronumpy.base import W_NDimArray from pypy.module.micronumpy import interp_dtype, types @@ -29,7 +29,6 @@ self.size = size self.values = values self.indexes = indexes - self.start = start def getitem(self, item): v = raw_storage_getitem(TP, self.values, item * self.stride_size @@ -44,6 +43,18 @@ self.start, rffi.cast(TP, item[0])) raw_storage_setitem(self.indexes, idx * self.index_stride_size + self.index_start, item[1]) + class ArgArrayRepWithStorage(ArgArrayRepresentation): + def __init__(self, index_stride_size, stride_size, size): + start = 0 + dtype = interp_dtype.get_dtype_cache(space).w_longdtype + self.indexes = dtype.itemtype.malloc(size*dtype.get_size()) + self.values = alloc_raw_storage(size*rffi.sizeof(TP), track_allocation=False) + ArgArrayRepresentation.__init__(self, index_stride_size, stride_size, + size, self.values, self.indexes, start, start) + + def __del__(self): + free_raw_storage(self.indexes, track_allocation=False) + free_raw_storage(self.values, track_allocation=False) def arg_getitem(lst, item): return lst.getitem(item) @@ -55,7 +66,11 @@ return lst.size def arg_getitem_slice(lst, start, stop): - xxx + retval = ArgArrayRepWithStorage(lst.index_stride_size, lst.stride_size, + stop-start) + for i in range(stop-start): + retval.setitem(i, lst.getitem(i+start)) + return retval def arg_lt(a, b): return a[0] < b[0] 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 @@ -2344,7 +2344,10 @@ from _numpypy import array a = array([[4, 2], [1, 3]]) assert (a.argsort() == [[1, 0], [0, 1]]).all() - #trigger timsort run mode + a = array(range(10) + range(10) + range(10)) + b = a.argsort() + assert (b[:3] == [0, 10, 20]).all() + #trigger timsort 'run' mode which calls arg_getitem_slice a = array(range(100) + range(100) + range(100)) b = a.argsort() assert (b[:3] == [0, 100, 200]).all() _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit