[pypy-commit] pypy py3k: hg merge default

rlamy noreply at buildbot.pypy.org
Thu Oct 23 15:35:54 CEST 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3k
Changeset: r74119:44d5b6ce30c0
Date: 2014-10-23 15:35 +0200
http://bitbucket.org/pypy/pypy/changeset/44d5b6ce30c0/

Log:	hg merge default

diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -16,6 +16,7 @@
 from pypy.module.micronumpy.base import W_NDimArray, W_NumpyObject
 from pypy.module.micronumpy.concrete import VoidBoxStorage
 from pypy.module.micronumpy.flagsobj import W_FlagsObject
+from pypy.module.micronumpy import support
 
 MIXIN_32 = (W_IntObject.typedef,) if LONG_BIT == 32 else ()
 MIXIN_64 = (W_IntObject.typedef,) if LONG_BIT == 64 else ()
@@ -144,6 +145,34 @@
     def item(self, space):
         return self.get_dtype(space).itemtype.to_builtin_type(space, self)
 
+    def descr_item(self, space, args_w):
+        if len(args_w) == 1 and space.isinstance_w(args_w[0], space.w_tuple):
+            args_w = space.fixedview(args_w[0])
+        if len(args_w) > 1:
+            raise oefmt(space.w_ValueError,
+                        "incorrect number of indices for array")
+        elif len(args_w) == 1:
+            try:
+                idx = support.index_w(space, args_w[0])
+            except OperationError:
+                raise oefmt(space.w_TypeError, "an integer is required")
+            if idx != 0:
+                raise oefmt(space.w_IndexError,
+                            "index %d is out of bounds for size 1", idx)
+        return self.item(space)
+
+    def descr_transpose(self, space, args_w):
+        if len(args_w) == 1 and space.isinstance_w(args_w[0], space.w_tuple):
+            args_w = space.fixedview(args_w[0])
+        if len(args_w) >= 1:
+            for w_arg in args_w:
+                try:
+                    idx = support.index_w(space, w_arg)
+                except OperationError:
+                    raise oefmt(space.w_TypeError, "an integer is required")
+            raise oefmt(space.w_ValueError, "axes don't match array")
+        return self
+
     def descr_getitem(self, space, w_item):
         from pypy.module.micronumpy.base import convert_to_array
         if space.is_w(w_item, space.w_Ellipsis) or \
@@ -359,6 +388,13 @@
 
     def descr_reshape(self, space, __args__):
         w_meth = space.getattr(self.descr_ravel(space), space.wrap('reshape'))
+        w_res = space.call_args(w_meth, __args__)
+        if isinstance(w_res, W_NDimArray) and len(w_res.get_shape()) == 0:
+            return w_res.get_scalar_value()
+        return w_res
+
+    def descr_nd_nonzero(self, space, __args__):
+        w_meth = space.getattr(self.descr_ravel(space), space.wrap('nonzero'))
         return space.call_args(w_meth, __args__)
 
     def descr_get_real(self, space):
@@ -374,6 +410,13 @@
             self.w_flags = W_FlagsObject(self)
         return self.w_flags
 
+    @unwrap_spec(axis1=int, axis2=int)
+    def descr_swapaxes(self, space, axis1, axis2):
+        return self
+
+    def descr_fill(self, space, w_value):
+        self.get_dtype(space).coerce(space, w_value)
+
 class W_BoolBox(W_GenericBox, PrimitiveBox):
     descr__new__, _get_dtype, descr_reduce = new_dtype_getter(NPY.BOOL)
 
@@ -607,6 +650,8 @@
     __hash__ = interp2app(W_GenericBox.descr_hash),
 
     tolist = interp2app(W_GenericBox.item),
+    item = interp2app(W_GenericBox.descr_item),
+    transpose = interp2app(W_GenericBox.descr_transpose),
     min = interp2app(W_GenericBox.descr_self),
     max = interp2app(W_GenericBox.descr_self),
     argmin = interp2app(W_GenericBox.descr_zero),
@@ -618,13 +663,18 @@
     ravel = interp2app(W_GenericBox.descr_ravel),
     round = interp2app(W_GenericBox.descr_round),
     conjugate = interp2app(W_GenericBox.descr_conjugate),
+    conj = interp2app(W_GenericBox.descr_conjugate),
     astype = interp2app(W_GenericBox.descr_astype),
     view = interp2app(W_GenericBox.descr_view),
     squeeze = interp2app(W_GenericBox.descr_self),
     copy = interp2app(W_GenericBox.descr_copy),
     byteswap = interp2app(W_GenericBox.descr_byteswap),
     tostring = interp2app(W_GenericBox.descr_tostring),
+    tobytes = interp2app(W_GenericBox.descr_tostring),
     reshape = interp2app(W_GenericBox.descr_reshape),
+    swapaxes = interp2app(W_GenericBox.descr_swapaxes),
+    nonzero = interp2app(W_GenericBox.descr_nd_nonzero),
+    fill = interp2app(W_GenericBox.descr_fill),
 
     dtype = GetSetProperty(W_GenericBox.descr_get_dtype),
     size = GetSetProperty(W_GenericBox.descr_get_size),
diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -483,8 +483,7 @@
         from .flatiter import W_FlatIterator
         return space.wrap(W_FlatIterator(self))
 
-    def descr_item(self, space, __args__):
-        args_w, kw_w = __args__.unpack()
+    def descr_item(self, space, args_w):
         if len(args_w) == 1 and space.isinstance_w(args_w[0], space.w_tuple):
             args_w = space.fixedview(args_w[0])
         shape = self.get_shape()
diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -3065,6 +3065,7 @@
         assert a.item((1, 1, 1)) == 16
         exc = raises(ValueError, a.item, 1, 1, 1, 1)
         assert str(exc.value) == "incorrect number of indices for array"
+        raises(TypeError, "array([1]).item(a=1)")
 
     def test_itemset(self):
         import numpy as np
diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -254,6 +254,7 @@
         assert np.int64(123).reshape((1,)).shape == (1,)
         exc = raises(ValueError, "np.int64(123).reshape((2,))")
         assert exc.value[0] == 'total size of new array must be unchanged'
+        assert type(np.int64(123).reshape(())) == np.int64
 
     def test_complex_scalar_complex_cast(self):
         import numpy as np
@@ -293,10 +294,123 @@
 
     def test_scalar_iter(self):
         from numpypy import int8, int16, int32, int64, float32, float64
-        for t in int8, int16, int32, int64, float32, float64:
-            try:
-                iter(t(17))
-            except TypeError:
-                pass
-            else:
-                assert False, "%s object should not be iterable." % t
+        from numpypy import complex64, complex128
+        for t in (int8, int16, int32, int64, float32, float64,
+                  complex64, complex128):
+            raises(TypeError, iter, t(17))
+
+    def test_item_tolist(self):
+        from numpypy import int8, int16, int32, int64, float32, float64
+        from numpypy import complex64, complex128, dtype
+
+        def _do_test(np_type, py_type, orig_val, exp_val):
+            val = np_type(orig_val)
+            assert val == orig_val
+            assert val.item() == exp_val
+            assert val.tolist() == exp_val
+            assert type(val.item()) is py_type
+            assert type(val.tolist()) is py_type
+            val.item(0)
+            val.item(())
+            val.item((0,))
+            raises(ValueError, val.item, 0, 1)
+            raises(ValueError, val.item, 0, '')
+            raises(TypeError, val.item, '')
+            raises(IndexError, val.item, 2)
+
+        for t in int8, int16, int32:
+            _do_test(t, int, 17, 17)
+
+        py_type = int if dtype('int').itemsize == 8 else long
+        _do_test(int64, py_type, 17, 17)
+
+        for t in float32, float64:
+            _do_test(t, float, 17, 17)
+
+        for t in complex64, complex128:
+            _do_test(t, complex, 17j, 17j)
+
+    def test_transpose(self):
+        from numpypy import int8, int16, int32, int64, float32, float64
+        from numpypy import complex64, complex128
+
+        def _do_test(np_type, orig_val, exp_val):
+            val = np_type(orig_val)
+            assert val == orig_val
+            assert val.transpose() == exp_val
+            assert type(val.transpose()) is np_type
+            val.transpose(())
+            raises(ValueError, val.transpose, 0, 1)
+            raises(TypeError, val.transpose, 0, '')
+            raises(ValueError, val.transpose, 0)
+
+        for t in int8, int16, int32, int64:
+            _do_test(t, 17, 17)
+
+        for t in float32, float64:
+            _do_test(t, 17, 17)
+
+        for t in complex64, complex128:
+            _do_test(t, 17j, 17j)
+
+    def test_swapaxes(self):
+        from numpypy import int8, int16, int32, int64, float32, float64
+        from numpypy import complex64, complex128
+
+        def _do_test(np_type, orig_val, exp_val):
+            val = np_type(orig_val)
+            assert val == orig_val
+            assert val.swapaxes(10, 20) == exp_val
+            assert type(val.swapaxes(0, 1)) is np_type
+            raises(TypeError, val.swapaxes, 0, ())
+
+        for t in int8, int16, int32, int64:
+            _do_test(t, 17, 17)
+
+        for t in float32, float64:
+            _do_test(t, 17, 17)
+
+        for t in complex64, complex128:
+            _do_test(t, 17j, 17j)
+
+    def test_nonzero(self):
+        from numpypy import int8, int16, int32, int64, float32, float64
+        from numpypy import complex64, complex128
+
+        for t in (int8, int16, int32, int64, float32, float64,
+                  complex64, complex128):
+            res, = t(17).nonzero()
+            assert len(res) == 1
+            assert res[0] == 0
+            res, = t(0).nonzero()
+            assert len(res) == 0
+
+    def test_fill(self):
+        import sys
+        from numpypy import int8, int16, int32, int64, float32, float64
+        from numpypy import complex64, complex128
+
+        for t in (int8, int16, int32, int64, float32, float64,
+                  complex64, complex128):
+            t(17).fill(2)
+            exc = (TypeError if t in (complex64, complex128)
+                   and '__pypy__' not in sys.builtin_module_names
+                   else ValueError)
+            raises(exc, t(17).fill, '')
+
+    def test_conj(self):
+        from numpypy import int8, int16, int32, int64, float32, float64
+        from numpypy import complex64, complex128
+
+        def _do_test(np_type, orig_val, exp_val):
+            val = np_type(orig_val)
+            assert val == orig_val
+            assert val.conj() == exp_val
+            assert val.conjugate() == exp_val
+
+        for t in (int8, int16, int32, int64, float32, float64,
+                  complex64, complex128):
+            _do_test(t, 17, 17)
+
+        for t in complex64, complex128:
+            _do_test(t, 17j, -17j)
diff --git a/pypy/module/pypyjit/test_pypy_c/test_string.py b/pypy/module/pypyjit/test_pypy_c/test_string.py
--- a/pypy/module/pypyjit/test_pypy_c/test_string.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_string.py
@@ -82,7 +82,10 @@
             strsetitem(p25, 0, i23)
             p93 = call(ConstClass(fromstr), p25, 16, descr=<Callr . ri EF=3>)
             guard_no_exception(descr=...)
