[pypy-commit] pypy numpy-multidim: shape
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48491:cc8b141031c6 Date: 2011-10-26 22:34 +0200 http://bitbucket.org/pypy/pypy/changeset/cc8b141031c6/ Log:shape 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 @@ -199,7 +199,7 @@ return space.wrap(self.find_dtype()) def descr_get_shape(self, space): -return space.newtuple([self.descr_len(space)]) +return space.newtuple([space.wrap(i) for i in self.shape]) def descr_copy(self, space): return space.call_function(space.gettypefor(BaseArray), self, self.find_dtype()) 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 @@ -605,6 +605,14 @@ a = numpy.zeros((2, 2)) assert len(a) == 2 +def test_shape(self): +import numpy +assert numpy.zeros(1).shape == (1,) +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 + + class AppTestSupport(object): def setup_class(cls): import struct ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: a better fix for test_zll_random
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48493:52416083d855 Date: 2011-10-27 10:24 +0200 http://bitbucket.org/pypy/pypy/changeset/52416083d855/ Log:a better fix for test_zll_random diff --git a/pypy/jit/backend/llsupport/regalloc.py b/pypy/jit/backend/llsupport/regalloc.py --- a/pypy/jit/backend/llsupport/regalloc.py +++ b/pypy/jit/backend/llsupport/regalloc.py @@ -178,8 +178,6 @@ cur_max_age = -1 candidate = None for next in self.reg_bindings: -if isinstance(next, TempBox): -continue reg = self.reg_bindings[next] if next in forbidden_vars: continue diff --git a/pypy/jit/backend/x86/regalloc.py b/pypy/jit/backend/x86/regalloc.py --- a/pypy/jit/backend/x86/regalloc.py +++ b/pypy/jit/backend/x86/regalloc.py @@ -1050,7 +1050,7 @@ tempvar = TempBox() index_loc = self.rm.force_result_in_reg(tempvar, op.getarg(1), args) # we're free to modify index now -value_loc = self.make_sure_var_in_reg(op.getarg(2), args, +value_loc = self.make_sure_var_in_reg(op.getarg(2), args + [tempvar], need_lower_byte=need_lower_byte) self.rm.possibly_free_var(tempvar) self.possibly_free_vars(args) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: tentative checkin
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48492:4dd7d695536a Date: 2011-10-27 00:04 +0200 http://bitbucket.org/pypy/pypy/changeset/4dd7d695536a/ Log:tentative checkin 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 @@ -223,17 +223,32 @@ concrete = self.get_concrete() return space.wrap([ + .join(concrete._getnums(True)) + ]) +def item_at_index(self, index, space): +# we assume C ordering for now +item = 0 +for i in range(len(index)): +if i != 0: +item *= self.shape[i] +if index[i] = self.shape[i]: +raise OperationError(space.w_IndexError, + space.wrap(index (%d) out of range (0=index%d % (index[i], self.shape[i]))) +item += index[i] +return item + def descr_getitem(self, space, w_idx): # TODO: indexing by arrays and lists if space.isinstance_w(w_idx, space.w_tuple): +# or any other sequence actually length = space.len_w(w_idx) if length == 0: return space.wrap(self) -if length 1: # only one dimension for now. +if length len(self.shape): raise OperationError(space.w_IndexError, space.wrap(invalid index)) -w_idx = space.getitem(w_idx, space.wrap(0)) -start, stop, step, slice_length = space.decode_index4(w_idx, self.find_size()) +indices = [space.int_w(w_item) for w_item in space.fixedview(w_idx)] +item = self.item_at_index(indices, space) +return self.get_concrete().eval(item).wrap(space) +start, stop, step, slice_length = space.decode_index4(w_idx, self.shape[0]) if step == 0: # Single index return self.get_concrete().eval(start).wrap(space) 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,7 +611,17 @@ 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 - + +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)) +assert a[1, 1, 0] == 0 +a[1, 2, 0] = 3 +assert a[1, 2, 0] == 3 +assert a[1, 1, 0] == 0 class AppTestSupport(object): def setup_class(cls): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Revert the hack to llsupport/regalloc. Implement a version that
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r48495:478d71b47de8 Date: 2011-10-27 10:51 +0200 http://bitbucket.org/pypy/pypy/changeset/478d71b47de8/ Log:Revert the hack to llsupport/regalloc. Implement a version that uses the hopefully correct and official API. diff --git a/pypy/jit/backend/llsupport/regalloc.py b/pypy/jit/backend/llsupport/regalloc.py --- a/pypy/jit/backend/llsupport/regalloc.py +++ b/pypy/jit/backend/llsupport/regalloc.py @@ -178,8 +178,6 @@ cur_max_age = -1 candidate = None for next in self.reg_bindings: -if isinstance(next, TempBox): -continue reg = self.reg_bindings[next] if next in forbidden_vars: continue diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py --- a/pypy/jit/backend/x86/assembler.py +++ b/pypy/jit/backend/x86/assembler.py @@ -1596,11 +1596,24 @@ genop_getarrayitem_gc_pure = genop_getarrayitem_gc genop_getarrayitem_raw = genop_getarrayitem_gc +def _get_interiorfield_index(self, temp_loc, index_loc, itemsize_loc): +assert isinstance(itemsize_loc, ImmedLoc) +if isinstance(index_loc, ImmedLoc): +return imm(index_loc.value * itemsize_loc.value) +else: +# XXX should not use IMUL in most cases +assert isinstance(temp_loc, RegLoc) +assert isinstance(index_loc, RegLoc) +self.mc.IMUL_rri(temp_loc.value, index_loc.value, + itemsize_loc.value) +return temp_loc + def genop_getinteriorfield_gc(self, op, arglocs, resloc): -base_loc, ofs_loc, itemsize_loc, fieldsize_loc, index_loc, sign_loc = arglocs -# XXX should not use IMUL in most cases -self.mc.IMUL(index_loc, itemsize_loc) -src_addr = AddressLoc(base_loc, index_loc, 0, ofs_loc.value) +(base_loc, ofs_loc, itemsize_loc, fieldsize_loc, +index_loc, sign_loc) = arglocs +temp_loc = self._get_interiorfield_index(resloc, index_loc, + itemsize_loc) +src_addr = AddressLoc(base_loc, temp_loc, 0, ofs_loc.value) self.load_from_mem(resloc, src_addr, fieldsize_loc, sign_loc) @@ -1611,13 +1624,11 @@ self.save_into_mem(dest_addr, value_loc, size_loc) def genop_discard_setinteriorfield_gc(self, op, arglocs): -base_loc, ofs_loc, itemsize_loc, fieldsize_loc, index_loc, value_loc = arglocs -# XXX should not use IMUL in most cases -if isinstance(index_loc, ImmedLoc): -index_loc = imm(index_loc.value * itemsize_loc.value) -else: -self.mc.IMUL(index_loc, itemsize_loc) -dest_addr = AddressLoc(base_loc, index_loc, 0, ofs_loc.value) +(base_loc, ofs_loc, itemsize_loc, fieldsize_loc, +index_loc, temp_loc, value_loc) = arglocs +temp_loc = self._get_interiorfield_index(temp_loc, index_loc, + itemsize_loc) +dest_addr = AddressLoc(base_loc, temp_loc, 0, ofs_loc.value) self.save_into_mem(dest_addr, value_loc, fieldsize_loc) def genop_discard_setarrayitem_gc(self, op, arglocs): diff --git a/pypy/jit/backend/x86/regalloc.py b/pypy/jit/backend/x86/regalloc.py --- a/pypy/jit/backend/x86/regalloc.py +++ b/pypy/jit/backend/x86/regalloc.py @@ -1046,16 +1046,26 @@ need_lower_byte = True else: need_lower_byte = False -base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), args) -tempvar = TempBox() -index_loc = self.rm.force_result_in_reg(tempvar, op.getarg(1), args) -# we're free to modify index now -value_loc = self.make_sure_var_in_reg(op.getarg(2), args, +box_base, box_index, box_value = args +base_loc = self.rm.make_sure_var_in_reg(box_base, args) +index_loc = self.rm.make_sure_var_in_reg(box_index, args) +value_loc = self.make_sure_var_in_reg(box_value, args, need_lower_byte=need_lower_byte) -self.rm.possibly_free_var(tempvar) -self.possibly_free_vars(args) +# If 'index_loc' is not an immediate, then we need a 'temp_loc' that +# is a register whose value will be destroyed. It's fine to destroy +# the same register as 'index_loc', but not the other ones. +self.rm.possibly_free_var(box_index) +if not isinstance(index_loc, ImmedLoc): +tempvar = TempBox() +temp_loc = self.rm.force_allocate_reg(tempvar, [box_base, +box_value]) +self.rm.possibly_free_var(tempvar) +else: +temp_loc = None +self.rm.possibly_free_var(box_base) +self.possibly_free_var(box_value) self.PerformDiscard(op, [base_loc, ofs, itemsize, fieldsize, -
[pypy-commit] pypy int-tag-untag-as-operations: make all optimizeopt tests pass
Author: Carl Friedrich Bolz cfb...@gmx.de Branch: int-tag-untag-as-operations Changeset: r48498:5dea661f90f6 Date: 2011-10-25 13:53 +0200 http://bitbucket.org/pypy/pypy/changeset/5dea661f90f6/ Log:make all optimizeopt tests pass diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py --- a/pypy/jit/backend/llgraph/llimpl.py +++ b/pypy/jit/backend/llgraph/llimpl.py @@ -87,10 +87,13 @@ 'int_is_true' : (('int',), 'bool'), 'int_is_zero' : (('int',), 'bool'), 'int_neg' : (('int',), 'int'), +'int_tag' : (('int', ), 'int'), +'int_untag' : (('int', ), 'int'), 'int_invert' : (('int',), 'int'), 'int_add_ovf' : (('int', 'int'), 'int'), 'int_sub_ovf' : (('int', 'int'), 'int'), 'int_mul_ovf' : (('int', 'int'), 'int'), +'int_tag_ovf' : (('int', ), 'int'), 'uint_add': (('int', 'int'), 'int'), 'uint_sub': (('int', 'int'), 'int'), 'uint_mul': (('int', 'int'), 'int'), diff --git a/pypy/jit/metainterp/optimizeopt/intbounds.py b/pypy/jit/metainterp/optimizeopt/intbounds.py --- a/pypy/jit/metainterp/optimizeopt/intbounds.py +++ b/pypy/jit/metainterp/optimizeopt/intbounds.py @@ -305,20 +305,20 @@ def optimize_INT_TAG(self, op): v1 = self.getvalue(op.getarg(0)) +self.emit_operation(op) r = self.getvalue(op.result) resbound = v1.intbound.mul(2).add(1) r.intbound.intersect(resbound) maxbounds = IntBound((-sys.maxint-1) 1, sys.maxint 1) v1.intbound.intersect(maxbounds) self.pure(rop.INT_UNTAG, [op.result], op.getarg(0)) -self.emit_operation(op) def optimize_INT_UNTAG(self, op): v1 = self.getvalue(op.getarg(0)) self.pure(rop.INT_TAG, [op.result], op.getarg(0)) +self.emit_operation(op) r = self.getvalue(op.result) r.intbound.intersect(v1.intbound.rshift_bound(IntBound(1, 1))) -self.emit_operation(op) def optimize_ARRAYLEN_GC(self, op): self.emit_operation(op) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -5124,6 +5124,7 @@ [i0] i1 = int_lt(i0, 1000) guard_true(i1), [] +i2 = int_tag(i0) i3 = int_add(i0, 1) jump(i3) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy int-tag-untag-as-operations: those are also not needed
Author: Carl Friedrich Bolz cfb...@gmx.de Branch: int-tag-untag-as-operations Changeset: r48499:be97182b1a31 Date: 2011-10-27 11:52 +0200 http://bitbucket.org/pypy/pypy/changeset/be97182b1a31/ Log:those are also not needed diff --git a/pypy/jit/metainterp/test/test_immutable.py b/pypy/jit/metainterp/test/test_immutable.py --- a/pypy/jit/metainterp/test/test_immutable.py +++ b/pypy/jit/metainterp/test/test_immutable.py @@ -64,7 +64,7 @@ l[2] = 30 a = escape(X(l)) return a.y[index] -res = self.interp_operations(f, [2], listops=True) +res = self.interp_operations(f, [2]) assert res == 30 self.check_operations_history(getfield_gc=0, getfield_gc_pure=1, getarrayitem_gc=0, getarrayitem_gc_pure=1) @@ -82,7 +82,7 @@ def f(x, index): y = escape(X([x], x+1)) return y.lst[index] + y.y + 5 -res = self.interp_operations(f, [23, 0], listops=True) +res = self.interp_operations(f, [23, 0]) assert res == 23 + 24 + 5 self.check_operations_history(getfield_gc=0, getfield_gc_pure=2, getarrayitem_gc=0, getarrayitem_gc_pure=1, diff --git a/pypy/jit/metainterp/test/test_list.py b/pypy/jit/metainterp/test/test_list.py --- a/pypy/jit/metainterp/test/test_list.py +++ b/pypy/jit/metainterp/test/test_list.py @@ -123,7 +123,7 @@ l2 = l[:] return l2[0] + l2[1] + l2[2] + l2[3] -res = self.interp_operations(f, [], listops=True) +res = self.interp_operations(f, []) assert res == 10 def test_arraycopy_full(self): diff --git a/pypy/jit/metainterp/test/test_slist.py b/pypy/jit/metainterp/test/test_slist.py --- a/pypy/jit/metainterp/test/test_slist.py +++ b/pypy/jit/metainterp/test/test_slist.py @@ -31,7 +31,7 @@ lst2.append(FooBar(5)) m += lst2.pop().z # 49 return m -res = self.interp_operations(f, [11], listops=True) +res = self.interp_operations(f, [11]) assert res == 49 self.check_operations_history(call=3) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] benchmarks default: fix a test
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r152:f04d6d63ba60 Date: 2011-10-27 11:57 +0200 http://bitbucket.org/pypy/benchmarks/changeset/f04d6d63ba60/ Log:fix a test diff --git a/benchmarks.py b/benchmarks.py --- a/benchmarks.py +++ b/benchmarks.py @@ -110,7 +110,6 @@ assert timings == [ ('annotate', 1.3), ('rtype', 4.6), -('stackcheck', 2.3), ('database', 0.4) ] ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: getsetitem for single items
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48501:345d2c256ce7 Date: 2011-10-27 12:02 +0200 http://bitbucket.org/pypy/pypy/changeset/345d2c256ce7/ Log:getsetitem for single items 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 @@ -223,8 +223,12 @@ concrete = self.get_concrete() return space.wrap([ + .join(concrete._getnums(True)) + ]) -def item_at_index(self, index, space): +def _single_item_at_index(self, space, w_idx): # we assume C ordering for now +if len(self.shape) == 1: +return space.int_w(w_idx) +index = [space.int_w(w_item) + for w_item in space.fixedview(w_idx)] item = 0 for i in range(len(index)): if i != 0: @@ -235,19 +239,31 @@ item += index[i] return item +def _single_item_result(self, space, w_idx): + The result of getitem/setitem is a single item if w_idx +is a list of scalars that match the size of shape + +if len(self.shape) == 1: +if (space.isinstance_w(w_idx, space.w_slice) or +space.isinstance_w(w_idx, space.w_int)): +return True +return False +lgt = space.len_w(w_idx) +if lgt len(self.shape): +raise OperationError(space.w_IndexError, + space.wrap(invalid index)) +if lgt len(self.shape): +return False +for w_item in space.fixedview(w_idx): +if space.isinstance_w(w_item, space.w_slice): +return False +return True + def descr_getitem(self, space, w_idx): -# TODO: indexing by arrays and lists -if space.isinstance_w(w_idx, space.w_tuple): -# or any other sequence actually -length = space.len_w(w_idx) -if length == 0: -return space.wrap(self) -if length len(self.shape): -raise OperationError(space.w_IndexError, - space.wrap(invalid index)) -indices = [space.int_w(w_item) for w_item in space.fixedview(w_idx)] -item = self.item_at_index(indices, space) +if self._single_item_result(space, w_idx): +item = self._single_item_at_index(space, w_idx) return self.get_concrete().eval(item).wrap(space) +xxx start, stop, step, slice_length = space.decode_index4(w_idx, self.shape[0]) if step == 0: # Single index @@ -263,6 +279,11 @@ 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) +self.get_concrete().setitem_w(space, item, w_value) +return +xxx if space.isinstance_w(w_idx, space.w_tuple): length = space.len_w(w_idx) if length 1: # only one dimension for now. 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 @@ -615,9 +615,9 @@ 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__, (0, 0, 0, 0)) +#raises(IndexError, a.__getitem__, (3,)) +#raises(IndexError, a.__getitem__, (1, 3)) 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
[pypy-commit] pypy numpy-multidim: few small fixes, start working on NDimSlice
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
[pypy-commit] extradoc extradoc: Add a blog post
Author: Maciej Fijalkowski fij...@gmail.com Branch: extradoc Changeset: r3939:bb06f91061f3 Date: 2011-10-27 14:58 +0200 http://bitbucket.org/pypy/extradoc/changeset/bb06f91061f3/ Log:Add a blog post diff --git a/blog/draft/faster-json.rst b/blog/draft/faster-json.rst new file mode 100644 --- /dev/null +++ b/blog/draft/faster-json.rst @@ -0,0 +1,107 @@ +Speeding up JSON encoding in PyPy += + +Hi + +Recently I spent a bit of effort into speeding up JSON in PyPy. I started with +writing a `benchmark`_, which is admiteddly not very good, but it's better +than nothing (suggestions to improve welcomed!). + +For this particular benchmark, the numbers are as follow. Note that CPython +uses hand-optimized C extension and PyPy uses a pure python version, +hand-optimized in trunk, default in older versions. I'm taking the third run, +when things are warmed up, full session `here`_. + +++-+ +| CPython 2.6| 22s | +++-+ +| CPython 2.7| **3.7s**| +++-+ +| CPython 2.7 no C extension | 44s | +++-+ +| PyPy 1.5 | 34s | +++-+ +| PyPy 1.6 | 22s | +++-+ +| PyPy trunk | **3.3s**| +++-+ + +.. _`benchmark`: https://bitbucket.org/pypy/benchmarks/src/f04d6d63ba60/own/json_bench.py +.. _`here`: http://paste.pocoo.org/show/498988/ + +Lessons learned: + +Expectations are high +- + +A lot of performance critical stuff in Python world is already written in a hand +optimized C. Writing C (especially when you interface with CPython C API) is +ugly and takes significant effort so it's only true for places which are +well separated enough, but still. People would expect PyPy to outperform +C extensions. Fortunately it's possible, but requires a bit of effort on +the programmer side as well. + +Often interface between the C and Python part is ugly +- + +This is very clear if you look at json module as implemented in CPython's +standard library. Not everything is in C (it would probably be just too +much effort) and the interface to what is in C is guided via profiling not +via what kind of interface makes sense. It's clear from CPython 2.6 to 2.7. +Just adapting the code to interface with C made the Python version slower. +Removing this clutter improves the readability a lot and improves PyPy's version +a bit, although I don't have hard numbers. + +JitViewer is crucial + + +In case you're fighting with PyPy's performance, `jitviewer`_ is worth a shot. +While it's not completely trivial to understand what's going on, it'll +definitely show you what kind of loops got compiled and how. + +.. _`jitviewer`: https://bitbucket.org/pypy/jitviewer + +No nice and fast way to build strings in Python +--- + +PyPy has a custom thing called ``__pypy__.builders.StringBuilder``. It has +few features that make it much easier to optimize than other ways like +``str.join()`` or ``cStringIO``. + +* You can specify the start size. Helps a lot if you can even provide a rough + estimate on the size of the string (less copying) +* Only append and build allowed. While string is built you can't seek or + do anything else. Once it's built you can never append any more. +* Unicode version available as well as ``__pypy__.builders.UnicodeBuilder``. + +Method calls are ok, immutable globals are ok +- + +PyPy's JIT seem to be good enough than at least in simple cases, calling +methods for common infrastructure or loading globals (instead of rebinding as +locals) is fast enough and improves code readability. + +I must admit I worked around PyPy's performance bug +--- + +For reasons obscure (although fixable), this:: + + for c in s: # s is string +del c + +is faster than:: + + for c in s: +pass + +This is a bug and should be fixed, but on different branch ;-) + +PyPy's JIT is kind of good +-- + +I was pretty surprised, but the JIT actually did make stuff work nicely. Seems +you can write code in Python if you want to make it run fast, but you have +to be a bit careful. Again, jitviewer is your friend + +Cheers, +fijal ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: few small fixes, start working on NDimSlice
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48503:6fd1b6212a20 Date: 2011-10-27 12:50 +0200 http://bitbucket.org/pypy/pypy/changeset/6fd1b6212a20/ 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 @@ -260,22 +260,24 @@ return False return True +def _create_slice(self, space, w_idx): +new_sig = signature.Signature.find_sig([ +NDimSlice.signature, self.signature +]) +if (space.isinstance_w(w_idx, space.w_int) or +space.isinstance_w(w_idx, space.w_slice)): +chunks = [space.decode_index4(w_idx, self.shape[0])] +else: +chunks = [] +for i, w_item in enumerate(space.fixedview(w_idx)): +chunks.append(space.decode_index4(w_item, self.shape[i])) +return NDimSlice(self, new_sig, chunks) + def descr_getitem(self, space, w_idx): if self._single_item_result(space, w_idx): item = self._single_item_at_index(space, w_idx) return self.get_concrete().eval(item).wrap(space) -xxx -start, stop, step, slice_length = space.decode_index4(w_idx, self.shape[0]) -if step == 0: -# Single index -return self.get_concrete().eval(start).wrap(space) -else: -# Slice -new_sig = signature.Signature.find_sig([ -SingleDimSlice.signature, self.signature -]) -res = SingleDimSlice(start, stop, step, slice_length, self, new_sig) -return space.wrap(res) +return space.wrap(self._create_slice(space, w_idx)) def descr_setitem(self, space, w_idx, w_value): self.invalidated() @@ -514,18 +516,10 @@ class NDimSlice(ViewArray): signature = signature.BaseSignature() -def __init__(self, start, stop, step, slice_length, parent, signature): +def __init__(self, parent, signature, chunks): ViewArray.__init__(self, parent, signature) -if isinstance(parent, NDimSlice): -self.start = parent.calc_index(start) -self.stop = parent.calc_index(stop) -self.step = parent.step * step -self.parent = parent.parent -else: -self.start = start -self.stop = stop -self.step = step -self.parent = parent +self.chunks = chunks + self.size = slice_length def get_root_storage(self): 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 @@ -624,6 +624,14 @@ assert a[1, 2, 0] == 3 assert a[1, 1, 0] == 0 +def test_slices(self): +import numpy +a = numpy.zeros((4, 3, 2)) +raises(IndexError, a.__getitem__, (4,)) +raises(IndexError, a.__getitem__, (3, 3)) +raises(IndexError, a.__getitem__, (:, 3)) + + class AppTestSupport(object): def setup_class(cls): import struct ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: Work on casting. Seems to fly
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48505:301f1937556a Date: 2011-10-27 16:13 +0200 http://bitbucket.org/pypy/pypy/changeset/301f1937556a/ Log:Work on casting. Seems to fly 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 @@ -211,7 +211,8 @@ def descr_repr(self, space): # Simple implementation so that we can see the array. Needs work. concrete = self.get_concrete() -res = array([ + , .join(concrete._getnums(False)) + ] +#res = array([ + , .join(concrete._getnums(False)) + ] +res = 'array()' dtype = concrete.find_dtype() if (dtype is not space.fromcache(interp_dtype.W_Float64Dtype) and dtype is not space.fromcache(interp_dtype.W_Int64Dtype)) or not self.find_size(): @@ -240,20 +241,29 @@ item += index[i] return item +def len_of_shape(self): +return len(self.shape) + +def get_root_shape(self): +return self.shape + def _single_item_result(self, space, w_idx): The result of getitem/setitem is a single item if w_idx is a list of scalars that match the size of shape -if len(self.shape) == 1: -if (space.isinstance_w(w_idx, space.w_slice) or -space.isinstance_w(w_idx, space.w_int)): +shape_len = self.len_of_shape() +if shape_len == 1: +if space.isinstance_w(w_idx, space.w_int): return True return False +if (space.isinstance_w(w_idx, space.w_slice) or +space.isinstance_w(w_idx, space.w_int)): +return False lgt = space.len_w(w_idx) -if lgt len(self.shape): +if lgt shape_len: raise OperationError(space.w_IndexError, space.wrap(invalid index)) -if lgt len(self.shape): +if lgt shape_len: return False for w_item in space.fixedview(w_idx): if space.isinstance_w(w_item, space.w_slice): @@ -266,12 +276,25 @@ ]) if (space.isinstance_w(w_idx, space.w_int) or space.isinstance_w(w_idx, space.w_slice)): -chunks = [space.decode_index4(w_idx, self.shape[0])] +start, stop, step, lgt = space.decode_index4(w_idx, self.shape[0]) +if lgt == 1: +shape = self.shape[1:] +else: +shape = self.shape +chunks = [(start, stop, step, lgt)] else: chunks = [] +shape = self.shape[:] for i, w_item in enumerate(space.fixedview(w_idx)): -chunks.append(space.decode_index4(w_item, self.shape[i])) -return NDimSlice(self, new_sig, chunks) +start, stop, step, lgt = space.decode_index4(w_item, + self.shape[i]) +chunks.append((start, stop, step, lgt)) +if lgt == 1: +shape[i] = -1 +else: +shape[i] = lgt +shape = [i for i in shape if i != -1] +return NDimSlice(self, new_sig, chunks, shape) def descr_getitem(self, space, w_idx): if self._single_item_result(space, w_idx): @@ -481,10 +504,13 @@ Class for representing views of arrays, they will reflect changes of parent arrays. Example: slices -def __init__(self, parent, signature): -BaseArray.__init__(self) +def __init__(self, parent, signature, shape): +BaseArray.__init__(self, shape) self.signature = signature self.parent = parent +self.size = 1 +for elem in shape: +self.size *= elem self.invalidates = parent.invalidates def get_concrete(self): @@ -506,9 +532,7 @@ raise NotImplementedError def descr_len(self, space): -xxx -# XXX find shape first -return space.wrap(self.find_size()) +return space.wrap(self.shape[0]) def calc_index(self, item): raise NotImplementedError @@ -516,11 +540,13 @@ class NDimSlice(ViewArray): signature = signature.BaseSignature() -def __init__(self, parent, signature, chunks): -ViewArray.__init__(self, parent, signature) +def __init__(self, parent, signature, chunks, shape): +ViewArray.__init__(self, parent, signature, shape) self.chunks = chunks - -self.size = slice_length +self.shape_reduction = 0 +for chunk in chunks: +if chunk[-1] == 1: +self.shape_reduction += 1 def get_root_storage(self): return self.parent.get_concrete().get_root_storage() @@ -532,14 +558,53 @@ return self.parent.find_dtype() def
[pypy-commit] pypy numpy-multidim: more tests
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48506:4fb18345b1ab Date: 2011-10-27 16:18 +0200 http://bitbucket.org/pypy/pypy/changeset/4fb18345b1ab/ Log:more tests 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 @@ -654,6 +654,7 @@ b = a[:][:,1][:] assert b[2,1] == 0.0 assert b[0,1] == 13 +raises(IndexError, b.__getitem__, (4, 1)) class AppTestSupport(object): def setup_class(cls): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: even more tests, you can never be sure
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48507:e6db0d0d0445 Date: 2011-10-27 16:19 +0200 http://bitbucket.org/pypy/pypy/changeset/e6db0d0d0445/ Log:even more tests, you can never be sure 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 @@ -655,6 +655,8 @@ assert b[2,1] == 0.0 assert b[0,1] == 13 raises(IndexError, b.__getitem__, (4, 1)) +assert a[0][1][1] == 13 +assert a[1][2][1] == 15 class AppTestSupport(object): def setup_class(cls): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: copy heapq to modified-2.7 and correctly deal with nlargest/nsmallest getting n 0, fixes issue924
Author: Ronny Pfannschmidt ronny.pfannschm...@gmx.de Branch: Changeset: r48508:3fec6b7c733c Date: 2011-10-27 16:35 +0200 http://bitbucket.org/pypy/pypy/changeset/3fec6b7c733c/ Log:copy heapq to modified-2.7 and correctly deal with nlargest/nsmallest getting n 0, fixes issue924 diff --git a/lib-python/modified-2.7/heapq.py b/lib-python/modified-2.7/heapq.py new file mode 100644 --- /dev/null +++ b/lib-python/modified-2.7/heapq.py @@ -0,0 +1,442 @@ +# -*- coding: latin-1 -*- + +Heap queue algorithm (a.k.a. priority queue). + +Heaps are arrays for which a[k] = a[2*k+1] and a[k] = a[2*k+2] for +all k, counting elements from 0. For the sake of comparison, +non-existing elements are considered to be infinite. The interesting +property of a heap is that a[0] is always its smallest element. + +Usage: + +heap = []# creates an empty heap +heappush(heap, item) # pushes a new item on the heap +item = heappop(heap) # pops the smallest item from the heap +item = heap[0] # smallest item on the heap without popping it +heapify(x) # transforms list into a heap, in-place, in linear time +item = heapreplace(heap, item) # pops and returns smallest item, and adds + # new item; the heap size is unchanged + +Our API differs from textbook heap algorithms as follows: + +- We use 0-based indexing. This makes the relationship between the + index for a node and the indexes for its children slightly less + obvious, but is more suitable since Python uses 0-based indexing. + +- Our heappop() method returns the smallest item, not the largest. + +These two make it possible to view the heap as a regular Python list +without surprises: heap[0] is the smallest item, and heap.sort() +maintains the heap invariant! + + +# Original code by Kevin O'Connor, augmented by Tim Peters and Raymond Hettinger + +__about__ = Heap queues + +[explanation by Fran#65533;ois Pinard] + +Heaps are arrays for which a[k] = a[2*k+1] and a[k] = a[2*k+2] for +all k, counting elements from 0. For the sake of comparison, +non-existing elements are considered to be infinite. The interesting +property of a heap is that a[0] is always its smallest element. + +The strange invariant above is meant to be an efficient memory +representation for a tournament. The numbers below are `k', not a[k]: + + 0 + + 1 2 + + 3 45 6 + + 7 8 9 10 11 12 13 14 + +15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 + + +In the tree above, each cell `k' is topping `2*k+1' and `2*k+2'. In +an usual binary tournament we see in sports, each cell is the winner +over the two cells it tops, and we can trace the winner down the tree +to see all opponents s/he had. However, in many computer applications +of such tournaments, we do not need to trace the history of a winner. +To be more memory efficient, when a winner is promoted, we try to +replace it by something else at a lower level, and the rule becomes +that a cell and the two cells it tops contain three different items, +but the top cell wins over the two topped cells. + +If this heap invariant is protected at all time, index 0 is clearly +the overall winner. The simplest algorithmic way to remove it and +find the next winner is to move some loser (let's say cell 30 in the +diagram above) into the 0 position, and then percolate this new 0 down +the tree, exchanging values, until the invariant is re-established. +This is clearly logarithmic on the total number of items in the tree. +By iterating over all items, you get an O(n ln n) sort. + +A nice feature of this sort is that you can efficiently insert new +items while the sort is going on, provided that the inserted items are +not better than the last 0'th element you extracted. This is +especially useful in simulation contexts, where the tree holds all +incoming events, and the win condition means the smallest scheduled +time. When an event schedule other events for execution, they are +scheduled into the future, so they can easily go into the heap. So, a +heap is a good structure for implementing schedulers (this is what I +used for my MIDI sequencer :-). + +Various structures for implementing schedulers have been extensively +studied, and heaps are good for this, as they are reasonably speedy, +the speed is almost constant, and the worst case is not much different +than the average case. However, there are other representations which +are more efficient overall, yet the worst cases might be terrible. + +Heaps are also very useful in big disk sorts. You most probably all +know that a big sort implies producing runs (which are pre-sorted +sequences, which size is usually related to the amount of CPU memory), +followed by a merging passes for these runs, which merging is often +very cleverly organised[1]. It is very
[pypy-commit] pypy int-tag-untag-as-operations: make tagged instances use the new operations as well
Author: Carl Friedrich Bolz cfb...@gmx.de Branch: int-tag-untag-as-operations Changeset: r48509:d3b9577c4c08 Date: 2011-10-27 17:27 +0200 http://bitbucket.org/pypy/pypy/changeset/d3b9577c4c08/ Log:make tagged instances use the new operations as well diff --git a/pypy/rpython/lltypesystem/rtagged.py b/pypy/rpython/lltypesystem/rtagged.py --- a/pypy/rpython/lltypesystem/rtagged.py +++ b/pypy/rpython/lltypesystem/rtagged.py @@ -4,6 +4,7 @@ from pypy.rpython.lltypesystem.rclass import InstanceRepr, CLASSTYPE, ll_inst_type from pypy.rpython.lltypesystem.rclass import MissingRTypeAttribute from pypy.rpython.lltypesystem.rclass import ll_issubclass_const +from pypy.rpython.lltypesystem.lloperation import llop from pypy.rpython.rmodel import TyperError, inputconst @@ -43,18 +44,17 @@ v_value = hop.inputarg(lltype.Signed, arg=1) c_one = hop.inputconst(lltype.Signed, 1) hop.exception_is_here() -v2 = hop.genop('int_add_ovf', [v_value, v_value], +v2 = hop.genop('int_tag_ovf', [v_value], resulttype = lltype.Signed) -v2p1 = hop.genop('int_add', [v2, c_one], - resulttype = lltype.Signed) -v_instance = hop.genop('cast_int_to_ptr', [v2p1], +v_instance = hop.genop('cast_int_to_ptr', [v2], resulttype = self.lowleveltype) return v_instance, False # don't call __init__ def convert_const_exact(self, value): self.setup() number = value.get_untagged_value() -return ll_int_to_unboxed(self.lowleveltype, number) +tagged = number * 2 + 1 +return lltype.cast_int_to_ptr(self.lowleveltype, tagged) def getvalue_from_unboxed(self, llops, vinst): assert not self.is_parent @@ -142,11 +142,9 @@ minid, maxid, c_answer_if_unboxed) -def ll_int_to_unboxed(PTRTYPE, value): -return lltype.cast_int_to_ptr(PTRTYPE, value*2+1) def ll_unboxed_to_int(p): -return lltype.cast_ptr_to_int(p) 1 +return llop.int_untag(lltype.Signed, lltype.cast_ptr_to_int(p)) def ll_unboxed_getclass_canbenone(instance, class_if_unboxed): if instance: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] extradoc extradoc: add another para
Author: Maciej Fijalkowski fij...@gmail.com Branch: extradoc Changeset: r3949:5c778250e982 Date: 2011-10-27 17:36 +0200 http://bitbucket.org/pypy/extradoc/changeset/5c778250e982/ Log:add another para diff --git a/blog/draft/faster-json.rst b/blog/draft/faster-json.rst --- a/blog/draft/faster-json.rst +++ b/blog/draft/faster-json.rst @@ -89,6 +89,17 @@ methods for common infrastructure or loading globals (instead of rebinding as locals) is fast enough and improves code readability. +Copying is expensive + + +If you use regular expressions replace, this would always copy a string as of +now. If you know your regexp is simple, first try to match it if there is +anything to replace in the first place. This is a pretty hard optimization to +do automatically -- simply matching the regular expression can be too costly +for it to make sense. In our particular example however, the regexp is really +simple, checking ranges of characters. It also seems that this is by far the +fastest way to escape characters as of now. + Generators are slower than they should be - ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: setitem with slice - part one
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48510:61f36db28f06 Date: 2011-10-27 17:37 +0200 http://bitbucket.org/pypy/pypy/changeset/61f36db28f06/ Log:setitem with slice - part one 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 @@ -10,9 +10,11 @@ numpy_driver = jit.JitDriver(greens = ['signature'], reds = ['result_size', 'i', 'self', 'result']) -all_driver = jit.JitDriver(greens=['signature'], reds=['i', 'size', 'self', 'dtype']) -any_driver = jit.JitDriver(greens=['signature'], reds=['i', 'size', 'self', 'dtype']) -slice_driver = jit.JitDriver(greens=['signature'], reds=['i', 'j', 'step', 'stop', 'source', 'dest']) +all_driver = jit.JitDriver(greens=['signature'], reds=['i', 'size', 'self', + 'dtype']) +any_driver = jit.JitDriver(greens=['signature'], reds=['i', 'size', 'self', + 'dtype']) +slice_driver = jit.JitDriver(greens=['signature'], reds=['i', 'self', 'source']) class BaseArray(Wrappable): _attrs_ = [invalidates, signature] @@ -304,55 +306,26 @@ def descr_setitem(self, space, w_idx, w_value): self.invalidated() -if self._single_item_at_index(space, w_idx): +if self._single_item_result(space, w_idx): item = self._single_item_at_index(space, w_idx) self.get_concrete().setitem_w(space, item, w_value) return -xxx -if space.isinstance_w(w_idx, space.w_tuple): -length = space.len_w(w_idx) -if length 1: # only one dimension for now. -raise OperationError(space.w_IndexError, - space.wrap(invalid index)) -if length == 0: -w_idx = space.newslice(space.wrap(0), - space.wrap(self.find_size()), - space.wrap(1)) -else: -w_idx = space.getitem(w_idx, space.wrap(0)) -start, stop, step, slice_length = space.decode_index4(w_idx, - self.find_size()) -if step == 0: -# Single index -self.get_concrete().setitem_w(space, start, w_value) +concrete = self.get_concrete() +if isinstance(w_value, BaseArray): +# for now we just copy if setting part of an array from +# part of itself. can be improved. +if (concrete.get_root_storage() == +w_value.get_concrete().get_root_storage()): +w_value = space.call_function(space.gettypefor(BaseArray), w_value) +assert isinstance(w_value, BaseArray) else: -concrete = self.get_concrete() -if isinstance(w_value, BaseArray): -# for now we just copy if setting part of an array from -# part of itself. can be improved. -if (concrete.get_root_storage() == -w_value.get_concrete().get_root_storage()): -w_value = space.call_function(space.gettypefor(BaseArray), w_value) -assert isinstance(w_value, BaseArray) -else: -w_value = convert_to_array(space, w_value) -concrete.setslice(space, start, stop, step, - slice_length, w_value) +w_value = convert_to_array(space, w_value) +view = self._create_slice(space, w_idx) +view.setslice(space, w_value) def descr_mean(self, space): return space.wrap(space.float_w(self.descr_sum(space))/self.find_size()) -def _sliceloop(self, start, stop, step, source, dest): -i = start -j = 0 -while (step 0 and i stop) or (step 0 and i stop): -slice_driver.jit_merge_point(signature=source.signature, step=step, - stop=stop, i=i, j=j, source=source, - dest=dest) -dest.setitem(i, source.eval(j).convert_to(dest.find_dtype())) -j += 1 -i += step - def convert_to_array(space, w_obj): if isinstance(w_obj, BaseArray): return w_obj @@ -557,13 +530,23 @@ def find_dtype(self): return self.parent.find_dtype() -def setslice(self, space, start, stop, step, slice_length, arr): -xxx -start = self.calc_index(start) -if stop != -1: -stop = self.calc_index(stop) -step = self.step * step -self._sliceloop(start, stop, step, arr, self.parent) +def setslice(self, space, w_value): +assert isinstance(w_value, NDimArray) +if self.shape !=
[pypy-commit] extradoc extradoc: some more fixes from rhyolite
Author: Maciej Fijalkowski fij...@gmail.com Branch: extradoc Changeset: r3950:f55956fe1956 Date: 2011-10-27 17:47 +0200 http://bitbucket.org/pypy/extradoc/changeset/f55956fe1956/ Log:some more fixes from rhyolite diff --git a/blog/draft/faster-json.rst b/blog/draft/faster-json.rst --- a/blog/draft/faster-json.rst +++ b/blog/draft/faster-json.rst @@ -89,12 +89,13 @@ methods for common infrastructure or loading globals (instead of rebinding as locals) is fast enough and improves code readability. -Copying is expensive - +String copying is expensive +--- -If you use regular expressions replace, this would always copy a string as of -now. If you know your regexp is simple, first try to match it if there is -anything to replace in the first place. This is a pretty hard optimization to +If you use ``re.sub``, the current implementation will always create a copy +of the string even if there was no match to replace. +If you know your regexp is simple, first try to check if there is +anything to replace. This is a pretty hard optimization to do automatically -- simply matching the regular expression can be too costly for it to make sense. In our particular example however, the regexp is really simple, checking ranges of characters. It also seems that this is by far the ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merged virtual-dicts branch, this branch makes it possible for array of structs to be virtualized, and allows inlining into a few rdict functions, which in practice allows
Author: Alex Gaynor alex.gay...@gmail.com Branch: Changeset: r48514:96310036438c Date: 2011-10-27 12:42 -0400 http://bitbucket.org/pypy/pypy/changeset/96310036438c/ Log:merged virtual-dicts branch, this branch makes it possible for array of structs to be virtualized, and allows inlining into a few rdict functions, which in practice allows dicts where all the operations on them are with constant keys to remain virtual. in python code this is useful for things like some str % {dict: value}, or g(x=x) with g(**kwargs): return kwargs['x'] diff --git a/pypy/jit/backend/llsupport/descr.py b/pypy/jit/backend/llsupport/descr.py --- a/pypy/jit/backend/llsupport/descr.py +++ b/pypy/jit/backend/llsupport/descr.py @@ -281,6 +281,9 @@ def is_float_field(self): return self.fielddescr.is_float_field() +def sort_key(self): +return self.fielddescr.sort_key() + def repr_of_descr(self): return 'InteriorFieldDescr %s' % self.fielddescr.repr_of_descr() diff --git a/pypy/jit/codewriter/jtransform.py b/pypy/jit/codewriter/jtransform.py --- a/pypy/jit/codewriter/jtransform.py +++ b/pypy/jit/codewriter/jtransform.py @@ -844,6 +844,10 @@ if self._is_gc(op.args[0]): return op +def rewrite_op_cast_opaque_ptr(self, op): +# None causes the result of this op to get aliased to op.args[0] +return [SpaceOperation('mark_opaque_ptr', op.args, None), None] + def rewrite_op_force_cast(self, op): v_arg = op.args[0] v_result = op.result diff --git a/pypy/jit/codewriter/test/test_jtransform.py b/pypy/jit/codewriter/test/test_jtransform.py --- a/pypy/jit/codewriter/test/test_jtransform.py +++ b/pypy/jit/codewriter/test/test_jtransform.py @@ -1128,3 +1128,16 @@ varoftype(lltype.Signed)) tr = Transformer(None, None) raises(NotImplementedError, tr.rewrite_operation, op) + +def test_cast_opaque_ptr(): +S = lltype.GcStruct(S, (x, lltype.Signed)) +v1 = varoftype(lltype.Ptr(S)) +v2 = varoftype(lltype.Ptr(rclass.OBJECT)) + +op = SpaceOperation('cast_opaque_ptr', [v1], v2) +tr = Transformer() +[op1, op2] = tr.rewrite_operation(op) +assert op1.opname == 'mark_opaque_ptr' +assert op1.args == [v1] +assert op1.result is None +assert op2 is None \ No newline at end of file diff --git a/pypy/jit/metainterp/blackhole.py b/pypy/jit/metainterp/blackhole.py --- a/pypy/jit/metainterp/blackhole.py +++ b/pypy/jit/metainterp/blackhole.py @@ -505,9 +505,6 @@ @arguments(r, r, returns=i) def bhimpl_instance_ptr_ne(a, b): return a != b -@arguments(r, returns=r) -def bhimpl_cast_opaque_ptr(a): -return a @arguments(r, returns=i) def bhimpl_cast_ptr_to_int(a): i = lltype.cast_ptr_to_int(a) @@ -518,6 +515,10 @@ ll_assert((i 1) == 1, bhimpl_cast_int_to_ptr: not an odd int) return lltype.cast_int_to_ptr(llmemory.GCREF, i) +@arguments(r) +def bhimpl_mark_opaque_ptr(a): +pass + @arguments(i, returns=i) def bhimpl_int_copy(a): return a diff --git a/pypy/jit/metainterp/heapcache.py b/pypy/jit/metainterp/heapcache.py --- a/pypy/jit/metainterp/heapcache.py +++ b/pypy/jit/metainterp/heapcache.py @@ -34,7 +34,6 @@ self.clear_caches(opnum, descr, argboxes) def mark_escaped(self, opnum, argboxes): -idx = 0 if opnum == rop.SETFIELD_GC: assert len(argboxes) == 2 box, valuebox = argboxes @@ -42,8 +41,20 @@ self.dependencies.setdefault(box, []).append(valuebox) else: self._escape(valuebox) -# GETFIELD_GC doesn't escape it's argument -elif opnum != rop.GETFIELD_GC: +elif opnum == rop.SETARRAYITEM_GC: +assert len(argboxes) == 3 +box, indexbox, valuebox = argboxes +if self.is_unescaped(box) and self.is_unescaped(valuebox): +self.dependencies.setdefault(box, []).append(valuebox) +else: +self._escape(valuebox) +# GETFIELD_GC, MARK_OPAQUE_PTR, PTR_EQ, and PTR_NE don't escape their +# arguments +elif (opnum != rop.GETFIELD_GC and + opnum != rop.MARK_OPAQUE_PTR and + opnum != rop.PTR_EQ and + opnum != rop.PTR_NE): +idx = 0 for box in argboxes: # setarrayitem_gc don't escape its first argument if not (idx == 0 and opnum in [rop.SETARRAYITEM_GC]): @@ -60,13 +71,13 @@ self._escape(dep) def clear_caches(self, opnum, descr, argboxes): -if opnum == rop.SETFIELD_GC: -return -if opnum == rop.SETARRAYITEM_GC: -return -if opnum == rop.SETFIELD_RAW: -return -if opnum == rop.SETARRAYITEM_RAW: +if (opnum == rop.SETFIELD_GC or +opnum ==
[pypy-commit] pypy ppc-jit-backend: Ok, there actually IS an SLWI instr. on PPC.
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r48515:064b64295d89 Date: 2011-10-26 10:38 +0200 http://bitbucket.org/pypy/pypy/changeset/064b64295d89/ Log:Ok, there actually IS an SLWI instr. on PPC. Improved generated code in emit_unicodegetitem and emit_unicodesetitem. diff --git a/pypy/jit/backend/ppc/ppcgen/opassembler.py b/pypy/jit/backend/ppc/ppcgen/opassembler.py --- a/pypy/jit/backend/ppc/ppcgen/opassembler.py +++ b/pypy/jit/backend/ppc/ppcgen/opassembler.py @@ -401,9 +401,7 @@ def emit_unicodegetitem(self, op, arglocs, regalloc): res, base_loc, ofs_loc, scale, basesize, itemsize = arglocs -# XXX agh, why does PPC not have an SLWI instruction ? -self.mc.li(r.r0.value, scale.value) -self.mc.slw(ofs_loc.value, ofs_loc.value, r.r0.value) +self.mc.slwi(ofs_loc.value, ofs_loc.value, scale.value) self.mc.add(res.value, base_loc.value, ofs_loc.value) if scale.value == 2: @@ -417,8 +415,7 @@ def emit_unicodesetitem(self, op, arglocs, regalloc): value_loc, base_loc, ofs_loc, scale, basesize, itemsize = arglocs -self.mc.li(r.r0.value, scale.value) -self.mc.slw(ofs_loc.value, ofs_loc.value, r.r0.value) +self.mc.slwi(ofs_loc.value, ofs_loc.value, scale.value) self.mc.add(base_loc.value, base_loc.value, ofs_loc.value) if scale.value == 2: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: Skip test_array_of_structs if floats are not supported.
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r48517:b6e8bd8c4973 Date: 2011-10-27 12:08 +0200 http://bitbucket.org/pypy/pypy/changeset/b6e8bd8c4973/ Log:Skip test_array_of_structs if floats are not supported. diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py --- a/pypy/jit/backend/test/runner_test.py +++ b/pypy/jit/backend/test/runner_test.py @@ -991,6 +991,8 @@ assert r.value == 7441 def test_array_of_structs(self): +if not self.cpu.supports_floats: +py.test.skip(floats are not supported) TP = lltype.GcStruct('x') ITEM = lltype.Struct('x', ('vs', lltype.Signed), ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: CAST_INT_TO_PTR, CAST_PTR_TO_INT.
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r48519:cffb9538d307 Date: 2011-10-27 19:05 +0200 http://bitbucket.org/pypy/pypy/changeset/cffb9538d307/ Log:CAST_INT_TO_PTR, CAST_PTR_TO_INT. diff --git a/pypy/jit/backend/ppc/ppcgen/opassembler.py b/pypy/jit/backend/ppc/ppcgen/opassembler.py --- a/pypy/jit/backend/ppc/ppcgen/opassembler.py +++ b/pypy/jit/backend/ppc/ppcgen/opassembler.py @@ -440,6 +440,9 @@ argloc, resloc = arglocs self.regalloc_mov(argloc, resloc) +emit_cast_ptr_to_int = emit_same_as +emit_cast_int_to_ptr = emit_same_as + def emit_debug_merge_point(self, op, arglocs, regalloc): pass diff --git a/pypy/jit/backend/ppc/ppcgen/regalloc.py b/pypy/jit/backend/ppc/ppcgen/regalloc.py --- a/pypy/jit/backend/ppc/ppcgen/regalloc.py +++ b/pypy/jit/backend/ppc/ppcgen/regalloc.py @@ -539,6 +539,9 @@ self.possibly_free_var(op.result) return [argloc, resloc] +prepare_cast_ptr_to_int = prepare_same_as +prepare_cast_int_to_ptr = prepare_same_as + def void(self, op): return [] ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: another test
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48520:1065599494c0 Date: 2011-10-27 17:38 +0200 http://bitbucket.org/pypy/pypy/changeset/1065599494c0/ Log:another test 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 @@ -663,6 +663,7 @@ a = numpy.zeros((3, 4)) a[1] = [1, 2, 3, 4] assert a[1, 2] == 3 +raises(TypeError, a[1].__setitem__, [1, 2, 3]) class AppTestSupport(object): def setup_class(cls): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: skip test_zjit for now
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48521:647e3d21832c Date: 2011-10-27 17:47 +0200 http://bitbucket.org/pypy/pypy/changeset/647e3d21832c/ Log:skip test_zjit for now diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -3,14 +3,14 @@ from pypy.module.micronumpy.compile import (numpy_compile, FakeSpace, FloatObject, IntObject) from pypy.module.micronumpy.interp_dtype import W_Int32Dtype, W_Float64Dtype, W_Int64Dtype, W_UInt64Dtype -from pypy.module.micronumpy.interp_numarray import (BaseArray, SingleDimArray, -SingleDimSlice, scalar_w) +from pypy.module.micronumpy.interp_numarray import (BaseArray, NDimArray, +NDimSlice, scalar_w) from pypy.rlib.nonconst import NonConstant from pypy.rpython.annlowlevel import llstr from pypy.rpython.test.test_llinterp import interpret import py - +py.test.skip(XXX) class TestNumpyJIt(LLJitMixin): def setup_class(cls): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy stm: A graph transformer, so far just renaming '{get, set}field'
Author: Armin Rigo ar...@tunes.org Branch: stm Changeset: r48526:3de5c2a4796d Date: 2011-10-27 16:34 +0200 http://bitbucket.org/pypy/pypy/changeset/3de5c2a4796d/ Log:A graph transformer, so far just renaming '{get,set}field' into 'stm_{get,set}field'. diff --git a/pypy/translator/stm/llstminterp.py b/pypy/translator/stm/llstminterp.py --- a/pypy/translator/stm/llstminterp.py +++ b/pypy/translator/stm/llstminterp.py @@ -27,9 +27,8 @@ 'stm_getfield', 'stm_setfield', 'stm_commit_transaction', ]) -ALLOW_WHEN_INEVITABLE_TRANSACTION = ALLOW_WHEN_REGULAR_TRANSACTION.union( -set([ -])) +ALLOW_WHEN_INEVITABLE_TRANSACTION = ALLOW_WHEN_REGULAR_TRANSACTION.union([ +]) def getoperationhandler(self, opname): stm_mode = self.llinterpreter.stm_mode diff --git a/pypy/translator/stm/test/test_transform.py b/pypy/translator/stm/test/test_transform.py new file mode 100644 --- /dev/null +++ b/pypy/translator/stm/test/test_transform.py @@ -0,0 +1,16 @@ +from pypy.rpython.lltypesystem import lltype +from pypy.rpython.test.test_llinterp import get_interpreter +from pypy.translator.stm.llstminterp import eval_stm_graph +from pypy.translator.stm.transform import transform_graph + + +def test_simple(): +S = lltype.GcStruct('S', ('x', lltype.Signed)) +p = lltype.malloc(S, immortal=True) +p.x = 42 +def func(p): +return p.x +interp, graph = get_interpreter(func, [p]) +transform_graph(graph) +res = eval_stm_graph(interp, graph, [p], stm_mode=regular_transaction) +assert res == 42 diff --git a/pypy/translator/stm/transform.py b/pypy/translator/stm/transform.py new file mode 100644 --- /dev/null +++ b/pypy/translator/stm/transform.py @@ -0,0 +1,29 @@ +from pypy.objspace.flow.model import SpaceOperation + + +class STMTransformer(object): + +def transform_block(self, block): +if block.operations == (): +return +newoperations = [] +for op in block.operations: +meth = getattr(self, 'stt_' + op.opname, list.append) +meth(newoperations, op) +block.operations = newoperations + +def transform_graph(self, graph): +for block in graph.iterblocks(): +self.transform_block(block) + +def stt_getfield(self, newoperations, op): +op1 = SpaceOperation('stm_getfield', op.args, op.result) +newoperations.append(op1) + +def stt_setfield(self, newoperations, op): +op1 = SpaceOperation('stm_setfield', op.args, op.result) +newoperations.append(op1) + + +def transform_graph(graph): +STMTransformer().transform_graph(graph) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy stm: We cannot return out of the frame that started a regular transaction.
Author: Armin Rigo ar...@tunes.org Branch: stm Changeset: r48527:070bf17d0fbb Date: 2011-10-27 16:47 +0200 http://bitbucket.org/pypy/pypy/changeset/070bf17d0fbb/ Log:We cannot return out of the frame that started a regular transaction. diff --git a/pypy/translator/stm/llstminterp.py b/pypy/translator/stm/llstminterp.py --- a/pypy/translator/stm/llstminterp.py +++ b/pypy/translator/stm/llstminterp.py @@ -5,12 +5,20 @@ class ForbiddenInstructionInSTMMode(Exception): pass +class ReturnWithTransactionActive(Exception): +pass + def eval_stm_graph(llinterp, graph, values, stm_mode=not_in_transaction): llinterp.frame_class = LLSTMFrame try: llinterp.stm_mode = stm_mode -return llinterp.eval_graph(graph, values) +llinterp.last_transaction_started_in_frame = None +res = llinterp.eval_graph(graph, values) +assert llinterp.stm_mode == stm_mode, ( +llinterp.stm_mode is %r after eval_graph, but should be %r % ( +llinterp.stm_mode, stm_mode)) +return res finally: llinterp.frame_class = LLFrame @@ -19,6 +27,7 @@ ALWAYS_ALLOW_OPERATIONS = set([ 'int_*', +'direct_call', ]) ALLOW_WHEN_NOT_IN_TRANSACTION = set([ 'stm_begin_transaction', @@ -30,6 +39,13 @@ ALLOW_WHEN_INEVITABLE_TRANSACTION = ALLOW_WHEN_REGULAR_TRANSACTION.union([ ]) +def eval(self): +res = LLFrame.eval(self) +if (self.llinterpreter.stm_mode == regular_transaction and +self.llinterpreter.last_transaction_started_in_frame is self): +raise ReturnWithTransactionActive(self.graph) +return res + def getoperationhandler(self, opname): stm_mode = self.llinterpreter.stm_mode attrname = '_opstm_%s__%s' % (stm_mode, opname) @@ -69,6 +85,7 @@ def op_stm_begin_transaction(self): assert self.llinterpreter.stm_mode == not_in_transaction self.llinterpreter.stm_mode = regular_transaction +self.llinterpreter.last_transaction_started_in_frame = self def op_stm_commit_transaction(self): assert self.llinterpreter.stm_mode != not_in_transaction diff --git a/pypy/translator/stm/test/test_llstminterp.py b/pypy/translator/stm/test/test_llstminterp.py --- a/pypy/translator/stm/test/test_llstminterp.py +++ b/pypy/translator/stm/test/test_llstminterp.py @@ -3,6 +3,7 @@ from pypy.rpython.test.test_llinterp import get_interpreter from pypy.translator.stm.llstminterp import eval_stm_graph from pypy.translator.stm.llstminterp import ForbiddenInstructionInSTMMode +from pypy.translator.stm.llstminterp import ReturnWithTransactionActive from pypy.translator.stm import rstm @@ -53,3 +54,25 @@ interp, graph = get_interpreter(func, [p]) res = eval_stm_graph(interp, graph, [p]) assert res == 42 + +def test_call_and_return_with_regular_transaction(): +def g(): +pass +g._dont_inline_ = True +def func(): +rstm.begin_transaction() +g() +rstm.commit_transaction() +interp, graph = get_interpreter(func, []) +eval_stm_graph(interp, graph, []) + +def test_cannot_return_with_regular_transaction(): +def g(): +rstm.begin_transaction() +g._dont_inline_ = True +def func(): +g() +rstm.commit_transaction() +interp, graph = get_interpreter(func, []) +py.test.raises(ReturnWithTransactionActive, + eval_stm_graph, interp, graph, []) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy stm: - Refactor to support getfield of immutables.
Author: Armin Rigo ar...@tunes.org Branch: stm Changeset: r48528:caa7e690cfc7 Date: 2011-10-27 17:05 +0200 http://bitbucket.org/pypy/pypy/changeset/caa7e690cfc7/ Log:- Refactor to support getfield of immutables. That's enough to raise simple exceptions. - Complain when an exception leaves the frame in which we did begin_transaction(). diff --git a/pypy/translator/stm/llstminterp.py b/pypy/translator/stm/llstminterp.py --- a/pypy/translator/stm/llstminterp.py +++ b/pypy/translator/stm/llstminterp.py @@ -1,4 +1,5 @@ -from pypy.rpython.llinterp import LLFrame +from pypy.rpython.lltypesystem import lltype +from pypy.rpython.llinterp import LLFrame, LLException from pypy.translator.stm import rstm @@ -26,35 +27,36 @@ class LLSTMFrame(LLFrame): ALWAYS_ALLOW_OPERATIONS = set([ -'int_*', +'int_*', 'same_as', 'cast_*', 'direct_call', ]) -ALLOW_WHEN_NOT_IN_TRANSACTION = set([ -'stm_begin_transaction', -]) -ALLOW_WHEN_REGULAR_TRANSACTION = set([ -'stm_getfield', 'stm_setfield', -'stm_commit_transaction', -]) -ALLOW_WHEN_INEVITABLE_TRANSACTION = ALLOW_WHEN_REGULAR_TRANSACTION.union([ -]) def eval(self): -res = LLFrame.eval(self) -if (self.llinterpreter.stm_mode == regular_transaction and -self.llinterpreter.last_transaction_started_in_frame is self): -raise ReturnWithTransactionActive(self.graph) +try: +res = LLFrame.eval(self) +except LLException, e: +self.returning_from_frame_now() +raise e +self.returning_from_frame_now() return res +def returning_from_frame_now(self): +if (self.llinterpreter.stm_mode == regular_transaction and +self.llinterpreter.last_transaction_started_in_frame is self): +raise ReturnWithTransactionActive(self.graph) + def getoperationhandler(self, opname): -stm_mode = self.llinterpreter.stm_mode -attrname = '_opstm_%s__%s' % (stm_mode, opname) -ophandler = getattr(self, attrname, None) -if ophandler is None: -self._validate_stmoperation_handler(stm_mode, opname) -ophandler = LLFrame.getoperationhandler(self, opname) -setattr(self, attrname, ophandler) -return ophandler +try: +return getattr(self, 'opstm_' + opname) +except AttributeError: +stm_mode = self.llinterpreter.stm_mode +attrname = '_opstm_%s__%s' % (stm_mode, opname) +ophandler = getattr(self, attrname, None) +if ophandler is None: +self._validate_stmoperation_handler(stm_mode, opname) +ophandler = LLFrame.getoperationhandler(self, opname) +setattr(self, attrname, ophandler) +return ophandler def _op_in_set(self, opname, set): if opname in set: @@ -67,26 +69,42 @@ def _validate_stmoperation_handler(self, stm_mode, opname): if self._op_in_set(opname, self.ALWAYS_ALLOW_OPERATIONS): return -allow = getattr(self, 'ALLOW_WHEN_' + stm_mode.upper()) -if self._op_in_set(opname, allow): -return raise ForbiddenInstructionInSTMMode(stm_mode, opname, self.graph) +# -- operations that are sometimes safe -- + +def opstm_getfield(self, struct, fieldname): +STRUCT = lltype.typeOf(struct).TO +if STRUCT._immutable_field(fieldname): +# immutable field reads are always allowed +return LLFrame.op_getfield(self, struct, fieldname) +else: +# mutable 'getfields' are always forbidden for now +self.check_stm_mode(lambda m: False) +xxx + # -- stm-only operations -- # Note that for these tests we assume no real multithreading, # so that we just emulate the operations the easy way -def op_stm_getfield(self, struct, fieldname): -return self.op_getfield(struct, fieldname) +def check_stm_mode(self, checker): +stm_mode = self.llinterpreter.stm_mode +if not checker(stm_mode): +raise ForbiddenInstructionInSTMMode(stm_mode, self.graph) -def op_stm_setfield(self, struct, fieldname, value): -self.op_setfield(struct, fieldname, value) +def opstm_stm_getfield(self, struct, fieldname): +self.check_stm_mode(lambda m: m != not_in_transaction) +return LLFrame.op_getfield(self, struct, fieldname) -def op_stm_begin_transaction(self): -assert self.llinterpreter.stm_mode == not_in_transaction +def opstm_stm_setfield(self, struct, fieldname, value): +self.check_stm_mode(lambda m: m != not_in_transaction) +LLFrame.op_setfield(self, struct, fieldname, value) + +def opstm_stm_begin_transaction(self): +self.check_stm_mode(lambda m: m ==
[pypy-commit] pypy stm: Simplify.
Author: Armin Rigo ar...@tunes.org Branch: stm Changeset: r48529:d382548b28e1 Date: 2011-10-27 17:10 +0200 http://bitbucket.org/pypy/pypy/changeset/d382548b28e1/ Log:Simplify. diff --git a/pypy/translator/stm/llstminterp.py b/pypy/translator/stm/llstminterp.py --- a/pypy/translator/stm/llstminterp.py +++ b/pypy/translator/stm/llstminterp.py @@ -46,17 +46,12 @@ raise ReturnWithTransactionActive(self.graph) def getoperationhandler(self, opname): -try: -return getattr(self, 'opstm_' + opname) -except AttributeError: -stm_mode = self.llinterpreter.stm_mode -attrname = '_opstm_%s__%s' % (stm_mode, opname) -ophandler = getattr(self, attrname, None) -if ophandler is None: -self._validate_stmoperation_handler(stm_mode, opname) -ophandler = LLFrame.getoperationhandler(self, opname) -setattr(self, attrname, ophandler) -return ophandler +ophandler = getattr(self, 'opstm_' + opname, None) +if ophandler is None: +self._validate_stmoperation_handler(opname) +ophandler = LLFrame.getoperationhandler(self, opname) +setattr(self, 'opstm_' + opname, ophandler) +return ophandler def _op_in_set(self, opname, set): if opname in set: @@ -66,10 +61,10 @@ return True return False -def _validate_stmoperation_handler(self, stm_mode, opname): +def _validate_stmoperation_handler(self, opname): if self._op_in_set(opname, self.ALWAYS_ALLOW_OPERATIONS): return -raise ForbiddenInstructionInSTMMode(stm_mode, opname, self.graph) +raise ForbiddenInstructionInSTMMode(opname, self.graph) # -- operations that are sometimes safe -- ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy stm: transform.py should not touch immutable getfields
Author: Armin Rigo ar...@tunes.org Branch: stm Changeset: r48530:df4fdd533f50 Date: 2011-10-27 17:14 +0200 http://bitbucket.org/pypy/pypy/changeset/df4fdd533f50/ Log:transform.py should not touch immutable getfields diff --git a/pypy/translator/stm/test/test_transform.py b/pypy/translator/stm/test/test_transform.py --- a/pypy/translator/stm/test/test_transform.py +++ b/pypy/translator/stm/test/test_transform.py @@ -1,5 +1,6 @@ from pypy.rpython.lltypesystem import lltype from pypy.rpython.test.test_llinterp import get_interpreter +from pypy.objspace.flow.model import summary from pypy.translator.stm.llstminterp import eval_stm_graph from pypy.translator.stm.transform import transform_graph @@ -12,5 +13,18 @@ return p.x interp, graph = get_interpreter(func, [p]) transform_graph(graph) +assert summary(graph) == {'stm_getfield': 1} res = eval_stm_graph(interp, graph, [p], stm_mode=regular_transaction) assert res == 42 + +def test_immutable_field(): +S = lltype.GcStruct('S', ('x', lltype.Signed), hints = {'immutable': True}) +p = lltype.malloc(S, immortal=True) +p.x = 42 +def func(p): +return p.x +interp, graph = get_interpreter(func, [p]) +transform_graph(graph) +assert summary(graph) == {'getfield': 1} +res = eval_stm_graph(interp, graph, [p], stm_mode=regular_transaction) +assert res == 42 diff --git a/pypy/translator/stm/transform.py b/pypy/translator/stm/transform.py --- a/pypy/translator/stm/transform.py +++ b/pypy/translator/stm/transform.py @@ -17,7 +17,11 @@ self.transform_block(block) def stt_getfield(self, newoperations, op): -op1 = SpaceOperation('stm_getfield', op.args, op.result) +STRUCT = op.args[0].concretetype.TO +if STRUCT._immutable_field(op.args[1].value): +op1 = op +else: +op1 = SpaceOperation('stm_getfield', op.args, op.result) newoperations.append(op1) def stt_setfield(self, newoperations, op): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: creation from sequences
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48532:57661ae58454 Date: 2011-10-27 19:40 +0200 http://bitbucket.org/pypy/pypy/changeset/57661ae58454/ Log:creation from sequences 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 @@ -680,6 +680,12 @@ a[1] = [1, 2, 3, 4] assert a[1, 2] == 3 raises(TypeError, a[1].__setitem__, [1, 2, 3]) +a = numpy.array([[1, 2], [3, 4]]) +assert a == [[1, 2], [3, 4]] +a[1] = numpy.array([5, 6]) +assert a == [[1, 2], [5, 6]] +a[:,1] = numpy.array([8, 10]) +assert a == [[1, 8], [5, 10]] class AppTestSupport(object): def setup_class(cls): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: optimize numpy.ones a bit
Author: Alex Gaynor alex.gay...@gmail.com Branch: Changeset: r48533:e54c4fc626c7 Date: 2011-10-27 13:49 -0400 http://bitbucket.org/pypy/pypy/changeset/e54c4fc626c7/ Log:optimize numpy.ones a bit diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -108,6 +108,12 @@ def setitem_w(self, space, storage, i, w_item): self.setitem(storage, i, self.unwrap(space, w_item)) +def fill(self, storage, item, start, stop): +storage = self.unerase(storage) +item = self.unbox(item) +for i in xrange(start, stop): +storage[i] = item + @specialize.argtype(1) def adapt_val(self, val): return self.box(rffi.cast(TP.TO.OF, val)) 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 @@ -565,8 +565,7 @@ arr = SingleDimArray(size, dtype=dtype) one = dtype.adapt_val(1) -for i in xrange(size): -arr.dtype.setitem(arr.storage, i, one) +arr.dtype.fill(arr.storage, one, 0, size) return space.wrap(arr) BaseArray.typedef = TypeDef( ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix this test
Author: Alex Gaynor alex.gay...@gmail.com Branch: Changeset: r48534:de9715d6219f Date: 2011-10-27 13:58 -0400 http://bitbucket.org/pypy/pypy/changeset/de9715d6219f/ Log:fix this test diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py @@ -4206,10 +4206,12 @@ class FakeCallInfoCollection: def callinfo_for_oopspec(self, oopspecindex): calldescrtype = type(LLtypeMixin.strequaldescr) +effectinfotype = type(LLtypeMixin.strequaldescr.get_extra_info()) for value in LLtypeMixin.__dict__.values(): if isinstance(value, calldescrtype): extra = value.get_extra_info() -if extra and extra.oopspecindex == oopspecindex: +if (extra and isinstance(extra, effectinfotype) and +extra.oopspecindex == oopspecindex): # returns 0 for 'func' in this test return value, 0 raise AssertionError(not found: oopspecindex=%d % diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -5800,10 +5800,12 @@ class FakeCallInfoCollection: def callinfo_for_oopspec(self, oopspecindex): calldescrtype = type(LLtypeMixin.strequaldescr) +effectinfotype = type(LLtypeMixin.strequaldescr.get_extra_info()) for value in LLtypeMixin.__dict__.values(): if isinstance(value, calldescrtype): extra = value.get_extra_info() -if extra and extra.oopspecindex == oopspecindex: +if (extra and isinstance(extra, effectinfotype) and +extra.oopspecindex == oopspecindex): # returns 0 for 'func' in this test return value, 0 raise AssertionError(not found: oopspecindex=%d % ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: nonzero support and more tests for slices
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48535:e7d27a90d510 Date: 2011-10-27 20:01 +0200 http://bitbucket.org/pypy/pypy/changeset/e7d27a90d510/ Log:nonzero support and more tests for slices 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 @@ -25,7 +25,7 @@ for w_item in space.listview(w_next): stack.append(w_item) else: -w_dtype = interp_ufuncs.find_dtype_for_scalar(space, w_item, w_dtype) +w_dtype = interp_ufuncs.find_dtype_for_scalar(space, w_next, w_dtype) if w_dtype is space.fromcache(interp_dtype.W_Float64Dtype): return w_dtype if w_dtype is None: @@ -71,14 +71,16 @@ def add_invalidates(self, other): self.invalidates.append(other) -def descr__new__(space, w_subtype, w_size_or_iterable, w_dtype=None): +def descr__new__(space, w_subtype, w_item_or_iterable, w_dtype=None): # find scalar if space.is_w(w_dtype, space.w_None): -w_dtype = _find_dtype(space, w_size_or_iterable) +w_dtype = _find_dtype(space, w_item_or_iterable) dtype = space.interp_w(interp_dtype.W_Dtype, space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype) ) -shape, elems_w = _find_shape_and_elems(space, w_size_or_iterable) +if not space.issequence_w(w_item_or_iterable): +return scalar_w(space, dtype, w_item_or_iterable) +shape, elems_w = _find_shape_and_elems(space, w_item_or_iterable) size = len(elems_w) arr = NDimArray(size, shape, dtype=dtype) i = 0 @@ -365,6 +367,12 @@ def descr_mean(self, space): return space.wrap(space.float_w(self.descr_sum(space))/self.find_size()) +def descr_nonzero(self, space): +if self.find_size() 1: +raise OperationError(space.w_ValueError, space.wrap( +The truth value of an array with more than one element is ambiguous. Use a.any() or a.all())) +return self.get_concrete().eval(0).wrap(space) + def convert_to_array(space, w_obj): if isinstance(w_obj, BaseArray): return w_obj @@ -395,7 +403,10 @@ self.value = value def find_size(self): -raise ValueError +return 1 + +def get_concrete(self): +return self def find_dtype(self): return self.dtype @@ -711,6 +722,7 @@ __pos__ = interp2app(BaseArray.descr_pos), __neg__ = interp2app(BaseArray.descr_neg), __abs__ = interp2app(BaseArray.descr_abs), +__nonzero__ = interp2app(BaseArray.descr_nonzero), __add__ = interp2app(BaseArray.descr_add), __sub__ = interp2app(BaseArray.descr_sub), 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 @@ -604,6 +604,16 @@ for i in xrange(5): assert c[i] == func(b[i], 3) +def test_nonzero(self): +from numpy import array +a = array([1, 2]) +raises(ValueError, bool, a) +raises(ValueError, bool, a == a) +assert bool(array(1)) +assert not bool(array(0)) +assert bool(array([1])) +assert not bool(array([0])) + class AppTestMultiDim(BaseNumpyAppTest): def test_init(self): import numpy @@ -672,7 +682,7 @@ a = numpy.array([[1, 2], [4, 5]]) assert a[0, 1] == a[0][1] == 2 a = numpy.array(([[[1, 2], [3, 4], [5, 6]]])) -assert a[0, 1] == [3, 4] +assert (a[0, 1] == [3, 4]).all() def test_setitem_slice(self): import numpy @@ -681,11 +691,13 @@ assert a[1, 2] == 3 raises(TypeError, a[1].__setitem__, [1, 2, 3]) a = numpy.array([[1, 2], [3, 4]]) -assert a == [[1, 2], [3, 4]] +assert (a == [[1, 2], [3, 4]]).all() a[1] = numpy.array([5, 6]) -assert a == [[1, 2], [5, 6]] +assert (a == [[1, 2], [5, 6]]).all() a[:,1] = numpy.array([8, 10]) -assert a == [[1, 8], [5, 10]] +assert (a == [[1, 8], [5, 10]]).all() +a[:,::-1] = numpy.array([11, 12]) +assert (a == [[12, 11], [12, 11]]).all() class AppTestSupport(object): def setup_class(cls): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: make the test test what I wanted to test
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48536:fbb3d36afef8 Date: 2011-10-27 20:04 +0200 http://bitbucket.org/pypy/pypy/changeset/fbb3d36afef8/ Log:make the test test what I wanted to test 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 @@ -696,8 +696,8 @@ assert (a == [[1, 2], [5, 6]]).all() a[:,1] = numpy.array([8, 10]) assert (a == [[1, 8], [5, 10]]).all() -a[:,::-1] = numpy.array([11, 12]) -assert (a == [[12, 11], [12, 11]]).all() +a[0,::-1] = numpy.array([11, 12]) +assert (a == [[12, 11], [5, 10]]).all() class AppTestSupport(object): def setup_class(cls): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-multidim: more tests
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-multidim Changeset: r48537:2944b13d49dd Date: 2011-10-27 20:22 +0200 http://bitbucket.org/pypy/pypy/changeset/2944b13d49dd/ Log:more tests 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 @@ -699,6 +699,11 @@ a[0,::-1] = numpy.array([11, 12]) assert (a == [[12, 11], [5, 10]]).all() +def test_ufunc(self): +from numpy import array +a = array([[1, 2], [3, 4], [5, 6]]) +assert ((a + a) == array([[1+1, 2+2], [3+3, 4+4], [5+5, 6+6]])).all() + class AppTestSupport(object): def setup_class(cls): import struct ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] extradoc extradoc: this is done
Author: Alex Gaynor alex.gay...@gmail.com Branch: extradoc Changeset: r3951:386468696bbc Date: 2011-10-27 14:30 -0400 http://bitbucket.org/pypy/extradoc/changeset/386468696bbc/ Log:this is done diff --git a/planning/jit.txt b/planning/jit.txt --- a/planning/jit.txt +++ b/planning/jit.txt @@ -190,7 +190,5 @@ - Better pointer aliasing analyzer that will emit guards that pointers are different when needed. - - Make heap optimizer aware of setitems produced by forcing virtuals. - - Movinging loop-invariant setitems out of the loops entierly. ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-minilang: pass the test_zjit finally
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-minilang Changeset: r48543:f1d8e024a3ed Date: 2011-10-27 23:31 +0200 http://bitbucket.org/pypy/pypy/changeset/f1d8e024a3ed/ Log:pass the test_zjit finally diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py --- a/pypy/module/micronumpy/compile.py +++ b/pypy/module/micronumpy/compile.py @@ -37,6 +37,9 @@ def issequence_w(self, w_obj): return w_obj.seq +def isinstance_w(self, w_obj, w_tp): +return False + @specialize.argtype(1) def wrap(self, obj): if isinstance(obj, float): @@ -87,6 +90,7 @@ @specialize.arg(1) def interp_w(self, tp, what): +assert isinstance(what, tp) return what class FloatObject(W_Root): @@ -176,7 +180,8 @@ if isinstance(w_rhs, Scalar): index = int(interp.space.float_w( w_rhs.value.wrap(interp.space))) -return w_lhs.get_concrete().eval(index) +dtype = interp.space.fromcache(W_Float64Dtype) +return Scalar(dtype, w_lhs.get_concrete().eval(index)) else: raise NotImplementedError else: @@ -204,6 +209,12 @@ def __init__(self, v): self.v = int(v) +def execute(self, interp): +w_list = interp.space.newlist( +[interp.space.wrap(float(i)) for i in range(self.v)]) +dtype = interp.space.fromcache(W_Float64Dtype) +return descr_new_array(interp.space, None, w_list, w_dtype=dtype) + def __repr__(self): return 'Range(%s)' % self.v @@ -223,7 +234,8 @@ def execute(self, interp): w_list = self.wrap(interp.space) -return descr_new_array(interp.space, None, w_list) +dtype = interp.space.fromcache(W_Float64Dtype) +return descr_new_array(interp.space, None, w_list, w_dtype=dtype) def __repr__(self): return [ + , .join([repr(item) for item in self.items]) + ] diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py --- a/pypy/module/micronumpy/interp_ufuncs.py +++ b/pypy/module/micronumpy/interp_ufuncs.py @@ -236,22 +236,20 @@ return dt def find_dtype_for_scalar(space, w_obj, current_guess=None): -w_type = space.type(w_obj) - bool_dtype = space.fromcache(interp_dtype.W_BoolDtype) long_dtype = space.fromcache(interp_dtype.W_LongDtype) int64_dtype = space.fromcache(interp_dtype.W_Int64Dtype) -if space.is_w(w_type, space.w_bool): +if space.isinstance_w(w_obj, space.w_bool): if current_guess is None or current_guess is bool_dtype: return bool_dtype return current_guess -elif space.is_w(w_type, space.w_int): +elif space.isinstance_w(w_obj, space.w_int): if (current_guess is None or current_guess is bool_dtype or current_guess is long_dtype): return long_dtype return current_guess -elif space.is_w(w_type, space.w_long): +elif space.isinstance_w(w_obj, space.w_long): if (current_guess is None or current_guess is bool_dtype or current_guess is long_dtype or current_guess is int64_dtype): return int64_dtype diff --git a/pypy/module/micronumpy/test/test_compile.py b/pypy/module/micronumpy/test/test_compile.py --- a/pypy/module/micronumpy/test/test_compile.py +++ b/pypy/module/micronumpy/test/test_compile.py @@ -112,5 +112,12 @@ a + b - 3 interp = self.run(code) -assert interp.results[0].val == 3 + 6 +assert interp.results[0].value.val == 3 + 6 +def test_range_getitem(self): +code = +r = |20| +r - 3 + +interp = self.run(code) +assert interp.results[0].value.val == 3 diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -4,7 +4,7 @@ FloatObject, IntObject, Parser) from pypy.module.micronumpy.interp_dtype import W_Int32Dtype, W_Float64Dtype, W_Int64Dtype, W_UInt64Dtype from pypy.module.micronumpy.interp_numarray import (BaseArray, SingleDimArray, -SingleDimSlice, scalar_w) +SingleDimSlice, scalar_w, Scalar) from pypy.rlib.nonconst import NonConstant from pypy.rpython.annlowlevel import llstr from pypy.rpython.test.test_llinterp import interpret @@ -17,6 +17,8 @@ # trick annotator c = a = 3 +b = [1,2] + [3,4] +c = a space = FakeSpace() @@ -26,7 +28,9 @@ def f(i): interp = InterpreterState(codes[i]) interp.run(space) -return interp.results[0] +res = interp.results[0] +assert isinstance(res, BaseArray) +return interp.space.float_w(res.eval(0).wrap(interp.space)) return
[pypy-commit] pypy numpy-minilang: a test and a fix. took a while :/
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-minilang Changeset: r48544:41172dd9df6f Date: 2011-10-27 23:57 +0200 http://bitbucket.org/pypy/pypy/changeset/41172dd9df6f/ Log:a test and a fix. took a while :/ diff --git a/pypy/rpython/lltypesystem/rstr.py b/pypy/rpython/lltypesystem/rstr.py --- a/pypy/rpython/lltypesystem/rstr.py +++ b/pypy/rpython/lltypesystem/rstr.py @@ -20,6 +20,7 @@ from pypy.rpython.rmodel import Repr from pypy.rpython.lltypesystem import llmemory from pypy.tool.sourcetools import func_with_new_name +from pypy.rpython.lltypesystem.lloperation import llop # # @@ -366,6 +367,8 @@ if right: while lpos rpos and s.chars[rpos] == ch: rpos -= 1 +if rpos = lpos: +return s.empty() r_len = rpos - lpos + 1 result = s.malloc(r_len) s.copy_contents(s, result, lpos, 0, r_len) diff --git a/pypy/rpython/test/test_rstr.py b/pypy/rpython/test/test_rstr.py --- a/pypy/rpython/test/test_rstr.py +++ b/pypy/rpython/test/test_rstr.py @@ -372,12 +372,16 @@ return const('!ab!').lstrip(const('!')) def right(): return const('!ab!').rstrip(const('!')) +def empty(): +return const('').strip(' ') res = self.interpret(both, []) assert self.ll_to_string(res) == const('ab') res = self.interpret(left, []) assert self.ll_to_string(res) == const('ab!') res = self.interpret(right, []) assert self.ll_to_string(res) == const('!ab') +res = self.interpret(empty, []) +assert self.ll_to_string(res) == const('') def test_upper(self): const = self.const ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-minilang: convert tests and some rpython fixes
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-minilang Changeset: r48545:c75ffa281f05 Date: 2011-10-28 00:00 +0200 http://bitbucket.org/pypy/pypy/changeset/c75ffa281f05/ Log:convert tests and some rpython fixes diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py --- a/pypy/module/micronumpy/compile.py +++ b/pypy/module/micronumpy/compile.py @@ -280,17 +280,19 @@ return stack[-1] def parse_constant(self, v): +lgt = len(v)-1 +assert lgt = 0 if v[0] == '[': return ArrayConstant([self.parse_constant(elem) - for elem in v[1:-1].split(,)]) + for elem in v[1:lgt].split(,)]) if v[0] == '|': -return RangeConstant(v[1:-1]) +return RangeConstant(v[1:lgt]) return FloatConstant(v) def is_identifier_or_const(self, v): c = v[0] if ((c = 'a' and c = 'z') or (c = 'A' and c = 'Z') or -(c = '0' and c = '9') or c in '-.['): +(c = '0' and c = '9') or c in '-.[|'): if v == '-' or v == -: return False return True diff --git a/pypy/module/micronumpy/test/test_compile.py b/pypy/module/micronumpy/test/test_compile.py --- a/pypy/module/micronumpy/test/test_compile.py +++ b/pypy/module/micronumpy/test/test_compile.py @@ -116,8 +116,8 @@ def test_range_getitem(self): code = -r = |20| +r = |20| + 3 r - 3 interp = self.run(code) -assert interp.results[0].value.val == 3 +assert interp.results[0].value.val == 6 diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -1,12 +1,11 @@ from pypy.jit.metainterp.test.support import LLJitMixin from pypy.module.micronumpy import interp_ufuncs, signature -from pypy.module.micronumpy.compile import (InterpreterState, FakeSpace, -FloatObject, IntObject, Parser) -from pypy.module.micronumpy.interp_dtype import W_Int32Dtype, W_Float64Dtype, W_Int64Dtype, W_UInt64Dtype +from pypy.module.micronumpy.compile import (FakeSpace, +FloatObject, IntObject, numpy_compile) from pypy.module.micronumpy.interp_numarray import (BaseArray, SingleDimArray, -SingleDimSlice, scalar_w, Scalar) +SingleDimSlice, scalar_w) from pypy.rlib.nonconst import NonConstant -from pypy.rpython.annlowlevel import llstr +from pypy.rpython.annlowlevel import llstr, hlstr from pypy.rpython.test.test_llinterp import interpret import py @@ -14,24 +13,16 @@ class TestNumpyJIt(LLJitMixin): def run(self, code): -# trick annotator -c = -a = 3 -b = [1,2] + [3,4] -c = a - space = FakeSpace() -parser = Parser() -codes = [parser.parse(code), parser.parse(c)] -def f(i): -interp = InterpreterState(codes[i]) +def f(code): +interp = numpy_compile(hlstr(code)) interp.run(space) res = interp.results[0] assert isinstance(res, BaseArray) return interp.space.float_w(res.eval(0).wrap(interp.space)) -return self.meta_interp(f, [0], listops=True, backendopt=True) +return self.meta_interp(f, [llstr(code)], listops=True, backendopt=True) def test_add(self): result = self.run( @@ -45,21 +36,14 @@ assert result == 3 + 3 def test_floatadd(self): -def f(i): -ar = SingleDimArray(i, dtype=self.float64_dtype) -v = interp_ufuncs.get(self.space).add.call(self.space, [ -ar, -scalar_w(self.space, self.float64_dtype, self.space.wrap(4.5)) -], -) -assert isinstance(v, BaseArray) -return v.get_concrete().eval(3).val - -result = self.meta_interp(f, [5], listops=True, backendopt=True) +result = self.run( +a = |30| + 3 +a - 3 +) +assert result == 3 + 3 self.check_loops({getarrayitem_raw: 1, float_add: 1, setarrayitem_raw: 1, int_add: 1, int_lt: 1, guard_true: 1, jump: 1}) -assert result == f(5) def test_sum(self): space = self.space ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-minilang: reuse the meta interped graph
Author: Maciej Fijalkowski fij...@gmail.com Branch: numpy-minilang Changeset: r48546:a9aa7bc83108 Date: 2011-10-28 00:20 +0200 http://bitbucket.org/pypy/pypy/changeset/a9aa7bc83108/ Log:reuse the meta interped graph diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -929,6 +929,9 @@ def view(self, **kwds): pass +def clear(self): +pass + class Stats(object): For tests. @@ -943,6 +946,12 @@ self.aborted_keys = [] self.invalidated_token_numbers = set() +def clear(self): +del self.loops[:] +del self.locations[:] +del self.aborted_keys[:] +self.invalidated_token_numbers.clear() + def set_history(self, history): self.operations = history.operations diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py --- a/pypy/jit/metainterp/warmspot.py +++ b/pypy/jit/metainterp/warmspot.py @@ -62,7 +62,7 @@ clear_tcache() return jittify_and_run(interp, graph, args, backendopt=backendopt, **kwds) -def jittify_and_run(interp, graph, args, repeat=1, +def jittify_and_run(interp, graph, args, repeat=1, graph_and_interp_only=False, backendopt=False, trace_limit=sys.maxint, inline=False, loop_longevity=0, retrace_limit=5, function_threshold=4, @@ -93,6 +93,8 @@ jd.warmstate.set_param_max_retrace_guards(max_retrace_guards) jd.warmstate.set_param_enable_opts(enable_opts) warmrunnerdesc.finish() +if graph_and_interp_only: +return interp, graph res = interp.eval_graph(graph, args) if not kwds.get('translate_support_code', False): warmrunnerdesc.metainterp_sd.profiler.finish() @@ -157,6 +159,9 @@ def get_stats(): return pyjitpl._warmrunnerdesc.stats +def reset_stats(): +pyjitpl._warmrunnerdesc.stats.clear() + def get_translator(): return pyjitpl._warmrunnerdesc.translator diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -7,13 +7,16 @@ from pypy.rlib.nonconst import NonConstant from pypy.rpython.annlowlevel import llstr, hlstr from pypy.rpython.test.test_llinterp import interpret +from pypy.jit.metainterp.warmspot import reset_stats import py class TestNumpyJIt(LLJitMixin): +graph = None +interp = None + def run(self, code): - space = FakeSpace() def f(code): @@ -22,7 +25,17 @@ res = interp.results[0] assert isinstance(res, BaseArray) return interp.space.float_w(res.eval(0).wrap(interp.space)) -return self.meta_interp(f, [llstr(code)], listops=True, backendopt=True) + +if self.graph is None: +interp, graph = self.meta_interp(f, [llstr(code)], + listops=True, + backendopt=True, + graph_and_interp_only=True) +self.__class__.interp = interp +self.__class__.graph = graph + +reset_stats() +return self.interp.eval_graph(self.graph, [llstr(code)]) def test_add(self): result = self.run( @@ -45,6 +58,7 @@ setarrayitem_raw: 1, int_add: 1, int_lt: 1, guard_true: 1, jump: 1}) +class TstXyz(object): def test_sum(self): space = self.space float64_dtype = self.float64_dtype ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] [OPEN] Pull request #13 for pypy/pypy: fixes issue 923
A new pull request has been opened by Bruno Gola. brunogola/pypy has changes to be pulled into pypy/pypy. https://bitbucket.org/pypy/pypy/pull-request/13/fixes-issue-923 Title: fixes issue 923 more info: https://bugs.pypy.org/issue923 Changes to be pulled: caf9fa132b86 by Bruno Gola: merged with default branch d4c7fe2ac048 by Bruno Gola: test_search.py and test_zinternal.py passing 4c56b2a60b5a by Bruno Gola: [fixes issue 923] matching RegExp with optional zero-width assertion groups -- This is an issue notification from bitbucket.org. You are receiving this either because you are the participating in a pull request, or you are following it. ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] [COMMENT] Pull request #13 for pypy/pypy: fixes issue 923
New comment on pull request: https://bitbucket.org/pypy/pypy/pull-request/13/fixes-issue-923#comment-673 Alex Gaynor (alex_gaynor) said: This looks basically correct, thanks for tracking this down! I'm not going to merge it though, because I'm not sufficiently confident in my knowledge of this code, hopefully armin or someone else can take a look and merge this. -- This is a pull request comment notification from bitbucket.org. You are receiving this either because you are participating in a pull request, or you are following it. ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit