[pypy-commit] pypy default: Test and check that we don't do stupid copies - it's not only inefficient, it's

fijal noreply at buildbot.pypy.org
Tue Nov 29 09:40:20 CET 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r49944:6fabd9a00be8
Date: 2011-11-29 10:39 +0200
http://bitbucket.org/pypy/pypy/changeset/6fabd9a00be8/

Log:	Test and check that we don't do stupid copies - it's not only
	inefficient, it's also wrong

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
@@ -726,13 +726,7 @@
             item = concrete._index_of_single_item(space, w_idx)
             concrete.setitem_w(space, item, w_value)
             return
-        if isinstance(w_value, BaseArray):
-            # for now we just copy if setting part of an array from part of
-            # itself. can be improved.
-            if (concrete.get_root_storage() ==
-                w_value.get_concrete().get_root_storage()):
-                w_value = w_value.descr_copy(space)
-        else:
+        if not isinstance(w_value, BaseArray):
             w_value = convert_to_array(space, w_value)
         chunks = self._prepare_slice_args(space, w_idx)
         view = self.create_slice(space, chunks)
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
@@ -750,6 +750,12 @@
         assert bool(array([1]))
         assert not bool(array([0]))
 
+    def test_slice_assignment(self):
+        from numpypy import arange
+        a = arange(5)
+        a[::-1] = a
+        assert (a == [0, 1, 2, 1, 0]).all()
+
 
 class AppTestMultiDim(BaseNumpyAppTest):
     def test_init(self):


More information about the pypy-commit mailing list