[pypy-commit] pypy default: Implement varargs for ndarray.reshape and add a test for a missing error case.

alex_gaynor noreply at buildbot.pypy.org
Tue Dec 6 19:53:45 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r50218:0ccb237a9de2
Date: 2011-12-06 13:53 -0500
http://bitbucket.org/pypy/pypy/changeset/0ccb237a9de2/

Log:	Implement varargs for ndarray.reshape and add a test for a missing
	error case.

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
@@ -109,9 +109,6 @@
     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:
@@ -845,7 +842,7 @@
         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)
 
@@ -857,9 +854,13 @@
     --------
     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)
+                                            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)
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
@@ -415,8 +415,9 @@
         # u is not a view, it is a copy!
         assert u[25] == 41
 
+        raises(ValueError, arange(10).reshape, (5, -1, -1))
+
     def test_reshape_varargs(self):
-        skip("unimplemented yet")
         from numpypy import arange
         z = arange(96).reshape(12, -1)
         y = z.reshape(4, 3, 8)


More information about the pypy-commit mailing list