Author: Hakan Ardo <ha...@debian.org> Branch: jit-targets Changeset: r50365:ba23d85f0f16 Date: 2011-12-11 10:32 +0100 http://bitbucket.org/pypy/pypy/changeset/ba23d85f0f16/
Log: hg merge default diff --git a/lib_pypy/distributed/socklayer.py b/lib_pypy/distributed/socklayer.py --- a/lib_pypy/distributed/socklayer.py +++ b/lib_pypy/distributed/socklayer.py @@ -2,7 +2,7 @@ import py from socket import socket -XXX needs import adaptation as 'green' is removed from py lib for years +raise ImportError("XXX needs import adaptation as 'green' is removed from py lib for years") from py.impl.green.msgstruct import decodemessage, message from socket import socket, AF_INET, SOCK_STREAM import marshal diff --git a/pypy/doc/conf.py b/pypy/doc/conf.py --- a/pypy/doc/conf.py +++ b/pypy/doc/conf.py @@ -45,9 +45,9 @@ # built documents. # # The short X.Y version. -version = '1.6' +version = '1.7' # The full version, including alpha/beta/rc tags. -release = '1.6' +release = '1.7' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py --- a/pypy/module/micronumpy/__init__.py +++ b/pypy/module/micronumpy/__init__.py @@ -24,11 +24,16 @@ 'number': 'interp_boxes.W_NumberBox', 'integer': 'interp_boxes.W_IntegerBox', 'signedinteger': 'interp_boxes.W_SignedIntegerBox', + 'unsignedinteger': 'interp_boxes.W_UnsignedIntegerBox', 'bool_': 'interp_boxes.W_BoolBox', 'int8': 'interp_boxes.W_Int8Box', + 'uint8': 'interp_boxes.W_UInt8Box', 'int16': 'interp_boxes.W_Int16Box', + 'uint16': 'interp_boxes.W_UInt16Box', 'int32': 'interp_boxes.W_Int32Box', + 'uint32': 'interp_boxes.W_UInt32Box', 'int64': 'interp_boxes.W_Int64Box', + 'uint64': 'interp_boxes.W_UInt64Box', 'int_': 'interp_boxes.W_LongBox', 'inexact': 'interp_boxes.W_InexactBox', 'floating': 'interp_boxes.W_FloatingBox', 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 @@ -38,6 +38,7 @@ w_ValueError = None w_TypeError = None w_IndexError = None + w_OverflowError = None w_None = None w_bool = "bool" @@ -149,6 +150,10 @@ # XXX array probably assert False + def exception_match(self, w_exc_type, w_check_class): + # Good enough for now + raise NotImplementedError + class FloatObject(W_Root): tp = FakeSpace.w_float def __init__(self, floatval): diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py --- a/pypy/module/micronumpy/interp_boxes.py +++ b/pypy/module/micronumpy/interp_boxes.py @@ -91,6 +91,9 @@ descr_neg = _unaryop_impl("negative") descr_abs = _unaryop_impl("absolute") + def descr_tolist(self, space): + return self.get_dtype(space).itemtype.to_builtin_type(space, self) + class W_BoolBox(W_GenericBox, PrimitiveBox): descr__new__, get_dtype = new_dtype_getter("bool") @@ -104,38 +107,38 @@ class W_SignedIntegerBox(W_IntegerBox): pass -class W_UnsignedIntgerBox(W_IntegerBox): +class W_UnsignedIntegerBox(W_IntegerBox): pass class W_Int8Box(W_SignedIntegerBox, PrimitiveBox): descr__new__, get_dtype = new_dtype_getter("int8") -class W_UInt8Box(W_UnsignedIntgerBox, PrimitiveBox): +class W_UInt8Box(W_UnsignedIntegerBox, PrimitiveBox): descr__new__, get_dtype = new_dtype_getter("uint8") class W_Int16Box(W_SignedIntegerBox, PrimitiveBox): descr__new__, get_dtype = new_dtype_getter("int16") -class W_UInt16Box(W_UnsignedIntgerBox, PrimitiveBox): +class W_UInt16Box(W_UnsignedIntegerBox, PrimitiveBox): descr__new__, get_dtype = new_dtype_getter("uint16") class W_Int32Box(W_SignedIntegerBox, PrimitiveBox): descr__new__, get_dtype = new_dtype_getter("int32") -class W_UInt32Box(W_UnsignedIntgerBox, PrimitiveBox): +class W_UInt32Box(W_UnsignedIntegerBox, PrimitiveBox): descr__new__, get_dtype = new_dtype_getter("uint32") class W_LongBox(W_SignedIntegerBox, PrimitiveBox): descr__new__, get_dtype = new_dtype_getter("long") -class W_ULongBox(W_UnsignedIntgerBox, PrimitiveBox): +class W_ULongBox(W_UnsignedIntegerBox, PrimitiveBox): pass class W_Int64Box(W_SignedIntegerBox, PrimitiveBox): descr__new__, get_dtype = new_dtype_getter("int64") -class W_UInt64Box(W_UnsignedIntgerBox, PrimitiveBox): - pass +class W_UInt64Box(W_UnsignedIntegerBox, PrimitiveBox): + descr__new__, get_dtype = new_dtype_getter("uint64") class W_InexactBox(W_NumberBox): _attrs_ = () @@ -179,6 +182,8 @@ __neg__ = interp2app(W_GenericBox.descr_neg), __abs__ = interp2app(W_GenericBox.descr_abs), + + tolist = interp2app(W_GenericBox.descr_tolist), ) W_BoolBox.typedef = TypeDef("bool_", W_GenericBox.typedef, @@ -198,13 +203,18 @@ __module__ = "numpypy", ) +W_UnsignedIntegerBox.typedef = TypeDef("unsignedinteger", W_IntegerBox.typedef, + __module__ = "numpypy", +) + W_Int8Box.typedef = TypeDef("int8", W_SignedIntegerBox.typedef, __module__ = "numpypy", __new__ = interp2app(W_Int8Box.descr__new__.im_func), ) -W_UInt8Box.typedef = TypeDef("uint8", W_UnsignedIntgerBox.typedef, +W_UInt8Box.typedef = TypeDef("uint8", W_UnsignedIntegerBox.typedef, __module__ = "numpypy", + __new__ = interp2app(W_UInt8Box.descr__new__.im_func), ) W_Int16Box.typedef = TypeDef("int16", W_SignedIntegerBox.typedef, @@ -212,8 +222,9 @@ __new__ = interp2app(W_Int16Box.descr__new__.im_func), ) -W_UInt16Box.typedef = TypeDef("uint16", W_UnsignedIntgerBox.typedef, +W_UInt16Box.typedef = TypeDef("uint16", W_UnsignedIntegerBox.typedef, __module__ = "numpypy", + __new__ = interp2app(W_UInt16Box.descr__new__.im_func), ) W_Int32Box.typedef = TypeDef("int32", W_SignedIntegerBox.typedef, @@ -221,8 +232,9 @@ __new__ = interp2app(W_Int32Box.descr__new__.im_func), ) -W_UInt32Box.typedef = TypeDef("uint32", W_UnsignedIntgerBox.typedef, +W_UInt32Box.typedef = TypeDef("uint32", W_UnsignedIntegerBox.typedef, __module__ = "numpypy", + __new__ = interp2app(W_UInt32Box.descr__new__.im_func), ) if LONG_BIT == 32: @@ -233,7 +245,7 @@ __module__ = "numpypy", ) -W_ULongBox.typedef = TypeDef("u" + long_name, W_UnsignedIntgerBox.typedef, +W_ULongBox.typedef = TypeDef("u" + long_name, W_UnsignedIntegerBox.typedef, __module__ = "numpypy", ) @@ -242,8 +254,9 @@ __new__ = interp2app(W_Int64Box.descr__new__.im_func), ) -W_UInt64Box.typedef = TypeDef("uint64", W_UnsignedIntgerBox.typedef, +W_UInt64Box.typedef = TypeDef("uint64", W_UnsignedIntegerBox.typedef, __module__ = "numpypy", + __new__ = interp2app(W_UInt64Box.descr__new__.im_func), ) W_InexactBox.typedef = TypeDef("inexact", W_NumberBox.typedef, 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 @@ -876,6 +876,17 @@ arr.setshape(space, new_shape) return arr + def descr_tolist(self, space): + if len(self.shape) == 0: + assert isinstance(self, Scalar) + return self.value.descr_tolist(space) + w_result = space.newlist([]) + for i in range(self.shape[0]): + space.call_method(w_result, "append", + space.call_method(self.descr_getitem(space, space.wrap(i)), "tolist") + ) + return w_result + def descr_mean(self, space): return space.div(self.descr_sum(space), space.wrap(self.find_size())) @@ -1485,6 +1496,7 @@ copy = interp2app(BaseArray.descr_copy), reshape = interp2app(BaseArray.descr_reshape), + tolist = interp2app(BaseArray.descr_tolist), ) diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py --- a/pypy/module/micronumpy/test/test_dtypes.py +++ b/pypy/module/micronumpy/test/test_dtypes.py @@ -174,6 +174,8 @@ raises(TypeError, numpy.integer, 0) exc = raises(TypeError, numpy.signedinteger, 0) assert str(exc.value) == "cannot create 'signedinteger' instances" + exc = raises(TypeError, numpy.unsignedinteger, 0) + assert str(exc.value) == "cannot create 'unsignedinteger' instances" raises(TypeError, numpy.floating, 0) raises(TypeError, numpy.inexact, 0) @@ -210,17 +212,54 @@ assert type(int(x)) is int assert int(x) == -128 + def test_uint8(self): + import numpypy as numpy + + assert numpy.uint8.mro() == [numpy.uint8, numpy.unsignedinteger, numpy.integer, numpy.number, numpy.generic, object] + + a = numpy.array([1, 2, 3], numpy.uint8) + assert type(a[1]) is numpy.uint8 + assert numpy.dtype("uint8").type is numpy.uint8 + + x = numpy.uint8(128) + assert x == 128 + assert x != -128 + assert type(x) is numpy.uint8 + assert repr(x) == "128" + + assert type(int(x)) is int + assert int(x) == 128 + + assert numpy.uint8(255) == 255 + assert numpy.uint8(256) == 0 + def test_int16(self): import numpypy as numpy x = numpy.int16(3) assert x == 3 + assert numpy.int16(32767) == 32767 + assert numpy.int16(32768) == -32768 + + def test_uint16(self): + import numpypy as numpy + + assert numpy.uint16(65535) == 65535 + assert numpy.uint16(65536) == 0 def test_int32(self): import numpypy as numpy x = numpy.int32(23) assert x == 23 + assert numpy.int32(2147483647) == 2147483647 + assert numpy.int32(2147483648) == -2147483648 + + def test_uint32(self): + import numpypy as numpy + + assert numpy.uint32(4294967295) == 4294967295 + assert numpy.uint32(4294967296) == 0 def test_int_(self): import numpypy as numpy @@ -240,6 +279,25 @@ assert numpy.dtype(numpy.int64).type is numpy.int64 assert numpy.int64(3) == 3 + assert numpy.int64(9223372036854775807) == 9223372036854775807 + raises(OverflowError, numpy.int64, 9223372036854775808) + + def test_uint64(self): + import sys + import numpypy as numpy + + assert numpy.uint64.mro() == [numpy.uint64, numpy.unsignedinteger, numpy.integer, numpy.number, numpy.generic, object] + + assert numpy.dtype(numpy.uint64).type is numpy.uint64 + skip("see comment") + # These tests pass "by chance" on numpy, things that are larger than + # platform long (i.e. a python int), don't get put in a normal box, + # instead they become an object array containing a long, we don't have + # yet, so these can't pass. + assert numpy.uint64(9223372036854775808) == 9223372036854775808 + assert numpy.uint64(18446744073709551615) == 18446744073709551615 + raises(OverflowError, numpy.uint64(18446744073709551616)) + def test_float32(self): import numpypy as numpy 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 @@ -879,6 +879,45 @@ b[0] = 3 assert b.__debug_repr__() == 'Call2(add, forced=Array)' + def test_tolist_scalar(self): + from numpypy import int32, bool_ + x = int32(23) + assert x.tolist() == 23 + assert type(x.tolist()) is int + y = bool_(True) + assert y.tolist() is True + + def test_tolist_zerodim(self): + from numpypy import array + x = array(3) + assert x.tolist() == 3 + assert type(x.tolist()) is int + + def test_tolist_singledim(self): + from numpypy import array + a = array(range(5)) + assert a.tolist() == [0, 1, 2, 3, 4] + assert type(a.tolist()[0]) is int + b = array([0.2, 0.4, 0.6]) + assert b.tolist() == [0.2, 0.4, 0.6] + + def test_tolist_multidim(self): + from numpypy import array + a = array([[1, 2], [3, 4]]) + assert a.tolist() == [[1, 2], [3, 4]] + + def test_tolist_view(self): + from numpypy import array + a = array([[1,2],[3,4]]) + assert (a + a).tolist() == [[2, 4], [6, 8]] + + def test_tolist_slice(self): + from numpypy import array + a = array([[17.1, 27.2], [40.3, 50.3]]) + assert a[:,0].tolist() == [17.1, 40.3] + assert a[0].tolist() == [17.1, 27.2] + + class AppTestMultiDim(BaseNumpyAppTest): def test_init(self): import numpypy 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 @@ -185,7 +185,8 @@ # sure it was optimized correctly. # XXX the comment above is wrong now. We need preferrably a way to # count the two loops separately - self.check_resops({'setinteriorfield_raw': 4, 'guard_nonnull': 1, 'getfield_gc': 41, + self.check_resops({'setinteriorfield_raw': 4, 'guard_nonnull': 1, + 'getfield_gc': 35, 'getfield_gc_pure': 6, 'guard_class': 22, 'int_add': 8, 'float_mul': 2, 'guard_isnull': 2, 'jump': 2, 'int_ge': 4, 'getinteriorfield_raw': 4, 'float_add': 2, 'guard_false': 4, diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py --- a/pypy/module/micronumpy/types.py +++ b/pypy/module/micronumpy/types.py @@ -1,6 +1,7 @@ import functools import math +from pypy.interpreter.error import OperationError from pypy.module.micronumpy import interp_boxes from pypy.objspace.std.floatobject import float2string from pypy.rlib import rfloat, libffi, clibffi @@ -77,6 +78,9 @@ w_obj.__init__(self._coerce(space, w_item).value) return w_obj + def to_builtin_type(self, space, box): + return space.wrap(self.unbox(box)) + def _coerce(self, space, w_item): raise NotImplementedError @@ -271,6 +275,19 @@ T = rffi.ULONGLONG BoxType = interp_boxes.W_UInt64Box + def _coerce(self, space, w_item): + try: + return Integer._coerce(self, space, w_item) + except OperationError, e: + if not e.match(space, space.w_OverflowError): + raise + bigint = space.bigint_w(w_item) + try: + value = bigint.toulonglong() + except OverflowError: + raise OperationError(space.w_OverflowError, space.w_None) + return self.box(value) + class Float(Primitive): _mixin_ = True diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py --- a/pypy/objspace/fake/objspace.py +++ b/pypy/objspace/fake/objspace.py @@ -238,6 +238,7 @@ t = TranslationContext(config=config) self.t = t # for debugging ann = t.buildannotator() + ann.policy.allow_someobjects = False if func is not None: ann.build_types(func, argtypes, complete_now=False) # _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit