[pypy-commit] pypy numpy-dtype-refactor: more updates to code and tests

alex_gaynor noreply at buildbot.pypy.org
Wed Nov 9 05:26:25 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-dtype-refactor
Changeset: r48984:b055942a4830
Date: 2011-11-08 23:26 -0500
http://bitbucket.org/pypy/pypy/changeset/b055942a4830/

Log:	more updates to code and tests

diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -4,7 +4,7 @@
 """
 
 from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root
-from pypy.module.micronumpy.interp_boxes import W_GenericBox
+from pypy.module.micronumpy import interp_boxes
 from pypy.module.micronumpy.interp_dtype import get_dtype_cache
 from pypy.module.micronumpy.interp_numarray import (Scalar, BaseArray,
      descr_new_array, scalar_w, SingleDimArray)
@@ -70,8 +70,10 @@
         return obj.items
 
     def float(self, w_obj):
-        assert isinstance(w_obj, FloatObject)
-        return w_obj
+        if isinstance(w_obj, FloatObject):
+            return w_obj
+        assert isinstance(w_obj, interp_boxes.W_FloatingBox)
+        return FloatObject(w_obj.value)
 
     def float_w(self, w_obj):
         assert isinstance(w_obj, FloatObject)
@@ -172,8 +174,8 @@
 
     def execute(self, interp):
         arr = interp.variables[self.name]
-        w_index = self.index.execute(interp).eval(0).wrap(interp.space)
-        w_val = self.expr.execute(interp).eval(0).wrap(interp.space)
+        w_index = self.index.execute(interp).eval(0)
+        w_val = self.expr.execute(interp).eval(0)
         arr.descr_setitem(interp.space, w_index, w_val)
 
     def __repr__(self):
@@ -210,15 +212,15 @@
             w_res = w_lhs.descr_sub(interp.space, w_rhs)
         elif self.name == '->':
             if isinstance(w_rhs, Scalar):
-                index = int(interp.space.float_w(
-                    w_rhs.value))
-                dtype = interp.space.fromcache(W_Float64Dtype)
+                index = int(interp.space.float_w(interp.space.float(w_rhs.value)))
+                dtype = get_dtype_cache(interp.space).w_float64dtype
                 return Scalar(dtype, w_lhs.get_concrete().eval(index))
             else:
                 raise NotImplementedError
         else:
             raise NotImplementedError
-        if not isinstance(w_res, BaseArray) and not isinstance(w_res, W_GenericBox):
+        if (not isinstance(w_res, BaseArray) and
+            not isinstance(w_res, interp_boxes.W_GenericBox)):
             dtype = interp.space.fromcache(W_Float64Dtype)
             w_res = scalar_w(interp.space, dtype, w_res)
         return w_res
@@ -246,8 +248,9 @@
 
     def execute(self, interp):
         w_list = interp.space.newlist(
-            [interp.space.wrap(float(i)) for i in range(self.v)])
-        dtype = interp.space.fromcache(W_Float64Dtype)
+            [interp.space.wrap(float(i)) for i in range(self.v)]
+        )
+        dtype = get_dtype_cache(interp.space).w_float64dtype
         return descr_new_array(interp.space, None, w_list, w_dtype=dtype)
 
     def __repr__(self):
@@ -331,6 +334,8 @@
                 dtype = interp.space.fromcache(W_Float64Dtype)
             elif isinstance(w_res, BoolObject):
                 dtype = interp.space.fromcache(W_BoolDtype)
+            elif isinstance(w_res, interp_boxes.W_GenericBox):
+                dtype = w_res.descr_get_dtype(interp.space)
             else:
                 dtype = None
             return scalar_w(interp.space, dtype, w_res)
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -309,7 +309,7 @@
         return scalar_w(space, dtype, w_obj)
 
 def scalar_w(space, dtype, w_obj):
-    return Scalar(dtype, dtype.unwrap(space, w_obj))
+    return Scalar(dtype, dtype.coerce(space, w_obj))
 
 class Scalar(BaseArray):
     """
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -74,7 +74,7 @@
         new_sig = signature.Signature.find_sig([
             self.reduce_signature, obj.signature
         ])
-        return self.reduce(new_sig, start, value, obj, dtype, size).wrap(space)
+        return self.reduce(new_sig, start, value, obj, dtype, size)
 
     def reduce(self, signature, start, value, obj, dtype, size):
         i = start
@@ -235,7 +235,7 @@
         if dt.kind == interp_dtype.BOOLLTR or dt.kind == interp_dtype.SIGNEDLTR:
             return space.fromcache(interp_dtype.W_Int64Dtype)
         elif dt.kind == interp_dtype.FLOATINGLTR:
-            return space.fromcache(interp_dtype.W_Float64Dtype)
+            return interp_dtype.get_dtype_cache(space).w_float64dtype
         elif dt.kind == interp_dtype.UNSIGNEDLTR:
             return space.fromcache(interp_dtype.W_UInt64Dtype)
         else:
diff --git a/pypy/module/micronumpy/test/test_compile.py b/pypy/module/micronumpy/test/test_compile.py
--- a/pypy/module/micronumpy/test/test_compile.py
+++ b/pypy/module/micronumpy/test/test_compile.py
@@ -5,7 +5,7 @@
 class TestCompiler(object):
     def compile(self, code):
         return numpy_compile(code)
-    
+
     def test_vars(self):
         code = """
         a = 2
@@ -25,7 +25,7 @@
         st = interp.code.statements[0]
         assert st.expr.items == [FloatConstant(1), FloatConstant(2),
                                  FloatConstant(3)]
-    
+
     def test_array_literal2(self):
         code = "a = [[1],[2],[3]]"
         interp = self.compile(code)
@@ -114,15 +114,15 @@
         a + b -> 3
         """
         interp = self.run(code)
-        assert interp.results[0].value.val == 3 + 6
-        
+        assert interp.results[0].value.value == 3 + 6
+
     def test_range_getitem(self):
         code = """
         r = |20| + 3
         r -> 3
         """
         interp = self.run(code)
-        assert interp.results[0].value.val == 6
+        assert interp.results[0].value.value == 6
 
     def test_sum(self):
         code = """
@@ -131,7 +131,7 @@
         r
         """
         interp = self.run(code)
-        assert interp.results[0].value.val == 15
+        assert interp.results[0].value.value == 15
 
     def test_array_write(self):
         code = """


More information about the pypy-commit mailing list