[pypy-commit] pypy numpy-back-to-applevel: merge default

fijal noreply at buildbot.pypy.org
Thu Jan 26 18:13:48 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-back-to-applevel
Changeset: r51801:2b3f50dad1dd
Date: 2012-01-26 17:25 +0200
http://bitbucket.org/pypy/pypy/changeset/2b3f50dad1dd/

Log:	merge default

diff --git a/pypy/bin/py.py b/pypy/bin/py.py
--- a/pypy/bin/py.py
+++ b/pypy/bin/py.py
@@ -76,6 +76,8 @@
     config.objspace.suggest(allworkingmodules=False)
     if config.objspace.allworkingmodules:
         pypyoption.enable_allworkingmodules(config)
+    if config.objspace.usemodules._continuation:
+        config.translation.continuation = True
     if config.objspace.usemodules.thread:
         config.translation.thread = True
 
diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -529,26 +529,31 @@
         import _socket, os
         if not hasattr(_socket, 'AF_UNIX'):
             skip('AF_UNIX not supported.')
-        sockpath = os.path.join(self.udir, 'app_test_unix_socket_connect')
+        oldcwd = os.getcwd()
+        os.chdir(self.udir)
+        try:
+            sockpath = 'app_test_unix_socket_connect'
 
-        serversock = _socket.socket(_socket.AF_UNIX)
-        serversock.bind(sockpath)
-        serversock.listen(1)
+            serversock = _socket.socket(_socket.AF_UNIX)
+            serversock.bind(sockpath)
+            serversock.listen(1)
 
-        clientsock = _socket.socket(_socket.AF_UNIX)
-        clientsock.connect(sockpath)
-        s, addr = serversock.accept()
-        assert not addr
+            clientsock = _socket.socket(_socket.AF_UNIX)
+            clientsock.connect(sockpath)
+            s, addr = serversock.accept()
+            assert not addr
 
-        s.send('X')
-        data = clientsock.recv(100)
-        assert data == 'X'
-        clientsock.send('Y')
-        data = s.recv(100)
-        assert data == 'Y'
+            s.send('X')
+            data = clientsock.recv(100)
+            assert data == 'X'
+            clientsock.send('Y')
+            data = s.recv(100)
+            assert data == 'Y'
 
-        clientsock.close()
-        s.close()
+            clientsock.close()
+            s.close()
+        finally:
+            os.chdir(oldcwd)
 
 
 class AppTestSocketTCP:
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
@@ -28,6 +28,7 @@
         'fromstring': 'interp_support.fromstring',
         'flatiter': 'interp_numarray.W_FlatIterator',
         'isna': 'interp_numarray.isna',
+        'concatenate': 'interp_numarray.concatenate',
 
         'set_string_function': 'appbridge.set_string_function',
         
diff --git a/pypy/module/micronumpy/app_numpy.py b/pypy/module/micronumpy/app_numpy.py
--- a/pypy/module/micronumpy/app_numpy.py
+++ b/pypy/module/micronumpy/app_numpy.py
@@ -59,7 +59,7 @@
     if not hasattr(a, "max"):
         a = _numpypy.array(a)
     return a.max(axis)
