Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: Changeset: r54408:dc0b12d91fe2 Date: 2012-04-16 11:45 +0200 http://bitbucket.org/pypy/pypy/changeset/dc0b12d91fe2/
Log: merge diff --git a/_pytest/assertion/oldinterpret.py b/_pytest/assertion/oldinterpret.py --- a/_pytest/assertion/oldinterpret.py +++ b/_pytest/assertion/oldinterpret.py @@ -1,8 +1,7 @@ import py import sys, inspect from compiler import parse, ast, pycodegen -from _pytest.assertion.util import format_explanation -from _pytest.assertion.reinterpret import BuiltinAssertionError +from _pytest.assertion.util import format_explanation, BuiltinAssertionError passthroughex = py.builtin._sysex diff --git a/_pytest/assertion/reinterpret.py b/_pytest/assertion/reinterpret.py --- a/_pytest/assertion/reinterpret.py +++ b/_pytest/assertion/reinterpret.py @@ -1,7 +1,6 @@ import sys import py - -BuiltinAssertionError = py.builtin.builtins.AssertionError +from _pytest.assertion.util import BuiltinAssertionError class AssertionError(BuiltinAssertionError): def __init__(self, *args): diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -2,6 +2,7 @@ import py +BuiltinAssertionError = py.builtin.builtins.AssertionError # The _reprcompare attribute on the util module is used by the new assertion # interpretation code and assertion rewriter to detect this plugin was diff --git a/lib_pypy/numpypy/core/fromnumeric.py b/lib_pypy/numpypy/core/fromnumeric.py --- a/lib_pypy/numpypy/core/fromnumeric.py +++ b/lib_pypy/numpypy/core/fromnumeric.py @@ -411,7 +411,8 @@ [3, 7]]]) """ - raise NotImplementedError('Waiting on interp level method') + swapaxes = a.swapaxes + return swapaxes(axis1, axis2) def transpose(a, axes=None): diff --git a/pypy/annotation/test/test_annrpython.py b/pypy/annotation/test/test_annrpython.py --- a/pypy/annotation/test/test_annrpython.py +++ b/pypy/annotation/test/test_annrpython.py @@ -3746,9 +3746,9 @@ return g(i) def main(i): if i == 2: - return f(i) + return f(2) elif i == 3: - return f(i) + return f(3) else: raise NotImplementedError diff --git a/pypy/module/_lsprof/interp_lsprof.py b/pypy/module/_lsprof/interp_lsprof.py --- a/pypy/module/_lsprof/interp_lsprof.py +++ b/pypy/module/_lsprof/interp_lsprof.py @@ -185,6 +185,7 @@ if subentry is not None: subentry._stop(tt, it) +@jit.elidable_promote() def create_spec(space, w_arg): if isinstance(w_arg, Method): w_function = w_arg.w_function 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 @@ -513,7 +513,30 @@ arr = concrete.copy(space) arr.setshape(space, new_shape) return arr - + + @unwrap_spec(axis1=int, axis2=int) + def descr_swapaxes(self, space, axis1, axis2): + """a.swapaxes(axis1, axis2) + + Return a view of the array with `axis1` and `axis2` interchanged. + + Refer to `numpy.swapaxes` for full documentation. + + See Also + -------- + numpy.swapaxes : equivalent function + """ + concrete = self.get_concrete() + shape = concrete.shape[:] + strides = concrete.strides[:] + backstrides = concrete.backstrides[:] + shape[axis1], shape[axis2] = shape[axis2], shape[axis1] + strides[axis1], strides[axis2] = strides[axis2], strides[axis1] + backstrides[axis1], backstrides[axis2] = backstrides[axis2], backstrides[axis1] + arr = W_NDimSlice(concrete.start, strides, + backstrides, shape, concrete) + return space.wrap(arr) + def descr_tolist(self, space): if len(self.shape) == 0: assert isinstance(self, Scalar) @@ -1412,6 +1435,7 @@ copy = interp2app(BaseArray.descr_copy), flatten = interp2app(BaseArray.descr_flatten), reshape = interp2app(BaseArray.descr_reshape), + swapaxes = interp2app(BaseArray.descr_swapaxes), tolist = interp2app(BaseArray.descr_tolist), take = interp2app(BaseArray.descr_take), compress = interp2app(BaseArray.descr_compress), 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 @@ -1410,6 +1410,35 @@ assert (array([1, 2]).repeat(2) == array([1, 1, 2, 2])).all() + def test_swapaxes(self): + from _numpypy import array + # testcases from numpy docstring + x = array([[1, 2, 3]]) + assert (x.swapaxes(0, 1) == array([[1], [2], [3]])).all() + x = array([[[0,1],[2,3]],[[4,5],[6,7]]]) # shape = (2, 2, 2) + assert (x.swapaxes(0, 2) == array([[[0, 4], [2, 6]], + [[1, 5], [3, 7]]])).all() + assert (x.swapaxes(0, 1) == array([[[0, 1], [4, 5]], + [[2, 3], [6, 7]]])).all() + assert (x.swapaxes(1, 2) == array([[[0, 2], [1, 3]], + [[4, 6],[5, 7]]])).all() + + # more complex shape i.e. (2, 2, 3) + x = array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) + assert (x.swapaxes(0, 1) == array([[[1, 2, 3], [7, 8, 9]], + [[4, 5, 6], [10, 11, 12]]])).all() + assert (x.swapaxes(0, 2) == array([[[1, 7], [4, 10]], [[2, 8], [5, 11]], + [[3, 9], [6, 12]]])).all() + assert (x.swapaxes(1, 2) == array([[[1, 4], [2, 5], [3, 6]], + [[7, 10], [8, 11],[9, 12]]])).all() + + # test slice + assert (x[0:1,0:2].swapaxes(0,2) == array([[[1], [4]], [[2], [5]], + [[3], [6]]])).all() + # test virtual + assert ((x + x).swapaxes(0,1) == array([[[ 2, 4, 6], [14, 16, 18]], + [[ 8, 10, 12], [20, 22, 24]]])).all() + class AppTestMultiDim(BaseNumpyAppTest): def test_init(self): import _numpypy diff --git a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py --- a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py +++ b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py @@ -136,4 +136,11 @@ raises(NotImplementedError, "transpose(x, axes=(1, 0, 2))") # x = ones((1, 2, 3)) # assert transpose(x, (1, 0, 2)).shape == (2, 1, 3) - + + def test_fromnumeric(self): + from numpypy import array, swapaxes + x = array([[1,2,3]]) + assert (swapaxes(x,0,1) == array([[1], [2], [3]])).all() + x = array([[[0,1],[2,3]],[[4,5],[6,7]]]) + assert (swapaxes(x,0,2) == array([[[0, 4], [2, 6]], + [[1, 5], [3, 7]]])).all() diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py --- a/pypy/objspace/std/stringobject.py +++ b/pypy/objspace/std/stringobject.py @@ -14,6 +14,7 @@ from pypy.objspace.std.tupleobject import W_TupleObject from pypy.rlib.rstring import StringBuilder, split from pypy.interpreter.buffer import StringBuffer +from pypy.rlib import jit from pypy.objspace.std.stringtype import sliced, wrapstr, wrapchar, \ stringendswith, stringstartswith, joined2 @@ -398,6 +399,8 @@ return _str_join_many_items(space, w_self, list_w, size) +@jit.look_inside_iff(lambda space, w_self, list_w, size: + jit.loop_unrolling_heuristic(list_w, size)) def _str_join_many_items(space, w_self, list_w, size): self = w_self._value reslen = len(self) * (size - 1) diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -16,6 +16,7 @@ from pypy.rlib.runicode import unicode_encode_unicode_escape from pypy.module.unicodedata import unicodedb from pypy.tool.sourcetools import func_with_new_name +from pypy.rlib import jit from pypy.objspace.std.formatting import mod_format from pypy.objspace.std.stringtype import stringstartswith, stringendswith @@ -214,6 +215,8 @@ return _unicode_join_many_items(space, w_self, list_w, size) +@jit.look_inside_iff(lambda space, w_self, list_w, size: + jit.loop_unrolling_heuristic(list_w, size)) def _unicode_join_many_items(space, w_self, list_w, size): self = w_self._value prealloc_size = len(self) * (size - 1) diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py --- a/pypy/rlib/jit.py +++ b/pypy/rlib/jit.py @@ -204,6 +204,14 @@ return NonConstant(False) isvirtual._annspecialcase_ = "specialize:call_location" +LIST_CUTOFF = 2 + +@specialize.call_location() +def loop_unrolling_heuristic(lst, size): + """ In which cases iterating over items of lst can be unrolled + """ + return isvirtual(lst) or (isconstant(size) and size <= LIST_CUTOFF) + class Entry(ExtRegistryEntry): _about_ = hint 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 @@ -709,7 +709,8 @@ return count @enforceargs(int, None) - @jit.look_inside_iff(lambda length, items: jit.isconstant(length) and length <= 2) + @jit.look_inside_iff(lambda length, items: jit.loop_unrolling_heuristic( + items, length)) def ll_join_strs(length, items): # Special case for length 1 items, helps both the JIT and other code if length == 1: diff --git a/pypy/tool/clean_old_branches.py b/pypy/tool/clean_old_branches.py --- a/pypy/tool/clean_old_branches.py +++ b/pypy/tool/clean_old_branches.py @@ -4,30 +4,28 @@ called 'closed-branch'. It reduces the number of heads. """ -import os, sys +import os +import sys +import commands -if not os.listdir('.hg'): +if not os.path.isdir('.hg'): print 'Must run this script from the top-level directory.' sys.exit(1) -def heads(args): - g = os.popen(r"hg heads --topo %s --template '{node|short}:{branches}\n'" - % args, 'r') - result = g.read() - g.close() +def heads(): + result = commands.getoutput( + "hg heads --topo --closed --template '{node|short}:{branches}:{extras}\n'") result = result.splitlines(False) + result = [s.split(':', 2) for s in result] for line in result: - if len(line.split(':', 1)) != 2: + if len(line) != 3: raise ValueError("'result' contains: %r" % line) - result = [s.split(':', 1) for s in result] - result = [(head, branch) for (head, branch) in result - if branch not in ['', 'closed-branches']] + result = [(head, branch) for (head, branch, extra) in result + if branch not in ['', 'closed-branches'] and 'close' in extra] return result -all_heads = heads("--closed") -opened_heads = heads("") -closed_heads = [s for s in all_heads if s not in opened_heads] +closed_heads = heads() if not closed_heads: print >> sys.stderr, 'no dangling closed heads.' @@ -56,16 +54,14 @@ print '*** error %r' % (err,) sys.exit(1) +print '*** switching to closed branches *** ' +do("hg up --clean closed-branches") +do("hg --config extensions.purge= purge --all") + for head, branch in closed_heads: print print '***** %s ***** %s *****' % (branch, head) - do("hg up --clean closed-branches") - do("hg --config extensions.purge= purge --all") - do("hg merge -y %s" % head) - for fn in os.listdir('.'): - if fn.lower() != '.hg': - do("rm -fr -- '%s'" % fn) - do("hg rm --after -- '%s' || true" % fn) + do("hg debugsetparents closed-branches %s" % head) do("hg ci -m'Merge closed head %s on branch %s'" % (head, branch)) print diff --git a/pypy/tool/test/test_udir.py b/pypy/tool/test/test_udir.py --- a/pypy/tool/test/test_udir.py +++ b/pypy/tool/test/test_udir.py @@ -13,6 +13,8 @@ def test_make_udir_with_basename(): root = str(udir.udir.ensure('make_udir2', dir=1)) p1 = udir.make_udir(dir=root, basename='foobar') + def assert_relto(path, root, expected): + assert path.relto(root) == expected, path.relto(root) assert p1.relto(root) == 'usession-foobar-0' p1 = udir.make_udir(dir=root, basename='-foobar') assert p1.relto(root) == 'usession-foobar-1' @@ -24,3 +26,5 @@ assert p1.relto(root) == 'usession-0' p1 = udir.make_udir(dir=root, basename='-') assert p1.relto(root) == 'usession-1' + p1 = udir.make_udir(dir=root, basename='fun/bar') + assert p1.relto(root) == 'usession-fun--bar-0' diff --git a/pypy/tool/udir.py b/pypy/tool/udir.py --- a/pypy/tool/udir.py +++ b/pypy/tool/udir.py @@ -41,6 +41,7 @@ basename = basename.encode(sys.getdefaultencoding()) else: basename = '' + basename = basename.replace('/', '--') if not basename.startswith('-'): basename = '-' + basename if not basename.endswith('-'): diff --git a/pypy/translator/driver.py b/pypy/translator/driver.py --- a/pypy/translator/driver.py +++ b/pypy/translator/driver.py @@ -115,12 +115,10 @@ backend, ts = self.get_backend_and_type_system() for task in self.tasks: explicit_task = task - parts = task.split('_') - if len(parts) == 1: - if task in ('annotate',): - expose_task(task) + if task == 'annotate': + expose_task(task) else: - task, postfix = parts + task, postfix = task.split('_') if task in ('rtype', 'backendopt', 'llinterpret', 'pyjitpl'): if ts: _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit