Matti Picus avatar Matti Picus committed 2280c23

fix complex math test cases for numpy compatibility (never raises)

Comments (0)

Files changed (3)

pypy/module/micronumpy/test/complex_testcases.txt

 -- special values
 atan1000 atan -0.0 0.0 -> -0.0 0.0
 atan1001 atan nan 0.0 -> nan 0.0
-atan1002 atan -0.0 1.0 -> -0.0 inf divide-by-zero
+atan1002 atan -0.0 1.0 -> nan inf divide-by-zero
 atan1003 atan -inf 0.0 -> -1.5707963267948966 0.0
 atan1004 atan -inf 2.2999999999999998 -> -1.5707963267948966 0.0
 atan1005 atan nan 2.2999999999999998 -> nan nan
 atan1012 atan -inf nan -> -1.5707963267948966 0.0 ignore-imag-sign
 atan1013 atan nan nan -> nan nan
 atan1014 atan 0.0 0.0 -> 0.0 0.0
-atan1015 atan 0.0 1.0 -> 0.0 inf divide-by-zero
+atan1015 atan 0.0 1.0 -> nan inf divide-by-zero
 atan1016 atan inf 0.0 -> 1.5707963267948966 0.0
 atan1017 atan inf 2.2999999999999998 -> 1.5707963267948966 0.0
 atan1018 atan 0.0 inf -> 1.5707963267948966 0.0
 atan1023 atan inf nan -> 1.5707963267948966 0.0 ignore-imag-sign
 atan1024 atan 0.0 -0.0 -> 0.0 -0.0
 atan1025 atan nan -0.0 -> nan -0.0
-atan1026 atan 0.0 -1.0 -> 0.0 -inf divide-by-zero
+atan1026 atan 0.0 -1.0 -> nan -inf divide-by-zero
 atan1027 atan inf -0.0 -> 1.5707963267948966 -0.0
 atan1028 atan inf -2.2999999999999998 -> 1.5707963267948966 -0.0
 atan1029 atan nan -2.2999999999999998 -> nan nan
 atan1032 atan inf -inf -> 1.5707963267948966 -0.0
 atan1033 atan nan -inf -> nan -0.0
 atan1034 atan -0.0 -0.0 -> -0.0 -0.0
-atan1035 atan -0.0 -1.0 -> -0.0 -inf divide-by-zero
+atan1035 atan -0.0 -1.0 -> nan -inf divide-by-zero
 atan1036 atan -inf -0.0 -> -1.5707963267948966 -0.0
 atan1037 atan -inf -2.2999999999999998 -> -1.5707963267948966 -0.0
 atan1038 atan -0.0 -inf -> -1.5707963267948966 -0.0
 log0201 log 0.79999999999999993 0.60000000000000009 -> 6.1629758220391547e-33 0.64350110879328448
 
 -- special values
-log1000 log -0.0 0.0 -> -inf 3.1415926535897931         divide-by-zero
+log1000 log -0.0 0.0 -> -inf 0.0         divide-by-zero
 log1001 log 0.0 0.0 -> -inf 0.0                         divide-by-zero
 log1002 log 0.0 inf -> inf 1.5707963267948966
 log1003 log 2.3 inf -> inf 1.5707963267948966
 log1019 log nan 2.3 -> nan nan
 log1020 log nan inf -> inf nan
 log1021 log nan nan -> nan nan
-log1022 log -0.0 -0.0 -> -inf -3.1415926535897931       divide-by-zero
-log1023 log 0.0 -0.0 -> -inf -0.0                       divide-by-zero
+log1022 log -0.0 -0.0 -> -inf 0.0       divide-by-zero
+log1023 log 0.0 -0.0 -> -inf 0.0        divide-by-zero
 log1024 log 0.0 -inf -> inf -1.5707963267948966
 log1025 log 2.3 -inf -> inf -1.5707963267948966
 log1026 log -0.0 -inf -> inf -1.5707963267948966
 logt0201 log10 0.79999999999999993 0.60000000000000009 -> 2.6765463916147622e-33 0.2794689806475476
 
 -- special values
-logt1000 log10 -0.0 0.0 -> -inf 1.3643763538418414         divide-by-zero
-logt1001 log10 0.0 0.0 -> -inf 0.0                         divide-by-zero
+logt1000 log10 -0.0 0.0 -> -inf 0.0         divide-by-zero
+logt1001 log10 0.0 0.0 -> -inf 0.0          divide-by-zero
 logt1002 log10 0.0 inf -> inf 0.68218817692092071
 logt1003 log10 2.3 inf -> inf 0.68218817692092071
 logt1004 log10 -0.0 inf -> inf 0.68218817692092071
 logt1019 log10 nan 2.3 -> nan nan
 logt1020 log10 nan inf -> inf nan
 logt1021 log10 nan nan -> nan nan
-logt1022 log10 -0.0 -0.0 -> -inf -1.3643763538418414       divide-by-zero
-logt1023 log10 0.0 -0.0 -> -inf -0.0                       divide-by-zero
+logt1022 log10 -0.0 -0.0 -> -inf 0.0       divide-by-zero
+logt1023 log10 0.0 -0.0 -> -inf 0.0        divide-by-zero
 logt1024 log10 0.0 -inf -> inf -0.68218817692092071
 logt1025 log10 2.3 -inf -> inf -0.68218817692092071
 logt1026 log10 -0.0 -inf -> inf -0.68218817692092071
 exp0046 exp -745.0 5.3 -> 0.0 -0.0
 
 -- values for which exp(z) overflows
-exp0050 exp 710.0 0.0 -> inf 0.0                        overflow
-exp0051 exp 711.0 0.7 -> inf inf                        overflow
-exp0052 exp 710.0 1.5 -> 1.5802653829857376e+307 inf    overflow
-exp0053 exp 710.0 1.6 -> -6.5231579995501372e+306 inf   overflow
-exp0054 exp 710.0 2.8 -> -inf 7.4836177417448528e+307   overflow
+exp0050 exp 710.0 0.0 -> inf nan                        overflow
+exp0051 exp 711.0 0.7 -> inf nan                        overflow
+exp0052 exp 710.0 1.5 -> inf nan                        overflow
+exp0053 exp 710.0 1.6 -> inf nan                        overflow
+exp0054 exp 710.0 2.8 -> inf nan                        overflow
 
 -- special values
 exp1000 exp 0.0 0.0 -> 1.0 0.0

pypy/module/micronumpy/test/test_ufuncs.py

             assert False, 'untested: copysign, reciprocal, sign, floor_div, ' + \
                      'signbit, fabs, fmax, fmin, floor, ceil, trunc, ' + \
                      'exp2, expm1, isnan, isinf, isneginf, isposinf, ' + \
-                     'isfinite, radians, degrees, log2, log10, log1p, ' + \
+                     'isfinite, radians, degrees, log2, log1p, ' + \
                      'logaddexp, npy_log2_1p, logaddexp2'
 
     def test_complex_math(self):

pypy/module/micronumpy/types.py

         else:
             return math.floor(v)
 
-    @simple_unary_op
+    @complex_unary_op
     def exp(self, v):
+        if math.isinf(v[1]):
+            return rfloat.NAN, rfloat.NAN
         try:
-            return math.exp(v)
+            return rcomplex.c_exp(*v)
         except OverflowError:
-            return rfloat.INFINITY
+            return rfloat.INFINITY, rfloat.NAN
 
-    @simple_unary_op
     def exp2(self, v):
         try:
-            return math.pow(2, v)
+            return self.pow(2, v)
         except OverflowError:
-            return rfloat.INFINITY
+            return rfloat.INFINITY, rfloat.NAN
 
-    @simple_unary_op
+    @complex_unary_op
     def expm1(self, v):
         try:
             return rfloat.expm1(v)
     @complex_unary_op
     def arctanh(self, v):
         if v[1] == 0 and (v[0] == 1.0 or v[0] == -1.0):
-            return math.copysign(rfloat.INFINITY, v[0]), 0.
-        if not -1.0 < v < 1.0:
-            return rfloat.NAN, 0.
+            return (math.copysign(rfloat.INFINITY, v[0]),
+                   math.copysign(0., v[1]))
         return rcomplex.c_atanh(*v)
             
             
 
     @complex_unary_op
     def log(self, v):
-        return rcomplex.c_log(v)
+        if v[0] == 0 and v[1] == 0:
+            return -rfloat.INFINITY, 0
+        return rcomplex.c_log(*v)
 
     @simple_unary_op
     def log2(self, v):
         return self.log(v) / log2
 
-    @simple_unary_op
+    @complex_unary_op
     def log10(self, v):
-        try:
-            return math.log10(v)
-        except ValueError:
-            if v == 0.0:
-                # CPython raises ValueError here, so we have to check
-                # the value to find the correct numpy return value
-                return -rfloat.INFINITY
-            return rfloat.NAN
+        if v[0] == 0 and v[1] == 0:
+            return -rfloat.INFINITY, 0
+        return rcomplex.c_log10(*v)
 
     @simple_unary_op
     def log1p(self, v):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.