Author: mattip Branch: matrixmath-dot Changeset: r51431:d512cc3a2cf4 Date: 2012-01-17 21:06 +0200 http://bitbucket.org/pypy/pypy/changeset/d512cc3a2cf4/
Log: merge from default diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -2,6 +2,9 @@ *.py[co] *~ .*.swp +.idea +.project +.pydevproject syntax: regexp ^testresult$ diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py --- a/pypy/config/pypyoption.py +++ b/pypy/config/pypyoption.py @@ -340,7 +340,7 @@ requires=[("objspace.std.builtinshortcut", True)]), BoolOption("withidentitydict", "track types that override __hash__, __eq__ or __cmp__ and use a special dict strategy for those which do not", - default=True), + default=False), ]), ]) @@ -370,6 +370,7 @@ config.objspace.std.suggest(getattributeshortcut=True) config.objspace.std.suggest(newshortcut=True) config.objspace.std.suggest(withspecialisedtuple=True) + config.objspace.std.suggest(withidentitydict=True) #if not IS_64_BITS: # config.objspace.std.suggest(withsmalllong=True) diff --git a/pypy/module/cpyext/include/patchlevel.h b/pypy/module/cpyext/include/patchlevel.h --- a/pypy/module/cpyext/include/patchlevel.h +++ b/pypy/module/cpyext/include/patchlevel.h @@ -29,7 +29,7 @@ #define PY_VERSION "2.7.1" /* PyPy version as a string */ -#define PYPY_VERSION "1.7.1" +#define PYPY_VERSION "1.8.1" /* Subversion Revision number of this file (not of the repository). * Empty since Mercurial migration. */ diff --git a/pypy/module/micronumpy/interp_iter.py b/pypy/module/micronumpy/interp_iter.py --- a/pypy/module/micronumpy/interp_iter.py +++ b/pypy/module/micronumpy/interp_iter.py @@ -157,6 +157,8 @@ offset += self.strides[i] break else: + if i == self.dim: + first_line = True indices[i] = 0 offset -= self.backstrides[i] else: 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 @@ -287,11 +287,11 @@ descr_rmod = _binop_right_impl("mod") def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False): - def impl(self, space, w_dim=None): - if space.is_w(w_dim, space.w_None): - w_dim = space.wrap(-1) + def impl(self, space, w_axis=None): + if space.is_w(w_axis, space.w_None): + w_axis = space.wrap(-1) return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space, - self, True, promote_to_largest, w_dim) + self, True, promote_to_largest, w_axis) return func_with_new_name(impl, "reduce_%s_impl" % ufunc_name) descr_sum = _reduce_ufunc_impl("add") @@ -635,14 +635,14 @@ ) return w_result - def descr_mean(self, space, w_dim=None): - if space.is_w(w_dim, space.w_None): - w_dim = space.wrap(-1) + def descr_mean(self, space, w_axis=None): + if space.is_w(w_axis, space.w_None): + w_axis = space.wrap(-1) w_denom = space.wrap(self.size) else: - dim = space.int_w(w_dim) + dim = space.int_w(w_axis) w_denom = space.wrap(self.shape[dim]) - return space.div(self.descr_sum_promote(space, w_dim), w_denom) + return space.div(self.descr_sum_promote(space, w_axis), w_denom) def descr_var(self, space): # var = mean((values - mean(values)) ** 2) 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 @@ -734,6 +734,7 @@ a = array(range(105)).reshape(3, 5, 7) b = mean(a, axis=0) b[0,0]==35. + assert a.mean(axis=0)[0, 0] == 35 assert (b == array(range(35, 70), dtype=float).reshape(5, 7)).all() assert (mean(a, 2) == array(range(0, 15), dtype=float).reshape(3, 5) * 7 + 3).all() @@ -756,6 +757,7 @@ assert array([]).sum() == 0.0 raises(ValueError, 'array([]).max()') assert (a.sum(0) == [30, 35, 40]).all() + assert (a.sum(axis=0) == [30, 35, 40]).all() assert (a.sum(1) == [3, 12, 21, 30, 39]).all() assert (a.max(0) == [12, 13, 14]).all() assert (a.max(1) == [2, 5, 8, 11, 14]).all() @@ -770,6 +772,8 @@ assert ((a + a).T.sum(2).T == (a + a).sum(0)).all() assert (a.reshape(1,-1).sum(0) == range(105)).all() assert (a.reshape(1,-1).sum(1) == 5460) + assert (array([[1,2],[3,4]]).prod(0) == [3, 8]).all() + assert (array([[1,2],[3,4]]).prod(1) == [2, 12]).all() def test_identity(self): from _numpypy import identity, array diff --git a/pypy/module/pypyjit/policy.py b/pypy/module/pypyjit/policy.py --- a/pypy/module/pypyjit/policy.py +++ b/pypy/module/pypyjit/policy.py @@ -127,7 +127,7 @@ 'imp', 'sys', 'array', '_ffi', 'itertools', 'operator', 'posix', '_socket', '_sre', '_lsprof', '_weakref', '__pypy__', 'cStringIO', '_collections', 'struct', - 'mmap', 'marshal']: + 'mmap', 'marshal', '_codecs']: if modname == 'pypyjit' and 'interp_resop' in rest: return False return True diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py --- a/pypy/module/sys/version.py +++ b/pypy/module/sys/version.py @@ -10,7 +10,7 @@ CPYTHON_VERSION = (2, 7, 1, "final", 42) #XXX # sync patchlevel.h CPYTHON_API_VERSION = 1013 #XXX # sync with include/modsupport.h -PYPY_VERSION = (1, 7, 1, "dev", 0) #XXX # sync patchlevel.h +PYPY_VERSION = (1, 8, 1, "dev", 0) #XXX # sync patchlevel.h if platform.name == 'msvc': COMPILER_INFO = 'MSC v.%d 32 bit' % (platform.version * 10 + 600) diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py --- a/pypy/objspace/std/test/test_unicodeobject.py +++ b/pypy/objspace/std/test/test_unicodeobject.py @@ -64,6 +64,12 @@ check(', '.join([u'a']), u'a') check(', '.join(['a', u'b']), u'a, b') check(u', '.join(['a', 'b']), u'a, b') + try: + u''.join([u'a', 2, 3]) + except TypeError, e: + assert 'sequence item 1' in str(e) + else: + raise Exception("DID NOT RAISE") if sys.version_info >= (2,3): def test_contains_ex(self): 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 @@ -201,7 +201,7 @@ return space.newbool(container.find(item) != -1) def unicode_join__Unicode_ANY(space, w_self, w_list): - list_w = space.unpackiterable(w_list) + list_w = space.listview(w_list) size = len(list_w) if size == 0: @@ -216,22 +216,21 @@ def _unicode_join_many_items(space, w_self, list_w, size): self = w_self._value - sb = UnicodeBuilder() + prealloc_size = len(self) * (size - 1) + for i in range(size): + try: + prealloc_size += len(space.unicode_w(list_w[i])) + except OperationError, e: + if not e.match(space, space.w_TypeError): + raise + raise operationerrfmt(space.w_TypeError, + "sequence item %d: expected string or Unicode", i) + sb = UnicodeBuilder(prealloc_size) for i in range(size): if self and i != 0: sb.append(self) w_s = list_w[i] - if isinstance(w_s, W_UnicodeObject): - # shortcut for performance - sb.append(w_s._value) - else: - try: - sb.append(space.unicode_w(w_s)) - except OperationError, e: - if not e.match(space, space.w_TypeError): - raise - raise operationerrfmt(space.w_TypeError, - "sequence item %d: expected string or Unicode", i) + sb.append(space.unicode_w(w_s)) return space.wrap(sb.build()) def hash__Unicode(space, w_uni): diff --git a/pypy/rlib/longlong2float.py b/pypy/rlib/longlong2float.py --- a/pypy/rlib/longlong2float.py +++ b/pypy/rlib/longlong2float.py @@ -79,19 +79,23 @@ longlong2float = rffi.llexternal( "pypy__longlong2float", [rffi.LONGLONG], rffi.DOUBLE, _callable=longlong2float_emulator, compilation_info=eci, - _nowrapper=True, elidable_function=True, sandboxsafe=True) + _nowrapper=True, elidable_function=True, sandboxsafe=True, + oo_primitive="pypy__longlong2float") float2longlong = rffi.llexternal( "pypy__float2longlong", [rffi.DOUBLE], rffi.LONGLONG, _callable=float2longlong_emulator, compilation_info=eci, - _nowrapper=True, elidable_function=True, sandboxsafe=True) + _nowrapper=True, elidable_function=True, sandboxsafe=True, + oo_primitive="pypy__float2longlong") uint2singlefloat = rffi.llexternal( "pypy__uint2singlefloat", [rffi.UINT], rffi.FLOAT, _callable=uint2singlefloat_emulator, compilation_info=eci, - _nowrapper=True, elidable_function=True, sandboxsafe=True) + _nowrapper=True, elidable_function=True, sandboxsafe=True, + oo_primitive="pypy__uint2singlefloat") singlefloat2uint = rffi.llexternal( "pypy__singlefloat2uint", [rffi.FLOAT], rffi.UINT, _callable=singlefloat2uint_emulator, compilation_info=eci, - _nowrapper=True, elidable_function=True, sandboxsafe=True) + _nowrapper=True, elidable_function=True, sandboxsafe=True, + oo_primitive="pypy__singlefloat2uint") diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py --- a/pypy/rlib/objectmodel.py +++ b/pypy/rlib/objectmodel.py @@ -420,7 +420,7 @@ vobj.concretetype.TO._gckind == 'gc') else: from pypy.rpython.ootypesystem import ootype - ok = isinstance(vobj.concretetype, ootype.Instance) + ok = isinstance(vobj.concretetype, (ootype.Instance, ootype.BuiltinType)) if not ok: from pypy.rpython.error import TyperError raise TyperError("compute_unique_id() cannot be applied to" diff --git a/pypy/rpython/lltypesystem/rclass.py b/pypy/rpython/lltypesystem/rclass.py --- a/pypy/rpython/lltypesystem/rclass.py +++ b/pypy/rpython/lltypesystem/rclass.py @@ -510,7 +510,13 @@ ctype = inputconst(Void, self.object_type) cflags = inputconst(Void, flags) vlist = [ctype, cflags] - vptr = llops.genop('malloc', vlist, + cnonmovable = self.classdef.classdesc.read_attribute( + '_alloc_nonmovable_', Constant(False)) + if cnonmovable.value: + opname = 'malloc_nonmovable' + else: + opname = 'malloc' + vptr = llops.genop(opname, vlist, resulttype = Ptr(self.object_type)) ctypeptr = inputconst(CLASSTYPE, self.rclass.getvtable()) self.setfield(vptr, '__class__', ctypeptr, llops) diff --git a/pypy/rpython/ootypesystem/ootype.py b/pypy/rpython/ootypesystem/ootype.py --- a/pypy/rpython/ootypesystem/ootype.py +++ b/pypy/rpython/ootypesystem/ootype.py @@ -512,6 +512,7 @@ "ll_append_char": Meth([CHARTP], Void), "ll_append": Meth([STRINGTP], Void), "ll_build": Meth([], STRINGTP), + "ll_getlength": Meth([], Signed), }) self._setup_methods({}) @@ -1376,6 +1377,9 @@ def _cast_to_object(self): return make_object(self) + def _identityhash(self): + return object.__hash__(self) + class _string(_builtin_type): def __init__(self, STRING, value = ''): @@ -1543,6 +1547,9 @@ else: return make_unicode(u''.join(self._buf)) + def ll_getlength(self): + return self.ll_build().ll_strlen() + class _null_string_builder(_null_mixin(_string_builder), _string_builder): def __init__(self, STRING_BUILDER): self.__dict__["_TYPE"] = STRING_BUILDER diff --git a/pypy/rpython/ootypesystem/rbuilder.py b/pypy/rpython/ootypesystem/rbuilder.py --- a/pypy/rpython/ootypesystem/rbuilder.py +++ b/pypy/rpython/ootypesystem/rbuilder.py @@ -21,6 +21,10 @@ builder.ll_append_char(char) @staticmethod + def ll_getlength(builder): + return builder.ll_getlength() + + @staticmethod def ll_append(builder, string): builder.ll_append(string) diff --git a/pypy/rpython/test/test_rbuilder.py b/pypy/rpython/test/test_rbuilder.py --- a/pypy/rpython/test/test_rbuilder.py +++ b/pypy/rpython/test/test_rbuilder.py @@ -124,9 +124,5 @@ pass class TestOOtype(BaseTestStringBuilder, OORtypeMixin): - def test_string_getlength(self): - py.test.skip("getlength(): not implemented on ootype") - def test_unicode_getlength(self): - py.test.skip("getlength(): not implemented on ootype") def test_append_charpsize(self): py.test.skip("append_charpsize(): not implemented on ootype") diff --git a/pypy/rpython/test/test_rbuiltin.py b/pypy/rpython/test/test_rbuiltin.py --- a/pypy/rpython/test/test_rbuiltin.py +++ b/pypy/rpython/test/test_rbuiltin.py @@ -463,6 +463,31 @@ assert x1 == intmask(x0) assert x3 == intmask(x2) + def test_id_on_builtins(self): + from pypy.rlib.objectmodel import compute_unique_id + from pypy.rlib.rstring import StringBuilder, UnicodeBuilder + def fn(): + return (compute_unique_id("foo"), + compute_unique_id(u"bar"), + compute_unique_id([1]), + compute_unique_id({"foo": 3}), + compute_unique_id(StringBuilder()), + compute_unique_id(UnicodeBuilder())) + res = self.interpret(fn, []) + for id in self.ll_unpack_tuple(res, 6): + assert isinstance(id, (int, r_longlong)) + + def test_uniqueness_of_id_on_strings(self): + from pypy.rlib.objectmodel import compute_unique_id + def fn(s1, s2): + return (compute_unique_id(s1), compute_unique_id(s2)) + + s1 = "foo" + s2 = ''.join(['f','oo']) + res = self.interpret(fn, [self.string_to_ll(s1), self.string_to_ll(s2)]) + i1, i2 = self.ll_unpack_tuple(res, 2) + assert i1 != i2 + def test_cast_primitive(self): from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy def llf(u): diff --git a/pypy/rpython/test/test_rclass.py b/pypy/rpython/test/test_rclass.py --- a/pypy/rpython/test/test_rclass.py +++ b/pypy/rpython/test/test_rclass.py @@ -1130,6 +1130,18 @@ assert sorted([u]) == [6] # 32-bit types assert sorted([i, r, d, l]) == [2, 3, 4, 5] # 64-bit types + def test_nonmovable(self): + for (nonmovable, opname) in [(True, 'malloc_nonmovable'), + (False, 'malloc')]: + class A(object): + _alloc_nonmovable_ = nonmovable + def f(): + return A() + t, typer, graph = self.gengraph(f, []) + assert summary(graph) == {opname: 1, + 'cast_pointer': 1, + 'setfield': 1} + class TestOOtype(BaseTestRclass, OORtypeMixin): diff --git a/pypy/translator/jvm/builtin.py b/pypy/translator/jvm/builtin.py --- a/pypy/translator/jvm/builtin.py +++ b/pypy/translator/jvm/builtin.py @@ -84,6 +84,9 @@ (ootype.StringBuilder.__class__, "ll_build"): jvm.Method.v(jStringBuilder, "toString", (), jString), + (ootype.StringBuilder.__class__, "ll_getlength"): + jvm.Method.v(jStringBuilder, "length", (), jInt), + (ootype.String.__class__, "ll_hash"): jvm.Method.v(jString, "hashCode", (), jInt), diff --git a/pypy/translator/jvm/database.py b/pypy/translator/jvm/database.py --- a/pypy/translator/jvm/database.py +++ b/pypy/translator/jvm/database.py @@ -358,7 +358,7 @@ ootype.Unsigned:jvm.PYPYSERIALIZEUINT, ootype.SignedLongLong:jvm.LONGTOSTRINGL, ootype.UnsignedLongLong: jvm.PYPYSERIALIZEULONG, - ootype.Float:jvm.DOUBLETOSTRINGD, + ootype.Float:jvm.PYPYSERIALIZEDOUBLE, ootype.Bool:jvm.PYPYSERIALIZEBOOLEAN, ootype.Void:jvm.PYPYSERIALIZEVOID, ootype.Char:jvm.PYPYESCAPEDCHAR, diff --git a/pypy/translator/jvm/metavm.py b/pypy/translator/jvm/metavm.py --- a/pypy/translator/jvm/metavm.py +++ b/pypy/translator/jvm/metavm.py @@ -92,6 +92,7 @@ CASTS = { # FROM TO (ootype.Signed, ootype.UnsignedLongLong): jvm.I2L, + (ootype.Unsigned, ootype.UnsignedLongLong): jvm.I2L, (ootype.SignedLongLong, ootype.Signed): jvm.L2I, (ootype.UnsignedLongLong, ootype.Unsigned): jvm.L2I, (ootype.UnsignedLongLong, ootype.Signed): jvm.L2I, diff --git a/pypy/translator/jvm/opcodes.py b/pypy/translator/jvm/opcodes.py --- a/pypy/translator/jvm/opcodes.py +++ b/pypy/translator/jvm/opcodes.py @@ -101,6 +101,7 @@ 'jit_force_virtualizable': Ignore, 'jit_force_virtual': DoNothing, 'jit_force_quasi_immutable': Ignore, + 'jit_is_virtual': PushPrimitive(ootype.Bool, False), 'debug_assert': [], # TODO: implement? 'debug_start_traceback': Ignore, diff --git a/pypy/translator/jvm/src/pypy/PyPy.java b/pypy/translator/jvm/src/pypy/PyPy.java --- a/pypy/translator/jvm/src/pypy/PyPy.java +++ b/pypy/translator/jvm/src/pypy/PyPy.java @@ -283,6 +283,14 @@ } } + public double pypy__longlong2float(long l) { + return Double.longBitsToDouble(l); + } + + public long pypy__float2longlong(double d) { + return Double.doubleToRawLongBits(d); + } + public double ooparse_float(String s) { try { return Double.parseDouble(s); @@ -353,6 +361,19 @@ return "False"; } + public static String serialize_double(double d) { + if (Double.isNaN(d)) { + return "float(\"nan\")"; + } else if (Double.isInfinite(d)) { + if (d > 0) + return "float(\"inf\")"; + else + return "float(\"-inf\")"; + } else { + return Double.toString(d); + } + } + private static String format_char(char c) { String res = "\\x"; if (c <= 0x0F) res = res + "0"; diff --git a/pypy/translator/jvm/test/runtest.py b/pypy/translator/jvm/test/runtest.py --- a/pypy/translator/jvm/test/runtest.py +++ b/pypy/translator/jvm/test/runtest.py @@ -56,6 +56,7 @@ # CLI could-be duplicate class JvmGeneratedSourceWrapper(object): + def __init__(self, gensrc): """ gensrc is an instance of JvmGeneratedSource """ self.gensrc = gensrc diff --git a/pypy/translator/jvm/test/test_builder.py b/pypy/translator/jvm/test/test_builder.py new file mode 100644 --- /dev/null +++ b/pypy/translator/jvm/test/test_builder.py @@ -0,0 +1,7 @@ +from pypy.translator.jvm.test.runtest import JvmTest +from pypy.rpython.test.test_rbuilder import BaseTestStringBuilder +import py + +class TestJvmStringBuilder(JvmTest, BaseTestStringBuilder): + def test_append_charpsize(self): + py.test.skip("append_charpsize(): not implemented on ootype") diff --git a/pypy/translator/jvm/test/test_longlong2float.py b/pypy/translator/jvm/test/test_longlong2float.py new file mode 100644 --- /dev/null +++ b/pypy/translator/jvm/test/test_longlong2float.py @@ -0,0 +1,20 @@ +from pypy.translator.jvm.test.runtest import JvmTest +from pypy.rlib.longlong2float import * +from pypy.rlib.test.test_longlong2float import enum_floats +from pypy.rlib.test.test_longlong2float import fn as float2longlong2float +import py + +class TestLongLong2Float(JvmTest): + + def test_float2longlong_and_longlong2float(self): + def func(f): + return float2longlong2float(f) + + for f in enum_floats(): + assert repr(f) == repr(self.interpret(func, [f])) + + def test_uint2singlefloat(self): + py.test.skip("uint2singlefloat is not implemented in ootype") + + def test_singlefloat2uint(self): + py.test.skip("singlefloat2uint is not implemented in ootype") diff --git a/pypy/translator/jvm/typesystem.py b/pypy/translator/jvm/typesystem.py --- a/pypy/translator/jvm/typesystem.py +++ b/pypy/translator/jvm/typesystem.py @@ -955,6 +955,7 @@ PYPYSERIALIZEUINT = Method.s(jPyPy, 'serialize_uint', (jInt,), jString) PYPYSERIALIZEULONG = Method.s(jPyPy, 'serialize_ulonglong', (jLong,),jString) PYPYSERIALIZEVOID = Method.s(jPyPy, 'serialize_void', (), jString) +PYPYSERIALIZEDOUBLE = Method.s(jPyPy, 'serialize_double', (jDouble,), jString) PYPYESCAPEDCHAR = Method.s(jPyPy, 'escaped_char', (jChar,), jString) PYPYESCAPEDUNICHAR = Method.s(jPyPy, 'escaped_unichar', (jChar,), jString) PYPYESCAPEDSTRING = Method.s(jPyPy, 'escaped_string', (jString,), jString) diff --git a/pypy/translator/oosupport/test_template/cast.py b/pypy/translator/oosupport/test_template/cast.py --- a/pypy/translator/oosupport/test_template/cast.py +++ b/pypy/translator/oosupport/test_template/cast.py @@ -13,6 +13,9 @@ def to_longlong(x): return r_longlong(x) +def to_ulonglong(x): + return r_ulonglong(x) + def uint_to_int(x): return intmask(x) @@ -56,6 +59,9 @@ def test_unsignedlonglong_to_unsigned4(self): self.check(to_uint, [r_ulonglong(18446744073709551615l)]) # max 64 bit num + def test_unsigned_to_usignedlonglong(self): + self.check(to_ulonglong, [r_uint(42)]) + def test_uint_to_int(self): self.check(uint_to_int, [r_uint(sys.maxint+1)]) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit