Author: Romain Guillebert <romain...@gmail.com>
Branch: numpy-subarrays
Changeset: r64391:905b68f9d7c3
Date: 2013-05-21 17:25 +0200
http://bitbucket.org/pypy/pypy/changeset/905b68f9d7c3/

Log:    Fix multidimensional subarrays

diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py 
b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -357,13 +357,13 @@
         self.strides = strides
         self.backstrides = backstrides
         self.shape = shape
+        if dtype is None:
+            dtype = parent.dtype
         if isinstance(parent, SliceArray):
             parent = parent.parent # one level only
         self.parent = parent
         self.storage = parent.storage
         self.order = parent.order
-        if dtype is None:
-            dtype = parent.dtype
         self.dtype = dtype
         self.size = support.product(shape) * 
self.dtype.itemtype.get_element_size()
         self.start = start
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
@@ -2718,8 +2718,11 @@
         d = dtype([("x", "int", (2, 3))])
         a = array([([[1, 2, 3], [4, 5, 6]],)], dtype=d)
 
+        assert a[0]["x"].dtype == dtype("int64")
+        assert a[0]["x"][0].dtype == dtype("int64")
+
+        assert (a[0]["x"][0] == [1, 2, 3]).all()
         assert (a[0]["x"] == [[1, 2, 3], [4, 5, 6]]).all()
-        assert (a[0]["x"][0] == [1, 2, 3]).all()
 
         d = dtype((float, (10, 10)))
         a = zeros((3,3), dtype=d)
@@ -2729,6 +2732,18 @@
         assert (a[0, 0, 0] == 500).all()
         assert a[0, 0, 0].shape == (10,)
 
+    def test_multidim_subarray(self):
+        from numpypy import dtype, array, zeros
+
+        d = dtype([("x", "int", (2, 3))])
+        a = array([([[1, 2, 3], [4, 5, 6]],)], dtype=d)
+
+        assert a[0]["x"].dtype == dtype("int64")
+        assert a[0]["x"][0].dtype == dtype("int64")
+
+        assert (a[0]["x"][0] == [1, 2, 3]).all()
+        assert (a[0]["x"] == [[1, 2, 3], [4, 5, 6]]).all()
+
     def test_list_record(self):
         from numpypy import dtype, array
 
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1733,13 +1733,12 @@
                 itemtype.store(arr, 0, ofs, w_box)
                 ofs += itemtype.get_element_size()
         else:
-            for i in range(len(items_w)):
+            for w_item in items_w:
                 size = 1
                 for dimension in shape[1:]:
                     size *= dimension
                 size *= itemtype.get_element_size()
-                for w_item in items_w:
-                    self._coerce(space, arr, ofs, dtype, w_item, shape[1:])
+                self._coerce(space, arr, ofs, dtype, w_item, shape[1:])
                 ofs += size
 
     def coerce(self, space, dtype, w_items):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to