Commits

Alex Gaynor committed e716ec8

handle string dtypes

Comments (0)

Files changed (2)

pypy/module/micronumpy/interp_dtype.py

     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 == "="
 
 
         typestr = space.str_w(w_obj)
         w_base_dtype = None
+        elsize = -1
 
         if not typestr:
             raise invalid_dtype(space, w_obj)
                         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

pypy/module/micronumpy/types.py

                                  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))
 
 class NonNativePrimitive(Primitive):
     _mixin_ = True
-    
+
     def _read(self, storage, width, i, offset):
         return byteswap(Primitive._read(self, storage, width, i, offset))
 
 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:
 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
 
 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
 
 
 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):