[pypy-commit] pypy default: provide bool() for complex types, test

bdkearns noreply at buildbot.pypy.org
Thu Oct 17 01:46:40 CEST 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r67451:271637e39b8a
Date: 2013-10-16 19:41 -0400
http://bitbucket.org/pypy/pypy/changeset/271637e39b8a/

Log:	provide bool() for complex types, test

diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -737,19 +737,38 @@
         assert dtype('i4').isnative == True
         assert dtype('>i8').isnative == False
 
-    def test_any_all(self):
+    def test_any_all_nonzero(self):
         import numpypy as numpy
         x = numpy.bool_(True)
         assert x.any()
         assert x.all()
+        assert x.__nonzero__()
+        assert isinstance(x.any(), numpy.bool_)
+        assert isinstance(x.__nonzero__(), bool)
         x = numpy.bool_(False)
         assert not x.any()
         assert not x.all()
+        assert not x.__nonzero__()
         assert isinstance(x.any(), numpy.bool_)
+        assert isinstance(x.__nonzero__(), bool)
         x = numpy.float64(0)
         assert not x.any()
         assert not x.all()
+        assert not x.__nonzero__()
         assert isinstance(x.any(), numpy.float64)
+        assert isinstance(x.__nonzero__(), bool)
+        x = numpy.complex128(0)
+        assert not x.any()
+        assert not x.all()
+        assert not x.__nonzero__()
+        assert isinstance(x.any(), numpy.complex128)
+        assert isinstance(x.__nonzero__(), bool)
+        x = numpy.complex128(0+1j)
+        assert x.any()
+        assert x.all()
+        assert x.__nonzero__()
+        assert isinstance(x.any(), numpy.complex128)
+        assert isinstance(x.__nonzero__(), bool)
 
     def test_ravel(self):
         from numpypy import float64, int8, array
@@ -762,7 +781,6 @@
         assert (x == array(42)).all()
 
 
-
 class AppTestStrUnicodeDtypes(BaseNumpyAppTest):
     def test_str_unicode(self):
         skip('numpypy differs from numpy')
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
@@ -1148,9 +1148,13 @@
         return v
 
     def to_builtin_type(self, space, box):
-        real,imag = self.for_computation(self.unbox(box))
+        real, imag = self.for_computation(self.unbox(box))
         return space.newcomplex(real, imag)
 
+    def bool(self, v):
+        real, imag = self.for_computation(self.unbox(v))
+        return bool(real) or bool(imag)
+
     def read_bool(self, arr, i, offset):
         v = self.for_computation(self._read(arr.storage, i, offset))
         return bool(v[0]) or bool(v[1])


More information about the pypy-commit mailing list