[Scipy-svn] r7063 - in branches/0.9.x/scipy/special: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Sun Jan 16 10:20:46 EST 2011


Author: rgommers
Date: 2011-01-16 09:20:38 -0600 (Sun, 16 Jan 2011)
New Revision: 7063

Modified:
   branches/0.9.x/scipy/special/orthogonal.py
   branches/0.9.x/scipy/special/tests/test_basic.py
   branches/0.9.x/scipy/special/tests/test_data.py
   branches/0.9.x/scipy/special/tests/test_lambertw.py
   branches/0.9.x/scipy/special/tests/test_orthogonal.py
   branches/0.9.x/scipy/special/tests/test_orthogonal_eval.py
Log:
TST: silence floating point test noise in scipy.special.

(backport of r7040)

Modified: branches/0.9.x/scipy/special/orthogonal.py
===================================================================
--- branches/0.9.x/scipy/special/orthogonal.py	2011-01-16 15:19:08 UTC (rev 7062)
+++ branches/0.9.x/scipy/special/orthogonal.py	2011-01-16 15:20:38 UTC (rev 7063)
@@ -179,18 +179,23 @@
         raise ValueError("alpha and beta must be greater than -1.")
     assert(n>0), "n must be positive."
 
-    (p,q) = (alpha,beta)
-    # from recurrence relations
-    sbn_J = lambda k: 2.0/(2.0*k+p+q)*sqrt((k+p)*(k+q)/(2*k+q+p+1)) * \
-                (np.where(k==1,1.0,sqrt(k*(k+p+q)/(2.0*k+p+q-1))))
-    if any(p == q):  # XXX any or all???
-        an_J = lambda k: 0.0*k
-    else:
-        an_J = lambda k: np.where(k==0,(q-p)/(p+q+2.0),
-                               (q*q - p*p)/((2.0*k+p+q)*(2.0*k+p+q+2)))
-    g = cephes.gamma
-    mu0 = 2.0**(p+q+1)*g(p+1)*g(q+1)/(g(p+q+2))
-    val = gen_roots_and_weights(n,an_J,sbn_J,mu0)
+    olderr = np.seterr(all='ignore')
+    try:
+        (p,q) = (alpha,beta)
+        # from recurrence relations
+        sbn_J = lambda k: 2.0/(2.0*k+p+q)*sqrt((k+p)*(k+q)/(2*k+q+p+1)) * \
+                    (np.where(k==1,1.0,sqrt(k*(k+p+q)/(2.0*k+p+q-1))))
+        if any(p == q):  # XXX any or all???
+            an_J = lambda k: 0.0*k
+        else:
+            an_J = lambda k: np.where(k==0,(q-p)/(p+q+2.0),
+                                   (q*q - p*p)/((2.0*k+p+q)*(2.0*k+p+q+2)))
+        g = cephes.gamma
+        mu0 = 2.0**(p+q+1)*g(p+1)*g(q+1)/(g(p+q+2))
+        val = gen_roots_and_weights(n,an_J,sbn_J,mu0)
+    finally:
+        np.seterr(**olderr)
+
     if mu:
         return val + [mu0]
     else:

Modified: branches/0.9.x/scipy/special/tests/test_basic.py
===================================================================
--- branches/0.9.x/scipy/special/tests/test_basic.py	2011-01-16 15:19:08 UTC (rev 7062)
+++ branches/0.9.x/scipy/special/tests/test_basic.py	2011-01-16 15:20:38 UTC (rev 7063)
@@ -907,8 +907,12 @@
                 correct[2*k] = -float(mathworld[k])
             else:
                 correct[2*k] = float(mathworld[k])
-        err = nan_to_num((eu24-correct)/correct)
-        errmax = max(err)
+        olderr = np.seterr(all='ignore')
+        try:
+            err = nan_to_num((eu24-correct)/correct)
+            errmax = max(err)
+        finally:
+            np.seterr(**olderr)
         assert_almost_equal(errmax, 0.0, 14)
 
 class TestExp(TestCase):
@@ -1034,7 +1038,7 @@
         assert_almost_equal(rgam,rlgam,8)
 
 class TestHankel(TestCase):
-    
+
     def test_negv1(self):
         assert_almost_equal(special.hankel1(-3,2), -special.hankel1(3,2), 14)
 
@@ -1319,7 +1323,7 @@
                                        123.70194191713507279,
                                        129.02417238949092824,
                                        134.00114761868422559]), rtol=1e-13)
-        
+
         jn301 = special.jn_zeros(301,5)
         assert_tol_equal(jn301, array([313.59097866698830153,
                                        323.21549776096288280,
@@ -1332,7 +1336,7 @@
         assert_tol_equal(jn0[260-1], 816.02884495068867280, rtol=1e-13)
         assert_tol_equal(jn0[280-1], 878.86068707124422606, rtol=1e-13)
         assert_tol_equal(jn0[300-1], 941.69253065317954064, rtol=1e-13)
-        
+
         jn10 = special.jn_zeros(10, 300)
         assert_tol_equal(jn10[260-1], 831.67668514305631151, rtol=1e-13)
         assert_tol_equal(jn10[280-1], 894.51275095371316931, rtol=1e-13)
@@ -1516,7 +1520,7 @@
         an = special.yn_zeros(4,2)
         assert_array_almost_equal(an,array([ 5.64515,  9.36162]),5)
         an = special.yn_zeros(443,5)
-        assert_tol_equal(an, [450.13573091578090314, 463.05692376675001542, 
+        assert_tol_equal(an, [450.13573091578090314, 463.05692376675001542,
                               472.80651546418663566, 481.27353184725625838,
                               488.98055964441374646], rtol=1e-15)
 
@@ -1570,7 +1574,7 @@
             for z in [-1300, -11, -10, -1, 1., 10., 200.5, 401., 600.5,
                       700.6, 1300, 10003]:
                 yield v, z
-                
+
         # check half-integers; these are problematic points at least
         # for cephes/iv
         for v in 0.5 + arange(-60, 60):
@@ -1605,7 +1609,11 @@
         self.check_cephes_vs_amos(special.yv, special.yn, rtol=1e-11, atol=1e-305, skip=skipper)
 
     def test_iv_cephes_vs_amos(self):
-        self.check_cephes_vs_amos(special.iv, special.iv, rtol=5e-9, atol=1e-305)
+        olderr = np.seterr(all='ignore')
+        try:
+            self.check_cephes_vs_amos(special.iv, special.iv, rtol=5e-9, atol=1e-305)
+        finally:
+            np.seterr(**olderr)
 
     @dec.slow
     def test_iv_cephes_vs_amos_mass_test(self):
@@ -1667,12 +1675,12 @@
         assert_tol_equal(special.iv(-2,   1+0j), 0.1357476697670383)
         assert_tol_equal(special.kv(-1,   1+0j), 0.6019072301972347)
         assert_tol_equal(special.kv(-2,   1+0j), 1.624838898635178)
-        
+
         assert_tol_equal(special.jv(-0.5, 1+0j), 0.43109886801837607952)
         assert_tol_equal(special.jv(-0.5, 1+1j), 0.2628946385649065-0.827050182040562j)
         assert_tol_equal(special.yv(-0.5, 1+0j), 0.6713967071418031)
         assert_tol_equal(special.yv(-0.5, 1+1j), 0.967901282890131+0.0602046062142816j)
-        
+
         assert_tol_equal(special.iv(-0.5, 1+0j), 1.231200214592967)
         assert_tol_equal(special.iv(-0.5, 1+1j), 0.77070737376928+0.39891821043561j)
         assert_tol_equal(special.kv(-0.5, 1+0j), 0.4610685044478945)
@@ -1799,8 +1807,8 @@
         y=(special.iv(0,2) + special.iv(2,2))/2
         x = special.ivp(1,2)
         assert_almost_equal(x,y,10)
-    
 
+
 class TestLaguerre(TestCase):
     def test_laguerre(self):
         lag0 = special.laguerre(0)
@@ -1890,7 +1898,11 @@
 
         # XXX: this is outside the domain of the current implementation,
         #      so ensure it returns a NaN rather than a wrong answer.
-        lp = special.lpmv(-1,-1,.001)
+        olderr = np.seterr(all='ignore')
+        try:
+            lp = special.lpmv(-1,-1,.001)
+        finally:
+            np.seterr(**olderr)
         assert_(lp != 0 or np.isnan(lp))
 
     def test_lqmn(self):
@@ -1978,7 +1990,7 @@
         eps = 1e-7 + 1e-7*abs(x)
         dp = (special.pbdv(eta, x + eps)[0] - special.pbdv(eta, x - eps)[0]) / eps / 2.
         assert_tol_equal(p[1], dp, rtol=1e-6, atol=1e-6)
-        
+
     def test_pbvv_gradient(self):
         x = np.linspace(-4, 4, 8)[:,None]
         eta = np.linspace(-10, 10, 5)[None,:]
@@ -1987,8 +1999,8 @@
         eps = 1e-7 + 1e-7*abs(x)
         dp = (special.pbvv(eta, x + eps)[0] - special.pbvv(eta, x - eps)[0]) / eps / 2.
         assert_tol_equal(p[1], dp, rtol=1e-6, atol=1e-6)
-        
 
+
 class TestPolygamma(TestCase):
     # from Table 6.2 (pg. 271) of A&S
     def test_polygamma(self):
@@ -2041,8 +2053,8 @@
         # correctly written.
         rndrl = (10,10,10,11)
         assert_array_equal(rnd,rndrl)
-        
 
+
 def test_sph_harm():
     # Tests derived from tables in
     # http://en.wikipedia.org/wiki/Table_of_spherical_harmonics
@@ -2076,7 +2088,7 @@
     def test_sph_harm(self):
         # see test_sph_harm function
         pass
-    
+
     def test_sph_in(self):
         i1n = special.sph_in(1,.2)
         inp0 = (i1n[0][1])

Modified: branches/0.9.x/scipy/special/tests/test_data.py
===================================================================
--- branches/0.9.x/scipy/special/tests/test_data.py	2011-01-16 15:19:08 UTC (rev 7062)
+++ branches/0.9.x/scipy/special/tests/test_data.py	2011-01-16 15:20:38 UTC (rev 7063)
@@ -206,8 +206,12 @@
         # tgamma_ratio_data.txt
     ]
 
-    for test in TESTS:
-        yield _test_factory, test
+    olderr = np.seterr(all='ignore')
+    try:
+        for test in TESTS:
+            yield _test_factory, test
+    finally:
+        np.seterr(**olderr)
 
 def _test_factory(test, dtype=np.double):
     """Boost test"""

Modified: branches/0.9.x/scipy/special/tests/test_lambertw.py
===================================================================
--- branches/0.9.x/scipy/special/tests/test_lambertw.py	2011-01-16 15:19:08 UTC (rev 7062)
+++ branches/0.9.x/scipy/special/tests/test_lambertw.py	2011-01-16 15:20:38 UTC (rev 7063)
@@ -6,6 +6,7 @@
 # [1] mpmath source code, Subversion revision 992
 #     http://code.google.com/p/mpmath/source/browse/trunk/mpmath/tests/test_functions2.py?spec=svn994&r=992
 
+import numpy as np
 from numpy.testing import assert_, assert_equal, assert_array_almost_equal
 from scipy.special import lambertw
 from numpy import nan, inf, pi, e, isnan, log, r_, array, complex_
@@ -78,7 +79,11 @@
 
     def w(x, y):
         return lambertw(x, y.real.astype(int))
-    FuncData(w, data, (0,1), 2, rtol=1e-10, atol=1e-13).check()
+    olderr = np.seterr(all='ignore')
+    try:
+        FuncData(w, data, (0,1), 2, rtol=1e-10, atol=1e-13).check()
+    finally:
+        np.seterr(**olderr)
 
 def test_ufunc():
     assert_array_almost_equal(

Modified: branches/0.9.x/scipy/special/tests/test_orthogonal.py
===================================================================
--- branches/0.9.x/scipy/special/tests/test_orthogonal.py	2011-01-16 15:19:08 UTC (rev 7062)
+++ branches/0.9.x/scipy/special/tests/test_orthogonal.py	2011-01-16 15:20:38 UTC (rev 7063)
@@ -10,10 +10,14 @@
     def test_chebyc(self):
         C0 = orth.chebyc(0)
         C1 = orth.chebyc(1)
-        C2 = orth.chebyc(2)
-        C3 = orth.chebyc(3)
-        C4 = orth.chebyc(4)
-        C5 = orth.chebyc(5)
+        olderr = np.seterr(all='ignore')
+        try:
+            C2 = orth.chebyc(2)
+            C3 = orth.chebyc(3)
+            C4 = orth.chebyc(4)
+            C5 = orth.chebyc(5)
+        finally:
+            np.seterr(**olderr)
 
         assert_array_almost_equal(C0.c,[2],13)
         assert_array_almost_equal(C1.c,[1,0],13)
@@ -247,7 +251,11 @@
                 orth.sh_legendre(%(n)d)
                 """ % dict(n=n)).split()
             ])
-        for pstr in poly:
-            p = eval(pstr)
-            assert_almost_equal(p(0.315), np.poly1d(p)(0.315), err_msg=pstr)
+        olderr = np.seterr(all='ignore')
+        try:
+            for pstr in poly:
+                p = eval(pstr)
+                assert_almost_equal(p(0.315), np.poly1d(p)(0.315), err_msg=pstr)
+        finally:
+            np.seterr(**olderr)
 

Modified: branches/0.9.x/scipy/special/tests/test_orthogonal_eval.py
===================================================================
--- branches/0.9.x/scipy/special/tests/test_orthogonal_eval.py	2011-01-16 15:19:08 UTC (rev 7062)
+++ branches/0.9.x/scipy/special/tests/test_orthogonal_eval.py	2011-01-16 15:20:38 UTC (rev 7063)
@@ -99,8 +99,12 @@
                    param_ranges=[], x_range=[-2, 2])
 
     def test_sh_chebyt(self):
-        self.check_poly(orth.eval_sh_chebyt, orth.sh_chebyt,
-                   param_ranges=[], x_range=[0, 1])
+        olderr = np.seterr(all='ignore')
+        try:
+            self.check_poly(orth.eval_sh_chebyt, orth.sh_chebyt,
+                            param_ranges=[], x_range=[0, 1])
+        finally:
+            np.seterr(**olderr)
 
     def test_sh_chebyu(self):
         self.check_poly(orth.eval_sh_chebyu, orth.sh_chebyu,
@@ -111,8 +115,12 @@
                    param_ranges=[], x_range=[-1, 1])
 
     def test_sh_legendre(self):
-        self.check_poly(orth.eval_sh_legendre, orth.sh_legendre,
-                   param_ranges=[], x_range=[0, 1])
+        olderr = np.seterr(all='ignore')
+        try:
+            self.check_poly(orth.eval_sh_legendre, orth.sh_legendre,
+                            param_ranges=[], x_range=[0, 1])
+        finally:
+            np.seterr(**olderr)
 
     def test_genlaguerre(self):
         self.check_poly(orth.eval_genlaguerre, orth.genlaguerre,




More information about the Scipy-svn mailing list