Author: Maciej Fijalkowski <[email protected]>
Branch: numpy-back-to-applevel
Changeset: r51866:938d4dcbaa69
Date: 2012-01-27 21:23 +0200
http://bitbucket.org/pypy/pypy/changeset/938d4dcbaa69/

Log:    make flatten use ravel, remove previous version, improve tests

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
@@ -272,8 +272,14 @@
     def descr_copy(self, space):
         return self.copy(space)
 
-    def descr_flatten(self, space):
-        return self.flatten(space)
+    def descr_flatten(self, space, w_order=None):
+        if isinstance(self, Scalar):
+            return self.copy(space)
+        concr = self.get_concrete()
+        w_res = concr.descr_ravel(space, w_order)
+        if w_res.storage == concr.storage:
+            return w_res.copy(space)
+        return w_res
 
     def copy(self, space):
         return self.get_concrete().copy(space)
@@ -282,9 +288,6 @@
         shape = self.shape
         return W_NDimArray(support.product(shape), shape[:], dtype, 'C')
 
-    def flatten(self, space):
-        return self.get_concrete().flatten(space)
-
     def descr_len(self, space):
         if len(self.shape):
             return space.wrap(self.shape[0])
@@ -681,11 +684,6 @@
     def copy(self, space):
         return Scalar(self.dtype, self.value)
 
-    def flatten(self, space):
-        array = W_NDimArray(self.size, [self.size], self.dtype)
-        array.setitem(0, self.value)
-        return array
-
     def fill(self, space, w_value):
         self.value = self.dtype.coerce(space, w_value)
 
@@ -981,15 +979,6 @@
         array.setslice(space, self)
         return array
 
-    def flatten(self, space):
-        array = W_NDimArray(self.size, [self.size], self.dtype, self.order)
-        if self.supports_fast_slicing():
-            array._fast_setslice(space, self)
-        else:
-            arr = SliceArray(array.shape, array.dtype, array, self, 
no_broadcast=True)
-            array._sliceloop(arr)
-        return array
-
     def fill(self, space, w_value):
         self.setslice(space, scalar_w(space, self.dtype, w_value))
 
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
@@ -1104,6 +1104,12 @@
     def test_flatten(self):
         from _numpypy import array
 
+        a = array([[1, 2], [3, 4]])
+        b = a.flatten()
+        c = a.ravel()
+        a[0, 0] = 15
+        assert b[0] == 1
+        assert c[0] == 15
         a = array([[1, 2, 3], [4, 5, 6]])
         assert (a.flatten() == [1, 2, 3, 4, 5, 6]).all()
         a = array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to