[pypy-commit] pypy numpy-subarrays: Start to make VoidType subarray friendly

rguillebert noreply at buildbot.pypy.org
Mon May 13 19:51:59 CEST 2013


Author: Romain Guillebert <romain.py at gmail.com>
Branch: numpy-subarrays
Changeset: r64040:3acd856274de
Date: 2013-05-13 19:51 +0200
http://bitbucket.org/pypy/pypy/changeset/3acd856274de/

Log:	Start to make VoidType subarray friendly

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
@@ -1700,6 +1700,24 @@
 class VoidType(BaseType, BaseStringType):
     T = lltype.Char
 
+    def coerce(self, space, dtype, w_items):
+        items_w = space.fixedview(w_items)
+        arr = VoidBoxStorage(self.size, dtype)
+        ofs = 0
+        for i in range(len(items_w)):
+            subdtype = dtype.subdtype
+            itemtype = subdtype.itemtype
+            w_box = itemtype.coerce(space, dtype.subdtype, items_w[i])
+            itemtype.store(arr, 0, ofs, w_box)
+            ofs += itemtype.get_element_size()
+        return interp_boxes.W_VoidBox(arr, 0, dtype)
+
+    @jit.unroll_safe
+    def store(self, arr, i, ofs, box):
+        assert isinstance(box, interp_boxes.W_VoidBox)
+        for k in range(self.get_element_size()):
+            arr.storage[k + ofs] = box.arr.storage[k + box.ofs]
+
 NonNativeVoidType = VoidType
 NonNativeStringType = StringType
 


More information about the pypy-commit mailing list