[pypy-commit] pypy default: merge newest changes to default

mattip noreply at buildbot.pypy.org
Sat May 16 22:18:22 CEST 2015


Author: mattip <matti.picus at gmail.com>
Branch: 
Changeset: r77351:9a19db5f50ef
Date: 2015-05-16 23:18 +0300
http://bitbucket.org/pypy/pypy/changeset/9a19db5f50ef/

Log:	merge newest changes to default

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
@@ -68,6 +68,7 @@
     w_complex = W_TypeObject("complex")
     w_dict = W_TypeObject("dict")
     w_object = W_TypeObject("object")
+    w_buffer = W_TypeObject("buffer")
 
     def __init__(self):
         """NOT_RPYTHON"""
diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -568,6 +568,8 @@
         # testing, handle manually
         if space.eq_w(w_spec, space.wrap('u4,u4,u4')):
             w_lst = space.newlist([space.wrap('u4')]*3)
+        if space.eq_w(w_spec, space.wrap('u4,u4,u4')):
+            w_lst = space.newlist([space.wrap('u4')]*3)
         else:
             raise oefmt(space.w_RuntimeError,
                     "cannot parse w_spec")
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
@@ -53,6 +53,11 @@
     def descr_set_shape(self, space, w_new_shape):
         shape = get_shape_from_iterable(space, self.get_size(), w_new_shape)
         self.implementation = self.implementation.set_shape(space, self, shape)
+        w_cls = space.type(self)
+        if not space.is_w(w_cls, space.gettypefor(W_NDimArray)):
+            # numpy madness - allow __array_finalize__(self, obj)
+            # to run, in MaskedArray this modifies obj._mask
+            wrap_impl(space, w_cls, self, self.implementation)
 
     def descr_get_strides(self, space):
         strides = self.implementation.get_strides()
@@ -883,6 +888,7 @@
         if dtype.is_object() != impl.dtype.is_object():
             raise oefmt(space.w_ValueError, 'expect trouble in ndarray.view,'
                 ' one of target dtype or dtype is object dtype')
+        w_type = w_type or space.type(self)
         v = impl.get_view(space, base, dtype, new_shape, strides, backstrides)
         w_ret = wrap_impl(space, w_type, self, v)
         return w_ret
diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -185,8 +185,14 @@
 
 
 def _find_shape_and_elems(space, w_iterable, is_rec_type):
+    from pypy.objspace.std.bufferobject import W_Buffer
     shape = [space.len_w(w_iterable)]
-    batch = space.listview(w_iterable)
+    if space.isinstance_w(w_iterable, space.w_buffer):
+        batch = [space.wrap(0)] * shape[0]
+        for i in range(shape[0]):
+            batch[i] = space.ord(space.getitem(w_iterable, space.wrap(i)))
+    else:
+        batch = space.listview(w_iterable)
     while True:
         if not batch:
             return shape[:], []
diff --git a/pypy/module/micronumpy/support.py b/pypy/module/micronumpy/support.py
--- a/pypy/module/micronumpy/support.py
+++ b/pypy/module/micronumpy/support.py
@@ -7,8 +7,9 @@
 def issequence_w(space, w_obj):
     from pypy.module.micronumpy.base import W_NDimArray
     return (space.isinstance_w(w_obj, space.w_tuple) or
-            space.isinstance_w(w_obj, space.w_list) or
-            isinstance(w_obj, W_NDimArray))
+           space.isinstance_w(w_obj, space.w_list) or
+           space.isinstance_w(w_obj, space.w_buffer) or
+           isinstance(w_obj, W_NDimArray))
 
 
 def index_w(space, w_obj):
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
@@ -3958,6 +3958,11 @@
         assert np.greater(a, a) is NotImplemented
         assert np.less_equal(a, a) is NotImplemented
 
+    def test_create_from_memory(self):
+        import numpy as np
+        dat = np.array(__builtins__.buffer('1.0'), dtype=np.float64)
+        assert (dat == [49.0, 46.0, 48.0]).all()
+
 
 class AppTestPyPy(BaseNumpyAppTest):
     def setup_class(cls):
diff --git a/pypy/module/micronumpy/test/test_subtype.py b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -82,6 +82,7 @@
         assert isinstance(b, matrix)
         assert b.__array_priority__ == 0.0
         assert (b == a).all()
+        assert isinstance(b.view(), matrix) 
         a = array(5)[()]
         for s in [matrix, ndarray]:
             b = a.view(s)
@@ -125,7 +126,7 @@
         import numpy as np
         class InfoArray(np.ndarray):
             def __new__(subtype, shape, dtype=float, buffer=None, offset=0,
-                          strides=None, order='C', info=None):
+                          strides=None, order='C', info=1):
                 obj = np.ndarray.__new__(subtype, shape, dtype, buffer,
                          offset, strides, order)
                 obj.info = info
@@ -133,25 +134,31 @@
 
             def __array_finalize__(self, obj):
                 if obj is None:
-                    print 'finalize with None'
                     return
                 # printing the object itself will crash the test
-                print 'finalize with something',type(obj)
-                self.info = getattr(obj, 'info', None)
+                self.info = 1 + getattr(obj, 'info', 0)
+                if hasattr(obj, 'info'):
+                    obj.info += 100
+
         obj = InfoArray(shape=(3,))
         assert isinstance(obj, InfoArray)
-        assert obj.info is None
-        obj = InfoArray(shape=(3,), info='information')
-        assert obj.info == 'information'
+        assert obj.info == 1
+        obj = InfoArray(shape=(3,), info=10)
+        assert obj.info == 10
         v = obj[1:]
         assert isinstance(v, InfoArray)
         assert v.base is obj
-        assert v.info == 'information'
+        assert v.info == 11
         arr = np.arange(10)
         cast_arr = arr.view(InfoArray)
         assert isinstance(cast_arr, InfoArray)
         assert cast_arr.base is arr
-        assert cast_arr.info is None
+        assert cast_arr.info == 1
+        # Test that setshape calls __array_finalize__
+        cast_arr.shape = (5,2)
+        z = cast_arr.info
+        assert z == 101
+
 
     def test_sub_where(self):
         from numpy import where, ones, zeros, array


More information about the pypy-commit mailing list