summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/tests/test_umath.py47
-rw-r--r--numpy/core/tests/test_umath_complex.py46
2 files changed, 53 insertions, 40 deletions
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 3e17b58dc..5d3f160da 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -5,6 +5,14 @@ import numpy.core.umath as ncu
import numpy as np
+class _FilterInvalids():
+ def setUp(self):
+ self.olderr = np.seterr(invalid='ignore')
+
+ def tearDown(self):
+ np.seterr(**olderr)
+
+
class TestDivision(TestCase):
def test_division_int(self):
# int division should follow Python
@@ -152,7 +160,7 @@ class TestExp2(TestCase):
assert_almost_equal(np.exp2(yf), xf)
-class TestLogAddExp2(object):
+class TestLogAddExp2(object, _FilterInvalids):
# Need test for intermediate precisions
def test_logaddexp2_values(self) :
x = [1, 2, 3, 4, 5]
@@ -219,7 +227,7 @@ class TestExp(TestCase):
assert_almost_equal(np.exp(yf), xf)
-class TestLogAddExp(object):
+class TestLogAddExp(object, _FilterInvalids):
def test_logaddexp_values(self) :
x = [1, 2, 3, 4, 5]
y = [5, 4, 3, 2, 1]
@@ -432,7 +440,7 @@ class TestLdexp(TestCase):
np.seterr(**err)
-class TestMaximum(TestCase):
+class TestMaximum(object, _FilterInvalids):
def test_reduce(self):
dflt = np.typecodes['AllFloat']
dint = np.typecodes['AllInteger']
@@ -479,7 +487,7 @@ class TestMaximum(TestCase):
assert_equal(np.maximum(arg1, arg2), arg2)
-class TestMinimum(TestCase):
+class TestMinimum(object, _FilterInvalids):
def test_reduce(self):
dflt = np.typecodes['AllFloat']
dint = np.typecodes['AllInteger']
@@ -526,7 +534,7 @@ class TestMinimum(TestCase):
assert_equal(np.minimum(arg1, arg2), arg1)
-class TestFmax(TestCase):
+class TestFmax(object, _FilterInvalids):
def test_reduce(self):
dflt = np.typecodes['AllFloat']
dint = np.typecodes['AllInteger']
@@ -568,7 +576,7 @@ class TestFmax(TestCase):
assert_equal(np.fmax(arg1, arg2), out)
-class TestFmin(TestCase):
+class TestFmin(object, _FilterInvalids):
def test_reduce(self):
dflt = np.typecodes['AllFloat']
dint = np.typecodes['AllInteger']
@@ -1217,19 +1225,24 @@ def test_complex_nan_comparisons():
fins = [complex(1, 0), complex(-1, 0), complex(0, 1), complex(0, -1),
complex(1, 1), complex(-1, -1), complex(0, 0)]
- for x in nans + fins:
- x = np.array([x])
- for y in nans + fins:
- y = np.array([y])
+ olderr = np.seterr(invalid='ignore')
+ try:
+ for x in nans + fins:
+ x = np.array([x])
+ for y in nans + fins:
+ y = np.array([y])
+
+ if np.isfinite(x) and np.isfinite(y):
+ continue
- if np.isfinite(x) and np.isfinite(y):
- continue
+ assert_equal(x < y, False, err_msg="%r < %r" % (x, y))
+ assert_equal(x > y, False, err_msg="%r > %r" % (x, y))
+ assert_equal(x <= y, False, err_msg="%r <= %r" % (x, y))
+ assert_equal(x >= y, False, err_msg="%r >= %r" % (x, y))
+ assert_equal(x == y, False, err_msg="%r == %r" % (x, y))
+ finally:
+ np.seterr(**olderr)
- assert_equal(x < y, False, err_msg="%r < %r" % (x, y))
- assert_equal(x > y, False, err_msg="%r > %r" % (x, y))
- assert_equal(x <= y, False, err_msg="%r <= %r" % (x, y))
- assert_equal(x >= y, False, err_msg="%r >= %r" % (x, y))
- assert_equal(x == y, False, err_msg="%r == %r" % (x, y))
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/core/tests/test_umath_complex.py b/numpy/core/tests/test_umath_complex.py
index 4fe0faa59..76fa29be8 100644
--- a/numpy/core/tests/test_umath_complex.py
+++ b/numpy/core/tests/test_umath_complex.py
@@ -12,7 +12,7 @@ import numpy as np
# At least on Windows the results of many complex functions are not conforming
# to the C99 standard. See ticket 1574.
# Ditto for Solaris (ticket 1642) and OS X on PowerPC.
-olderr = np.seterr(divide='ignore')
+olderr = np.seterr(all='ignore')
try:
functions_seem_flaky = ((np.exp(complex(np.inf, 0)).imag != 0)
or (np.log(complex(np.NZERO, 0)).imag != np.pi))
@@ -381,16 +381,18 @@ class TestCsqrt(object):
# cuts first)
class TestCpow(TestCase):
+ def setUp(self):
+ self.olderr = np.seterr(invalid='ignore')
+
+ def tearDown(self):
+ np.seterr(**self.olderr)
+
def test_simple(self):
x = np.array([1+1j, 0+2j, 1+2j, np.inf, np.nan])
- err = np.seterr(invalid='ignore')
- try:
- y_r = x ** 2
- y = np.power(x, 2)
- for i in range(len(x)):
- assert_almost_equal(y[i], y_r[i])
- finally:
- np.seterr(**err)
+ y_r = x ** 2
+ y = np.power(x, 2)
+ for i in range(len(x)):
+ assert_almost_equal(y[i], y_r[i])
def test_scalar(self):
x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan])
@@ -401,13 +403,9 @@ class TestCpow(TestCase):
# Substitute a result allowed by C99 standard
p_r[4] = complex(np.inf, np.nan)
# Do the same with numpy complex scalars
- err = np.seterr(invalid='ignore')
- try:
- n_r = [x[i] ** y[i] for i in lx]
- for i in lx:
- assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i)
- finally:
- np.seterr(**err)
+ n_r = [x[i] ** y[i] for i in lx]
+ for i in lx:
+ assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i)
def test_array(self):
x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan])
@@ -418,15 +416,17 @@ class TestCpow(TestCase):
# Substitute a result allowed by C99 standard
p_r[4] = complex(np.inf, np.nan)
# Do the same with numpy arrays
- err = np.seterr(invalid='ignore')
- try:
- n_r = x ** y
- for i in lx:
- assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i)
- finally:
- np.seterr(**err)
+ n_r = x ** y
+ for i in lx:
+ assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i)
class TestCabs(object):
+ def setUp(self):
+ self.olderr = np.seterr(invalid='ignore')
+
+ def tearDown(self):
+ np.seterr(**self.olderr)
+
def test_simple(self):
x = np.array([1+1j, 0+2j, 1+2j, np.inf, np.nan])
y_r = np.array([np.sqrt(2.), 2, np.sqrt(5), np.inf, np.nan])