[pypy-commit] pypy win64-stage1: merge default

ctismer noreply at buildbot.pypy.org
Tue Dec 6 22:58:29 CET 2011


Author: Christian Tismer <tismer at stackless.com>
Branch: win64-stage1
Changeset: r50228:2e5389e1972f
Date: 2011-12-06 22:34 +0100
http://bitbucket.org/pypy/pypy/changeset/2e5389e1972f/

Log:	merge default

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
@@ -37,10 +37,11 @@
         i += step
     return arr
 
+
 def reshape(a, shape):
     '''reshape(a, newshape)
     Gives a new shape to an array without changing its data.
-    
+
     Parameters
     ----------
     a : array_like
@@ -50,21 +51,21 @@
         an integer, then the result will be a 1-D array of that length.
         One shape dimension can be -1. In this case, the value is inferred
         from the length of the array and remaining dimensions.
-    
+
     Returns
     -------
     reshaped_array : ndarray
         This will be a new view object if possible; otherwise, it will
         be a copy.
-    
-    
+
+
     See Also
     --------
     ndarray.reshape : Equivalent method.
-    
+
     Notes
     -----
-    
+
     It is not always possible to change the shape of an array without
     copying the data. If you want an error to be raise if the data is copied,
     you should assign the new shape to the shape attribute of the array
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
@@ -105,17 +105,14 @@
         new_size = space.int_w(w_iterable)
         if new_size < 0:
             new_size = old_size
-        new_shape = [new_size, ]
+        new_shape = [new_size]
     else:
         neg_dim = -1
         batch = space.listview(w_iterable)
-        #Allow for shape = (1,2,3) or shape = ((1,2,3))
-        if len(batch) > 1 and space.issequence_w(batch[0]):
-            batch = space.listview(batch[0])
         new_size = 1
         if len(batch) < 1:
             if old_size == 1:
-                #Scalars can have an empty size.
+                # Scalars can have an empty size.
                 new_size = 1
             else:
                 new_size = 0
@@ -140,16 +137,16 @@
                 space.wrap("total size of new array must be unchanged"))
     return new_shape
 
-#Recalculating strides. Find the steps that the iteration does for each
-#dimension, given the stride and shape. Then try to create a new stride that
-#fits the new shape, using those steps. If there is a shape/step mismatch
-#(meaning that the realignment of elements crosses from one step into another)
-#return None so that the caller can raise an exception.
+# Recalculating strides. Find the steps that the iteration does for each
+# dimension, given the stride and shape. Then try to create a new stride that
+# fits the new shape, using those steps. If there is a shape/step mismatch
+# (meaning that the realignment of elements crosses from one step into another)
+# return None so that the caller can raise an exception.
 def calc_new_strides(new_shape, old_shape, old_strides):
-    #Return the proper strides for new_shape, or None
-    # if the mapping crosses stepping boundaries
+    # Return the proper strides for new_shape, or None if the mapping crosses
+    # stepping boundaries
 
-    #Assumes that prod(old_shape) ==prod(new_shape), len(old_shape) > 1 and
+    # Assumes that prod(old_shape) == prod(new_shape), len(old_shape) > 1, and
     # len(new_shape) > 0
     steps = []
     last_step = 1
@@ -589,7 +586,7 @@
 
     def descr_set_shape(self, space, w_iterable):
         concrete = self.get_concrete()
-        new_shape = get_shape_from_iterable(space, 
+        new_shape = get_shape_from_iterable(space,
                             concrete.find_size(), w_iterable)
         concrete.setshape(space, new_shape)
 
@@ -717,11 +714,6 @@
     def _index_of_single_item(self, space, w_idx):
         if space.isinstance_w(w_idx, space.w_int):
             idx = space.int_w(w_idx)
-            if not self.shape:
-                if idx != 0:
-                    raise OperationError(space.w_IndexError,
-                                         space.wrap("index out of range"))
-                return 0
             if idx < 0:
                 idx = self.shape[0] + idx
             if idx < 0 or idx >= self.shape[0]:
@@ -845,28 +837,33 @@
         return W_NDimSlice(self, new_sig, start, strides[:], backstrides[:],
                            shape[:])
 
-    def descr_reshape(self, space, w_args):
+    def descr_reshape(self, space, args_w):
         """reshape(...)
     a.reshape(shape)
-    
+
     Returns an array containing the same data with a new shape.
-    
-    Refer to `%s.reshape` for full documentation.
-    
+
+    Refer to `numpypy.reshape` for full documentation.
+
     See Also
     --------
-    numpy.reshape : equivalent function
-""" % 'numpypy'
+    numpypy.reshape : equivalent function
+"""
+        if len(args_w) == 1:
+            w_shape = args_w[0]
+        else:
+            w_shape = space.newlist(args_w)
         concrete = self.get_concrete()
-        new_shape = get_shape_from_iterable(space, 
-                                            concrete.find_size(), w_args)
-        #Since we got to here, prod(new_shape) == self.size
-        new_strides = calc_new_strides(new_shape, 
+        new_shape = get_shape_from_iterable(space,
+                                            concrete.find_size(), w_shape)
+        # Since we got to here, prod(new_shape) == self.size
+        new_strides = calc_new_strides(new_shape,
                                        concrete.shape, concrete.strides)
         if new_strides:
-            #We can create a view, strides somehow match up.
+            # We can create a view, strides somehow match up.
             new_sig = signature.Signature.find_sig([
-                W_NDimSlice.signature, self.signature, ])
+                W_NDimSlice.signature, self.signature
+            ])
             ndims = len(new_shape)
             new_backstrides = [0] * ndims
             for nd in range(ndims):
@@ -874,7 +871,7 @@
             arr = W_NDimSlice(self, new_sig, self.start, new_strides,
                               new_backstrides, new_shape)
         else:
-            #Create copy with contiguous data
+            # Create copy with contiguous data
             arr = concrete.copy()
             arr.setshape(space, new_shape)
         return arr
@@ -975,7 +972,7 @@
         return 'Scalar'
 
     def setshape(self, space, new_shape):
-        # In order to get here, we already checked that prod(new_shape)==1,
+        # In order to get here, we already checked that prod(new_shape) == 1,
         # so in order to have a consistent API, let it go through.
         pass
 
@@ -1175,8 +1172,8 @@
         if len(self.shape) < 1:
             return
         elif len(self.shape) < 2:
-            #TODO: this code could be refactored into calc_strides
-            #but then calc_strides would have to accept a stepping factor
+            # TODO: this code could be refactored into calc_strides
+            # but then calc_strides would have to accept a stepping factor
             strides = []
             backstrides = []
             s = self.strides[0]
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
@@ -330,8 +330,8 @@
     def test_scalar(self):
         from numpypy import array, dtype
         a = array(3)
-        #assert a[0] == 3
         raises(IndexError, "a[0]")
+        raises(IndexError, "a[0] = 5")
         assert a.size == 1
         assert a.shape == ()
         assert a.dtype is dtype(int)
@@ -408,18 +408,23 @@
         u = v.reshape(64)
         assert y[1, 2, 1] == z[5, 1]
         y[1, 2, 1] = 1000
-        #z, y, w, v are views of eachother
+        # z, y, w, v are views of eachother
         assert z[5, 1] == 1000
         assert v[1, 1, 1] == 1000
         assert w[41] == 1000
-        #u is not a view, it is a copy!
+        # u is not a view, it is a copy!
         assert u[25] == 41
 
+        a = zeros((5, 2))
+        assert a.reshape(-1).shape == (10,)
+
+        raises(ValueError, arange(10).reshape, (5, -1, -1))
+
     def test_reshape_varargs(self):
-        skip("How do I do varargs in rpython? reshape should accept a"
-             " variable number of arguments")
+        from numpypy import arange
         z = arange(96).reshape(12, -1)
         y = z.reshape(4, 3, 8)
+        assert y.shape == (4, 3, 8)
 
     def test_add(self):
         from numpypy import array
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,8 +185,7 @@
         # sure it was optimized correctly.
         # XXX the comment above is wrong now.  We need preferrably a way to
         # count the two loops separately
-        py.test.skip("counting exact number of classes is nonsense")
-        self.check_resops({'setarrayitem_raw': 4, 'guard_nonnull': 1, 'getfield_gc': 35,
+        self.check_resops({'setinteriorfield_raw': 4, 'guard_nonnull': 1, 'getfield_gc': 41,
                            'guard_class': 22, 'int_add': 8, 'float_mul': 2,
                            'guard_isnull': 2, 'jump': 4, 'int_ge': 4,
                            'getinteriorfield_raw': 4, 'float_add': 2, 'guard_false': 4,


More information about the pypy-commit mailing list