-            i94 = call(ConstClass(rbigint.toint), p93, descr=<Calli . r EF=3>)
+            i95 = getfield_gc_pure(p93, descr=<FieldS rpython.rlib.rbigint.rbigint.inst_size .*>)
+            i96 = int_gt(i95, .*)
+            guard_false(i96, descr=...)
+            i94 = call(ConstClass(rbigint._toint_helper), p93, descr=<Calli 8 r EF=3>)
             guard_no_exception(descr=...)
             i95 = int_add_ovf(i6, i94)
             guard_no_overflow(descr=...)
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -1558,6 +1558,26 @@
         """
         self.optimize_loop(ops, expected)
 
+    def test_varray_clear_unroll_bug(self):
+        ops = """
+        [p0]
+        i0 = getarrayitem_gc(p0, 0, descr=arraydescr)
+        i1 = getarrayitem_gc(p0, 1, descr=arraydescr)
+        i2 = getarrayitem_gc(p0, 2, descr=arraydescr)
+        i3 = int_add(i0, i1)
+        i4 = int_add(i3, i2)
+        p1 = new_array_clear(3, descr=arraydescr)
+        setarrayitem_gc(p1, 1, i4, descr=arraydescr)
+        setarrayitem_gc(p1, 0, 25, descr=arraydescr)
+        jump(p1)
+        """
+        expected = """
+        [i1]
+        i2 = int_add(i1, 25)
+        jump(i2)
+        """
+        self.optimize_loop(ops, expected)
+
     def test_varray_alloc_and_set(self):
         ops = """
         [i1]
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
@@ -761,6 +761,24 @@
         assert not vstate1.generalization_of(vstate2)
         
 
+    def test_crash_varay_clear(self):
+        innervalue1 = OptValue(self.nodebox)
+        constclassbox = self.cpu.ts.cls_of_box(self.nodebox)
+        innervalue1.make_constant_class(constclassbox, -1)
+        innerinfo1 = NotVirtualStateInfo(innervalue1)
+        innerinfo1.position = 1
+        innerinfo1.position_in_notvirtuals = 0
+
+        descr = object()
+
+        info1 = VArrayStateInfo(descr)
+        info1.fieldstate = [innerinfo1]
+
+        constvalue = self.cpu.ts.CVAL_NULLREF
+        value1 = VArrayValue(descr, constvalue, 1, self.nodebox, clear=True)
+        value1._items[0] = constvalue
+        info1.enum_forced_boxes([None], value1, None)
+
 class BaseTestBridges(BaseTest):
     enable_opts = "intbounds:rewrite:virtualize:string:pure:heap:unroll"
 
diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py b/rpython/jit/metainterp/optimizeopt/virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py
@@ -205,6 +205,8 @@
             raise BadVirtualState
         for i in range(len(self.fieldstate)):
             v = value.get_item_value(i)
+            if v is None:
+                v = value.get_missing_null_value()
             s = self.fieldstate[i]
             if s.position > self.position:
                 s.enum_forced_boxes(boxes, v, optimizer)
diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -688,10 +688,10 @@
     if hop.s_result.is_constant():
         return hop.inputconst(lltype.Bool, hop.s_result.const)
 
-    if hop.args_s[1].is_constant() and hop.args_s[1].const in (str, list):
-        if hop.args_s[0].knowntype not in (str, list):
-            raise TyperError("isinstance(x, str/list) expects x to be known"
-                             " statically to be a str/list or None")
+    if hop.args_s[1].is_constant() and hop.args_s[1].const in (str, list, unicode):
+        if hop.args_s[0].knowntype not in (str, list, unicode):
+            raise TyperError("isinstance(x, str/list/unicode) expects x to be known"
+                             " statically to be a str/list/unicode or None")
         rstrlist = hop.args_r[0]
         vstrlist = hop.inputarg(rstrlist, arg=0)
         cnone = hop.inputconst(rstrlist, None)
diff --git a/rpython/rtyper/test/test_rbuiltin.py b/rpython/rtyper/test/test_rbuiltin.py
--- a/rpython/rtyper/test/test_rbuiltin.py
+++ b/rpython/rtyper/test/test_rbuiltin.py
@@ -393,6 +393,21 @@
         res = self.interpret(f, [1])
         assert res is False
 
+    def test_isinstance_unicode(self):
+        def g():
+            pass
+        def f(i):
+            if i == 0:
+                l = u"foobar"
+            else:
+                l = None
+            g()
+            return isinstance(l, unicode)
+        res = self.interpret(f, [0])
+        assert res is True
+        res = self.interpret(f, [1])
+        assert res is False
+
     def test_instantiate(self):
         class A:
             pass


More information about the pypy-commit mailing list