[pypy-commit] pypy default: improve the test and fix it. This is just a workaround for quirky math.exp

fijal noreply at buildbot.pypy.org
Fri May 20 11:33:08 CEST 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r44318:b6ae955cf87e
Date: 2011-05-20 11:42 +0200
http://bitbucket.org/pypy/pypy/changeset/b6ae955cf87e/

Log:	improve the test and fix it. This is just a workaround for quirky
	math.exp behavior, it should not affect the compiled version

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
@@ -36,7 +36,10 @@
 
 @ufunc
 def exp(value):
-    return math.exp(value)
+    try:
+        return math.exp(value)
+    except OverflowError:
+        return rfloat.INFINITY
 
 @ufunc2
 def maximum(lvalue, rvalue):
@@ -60,4 +63,4 @@
 def sign(value):
     if value == 0.0:
         return 0.0
-    return rfloat.copysign(1.0, value)
\ No newline at end of file
+    return rfloat.copysign(1.0, value)
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -74,7 +74,12 @@
         import math
         from numpy import array, exp
 
-        a = array([-5.0, -0.0, 0.0, float("inf")])
+        a = array([-5.0, -0.0, 0.0, 12345678.0, float("inf"),
+                   -float('inf'), -12343424.0])
         b = exp(a)
         for i in range(4):
-            assert b[i] == math.exp(a[i])
+            try:
+                res = math.exp(a[i])
+            except OverflowError:
+                res = float('inf')
+            assert b[i] == res


More information about the pypy-commit mailing list