[pypy-commit] pypy numpy-dtype-refactor: translation fixes

alex_gaynor noreply at buildbot.pypy.org
Wed Nov 16 20:42:34 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-dtype-refactor
Changeset: r49479:f0a1bcf419fb
Date: 2011-11-16 13:43 -0500
http://bitbucket.org/pypy/pypy/changeset/f0a1bcf419fb/

Log:	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
@@ -3,6 +3,7 @@
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.typedef import TypeDef
 from pypy.objspace.std.inttype import int_typedef
+from pypy.objspace.std.typeobject import W_TypeObject
 from pypy.rlib.rarithmetic import LONG_BIT
 from pypy.tool.sourcetools import func_with_new_name
 
@@ -35,6 +36,7 @@
         for dtype in get_dtype_cache(space).builtin_dtypes:
             if w_subtype is dtype.w_box_type:
                 return dtype.coerce(space, w_value)
+        assert isinstance(w_subtype, W_TypeObject)
         raise operationerrfmt(space.w_TypeError, "cannot create '%s' instances",
             w_subtype.get_module_type_name()
         )
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
@@ -29,6 +29,14 @@
         )
     return dispatcher
 
+def raw_binary_op(func):
+    def dispatcher(self, v1, v2):
+        return func(self,
+            self.for_computation(self.unbox(v1)),
+            self.for_computation(self.unbox(v2))
+        )
+    return dispatcher
+
 class BaseType(object):
     def _unimplemented_ufunc(self, *args):
         raise NotImplementedError
@@ -100,23 +108,29 @@
     def abs(self, v):
         return abs(v)
 
+    @raw_binary_op
     def eq(self, v1, v2):
-        return self.unbox(v1) == self.unbox(v2)
+        return v1 == v2
 
+    @raw_binary_op
     def ne(self, v1, v2):
-        return self.unbox(v1) != self.unbox(v2)
+        return v1 != v2
 
+    @raw_binary_op
     def lt(self, v1, v2):
-        return self.unbox(v1) < self.unbox(v2)
+        return v1 < v2
 
+    @raw_binary_op
     def le(self, v1, v2):
-        return self.unbox(v1) <= self.unbox(v2)
+        return v1 <= v2
 
+    @raw_binary_op
     def gt(self, v1, v2):
-        return self.unbox(v1) > self.unbox(v2)
+        return v1 > v2
 
+    @raw_binary_op
     def ge(self, v1, v2):
-        return self.unbox(v1) >= self.unbox(v2)
+        return v1 >= v2
 
     def bool(self, v):
         return bool(self.for_computation(self.unbox(v)))
@@ -235,7 +249,7 @@
 
     def str_format(self, box):
         value = self.unbox(box)
-        return float2string(value, "g", rfloat.DTSF_STR_PRECISION)
+        return float2string(self.for_computation(value), "g", rfloat.DTSF_STR_PRECISION)
 
     def for_computation(self, v):
         return float(v)


More information about the pypy-commit mailing list