[pypy-commit] pypy numpy-record-type-pure-python: handle string dtypes

alex_gaynor noreply at buildbot.pypy.org
Fri Feb 24 19:41:44 CET 2012


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-record-type-pure-python
Changeset: r52869:e716ec8de597
Date: 2012-02-24 13:41 -0500
http://bitbucket.org/pypy/pypy/changeset/e716ec8de597/

Log:	handle string dtypes

diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -138,6 +138,9 @@
     else:
         raise OperationError(space.w_TypeError, space.wrap("data type not understood"))
 
+def dtype_from_list(space, items_w):
+    pass
+
 def is_byteorder(ch):
     return ch == ">" or ch == "<" or ch == "|" or ch == "="
 
@@ -188,6 +191,7 @@
 
         typestr = space.str_w(w_obj)
         w_base_dtype = None
+        elsize = -1
 
         if not typestr:
             raise invalid_dtype(space, w_obj)
@@ -230,12 +234,21 @@
                         if (dtype.kind == kind and
                             dtype.itemtype.get_element_size() == elsize):
                             w_base_dtype = dtype
+                            elsize = -1
                             break
                     else:
                         raise invalid_dtype(space, w_obj)
 
         if w_base_dtype is not None:
-            if elsize is not None:
+            if elsize != -1:
+                itemtype = w_base_dtype.itemtype.array(elsize)
+                w_base_dtype = W_Dtype(
+                    itemtype, w_base_dtype.num, w_base_dtype.kind,
+                    w_base_dtype.name + str(itemtype.get_element_size() * 8),
+                    w_base_dtype.char, w_base_dtype.w_box_type,
+                    byteorder=w_base_dtype.byteorder,
+                    builtin_type=w_base_dtype.builtin_type
+                )
             if endian != "=" and endian != nonnative_byteorder_prefix:
                 endian = "="
             if (endian != "=" and w_base_dtype.byteorder != "|" and
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
@@ -128,7 +128,7 @@
                                  width, storage, i, offset, value)
         else:
             libffi.array_setitem_T(self.T, width, storage, i, offset, value)
-        
+
 
     def store(self, arr, width, i, offset, box):
         self._write(arr.storage, width, i, offset, self.unbox(box))
@@ -229,7 +229,7 @@
 
 class NonNativePrimitive(Primitive):
     _mixin_ = True
-    
+
     def _read(self, storage, width, i, offset):
         return byteswap(Primitive._read(self, storage, width, i, offset))
 
@@ -448,7 +448,7 @@
 class NonNativeInt64(BaseType, NonNativeInteger):
     T = rffi.LONGLONG
     BoxType = interp_boxes.W_Int64Box
-    format_code = "q"    
+    format_code = "q"
 
 def _uint64_coerce(self, space, w_item):
     try:
@@ -611,7 +611,7 @@
 class NonNativeFloat32(BaseType, NonNativeFloat):
     T = rffi.FLOAT
     BoxType = interp_boxes.W_Float32Box
-    format_code = "f"    
+    format_code = "f"
 
 class Float64(BaseType, Float):
     T = rffi.DOUBLE
@@ -633,13 +633,16 @@
 
 class BaseStringType(object):
     _mixin_ = True
-    
+
     def __init__(self, size=0):
         self.size = size
 
     def get_element_size(self):
         return self.size * rffi.sizeof(self.T)
 
+    def array(self, size):
+        return type(self)(size)
+
 class StringType(BaseType, BaseStringType):
     T = lltype.Char
 
@@ -656,12 +659,12 @@
 
 class RecordType(CompositeType):
     T = lltype.Char
-    
+
     def read(self, arr, width, i, offset):
         return interp_boxes.W_VoidBox(arr, i)
 
     @jit.unroll_safe
-    def coerce(self, space, dtype, w_item): 
+    def coerce(self, space, dtype, w_item):
         from pypy.module.micronumpy.interp_numarray import W_NDimArray
 
         if isinstance(w_item, interp_boxes.W_VoidBox):


More information about the pypy-commit mailing list