[pypy-commit] pypy numpy-record-dtypes: various translation fixes

fijal noreply at buildbot.pypy.org
Mon Feb 20 23:30:11 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-record-dtypes
Changeset: r52690:090669b997a9
Date: 2012-02-20 11:21 +0100
http://bitbucket.org/pypy/pypy/changeset/090669b997a9/

Log:	various translation fixes

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
@@ -14,13 +14,14 @@
 MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else ()
 
 def new_dtype_getter(name):
-    def get_dtype(space):
+    def get_dtype(self, space):
         from pypy.module.micronumpy.interp_dtype import get_dtype_cache
         return getattr(get_dtype_cache(space), "w_%sdtype" % name)
     def new(space, w_subtype, w_value):
-        dtype = get_dtype(space)
+        from pypy.module.micronumpy.interp_dtype import get_dtype_cache
+        dtype = getattr(get_dtype_cache(space), "w_%sdtype" % name)
         return dtype.itemtype.coerce_subtype(space, w_subtype, w_value)
-    return func_with_new_name(new, name + "_box_new"), staticmethod(get_dtype)
+    return func_with_new_name(new, name + "_box_new"), get_dtype
 
 class PrimitiveBox(object):
     _mixin_ = True
@@ -47,12 +48,12 @@
         return space.wrap(self.get_dtype(space).itemtype.str_format(self))
 
     def descr_int(self, space):
-        box = self.convert_to(W_LongBox.get_dtype(space))
+        box = self.convert_to(W_LongBox.get_dtype(self, space))
         assert isinstance(box, W_LongBox)
         return space.wrap(box.value)
 
     def descr_float(self, space):
-        box = self.convert_to(W_Float64Box.get_dtype(space))
+        box = self.convert_to(W_Float64Box.get_dtype(self, space))
         assert isinstance(box, W_Float64Box)
         return space.wrap(box.value)
 
@@ -342,11 +343,11 @@
     __module__ = "numpypy",
 )
 
-W_StringBox.typedef = TypeDef("string_", (str_typedef, W_CharacterBox.typedef),
+W_StringBox.typedef = TypeDef("string_", (W_CharacterBox.typedef, str_typedef),
     __module__ = "numpypy",
 )
 
-W_UnicodeBox.typedef = TypeDef("unicode_", (unicode_typedef, W_CharacterBox.typedef),
+W_UnicodeBox.typedef = TypeDef("unicode_", (W_CharacterBox.typedef, unicode_typedef),
     __module__ = "numpypy",
 )
                                           
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
@@ -134,6 +134,7 @@
         fldname = space.str_w(w_fldname)
         if fldname in fields:
             raise OperationError(space.w_ValueError, space.wrap("two fields with the same name"))
+        assert isinstance(subdtype, W_Dtype)
         fields[fldname] = (offset, subdtype)
         ofs_and_items.append((offset, subdtype.itemtype))
         offset += subdtype.itemtype.get_element_size()
diff --git a/pypy/module/micronumpy/interp_support.py b/pypy/module/micronumpy/interp_support.py
--- a/pypy/module/micronumpy/interp_support.py
+++ b/pypy/module/micronumpy/interp_support.py
@@ -63,6 +63,7 @@
     from pypy.module.micronumpy.interp_numarray import W_NDimArray
     
     itemsize = dtype.itemtype.get_element_size()
+    assert itemsize >= 0
     if count == -1:
         count = length / itemsize
     if length % itemsize != 0:
@@ -76,7 +77,9 @@
     a = W_NDimArray([count], dtype=dtype)
     ai = a.create_iter()
     for i in range(count):
-        val = dtype.itemtype.runpack_str(s[i*itemsize:i*itemsize + itemsize])
+        start = i*itemsize
+        assert start >= 0
+        val = dtype.itemtype.runpack_str(s[start:start + itemsize])
         a.dtype.setitem(a, ai.offset, val)
         ai = ai.next(1)
         
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
@@ -649,10 +649,11 @@
         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):
             return w_item
-        from pypy.module.micronumpy.interp_numarray import W_NDimArray
         # we treat every sequence as sequence, no special support
         # for arrays
         if not space.issequence_w(w_item):
@@ -675,11 +676,13 @@
 
     @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 + i] = box.arr.storage[k + box.ofs]
 
     @jit.unroll_safe
     def str_format(self, box):
+        assert isinstance(box, interp_boxes.W_VoidBox)
         pieces = ["("]
         first = True
         for ofs, tp in self.offsets_and_fields:


More information about the pypy-commit mailing list