[pypy-commit] pypy matrixmath-reshape-merge: cleanup, fix incorrect tests; ready for review

mattip noreply at buildbot.pypy.org
Sat Dec 3 19:41:18 CET 2011


Author: mattip
Branch: matrixmath-reshape-merge
Changeset: r50094:ff635955ea46
Date: 2011-12-03 20:40 +0200
http://bitbucket.org/pypy/pypy/changeset/ff635955ea46/

Log:	cleanup, fix incorrect tests; ready for review

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
@@ -110,11 +110,11 @@
         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]):
+        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:
+            if old_size == 1:
                 #Scalars can have an empty size.
                 new_size = 1
             else:
@@ -208,7 +208,7 @@
             w_dtype = interp_ufuncs.find_dtype_for_scalar(space,
                                                           w_item_or_iterable)
         dtype = space.interp_w(interp_dtype.W_Dtype,
-            space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype)
+           space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype)
         )
         return scalar_w(space, dtype, w_item_or_iterable)
     if w_order is None:
@@ -581,6 +581,7 @@
                 return False
             i = i.next(shapelen)
         return True
+
     def descr_all(self, space):
         return space.wrap(self._all())
 
@@ -596,6 +597,7 @@
                 return True
             i = i.next(shapelen)
         return False
+
     def descr_any(self, space):
         return space.wrap(self._any())
 
@@ -620,10 +622,10 @@
     def descr_get_shape(self, space):
         return space.newtuple([space.wrap(i) for i in self.shape])
 
-
     def descr_set_shape(self, space, w_iterable):
         concrete = self.get_concrete()
-        new_shape = get_shape_from_iterable(space, concrete.find_size(), w_iterable)
+        new_shape = get_shape_from_iterable(space, 
+                            concrete.find_size(), w_iterable)
         concrete.setshape(space, new_shape)
 
     def descr_get_size(self, space):
@@ -882,9 +884,11 @@
         """Return a reshaped view into the original array's data
         """
         concrete = self.get_concrete()
-        new_shape = get_shape_from_iterable(space, concrete.find_size(), w_args)
+        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, concrete.shape, concrete.strides)
+        new_strides = calc_new_strides(new_shape, 
+                                       concrete.shape, concrete.strides)
         if new_strides:
             #We can create a view, strides somehow match up.
             new_sig = signature.Signature.find_sig([
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
@@ -159,13 +159,12 @@
                 [5, 2], [4, 3, 5, 2]) == [4, 3, 5, 2]
 
     def test_calc_new_strides(self):
-	from pypy.module.micronumpy.interp_numarray import calc_new_strides
+        from pypy.module.micronumpy.interp_numarray import calc_new_strides
         assert calc_new_strides([2, 4], [4, 2], [4, 2]) == [8, 2]
         assert calc_new_strides([2, 4, 3], [8, 3], [1, 16]) == [1, 2, 16]
         assert calc_new_strides([2, 3, 4], [8, 3], [1, 16]) is None
-        assert calc_new_strides([8, 3], [2, 4, 3], [48, 6, 1]) == [6, 1]
         assert calc_new_strides([24], [2, 4, 3], [48, 6, 1]) is None
-        assert calc_new_strides([24], [2, 4, 3], [48, 6, 2]) is None
+        assert calc_new_strides([24], [2, 4, 3], [24, 6, 2]) == [2]
 
 class AppTestNumArray(BaseNumpyAppTest):
     def test_type(self):
@@ -386,10 +385,10 @@
         c = b.reshape((2, 4))
         assert (c == [[1, 3, 5, 7], [9, 11, 13, 15]]).all()
 
-        z=arange(96).reshape((12, -1))
+        z = arange(96).reshape((12, -1))
         assert z.shape == (12, 8)
-        y=z.reshape((4,3,8))
-        v=y[:,::2,:]
+        y = z.reshape((4, 3, 8))
+        v = y[:, ::2, :]
         w = y.reshape(96)
         u = v.reshape(64)
         assert y[1, 2, 1] == z[5, 1]
@@ -399,14 +398,14 @@
         assert v[1, 1, 1] == 1000
         assert w[41] == 1000
         #u is not a view, it is a copy!
-        assert u[25] == 41 
+        assert u[25] == 41
 
     def test_reshape_varargs(self):
         skip("How do I do varargs in rpython? reshape should accept a"
              " variable number of arguments")
-        z=arange(96).reshape(12, -1)
-        y=z.reshape(4,3,8)
-    
+        z = arange(96).reshape(12, -1)
+        y = z.reshape(4, 3, 8)
+
     def test_add(self):
         from numpypy import array
         a = array(range(5))


More information about the pypy-commit mailing list