Commits

Maciej Fijalkowski committed 3c80e27

make record dtypes work

Comments (0)

Files changed (4)

pypy/module/micronumpy/interp_boxes.py

         except KeyError:
             raise OperationError(space.w_IndexError,
                                  space.wrap("Field %s does not exist" % item))
-        self.arr.dtype.itemtype.get_element_size()
-        return dtype.itemtype.read(self.arr,
-                                   dtype.itemtype.get_element_size(), self.i,
-                                   ofs)
+        width = self.arr.dtype.itemtype.get_element_size()
+        return dtype.itemtype.read(self.arr, width, self.i, ofs)
 
     @unwrap_spec(item=str)
     def descr_setitem(self, space, item, w_value):
         except KeyError:
             raise OperationError(space.w_IndexError,
                                  space.wrap("Field %s does not exist" % item))
-        dtype.itemtype.store(self.arr,
-                             dtype.itemtype.get_element_size(), 0, ofs,
+        width = self.arr.dtype.itemtype.get_element_size()
+        dtype.itemtype.store(self.arr, width, self.i, ofs,
                              dtype.coerce(space, w_value))
 
 class W_CharacterBox(W_FlexibleBox):

pypy/module/micronumpy/interp_dtype.py

     def is_bool_type(self):
         return self.kind == BOOLLTR
 
+    def __repr__(self):
+        if self.fields is not None:
+            return '<DType %r>' % self.fields
+        return '<DType %r>' % self.itemtype
+
 def dtype_from_list(space, w_lst):
     lst_w = space.listview(w_lst)
     fields = {}

pypy/module/micronumpy/test/test_numarray.py

         assert a[0]['x'] == 13
         a[1] = (1, 2)
         assert a[1]['y'] == 2
+        b = zeros(2, dtype=[('x', int), ('y', float)])
+        b[1] = a[1]
+        assert a[1]['y'] == 2
+

pypy/module/micronumpy/types.py

                              zero=True, flavor="raw",
                              track_allocation=False, add_memory_pressure=True)
 
+    def __repr__(self):
+        return self.__class__.__name__
+
 class Primitive(object):
     _mixin_ = True
 
 
     @jit.unroll_safe
     def coerce(self, space, dtype, w_item):
+        if isinstance(w_item, interp_boxes.W_VoidBox):
+            return w_item
         from pypy.module.micronumpy.interp_numarray import W_NDimArray
         # we treat every sequence as sequence, no special support
         # for arrays
             w_item = items_w[i]
             w_box = itemtype.coerce(space, subdtype, w_item)
             width = itemtype.get_element_size()
-            import pdb
-            pdb.set_trace()
             itemtype.store(arr, width, 0, ofs, w_box)
         return interp_boxes.W_VoidBox(arr, 0)
 
     @jit.unroll_safe
     def store(self, arr, width, i, ofs, box):
         for k in range(width):
-            arr[k + i] = box.arr.storage[k + box.i]
+            arr[k + i * width] = box.arr.storage[k + box.i * width]
 
 for tp in [Int32, Int64]:
     if tp.T == lltype.Signed: