[Numpy-svn] r3368 - in trunk/numpy: core/tests lib/tests

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Oct 19 11:45:43 CDT 2006


Author: tim_hochberg
Date: 2006-10-19 11:45:36 -0500 (Thu, 19 Oct 2006)
New Revision: 3368

Modified:
   trunk/numpy/core/tests/test_ma.py
   trunk/numpy/lib/tests/test_type_check.py
   trunk/numpy/lib/tests/test_ufunclike.py
Log:
Fix tests to run cleanly with new, tighter error handling.

Modified: trunk/numpy/core/tests/test_ma.py
===================================================================
--- trunk/numpy/core/tests/test_ma.py	2006-10-19 15:18:55 UTC (rev 3367)
+++ trunk/numpy/core/tests/test_ma.py	2006-10-19 16:45:36 UTC (rev 3368)
@@ -86,11 +86,15 @@
             self.failUnless(eq(x + y, xm + ym))
             self.failUnless(eq(x - y, xm - ym))
             self.failUnless(eq(x * y, xm * ym))
+            olderr = numpy.seterr(divide='ignore', invalid='ignore')
             self.failUnless(eq(x / y, xm / ym))
+            numpy.seterr(**olderr)
             self.failUnless(eq(a10 + y, a10 + ym))
             self.failUnless(eq(a10 - y, a10 - ym))
             self.failUnless(eq(a10 * y, a10 * ym))
+            olderr = numpy.seterr(divide='ignore', invalid='ignore')
             self.failUnless(eq(a10 / y, a10 / ym))
+            numpy.seterr(**olderr)
             self.failUnless(eq(x + a10, xm + a10))
             self.failUnless(eq(x - a10, xm - a10))
             self.failUnless(eq(x * a10, xm * a10))
@@ -101,7 +105,9 @@
             self.failUnless(eq(numpy.add(x,y), add(xm, ym)))
             self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))
             self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))
+            olderr = numpy.seterr(divide='ignore', invalid='ignore')
             self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))
+            numpy.seterr(**olderr)
 
 
     def check_testMixedArithmetic(self):
@@ -119,7 +125,9 @@
         self.failUnless (eq(numpy.sinh(x), sinh(xm)))
         self.failUnless (eq(numpy.tan(x), tan(xm)))
         self.failUnless (eq(numpy.tanh(x), tanh(xm)))
+        olderr = numpy.seterr(divide='ignore', invalid='ignore')
         self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))
+        numpy.seterr(**olderr)
         self.failUnless (eq(numpy.log(abs(x)), log(xm)))
         self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))
         self.failUnless (eq(numpy.exp(x), exp(xm)))
@@ -671,8 +679,14 @@
                 uf = getattr(fromnumeric, f)
             mf = getattr(numpy.ma, f)
             args = self.d[:uf.nin]
+            olderr = numpy.geterr()
+            if f in ['sqrt', 'arctanh', 'arcsin', 'arccos', 'arccosh', 'arctanh']:
+                numpy.seterr(invalid='ignore')
+            if f in ['arctanh']:
+                numpyseterr(divide='ignore']
             ur = uf(*args)
             mr = mf(*args)
+            numpy.seterr(**olderr)
             self.failUnless(eq(ur.filled(0), mr.filled(0), f))
             self.failUnless(eqmask(ur.mask, mr.mask))
 

Modified: trunk/numpy/lib/tests/test_type_check.py
===================================================================
--- trunk/numpy/lib/tests/test_type_check.py	2006-10-19 15:18:55 UTC (rev 3367)
+++ trunk/numpy/lib/tests/test_type_check.py	2006-10-19 16:45:36 UTC (rev 3368)
@@ -127,11 +127,17 @@
         res = isnan(z) == 0
         assert_all(alltrue(res,axis=0))
     def check_posinf(self):
+        olderr = seterr(divide='ignore')
         assert_all(isnan(array((1.,))/0.) == 0)
+        seterr(**olderr)
     def check_neginf(self):
+        olderr = seterr(divide='ignore')
         assert_all(isnan(array((-1.,))/0.) == 0)
+        seterr(**olderr)
     def check_ind(self):
+        olderr = seterr(divide='ignore', invalid='ignore')
         assert_all(isnan(array((0.,))/0.) == 1)
+        seterr(**olderr)
     #def check_qnan(self):             log(-1) return pi*j now
     #    assert_all(isnan(log(-1.)) == 1)
     def check_integer(self):
@@ -139,7 +145,9 @@
     def check_complex(self):
         assert_all(isnan(1+1j) == 0)
     def check_complex1(self):
+        olderr = seterr(divide='ignore', invalid='ignore')
         assert_all(isnan(array(0+0j)/0.) == 1)
+        seterr(**olderr)
 
 class test_isfinite(NumpyTestCase):
     def check_goodvalues(self):
@@ -147,11 +155,17 @@
         res = isfinite(z) == 1
         assert_all(alltrue(res,axis=0))
     def check_posinf(self):
+        olderr = seterr(divide='ignore')
         assert_all(isfinite(array((1.,))/0.) == 0)
+        seterr(**olderr)
     def check_neginf(self):
+        olderr = seterr(divide='ignore')
         assert_all(isfinite(array((-1.,))/0.) == 0)
+        seterr(**olderr)
     def check_ind(self):
+        olderr = seterr(divide='ignore', invalid='ignore')
         assert_all(isfinite(array((0.,))/0.) == 0)
+        seterr(**olderr)
     #def check_qnan(self):
     #    assert_all(isfinite(log(-1.)) == 0)
     def check_integer(self):
@@ -159,7 +173,9 @@
     def check_complex(self):
         assert_all(isfinite(1+1j) == 1)
     def check_complex1(self):
+        olderr = seterr(divide='ignore', invalid='ignore')
         assert_all(isfinite(array(1+1j)/0.) == 0)
+        seterr(**olderr)
 
 class test_isinf(NumpyTestCase):
     def check_goodvalues(self):
@@ -167,36 +183,52 @@
         res = isinf(z) == 0
         assert_all(alltrue(res,axis=0))
     def check_posinf(self):
+        olderr = seterr(divide='ignore')
         assert_all(isinf(array((1.,))/0.) == 1)
+        seterr(**olderr)
     def check_posinf_scalar(self):
+        olderr = seterr(divide='ignore')
         assert_all(isinf(array(1.,)/0.) == 1)
+        seterr(**olderr)
     def check_neginf(self):
+        olderr = seterr(divide='ignore')
         assert_all(isinf(array((-1.,))/0.) == 1)
+        seterr(**olderr)
     def check_neginf_scalar(self):
+        olderr = seterr(divide='ignore')
         assert_all(isinf(array(-1.)/0.) == 1)
+        seterr(**olderr)
     def check_ind(self):
+        olderr = seterr(divide='ignore', invalid='ignore')
         assert_all(isinf(array((0.,))/0.) == 0)
+        seterr(**olderr)
     #def check_qnan(self):
     #    assert_all(isinf(log(-1.)) == 0)
     #    assert_all(isnan(log(-1.)) == 1)
 
 class test_isposinf(NumpyTestCase):
     def check_generic(self):
+        olderr = seterr(divide='ignore', invalid='ignore')
         vals = isposinf(array((-1.,0,1))/0.)
+        seterr(**olderr)
         assert(vals[0] == 0)
         assert(vals[1] == 0)
         assert(vals[2] == 1)
 
 class test_isneginf(NumpyTestCase):
     def check_generic(self):
+        olderr = seterr(divide='ignore', invalid='ignore')
         vals = isneginf(array((-1.,0,1))/0.)
+        seterr(**olderr)
         assert(vals[0] == 1)
         assert(vals[1] == 0)
         assert(vals[2] == 0)
 
 class test_nan_to_num(NumpyTestCase):
     def check_generic(self):
+        olderr = seterr(divide='ignore', invalid='ignore')
         vals = nan_to_num(array((-1.,0,1))/0.)
+        seterr(**olderr)
         assert_all(vals[0] < -1e10) and assert_all(isfinite(vals[0]))
         assert(vals[1] == 0)
         assert_all(vals[2] > 1e10) and assert_all(isfinite(vals[2]))
@@ -208,13 +240,17 @@
         assert_all(vals == 1+1j)
     def check_complex_bad(self):
         v = 1+1j
+        olderr = seterr(divide='ignore', invalid='ignore')
         v += array(0+1.j)/0.
+        seterr(**olderr)
         vals = nan_to_num(v)
         # !! This is actually (unexpectedly) zero
         assert_all(isfinite(vals))
     def check_complex_bad2(self):
         v = 1+1j
+        olderr = seterr(divide='ignore', invalid='ignore')
         v += array(-1+1.j)/0.
+        seterr(**olderr)
         vals = nan_to_num(v)
         assert_all(isfinite(vals))
         #assert_all(vals.imag > 1e10)  and assert_all(isfinite(vals))

Modified: trunk/numpy/lib/tests/test_ufunclike.py
===================================================================
--- trunk/numpy/lib/tests/test_ufunclike.py	2006-10-19 15:18:55 UTC (rev 3367)
+++ trunk/numpy/lib/tests/test_ufunclike.py	2006-10-19 16:45:36 UTC (rev 3368)
@@ -21,8 +21,10 @@
 array([True, False, False, False, False, False], dtype=bool)
 >>> U.isneginf(a)
 array([False, True, False, False, False, False], dtype=bool)
+>>> olderr = nx.seterr(invalid='ignore')
 >>> nx.sign(a)
 array([ 1., -1.,  0.,  0.,  1., -1.])
+>>> olderr = nx.seterr(**olderr)
 
 Same thing with an output array:
 >>> y = nx.zeros(a.shape, bool)
@@ -34,8 +36,10 @@
 array([False, True, False, False, False, False], dtype=bool)
 >>> y
 array([False, True, False, False, False, False], dtype=bool)
+>>> olderr = nx.seterr(invalid='ignore')
 >>> nx.sign(a, y)
 array([True, True, False, False, True, True], dtype=bool)
+>>> olderr = nx.seterr(**olderr)
 >>> y
 array([True, True, False, False, True, True], dtype=bool)
 



More information about the Numpy-svn mailing list