[pypy-commit] pypy numpy-record-dtypes: work in progress

fijal noreply at buildbot.pypy.org
Sun Mar 4 04:17:33 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-record-dtypes
Changeset: r53165:b07f0c00db53
Date: 2012-03-03 19:00 -0800
http://bitbucket.org/pypy/pypy/changeset/b07f0c00db53/

Log:	work in progress

diff --git a/REVIEW.rst b/REVIEW.rst
--- a/REVIEW.rst
+++ b/REVIEW.rst
@@ -1,7 +1,6 @@
 REVIEW
 ======
 
-* Why is width == 1 in W_VoidBox.descr_{get,set}item? That doesn't seem right.
 * expose endianess on dtypes
 * RecordType.str_format should use Builder
 * IntP and UIntP aren't the right size, they should be the same size of rffi.VOIDP, not as Signed/Unsigned
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -197,9 +197,10 @@
 
 
 class W_FlexibleBox(W_GenericBox):
-    def __init__(self, arr, ofs):
+    def __init__(self, arr, ofs, dtype):
         self.arr = arr # we have to keep array alive
         self.ofs = ofs
+        self.dtype = dtype
 
     def get_dtype(self, space):
         return self.arr.dtype
@@ -212,16 +213,16 @@
     @unwrap_spec(item=str)
     def descr_getitem(self, space, item):
         try:
-            ofs, dtype = self.arr.dtype.fields[item]
+            ofs, dtype = self.dtype.fields[item]
         except KeyError:
             raise OperationError(space.w_IndexError,
                                  space.wrap("Field %s does not exist" % item))
-        return dtype.itemtype.read(self.arr, 1, self.ofs, ofs)
+        return dtype.itemtype.read(self.arr, 1, self.ofs, ofs, dtype)
 
     @unwrap_spec(item=str)
     def descr_setitem(self, space, item, w_value):
         try:
-            ofs, dtype = self.arr.dtype.fields[item]
+            ofs, dtype = self.dtype.fields[item]
         except KeyError:
             raise OperationError(space.w_IndexError,
                                  space.wrap("Field %s does not exist" % item))
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
@@ -1919,3 +1919,16 @@
         from _numpypy import array
         a = array([(1, 2), (3, 4)], dtype=[('x', int), ('y', float)])
         assert repr(a[0]) == '(1, 2.0)'
+
+    def test_nested_dtype(self):
+        from _numpypy import zeros
+        a = [('x', int), ('y', float)]
+        b = [('x', int), ('y', a)]
+        arr = zeros(3, dtype=b)
+        arr[1]['x'] = 15
+        assert arr[1]['x'] == 15
+        arr[1]['y']['y'] = 3.5
+        assert arr[1]['y']['y'] == 3.5
+        assert arr[1]['y']['x'] == 0.0
+        assert arr[1]['x'] == 15
+        
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
@@ -116,7 +116,7 @@
         else:
             return libffi.array_getitem_T(self.T, width, storage, i, offset)
 
-    def read(self, arr, width, i, offset):
+    def read(self, arr, width, i, offset, dtype=None):
         return self.box(self._read(arr.storage, width, i, offset))
 
     def read_bool(self, arr, width, i, offset):
@@ -675,8 +675,10 @@
 class RecordType(CompositeType):
     T = lltype.Char
     
-    def read(self, arr, width, i, offset):
-        return interp_boxes.W_VoidBox(arr, i)
+    def read(self, arr, width, i, offset, dtype=None):
+        if dtype is None:
+            dtype = arr.dtype
+        return interp_boxes.W_VoidBox(arr, i, dtype)
 
     @jit.unroll_safe
     def coerce(self, space, dtype, w_item): 


More information about the pypy-commit mailing list