[pypy-commit] pypy default: add more tests, fix by adding __float__ (ronan, mattip)

mattip noreply at buildbot.pypy.org
Mon Apr 8 20:35:07 CEST 2013


Author: mattip <matti.picus at gmail.com>
Branch: 
Changeset: r63153:84ff2854255f
Date: 2013-04-08 21:21 +0300
http://bitbucket.org/pypy/pypy/changeset/84ff2854255f/

Log:	add more tests, fix by adding __float__ (ronan, mattip)

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
@@ -772,6 +772,16 @@
             return space.int(self.descr_getitem(space, space.wrap(0)))
         raise OperationError(space.w_TypeError, space.wrap("only length-1 arrays can be converted to Python scalars"))
 
+    def descr_float(self, space):
+        shape = self.get_shape()
+        if len(shape) == 0:
+            assert isinstance(self.implementation, scalar.Scalar)
+            return space.float(space.wrap(self.implementation.get_scalar_value()))
+        if shape == [1]:
+            return space.float(self.descr_getitem(space, space.wrap(0)))
+        raise OperationError(space.w_TypeError, space.wrap("only length-1 arrays can be converted to Python scalars"))
+
+
 
 @unwrap_spec(offset=int)
 def descr_new_array(space, w_subtype, w_shape, w_dtype=None, w_buffer=None,
@@ -813,6 +823,7 @@
     __repr__ = interp2app(W_NDimArray.descr_repr),
     __str__ = interp2app(W_NDimArray.descr_str),
     __int__ = interp2app(W_NDimArray.descr_int),
+    __float__ = interp2app(W_NDimArray.descr_float),
 
     __pos__ = interp2app(W_NDimArray.descr_pos),
     __neg__ = interp2app(W_NDimArray.descr_neg),
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -422,11 +422,17 @@
         assert a[4] == 5.0
         raises(IndexError, "a[5] = 0.0")
         raises(IndexError, "a[-6] = 3.0")
+        a[1] = array(100)
+        a[2] = array([100])
+        assert a[1] == 100
+        assert a[2] == 100
         a = array(range(5), dtype=float)
         a[0] = 0.005
         assert a[0] == 0.005
         a[1] = array(-0.005)
+        a[2] = array([-0.005])
         assert a[1] == -0.005
+        assert a[2] == -0.005
 
 
     def test_setitem_tuple(self):


More information about the pypy-commit mailing list