[pypy-commit] pypy default: test/fix segfault on bool_(x).round()

bdkearns noreply at buildbot.pypy.org
Tue Oct 29 23:42:31 CET 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r67714:66afd260d5e5
Date: 2013-10-29 18:31 -0400
http://bitbucket.org/pypy/pypy/changeset/66afd260d5e5/

Log:	test/fix segfault on bool_(x).round()

diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -23,19 +23,19 @@
         assert loads(dumps(sum(a))) == sum(a)
 
     def test_round(self):
-        from numpypy import int32, float64, complex128, bool
+        from numpypy import int32, float64, complex128, bool_
         i = int32(1337)
         f = float64(13.37)
         c = complex128(13 + 37.j)
-        b = bool(0)
+        b = bool_(1)
         assert i.round(decimals=-2) == 1300
         assert i.round(decimals=1) == 1337
         assert c.round() == c
         assert f.round() == 13.
         assert f.round(decimals=-1) == 10.
         assert f.round(decimals=1) == 13.4
-        exc = raises(AttributeError, 'b.round()')
-        assert exc.value[0] == "'bool' object has no attribute 'round'"
+        assert b.round() == 1.0
+        assert b.round(decimals=5) is b
 
     def test_attributes(self):
         import numpypy as np
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
@@ -400,6 +400,12 @@
             return 1
         return 0
 
+    @specialize.argtype(1)
+    def round(self, v, decimals=0):
+        if decimals != 0:
+            return v
+        return Float64().box(self.unbox(v))
+
 class Integer(Primitive):
     _mixin_ = True
 


More information about the pypy-commit mailing list