-
+    
 def arange(start, stop=None, step=1, dtype=None):
     '''arange([start], stop[, step], dtype=None)
     Generate values in the half-interval [start, stop).
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
@@ -9,6 +9,7 @@
 from pypy.rpython.lltypesystem import rffi, lltype
 
 MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else ()
+MIXIN_32 = () if LONG_BIT == 64 else (int_typedef,)
 
 def new_dtype_getter(name):
     def get_dtype(space):
@@ -232,7 +233,7 @@
     __new__ = interp2app(W_UInt16Box.descr__new__.im_func),
 )
 
-W_Int32Box.typedef = TypeDef("int32", W_SignedIntegerBox.typedef,
+W_Int32Box.typedef = TypeDef("int32", (W_SignedIntegerBox.typedef,) + MIXIN_32,
     __module__ = "numpypy",
     __new__ = interp2app(W_Int32Box.descr__new__.im_func),
 )
@@ -242,24 +243,18 @@
     __new__ = interp2app(W_UInt32Box.descr__new__.im_func),
 )
 
-if LONG_BIT == 32:
-    long_name = "int32"
-elif LONG_BIT == 64:
-    long_name = "int64"
-W_LongBox.typedef = TypeDef(long_name, (W_SignedIntegerBox.typedef, int_typedef,),
-    __module__ = "numpypy",
-   __new__ = interp2app(W_LongBox.descr__new__.im_func),
-)
-
-W_ULongBox.typedef = TypeDef("u" + long_name, W_UnsignedIntegerBox.typedef,
-    __module__ = "numpypy",
-)
-
 W_Int64Box.typedef = TypeDef("int64", (W_SignedIntegerBox.typedef,) + MIXIN_64,
     __module__ = "numpypy",
     __new__ = interp2app(W_Int64Box.descr__new__.im_func),
 )
 
+if LONG_BIT == 32:
+    W_LongBox = W_Int32Box
+    W_ULongBox = W_UInt32Box
+elif LONG_BIT == 64:
+    W_LongBox = W_Int64Box
+    W_ULongBox = W_UInt64Box
+
 W_UInt64Box.typedef = TypeDef("uint64", W_UnsignedIntegerBox.typedef,
     __module__ = "numpypy",
     __new__ = interp2app(W_UInt64Box.descr__new__.im_func),
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
@@ -17,6 +17,10 @@
         if self.step != 0:
             shape.append(self.lgt)
 
+    def __repr__(self):
+        return 'Chunk(%d, %d, %d, %d)' % (self.start, self.stop, self.step,
+                                          self.lgt)
+
 class BaseTransform(object):
     pass
 
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
@@ -1273,6 +1273,42 @@
         return convert_to_array(space, w_obj2).descr_dot(space, w_arr)
     return w_arr.descr_dot(space, w_obj2)
 
+ at unwrap_spec(axis=int)
+def concatenate(space, w_args, axis=0):
+    args_w = space.listview(w_args)
+    if len(args_w) == 0:
+        raise OperationError(space.w_ValueError, space.wrap("concatenation of zero-length sequences is impossible"))
+    args_w = [convert_to_array(space, w_arg) for w_arg in args_w]
+    dtype = args_w[0].find_dtype()
+    shape = args_w[0].shape[:]
+    if len(shape) <= axis:
+        raise OperationError(space.w_ValueError,
+                             space.wrap("bad axis argument"))
+    for arr in args_w[1:]:
+        dtype = interp_ufuncs.find_binop_result_dtype(space, dtype,
+                                                      arr.find_dtype())
+        if len(arr.shape) <= axis:
+            raise OperationError(space.w_ValueError,
+                                 space.wrap("bad axis argument"))
+        for i, axis_size in enumerate(arr.shape):
+            if len(arr.shape) != len(shape) or (i != axis and axis_size != shape[i]):
+                raise OperationError(space.w_ValueError, space.wrap(
+                    "array dimensions must agree except for axis being concatenated"))
+            elif i == axis:
+                shape[i] += axis_size
+    size = 1
+    for elem in shape:
+        size *= elem
+    res = W_NDimArray(size, shape, dtype, 'C')
+    chunks = [Chunk(0, i, 1, i) for i in shape]
+    axis_start = 0
+    for arr in args_w:
+        chunks[axis] = Chunk(axis_start, axis_start + arr.shape[axis], 1,
+                             arr.shape[axis])
+        res.create_slice(chunks).setslice(space, arr)
+        axis_start += arr.shape[axis]
+    return res
+
 BaseArray.typedef = TypeDef(
     'ndarray',
     __module__ = "numpypy",
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
@@ -382,3 +382,14 @@
         skip("waiting for removal of multimethods of __index__")
         from _numpypy import int_
         assert (1, 2, 3)[int_(1)] == 2
+
+    def test_int(self):
+        import sys
+        from _numpypy import int32, int64, int_
+        assert issubclass(int_, int)
+        if sys.maxint == (1<<31) - 1:
+            assert issubclass(int32, int)
+            assert int_ is int32
+        else:
+            assert issubclass(int64, int)
+            assert int_ is int64
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
@@ -1039,6 +1039,40 @@
         assert (a.var(0) == [8, 8]).all()
         assert (a.var(1) == [.25] * 5).all()
 
+    def test_concatenate(self):
+        from numpypy import array, concatenate, dtype
+        a1 = array([0,1,2])
+        a2 = array([3,4,5])
+        a = concatenate((a1, a2))
+        assert len(a) == 6
+        assert (a == [0,1,2,3,4,5]).all()
+        assert a.dtype is dtype(int)
+        b1 = array([[1, 2], [3, 4]])
+        b2 = array([[5, 6]])
+        b = concatenate((b1, b2), axis=0)
+        assert (b == [[1, 2],[3, 4],[5, 6]]).all()
+        c = concatenate((b1, b2.T), axis=1)
+        assert (c == [[1, 2, 5],[3, 4, 6]]).all()
+        d = concatenate(([0],[1]))
+        assert (d == [0,1]).all()
+        e1 = array([[0,1],[2,3]])
+        e = concatenate(e1)
+        assert (e == [0,1,2,3]).all()
+        f1 = array([0,1])
+        f = concatenate((f1, [2], f1, [7]))
+        assert (f == [0,1,2,0,1,7]).all()
+        
+        bad_axis = raises(ValueError, concatenate, (a1,a2), axis=1)
+        assert str(bad_axis.value) == "bad axis argument"
+        
+        concat_zero = raises(ValueError, concatenate, ())
+        assert str(concat_zero.value) == \
+            "concatenation of zero-length sequences is impossible"
+        
+        dims_disagree = raises(ValueError, concatenate, (a1, b1), axis=0)
+        assert str(dims_disagree.value) == \
+            "array dimensions must agree except for axis being concatenated"
+
     def test_std(self):
         from _numpypy import array
         a = array(range(10))
@@ -1062,7 +1096,6 @@
         a = array([[1, 2], [3, 4]])
         assert (a.T.flatten() == [1, 3, 2, 4]).all()
 
-
 class AppTestMultiDim(BaseNumpyAppTest):
     def test_init(self):
         import _numpypy
diff --git a/pypy/module/thread/ll_thread.py b/pypy/module/thread/ll_thread.py
--- a/pypy/module/thread/ll_thread.py
+++ b/pypy/module/thread/ll_thread.py
@@ -4,7 +4,7 @@
 import py
 from pypy.rlib import jit, rgc
 from pypy.rlib.debug import ll_assert
-from pypy.rlib.objectmodel import we_are_translated
+from pypy.rlib.objectmodel import we_are_translated, specialize
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.tool import rffi_platform
 from pypy.tool import autopath
@@ -85,6 +85,7 @@
 def allocate_lock():
     return Lock(allocate_ll_lock())
 
+ at specialize.arg(0)
 def ll_start_new_thread(func):
     ident = c_thread_start(func)
     if ident == -1:
@@ -97,6 +98,7 @@
 def get_ident():
     return rffi.cast(lltype.Signed, c_thread_get_ident())
 
+ at specialize.arg(0)
 def start_new_thread(x, y):
     """In RPython, no argument can be passed.  You have to use global
     variables to pass information to the new thread.  That's not very
diff --git a/pypy/module/thread/test/test_ll_thread.py b/pypy/module/thread/test/test_ll_thread.py
--- a/pypy/module/thread/test/test_ll_thread.py
+++ b/pypy/module/thread/test/test_ll_thread.py
@@ -34,72 +34,34 @@
     use_threads = True
 
     def test_start_new_thread(self):
-        py.test.skip("xxx ideally, investigate why it fails randomly")
-        # xxx but in practice start_new_thread() is also tested by the
-        # next test, and it's a mess to test start_new_thread() without
-        # the proper GIL to protect the GC
         import time
 
         class State:
             pass
         state = State()
 
-        class Z:
-            def __init__(self, value):
-                self.value = value
-            def __del__(self):
-                state.freed_counter += 1
-
-        def bootstrap():
-            state.my_thread_ident = state.z.ident = get_ident()
-            assert state.my_thread_ident == get_ident()
-            assert get_ident() == state.z.ident
-            state.seen_value = state.z.value
-            state.z = None
-            # I think that we would need here a memory barrier in order
-            # to make the test pass reliably.  The issue is that the
-            # main thread may see 'state.done = 1' before seeing the
-            # effect of the other assignments done above.  For now let's
-            # emulate the write barrier by doing a system call and
-            # waiting a bit...
-            time.sleep(0.012)
-            state.done = 1
-
-        def g(i):
-            state.z = Z(i)
-            return start_new_thread(bootstrap, ())
-        g._dont_inline_ = True
+        def bootstrap1():
+            state.my_thread_ident1 = get_ident()
+        def bootstrap2():
+            state.my_thread_ident2 = get_ident()
 
         def f():
-            main_ident = get_ident()
-            assert main_ident == get_ident()
-            state.freed_counter = 0
-            for i in range(50):
-                state.done = 0
-                state.seen_value = 0
-                ident = g(i)
-                gc.collect()
-                willing_to_wait_more = 1000
-                while not state.done:
-                    willing_to_wait_more -= 1
-                    if not willing_to_wait_more:
-                        raise Exception("thread didn't start?")
-                    time.sleep(0.01)
-                assert state.my_thread_ident != main_ident
-                assert state.my_thread_ident == ident
-                assert state.seen_value == i
-            # try to force Boehm to do some freeing
-            for i in range(3):
-                gc.collect()
-            return state.freed_counter
+            state.my_thread_ident1 = get_ident()
+            state.my_thread_ident2 = get_ident()
+            start_new_thread(bootstrap1, ())
+            start_new_thread(bootstrap2, ())
+            willing_to_wait_more = 1000
+            while (state.my_thread_ident1 == get_ident() or
+                   state.my_thread_ident2 == get_ident()):
+                willing_to_wait_more -= 1
+                if not willing_to_wait_more:
+                    raise Exception("thread didn't start?")
+                time.sleep(0.01)
+            return 42
 
         fn = self.getcompiled(f, [])
-        freed_counter = fn()
-        print freed_counter
-        if self.gcpolicy == 'boehm':
-            assert freed_counter > 0
-        else:
-            assert freed_counter == 50
+        res = fn()
+        assert res == 42
 
     def test_gc_locking(self):
         import time
@@ -202,6 +164,9 @@
     def getcompiled(self, f, argtypes):
         return f
 
+    def test_start_new_thread(self):
+        py.test.skip("deadlocks occasionally -- why???")
+
 class TestUsingBoehm(AbstractThreadTests):
     gcpolicy = 'boehm'
 
diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -130,19 +130,29 @@
         if self is other:
             return 0
         else:
-            raise TypeError("Symbolics can not be compared!")
+            raise TypeError("Symbolics can not be compared! (%r, %r)"
+                            % (self, other))
 
     def __hash__(self):
-        raise TypeError("Symbolics are not hashable!")
+        raise TypeError("Symbolics are not hashable! %r" % (self,))
 
     def __nonzero__(self):
-        raise TypeError("Symbolics are not comparable")
+        raise TypeError("Symbolics are not comparable! %r" % (self,))
 
 class ComputedIntSymbolic(Symbolic):
 
     def __init__(self, compute_fn):
         self.compute_fn = compute_fn
 
+    def __repr__(self):
+        # repr(self.compute_fn) can arrive back here in an
+        # infinite recursion
+        try:
+            name = self.compute_fn.__name__
+        except (AttributeError, TypeError):
+            name = hex(id(self.compute_fn))
+        return '%s(%r)' % (self.__class__.__name__, name)
+
     def annotation(self):
         from pypy.annotation import model
         return model.SomeInteger()
@@ -157,6 +167,9 @@
         self.expr = expr
         self.default = default
 
+    def __repr__(self):
+        return '%s(%r)' % (self.__class__.__name__, self.expr)
+
     def annotation(self):
         from pypy.annotation import model
         return model.SomeInteger()
diff --git a/pypy/rpython/lltypesystem/llgroup.py b/pypy/rpython/lltypesystem/llgroup.py
--- a/pypy/rpython/lltypesystem/llgroup.py
+++ b/pypy/rpython/lltypesystem/llgroup.py
@@ -76,6 +76,10 @@
         self.index = memberindex
         self.member = grp.members[memberindex]._as_ptr()
 
+    def __repr__(self):
+        return '%s(%s, %s)' % (self.__class__.__name__,
+                               self.grpptr, self.index)
+
     def __nonzero__(self):
         return True
 
diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -27,6 +27,10 @@
         self.c_name = c_name
         self.TP = TP
 
+    def __repr__(self):
+        return '%s(%r, %s)' % (self.__class__.__name__,
+                               self.c_name, self.TP)
+
     def annotation(self):
         return lltype_to_annotation(self.TP)
 


More information about the pypy-commit mailing list