[pypy-commit] pypy matrixmath: split tests - work in progress

mattip noreply at buildbot.pypy.org
Sat Nov 26 19:58:19 CET 2011


Author: mattip
Branch: matrixmath
Changeset: r49829:56a9a8fc133e
Date: 2011-11-26 18:57 +0200
http://bitbucket.org/pypy/pypy/changeset/56a9a8fc133e/

Log:	split tests - work in progress

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
@@ -786,11 +786,18 @@
         new_sig = signature.Signature.find_sig([
             NDimSlice.signature, self.signature,
         ])
-        #Does the [:] actually create a copy?
-        #I should do it explicitly
-        arr = NDimSlice(self, new_sig, self.start, self.strides[:],
-                self.backstrides[:], self.shape[:])
-
+        concrete = self.get_concrete()
+        #concrete = self
+        ndims = len(self.shape)
+        strides = [0]*ndims
+        backstrides = [0]*ndims
+        shape = []*ndims
+        for i in range(len(concrete.shape)):
+            strides[i] = concrete.strides[i]
+            backstrides[i] = concrete.backstrides[i]
+            shape[i] = concrete.shape[i]
+        arr = NDimSlice(self, new_sig, self.start, strides,
+                backstrides, shape)
         arr.descr_set_shape(space, w_iterable)
         return arr
 
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
@@ -334,23 +334,29 @@
         assert a.shape == (3, 2, 2)
         a.shape = 12
         assert a.shape == (12, )
+        exc = raises(ValueError, "a.shape = 10")
+        assert str(exc.value) == "total size of new array must be unchanged"
+    def test_reshape(self):
+        from numpypy import array, zeros
+        a = array(range(12))
         exc = raises(ValueError, "b = a.reshape((3, 10))")
         assert str(exc.value) == "total size of new array must be unchanged"
-        exc = raises(ValueError, "a.shape = 10")
-        assert str(exc.value) == "total size of new array must be unchanged"
+        b = a.reshape((3, 4))
+        assert (b == [range(4), range(4, 8), range(8, 12)]).all()
+        b[:, 0] = 1000
+        assert (a == [1000, 1, 2, 3, 1000, 5, 6, 7, 1000, 9, 10, 11]).all()
         a = zeros((4, 2, 3))
+        a.shape = (12, 2)
+    def test_slice_reshape(self):
+        from numpypy import array, zeros
+        a = array(range(12))
         b = a[::2, :, :]
         b.shape = (2,6)
         exc = raises(AttributeError, "b.shape = 12")
         assert str(exc.value) == \
                            "incompatible shape for a non-contiguous array"
         b.shape = (2, 6)
-        a.shape = (12, 2)
         a = array(range(12))
-        b = a.reshape((3, 4))
-        assert (b == [range(4), range(4, 8), range(8, 12)]).all()
-        b[:, 0] = 1000
-        assert (a == [1000, 1, 2, 3, 1000, 5, 6, 7, 1000, 9, 10, 11]).all()
 
     def test_add(self):
         from numpypy import array


More information about the pypy-commit mailing list