[pypy-commit] pypy default: numpy nightly testing asserted, I could not reproduce. Raise an exception instead

mattip noreply at buildbot.pypy.org
Thu Feb 5 23:37:39 CET 2015


Author: mattip <matti.picus at gmail.com>
Branch: 
Changeset: r75730:a9264f529424
Date: 2015-02-06 00:38 +0200
http://bitbucket.org/pypy/pypy/changeset/a9264f529424/

Log:	numpy nightly testing asserted, I could not reproduce. Raise an
	exception instead

diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -77,12 +77,15 @@
             else:
                 new_strides = calc_new_strides(new_shape, self.get_shape(),
                                                self.get_strides(), self.order)
+                if new_strides is None or len(new_strides) != len(new_shape):
+                    return None
         if new_strides is not None:
             # We can create a view, strides somehow match up.
             new_backstrides = calc_backstrides(new_strides, new_shape)
             assert isinstance(orig_array, W_NDimArray) or orig_array is None
             return SliceArray(self.start, new_strides, new_backstrides,
                               new_shape, self, orig_array)
+        return None
 
     def get_view(self, space, orig_array, dtype, new_shape):
         strides, backstrides = calc_strides(new_shape, dtype,
@@ -452,7 +455,7 @@
         new_strides = calc_new_strides(new_shape, self.get_shape(),
                                        self.get_strides(),
                                        self.order)
-        if new_strides is None:
+        if new_strides is None or len(new_strides) != len(new_shape):
             raise oefmt(space.w_AttributeError,
                 "incompatible shape for a non-contiguous array")
         new_backstrides = [0] * len(new_shape)
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
@@ -334,8 +334,12 @@
         # Create copy with contiguous data
         arr = self.descr_copy(space)
         if arr.get_size() > 0:
-            arr.implementation = arr.implementation.reshape(self, new_shape)
-            assert arr.implementation
+            new_implementation = arr.implementation.reshape(self, new_shape)
+            if new_implementation is None:
+                raise oefmt(space.w_ValueError,
+                            'could not reshape array of size %d to shape %s',
+                            arr.get_size(), str(new_shape))
+            arr.implementation = new_implementation
         else:
             arr.implementation.shape = new_shape
         return arr
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
@@ -427,7 +427,6 @@
                 if oldI >= -len(old_shape):
                     cur_step = steps[oldI]
                     n_old_elems_to_use *= old_shape[oldI]
-    assert len(new_strides) == len(new_shape)
     return new_strides[:]
 
 @jit.unroll_safe


More information about the pypy-commit mailing list