diff options
Diffstat (limited to 'numpy/polynomial/tests')
-rw-r--r-- | numpy/polynomial/tests/test_chebyshev.py | 68 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_classes.py | 6 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_hermite.py | 66 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_hermite_e.py | 84 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_laguerre.py | 78 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_legendre.py | 72 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_polynomial.py | 72 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_polyutils.py | 22 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_printing.py | 24 |
9 files changed, 246 insertions, 246 deletions
diff --git a/numpy/polynomial/tests/test_chebyshev.py b/numpy/polynomial/tests/test_chebyshev.py index 367d81f58..70eccdd0a 100644 --- a/numpy/polynomial/tests/test_chebyshev.py +++ b/numpy/polynomial/tests/test_chebyshev.py @@ -64,8 +64,8 @@ class TestArithmetic(TestCase) : def test_chebadd(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] += 1 res = cheb.chebadd([0]*i + [1], [0]*j + [1]) @@ -74,8 +74,8 @@ class TestArithmetic(TestCase) : def test_chebsub(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] -= 1 res = cheb.chebsub([0]*i + [1], [0]*j + [1]) @@ -83,7 +83,7 @@ class TestArithmetic(TestCase) : def test_chebmulx(self): assert_equal(cheb.chebmulx([0]), [0]) - assert_equal(cheb.chebmulx([1]), [0,1]) + assert_equal(cheb.chebmulx([1]), [0, 1]) for i in range(1, 5): ser = [0]*i + [1] tgt = [0]*(i - 1) + [.5, 0, .5] @@ -92,7 +92,7 @@ class TestArithmetic(TestCase) : def test_chebmul(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += .5 tgt[abs(i - j)] += .5 @@ -102,7 +102,7 @@ class TestArithmetic(TestCase) : def test_chebdiv(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1] cj = [0]*j + [1] tgt = cheb.chebadd(ci, cj) @@ -127,7 +127,7 @@ class TestEvaluation(TestCase): assert_equal(cheb.chebval([], [1]).size, 0) #check normal input) - x = np.linspace(-1,1) + x = np.linspace(-1, 1) y = [polyval(x, c) for c in Tlist] for i in range(10) : msg = "At i=%d" % i @@ -140,8 +140,8 @@ class TestEvaluation(TestCase): dims = [2]*i x = np.zeros(dims) assert_equal(cheb.chebval(x, [1]).shape, dims) - assert_equal(cheb.chebval(x, [1,0]).shape, dims) - assert_equal(cheb.chebval(x, [1,0,0]).shape, dims) + assert_equal(cheb.chebval(x, [1, 0]).shape, dims) + assert_equal(cheb.chebval(x, [1, 0, 0]).shape, dims) def test_chebval2d(self): x1, x2, x3 = self.x @@ -156,9 +156,9 @@ class TestEvaluation(TestCase): assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = cheb.chebval2d(z, z, self.c2d) - assert_(res.shape == (2,3)) + assert_(res.shape == (2, 3)) def test_chebval3d(self): x1, x2, x3 = self.x @@ -173,9 +173,9 @@ class TestEvaluation(TestCase): assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = cheb.chebval3d(z, z, z, self.c3d) - assert_(res.shape == (2,3)) + assert_(res.shape == (2, 3)) def test_chebgrid2d(self): x1, x2, x3 = self.x @@ -187,7 +187,7 @@ class TestEvaluation(TestCase): assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = cheb.chebgrid2d(z, z, self.c2d) assert_(res.shape == (2, 3)*2) @@ -201,7 +201,7 @@ class TestEvaluation(TestCase): assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = cheb.chebgrid3d(z, z, z, self.c3d) assert_(res.shape == (2, 3)*3) @@ -212,7 +212,7 @@ class TestIntegral(TestCase) : # check exceptions assert_raises(ValueError, cheb.chebint, [0], .5) assert_raises(ValueError, cheb.chebint, [0], -1) - assert_raises(ValueError, cheb.chebint, [0], 1, [0,0]) + assert_raises(ValueError, cheb.chebint, [0], 1, [0, 0]) # test integration of zero polynomial for i in range(2, 5): @@ -250,7 +250,7 @@ class TestIntegral(TestCase) : # check multiple integrations with default k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -260,7 +260,7 @@ class TestIntegral(TestCase) : # check multiple integrations with defined k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -270,7 +270,7 @@ class TestIntegral(TestCase) : # check multiple integrations with lbnd for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -280,7 +280,7 @@ class TestIntegral(TestCase) : # check multiple integrations with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -320,14 +320,14 @@ class TestDerivative(TestCase) : # check that derivation is the inverse of integration for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = cheb.chebder(cheb.chebint(tgt, m=j), m=j) assert_almost_equal(trim(res), trim(tgt)) # check derivation with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = cheb.chebder(cheb.chebint(tgt, m=j, scl=2), m=j, scl=.5) assert_almost_equal(trim(res), trim(tgt)) @@ -409,10 +409,10 @@ class TestFitting(TestCase): assert_raises(TypeError, cheb.chebfit, [1, 2], [1], 0) assert_raises(TypeError, cheb.chebfit, [1], [1, 2], 0) assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[[1]]) - assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[1,1]) + assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[1, 1]) # Test fit - x = np.linspace(0,2) + x = np.linspace(0, 2) y = f(x) # coef3 = cheb.chebfit(x, y, 3) @@ -423,8 +423,8 @@ class TestFitting(TestCase): assert_equal(len(coef4), 5) assert_almost_equal(cheb.chebval(x, coef4), y) # - coef2d = cheb.chebfit(x, np.array([y,y]).T, 3) - assert_almost_equal(coef2d, np.array([coef3,coef3]).T) + coef2d = cheb.chebfit(x, np.array([y, y]).T, 3) + assert_almost_equal(coef2d, np.array([coef3, coef3]).T) # test weighting w = np.zeros_like(x) yw = y.copy() @@ -433,8 +433,8 @@ class TestFitting(TestCase): wcoef3 = cheb.chebfit(x, yw, 3, w=w) assert_almost_equal(wcoef3, coef3) # - wcoef2d = cheb.chebfit(x, np.array([yw,yw]).T, 3, w=w) - assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) + wcoef2d = cheb.chebfit(x, np.array([yw, yw]).T, 3, w=w) + assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T) # test scaling with complex values x points whose square # is zero when summed. x = [1, 1j, -1, -1j] @@ -467,7 +467,7 @@ class TestGauss(TestCase): v = cheb.chebvander(x, 99) vv = np.dot(v.T * w, v) vd = 1/np.sqrt(vv.diagonal()) - vv = vd[:,None] * vv * vd + vv = vd[:, None] * vv * vd assert_almost_equal(vv, np.eye(100)) # check that the integral of 1 is correct @@ -480,16 +480,16 @@ class TestMisc(TestCase) : def test_chebfromroots(self) : res = cheb.chebfromroots([]) assert_almost_equal(trim(res), [1]) - for i in range(1,5) : + for i in range(1, 5) : roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2]) tgt = [0]*i + [1] res = cheb.chebfromroots(roots)*2**(i-1) - assert_almost_equal(trim(res),trim(tgt)) + assert_almost_equal(trim(res), trim(tgt)) def test_chebroots(self) : assert_almost_equal(cheb.chebroots([1]), []) assert_almost_equal(cheb.chebroots([1, 2]), [-.5]) - for i in range(2,5) : + for i in range(2, 5) : tgt = np.linspace(-1, 1, i) res = cheb.chebroots(cheb.chebfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt)) @@ -506,7 +506,7 @@ class TestMisc(TestCase) : assert_equal(cheb.chebtrim(coef, 2), [0]) def test_chebline(self) : - assert_equal(cheb.chebline(3,4), [3, 4]) + assert_equal(cheb.chebline(3, 4), [3, 4]) def test_cheb2poly(self) : for i in range(10) : diff --git a/numpy/polynomial/tests/test_classes.py b/numpy/polynomial/tests/test_classes.py index f8910a473..5708d936f 100644 --- a/numpy/polynomial/tests/test_classes.py +++ b/numpy/polynomial/tests/test_classes.py @@ -155,12 +155,12 @@ def check_fit(Poly) : def f(x) : return x*(x - 1)*(x - 2) - x = np.linspace(0,3) + x = np.linspace(0, 3) y = f(x) # check default value of domain and window p = Poly.fit(x, y, 3) - assert_almost_equal(p.domain, [0,3]) + assert_almost_equal(p.domain, [0, 3]) assert_almost_equal(p(x), y) assert_equal(p.degree(), 3) @@ -441,7 +441,7 @@ def check_deriv(Poly): def check_linspace(Poly): d = Poly.domain + random((2,))*.25 w = Poly.window + random((2,))*.25 - p = Poly([1,2,3], domain=d, window=w) + p = Poly([1, 2, 3], domain=d, window=w) # check default domain xtgt = np.linspace(d[0], d[1], 20) ytgt = p(xtgt) diff --git a/numpy/polynomial/tests/test_hermite.py b/numpy/polynomial/tests/test_hermite.py index 327283d0e..978c9c79b 100644 --- a/numpy/polynomial/tests/test_hermite.py +++ b/numpy/polynomial/tests/test_hermite.py @@ -49,8 +49,8 @@ class TestArithmetic(TestCase) : def test_hermadd(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] += 1 res = herm.hermadd([0]*i + [1], [0]*j + [1]) @@ -59,8 +59,8 @@ class TestArithmetic(TestCase) : def test_hermsub(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] -= 1 res = herm.hermsub([0]*i + [1], [0]*j + [1]) @@ -68,7 +68,7 @@ class TestArithmetic(TestCase) : def test_hermmulx(self): assert_equal(herm.hermmulx([0]), [0]) - assert_equal(herm.hermmulx([1]), [0,.5]) + assert_equal(herm.hermmulx([1]), [0, .5]) for i in range(1, 5): ser = [0]*i + [1] tgt = [0]*(i - 1) + [i, 0, .5] @@ -80,7 +80,7 @@ class TestArithmetic(TestCase) : pol1 = [0]*i + [1] val1 = herm.hermval(self.x, pol1) for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) pol2 = [0]*j + [1] val2 = herm.hermval(self.x, pol2) pol3 = herm.hermmul(pol1, pol2) @@ -91,7 +91,7 @@ class TestArithmetic(TestCase) : def test_hermdiv(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1] cj = [0]*j + [1] tgt = herm.hermadd(ci, cj) @@ -116,7 +116,7 @@ class TestEvaluation(TestCase) : assert_equal(herm.hermval([], [1]).size, 0) #check normal input) - x = np.linspace(-1,1) + x = np.linspace(-1, 1) y = [polyval(x, c) for c in Hlist] for i in range(10) : msg = "At i=%d" % i @@ -130,8 +130,8 @@ class TestEvaluation(TestCase) : dims = [2]*i x = np.zeros(dims) assert_equal(herm.hermval(x, [1]).shape, dims) - assert_equal(herm.hermval(x, [1,0]).shape, dims) - assert_equal(herm.hermval(x, [1,0,0]).shape, dims) + assert_equal(herm.hermval(x, [1, 0]).shape, dims) + assert_equal(herm.hermval(x, [1, 0, 0]).shape, dims) def test_hermval2d(self): x1, x2, x3 = self.x @@ -146,9 +146,9 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = herm.hermval2d(z, z, self.c2d) - assert_(res.shape == (2,3)) + assert_(res.shape == (2, 3)) def test_hermval3d(self): x1, x2, x3 = self.x @@ -163,9 +163,9 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = herm.hermval3d(z, z, z, self.c3d) - assert_(res.shape == (2,3)) + assert_(res.shape == (2, 3)) def test_hermgrid2d(self): x1, x2, x3 = self.x @@ -177,7 +177,7 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = herm.hermgrid2d(z, z, self.c2d) assert_(res.shape == (2, 3)*2) @@ -191,7 +191,7 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = herm.hermgrid3d(z, z, z, self.c3d) assert_(res.shape == (2, 3)*3) @@ -202,7 +202,7 @@ class TestIntegral(TestCase) : # check exceptions assert_raises(ValueError, herm.hermint, [0], .5) assert_raises(ValueError, herm.hermint, [0], -1) - assert_raises(ValueError, herm.hermint, [0], 1, [0,0]) + assert_raises(ValueError, herm.hermint, [0], 1, [0, 0]) # test integration of zero polynomial for i in range(2, 5): @@ -240,7 +240,7 @@ class TestIntegral(TestCase) : # check multiple integrations with default k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -250,7 +250,7 @@ class TestIntegral(TestCase) : # check multiple integrations with defined k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -260,7 +260,7 @@ class TestIntegral(TestCase) : # check multiple integrations with lbnd for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -270,7 +270,7 @@ class TestIntegral(TestCase) : # check multiple integrations with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -310,14 +310,14 @@ class TestDerivative(TestCase) : # check that derivation is the inverse of integration for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = herm.hermder(herm.hermint(tgt, m=j), m=j) assert_almost_equal(trim(res), trim(tgt)) # check derivation with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = herm.hermder(herm.hermint(tgt, m=j, scl=2), m=j, scl=.5) assert_almost_equal(trim(res), trim(tgt)) @@ -399,10 +399,10 @@ class TestFitting(TestCase): assert_raises(TypeError, herm.hermfit, [1, 2], [1], 0) assert_raises(TypeError, herm.hermfit, [1], [1, 2], 0) assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[[1]]) - assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[1,1]) + assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[1, 1]) # Test fit - x = np.linspace(0,2) + x = np.linspace(0, 2) y = f(x) # coef3 = herm.hermfit(x, y, 3) @@ -413,8 +413,8 @@ class TestFitting(TestCase): assert_equal(len(coef4), 5) assert_almost_equal(herm.hermval(x, coef4), y) # - coef2d = herm.hermfit(x, np.array([y,y]).T, 3) - assert_almost_equal(coef2d, np.array([coef3,coef3]).T) + coef2d = herm.hermfit(x, np.array([y, y]).T, 3) + assert_almost_equal(coef2d, np.array([coef3, coef3]).T) # test weighting w = np.zeros_like(x) yw = y.copy() @@ -423,8 +423,8 @@ class TestFitting(TestCase): wcoef3 = herm.hermfit(x, yw, 3, w=w) assert_almost_equal(wcoef3, coef3) # - wcoef2d = herm.hermfit(x, np.array([yw,yw]).T, 3, w=w) - assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) + wcoef2d = herm.hermfit(x, np.array([yw, yw]).T, 3, w=w) + assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T) # test scaling with complex values x points whose square # is zero when summed. x = [1, 1j, -1, -1j] @@ -457,7 +457,7 @@ class TestGauss(TestCase): v = herm.hermvander(x, 99) vv = np.dot(v.T * w, v) vd = 1/np.sqrt(vv.diagonal()) - vv = vd[:,None] * vv * vd + vv = vd[:, None] * vv * vd assert_almost_equal(vv, np.eye(100)) # check that the integral of 1 is correct @@ -470,7 +470,7 @@ class TestMisc(TestCase) : def test_hermfromroots(self) : res = herm.hermfromroots([]) assert_almost_equal(trim(res), [1]) - for i in range(1,5) : + for i in range(1, 5) : roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2]) pol = herm.hermfromroots(roots) res = herm.hermval(roots, pol) @@ -482,7 +482,7 @@ class TestMisc(TestCase) : def test_hermroots(self) : assert_almost_equal(herm.hermroots([1]), []) assert_almost_equal(herm.hermroots([1, 1]), [-.5]) - for i in range(2,5) : + for i in range(2, 5) : tgt = np.linspace(-1, 1, i) res = herm.hermroots(herm.hermfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt)) @@ -499,7 +499,7 @@ class TestMisc(TestCase) : assert_equal(herm.hermtrim(coef, 2), [0]) def test_hermline(self) : - assert_equal(herm.hermline(3,4), [3, 2]) + assert_equal(herm.hermline(3, 4), [3, 2]) def test_herm2poly(self) : for i in range(10) : diff --git a/numpy/polynomial/tests/test_hermite_e.py b/numpy/polynomial/tests/test_hermite_e.py index 404a46fc7..b27e8576b 100644 --- a/numpy/polynomial/tests/test_hermite_e.py +++ b/numpy/polynomial/tests/test_hermite_e.py @@ -9,15 +9,15 @@ from numpy.polynomial.polynomial import polyval from numpy.testing import * He0 = np.array([ 1 ]) -He1 = np.array([ 0 , 1 ]) -He2 = np.array([ -1 ,0 , 1 ]) -He3 = np.array([ 0 , -3 ,0 , 1 ]) -He4 = np.array([ 3 ,0 , -6 ,0 , 1 ]) -He5 = np.array([ 0 , 15 ,0 , -10 ,0 , 1 ]) -He6 = np.array([ -15 ,0 , 45 ,0 , -15 ,0 , 1 ]) -He7 = np.array([ 0 , -105 ,0 , 105 ,0 , -21 ,0 , 1 ]) -He8 = np.array([ 105 ,0 , -420 ,0 , 210 ,0 , -28 ,0 , 1 ]) -He9 = np.array([ 0 , 945 ,0 , -1260 ,0 , 378 ,0 , -36 ,0 , 1 ]) +He1 = np.array([ 0, 1 ]) +He2 = np.array([ -1, 0, 1 ]) +He3 = np.array([ 0, -3, 0, 1 ]) +He4 = np.array([ 3, 0, -6, 0, 1 ]) +He5 = np.array([ 0, 15, 0, -10, 0, 1 ]) +He6 = np.array([ -15, 0, 45, 0, -15, 0, 1 ]) +He7 = np.array([ 0, -105, 0, 105, 0, -21, 0, 1 ]) +He8 = np.array([ 105, 0, -420, 0, 210, 0, -28, 0, 1 ]) +He9 = np.array([ 0, 945, 0, -1260, 0, 378, 0, -36, 0, 1 ]) Helist = [He0, He1, He2, He3, He4, He5, He6, He7, He8, He9] @@ -46,8 +46,8 @@ class TestArithmetic(TestCase) : def test_hermeadd(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] += 1 res = herme.hermeadd([0]*i + [1], [0]*j + [1]) @@ -56,8 +56,8 @@ class TestArithmetic(TestCase) : def test_hermesub(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] -= 1 res = herme.hermesub([0]*i + [1], [0]*j + [1]) @@ -65,7 +65,7 @@ class TestArithmetic(TestCase) : def test_hermemulx(self): assert_equal(herme.hermemulx([0]), [0]) - assert_equal(herme.hermemulx([1]), [0,1]) + assert_equal(herme.hermemulx([1]), [0, 1]) for i in range(1, 5): ser = [0]*i + [1] tgt = [0]*(i - 1) + [i, 0, 1] @@ -77,7 +77,7 @@ class TestArithmetic(TestCase) : pol1 = [0]*i + [1] val1 = herme.hermeval(self.x, pol1) for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) pol2 = [0]*j + [1] val2 = herme.hermeval(self.x, pol2) pol3 = herme.hermemul(pol1, pol2) @@ -88,7 +88,7 @@ class TestArithmetic(TestCase) : def test_hermediv(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1] cj = [0]*j + [1] tgt = herme.hermeadd(ci, cj) @@ -113,7 +113,7 @@ class TestEvaluation(TestCase) : assert_equal(herme.hermeval([], [1]).size, 0) #check normal input) - x = np.linspace(-1,1) + x = np.linspace(-1, 1) y = [polyval(x, c) for c in Helist] for i in range(10) : msg = "At i=%d" % i @@ -127,8 +127,8 @@ class TestEvaluation(TestCase) : dims = [2]*i x = np.zeros(dims) assert_equal(herme.hermeval(x, [1]).shape, dims) - assert_equal(herme.hermeval(x, [1,0]).shape, dims) - assert_equal(herme.hermeval(x, [1,0,0]).shape, dims) + assert_equal(herme.hermeval(x, [1, 0]).shape, dims) + assert_equal(herme.hermeval(x, [1, 0, 0]).shape, dims) def test_hermeval2d(self): x1, x2, x3 = self.x @@ -143,9 +143,9 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = herme.hermeval2d(z, z, self.c2d) - assert_(res.shape == (2,3)) + assert_(res.shape == (2, 3)) def test_hermeval3d(self): x1, x2, x3 = self.x @@ -160,9 +160,9 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = herme.hermeval3d(z, z, z, self.c3d) - assert_(res.shape == (2,3)) + assert_(res.shape == (2, 3)) def test_hermegrid2d(self): x1, x2, x3 = self.x @@ -174,7 +174,7 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = herme.hermegrid2d(z, z, self.c2d) assert_(res.shape == (2, 3)*2) @@ -188,7 +188,7 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = herme.hermegrid3d(z, z, z, self.c3d) assert_(res.shape == (2, 3)*3) @@ -199,7 +199,7 @@ class TestIntegral(TestCase): # check exceptions assert_raises(ValueError, herme.hermeint, [0], .5) assert_raises(ValueError, herme.hermeint, [0], -1) - assert_raises(ValueError, herme.hermeint, [0], 1, [0,0]) + assert_raises(ValueError, herme.hermeint, [0], 1, [0, 0]) # test integration of zero polynomial for i in range(2, 5): @@ -237,7 +237,7 @@ class TestIntegral(TestCase): # check multiple integrations with default k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -247,7 +247,7 @@ class TestIntegral(TestCase): # check multiple integrations with defined k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -257,7 +257,7 @@ class TestIntegral(TestCase): # check multiple integrations with lbnd for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -267,7 +267,7 @@ class TestIntegral(TestCase): # check multiple integrations with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -307,14 +307,14 @@ class TestDerivative(TestCase) : # check that derivation is the inverse of integration for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = herme.hermeder(herme.hermeint(tgt, m=j), m=j) assert_almost_equal(trim(res), trim(tgt)) # check derivation with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = herme.hermeder(herme.hermeint(tgt, m=j, scl=2), m=j, scl=.5) assert_almost_equal(trim(res), trim(tgt)) @@ -396,10 +396,10 @@ class TestFitting(TestCase): assert_raises(TypeError, herme.hermefit, [1, 2], [1], 0) assert_raises(TypeError, herme.hermefit, [1], [1, 2], 0) assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[[1]]) - assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[1,1]) + assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[1, 1]) # Test fit - x = np.linspace(0,2) + x = np.linspace(0, 2) y = f(x) # coef3 = herme.hermefit(x, y, 3) @@ -410,8 +410,8 @@ class TestFitting(TestCase): assert_equal(len(coef4), 5) assert_almost_equal(herme.hermeval(x, coef4), y) # - coef2d = herme.hermefit(x, np.array([y,y]).T, 3) - assert_almost_equal(coef2d, np.array([coef3,coef3]).T) + coef2d = herme.hermefit(x, np.array([y, y]).T, 3) + assert_almost_equal(coef2d, np.array([coef3, coef3]).T) # test weighting w = np.zeros_like(x) yw = y.copy() @@ -420,8 +420,8 @@ class TestFitting(TestCase): wcoef3 = herme.hermefit(x, yw, 3, w=w) assert_almost_equal(wcoef3, coef3) # - wcoef2d = herme.hermefit(x, np.array([yw,yw]).T, 3, w=w) - assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) + wcoef2d = herme.hermefit(x, np.array([yw, yw]).T, 3, w=w) + assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T) # test scaling with complex values x points whose square # is zero when summed. x = [1, 1j, -1, -1j] @@ -454,7 +454,7 @@ class TestGauss(TestCase): v = herme.hermevander(x, 99) vv = np.dot(v.T * w, v) vd = 1/np.sqrt(vv.diagonal()) - vv = vd[:,None] * vv * vd + vv = vd[:, None] * vv * vd assert_almost_equal(vv, np.eye(100)) # check that the integral of 1 is correct @@ -467,7 +467,7 @@ class TestMisc(TestCase) : def test_hermefromroots(self) : res = herme.hermefromroots([]) assert_almost_equal(trim(res), [1]) - for i in range(1,5) : + for i in range(1, 5) : roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2]) pol = herme.hermefromroots(roots) res = herme.hermeval(roots, pol) @@ -479,7 +479,7 @@ class TestMisc(TestCase) : def test_hermeroots(self) : assert_almost_equal(herme.hermeroots([1]), []) assert_almost_equal(herme.hermeroots([1, 1]), [-1]) - for i in range(2,5) : + for i in range(2, 5) : tgt = np.linspace(-1, 1, i) res = herme.hermeroots(herme.hermefromroots(tgt)) assert_almost_equal(trim(res), trim(tgt)) @@ -496,7 +496,7 @@ class TestMisc(TestCase) : assert_equal(herme.hermetrim(coef, 2), [0]) def test_hermeline(self) : - assert_equal(herme.hermeline(3,4), [3, 4]) + assert_equal(herme.hermeline(3, 4), [3, 4]) def test_herme2poly(self) : for i in range(10) : diff --git a/numpy/polynomial/tests/test_laguerre.py b/numpy/polynomial/tests/test_laguerre.py index 38fcce299..d42bac67c 100644 --- a/numpy/polynomial/tests/test_laguerre.py +++ b/numpy/polynomial/tests/test_laguerre.py @@ -11,12 +11,12 @@ from numpy.testing import ( assert_equal, assert_, run_module_suite) L0 = np.array([1 ])/1 -L1 = np.array([1 , -1 ])/1 -L2 = np.array([2 , -4 , 1 ])/2 -L3 = np.array([6 , -18 , 9 , -1 ])/6 -L4 = np.array([24 , -96 , 72 , -16 , 1 ])/24 -L5 = np.array([120 , -600 , 600 , -200 , 25 , -1 ])/120 -L6 = np.array([720 , -4320 , 5400 , -2400 , 450 , -36 , 1 ])/720 +L1 = np.array([1, -1 ])/1 +L2 = np.array([2, -4, 1 ])/2 +L3 = np.array([6, -18, 9, -1 ])/6 +L4 = np.array([24, -96, 72, -16, 1 ])/24 +L5 = np.array([120, -600, 600, -200, 25, -1 ])/120 +L6 = np.array([720, -4320, 5400, -2400, 450, -36, 1 ])/720 Llist = [L0, L1, L2, L3, L4, L5, L6] @@ -45,8 +45,8 @@ class TestArithmetic(TestCase) : def test_lagadd(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] += 1 res = lag.lagadd([0]*i + [1], [0]*j + [1]) @@ -55,8 +55,8 @@ class TestArithmetic(TestCase) : def test_lagsub(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] -= 1 res = lag.lagsub([0]*i + [1], [0]*j + [1]) @@ -64,7 +64,7 @@ class TestArithmetic(TestCase) : def test_lagmulx(self): assert_equal(lag.lagmulx([0]), [0]) - assert_equal(lag.lagmulx([1]), [1,-1]) + assert_equal(lag.lagmulx([1]), [1, -1]) for i in range(1, 5): ser = [0]*i + [1] tgt = [0]*(i - 1) + [-i, 2*i + 1, -(i + 1)] @@ -76,7 +76,7 @@ class TestArithmetic(TestCase) : pol1 = [0]*i + [1] val1 = lag.lagval(self.x, pol1) for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) pol2 = [0]*j + [1] val2 = lag.lagval(self.x, pol2) pol3 = lag.lagmul(pol1, pol2) @@ -87,7 +87,7 @@ class TestArithmetic(TestCase) : def test_lagdiv(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1] cj = [0]*j + [1] tgt = lag.lagadd(ci, cj) @@ -111,7 +111,7 @@ class TestEvaluation(TestCase) : assert_equal(lag.lagval([], [1]).size, 0) #check normal input) - x = np.linspace(-1,1) + x = np.linspace(-1, 1) y = [polyval(x, c) for c in Llist] for i in range(7) : msg = "At i=%d" % i @@ -125,8 +125,8 @@ class TestEvaluation(TestCase) : dims = [2]*i x = np.zeros(dims) assert_equal(lag.lagval(x, [1]).shape, dims) - assert_equal(lag.lagval(x, [1,0]).shape, dims) - assert_equal(lag.lagval(x, [1,0,0]).shape, dims) + assert_equal(lag.lagval(x, [1, 0]).shape, dims) + assert_equal(lag.lagval(x, [1, 0, 0]).shape, dims) def test_lagval2d(self): x1, x2, x3 = self.x @@ -141,9 +141,9 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = lag.lagval2d(z, z, self.c2d) - assert_(res.shape == (2,3)) + assert_(res.shape == (2, 3)) def test_lagval3d(self): x1, x2, x3 = self.x @@ -158,9 +158,9 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = lag.lagval3d(z, z, z, self.c3d) - assert_(res.shape == (2,3)) + assert_(res.shape == (2, 3)) def test_laggrid2d(self): x1, x2, x3 = self.x @@ -172,7 +172,7 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = lag.laggrid2d(z, z, self.c2d) assert_(res.shape == (2, 3)*2) @@ -186,7 +186,7 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = lag.laggrid3d(z, z, z, self.c3d) assert_(res.shape == (2, 3)*3) @@ -197,7 +197,7 @@ class TestIntegral(TestCase) : # check exceptions assert_raises(ValueError, lag.lagint, [0], .5) assert_raises(ValueError, lag.lagint, [0], -1) - assert_raises(ValueError, lag.lagint, [0], 1, [0,0]) + assert_raises(ValueError, lag.lagint, [0], 1, [0, 0]) # test integration of zero polynomial for i in range(2, 5): @@ -235,7 +235,7 @@ class TestIntegral(TestCase) : # check multiple integrations with default k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -245,7 +245,7 @@ class TestIntegral(TestCase) : # check multiple integrations with defined k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -255,7 +255,7 @@ class TestIntegral(TestCase) : # check multiple integrations with lbnd for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -265,7 +265,7 @@ class TestIntegral(TestCase) : # check multiple integrations with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -305,14 +305,14 @@ class TestDerivative(TestCase) : # check that derivation is the inverse of integration for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = lag.lagder(lag.lagint(tgt, m=j), m=j) assert_almost_equal(trim(res), trim(tgt)) # check derivation with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = lag.lagder(lag.lagint(tgt, m=j, scl=2), m=j, scl=.5) assert_almost_equal(trim(res), trim(tgt)) @@ -394,10 +394,10 @@ class TestFitting(TestCase): assert_raises(TypeError, lag.lagfit, [1, 2], [1], 0) assert_raises(TypeError, lag.lagfit, [1], [1, 2], 0) assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[[1]]) - assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[1,1]) + assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[1, 1]) # Test fit - x = np.linspace(0,2) + x = np.linspace(0, 2) y = f(x) # coef3 = lag.lagfit(x, y, 3) @@ -408,8 +408,8 @@ class TestFitting(TestCase): assert_equal(len(coef4), 5) assert_almost_equal(lag.lagval(x, coef4), y) # - coef2d = lag.lagfit(x, np.array([y,y]).T, 3) - assert_almost_equal(coef2d, np.array([coef3,coef3]).T) + coef2d = lag.lagfit(x, np.array([y, y]).T, 3) + assert_almost_equal(coef2d, np.array([coef3, coef3]).T) # test weighting w = np.zeros_like(x) yw = y.copy() @@ -418,8 +418,8 @@ class TestFitting(TestCase): wcoef3 = lag.lagfit(x, yw, 3, w=w) assert_almost_equal(wcoef3, coef3) # - wcoef2d = lag.lagfit(x, np.array([yw,yw]).T, 3, w=w) - assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) + wcoef2d = lag.lagfit(x, np.array([yw, yw]).T, 3, w=w) + assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T) # test scaling with complex values x points whose square # is zero when summed. x = [1, 1j, -1, -1j] @@ -452,7 +452,7 @@ class TestGauss(TestCase): v = lag.lagvander(x, 99) vv = np.dot(v.T * w, v) vd = 1/np.sqrt(vv.diagonal()) - vv = vd[:,None] * vv * vd + vv = vd[:, None] * vv * vd assert_almost_equal(vv, np.eye(100)) # check that the integral of 1 is correct @@ -465,7 +465,7 @@ class TestMisc(TestCase) : def test_lagfromroots(self) : res = lag.lagfromroots([]) assert_almost_equal(trim(res), [1]) - for i in range(1,5) : + for i in range(1, 5) : roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2]) pol = lag.lagfromroots(roots) res = lag.lagval(roots, pol) @@ -477,7 +477,7 @@ class TestMisc(TestCase) : def test_lagroots(self) : assert_almost_equal(lag.lagroots([1]), []) assert_almost_equal(lag.lagroots([0, 1]), [1]) - for i in range(2,5) : + for i in range(2, 5) : tgt = np.linspace(0, 3, i) res = lag.lagroots(lag.lagfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt)) @@ -494,7 +494,7 @@ class TestMisc(TestCase) : assert_equal(lag.lagtrim(coef, 2), [0]) def test_lagline(self) : - assert_equal(lag.lagline(3,4), [7, -4]) + assert_equal(lag.lagline(3, 4), [7, -4]) def test_lag2poly(self) : for i in range(7) : diff --git a/numpy/polynomial/tests/test_legendre.py b/numpy/polynomial/tests/test_legendre.py index 379bdee31..ae7a85851 100644 --- a/numpy/polynomial/tests/test_legendre.py +++ b/numpy/polynomial/tests/test_legendre.py @@ -16,10 +16,10 @@ L2 = np.array([-1, 0, 3])/2 L3 = np.array([ 0, -3, 0, 5])/2 L4 = np.array([ 3, 0, -30, 0, 35])/8 L5 = np.array([ 0, 15, 0, -70, 0, 63])/8 -L6 = np.array([-5, 0, 105, 0,-315, 0, 231])/16 -L7 = np.array([ 0,-35, 0, 315, 0, -693, 0, 429])/16 -L8 = np.array([35, 0,-1260, 0,6930, 0,-12012, 0,6435])/128 -L9 = np.array([ 0,315, 0,-4620, 0,18018, 0,-25740, 0,12155])/128 +L6 = np.array([-5, 0, 105, 0, -315, 0, 231])/16 +L7 = np.array([ 0, -35, 0, 315, 0, -693, 0, 429])/16 +L8 = np.array([35, 0, -1260, 0, 6930, 0, -12012, 0, 6435])/128 +L9 = np.array([ 0, 315, 0, -4620, 0, 18018, 0, -25740, 0, 12155])/128 Llist = [L0, L1, L2, L3, L4, L5, L6, L7, L8, L9] @@ -48,8 +48,8 @@ class TestArithmetic(TestCase) : def test_legadd(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] += 1 res = leg.legadd([0]*i + [1], [0]*j + [1]) @@ -58,8 +58,8 @@ class TestArithmetic(TestCase) : def test_legsub(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] -= 1 res = leg.legsub([0]*i + [1], [0]*j + [1]) @@ -67,7 +67,7 @@ class TestArithmetic(TestCase) : def test_legmulx(self): assert_equal(leg.legmulx([0]), [0]) - assert_equal(leg.legmulx([1]), [0,1]) + assert_equal(leg.legmulx([1]), [0, 1]) for i in range(1, 5): tmp = 2*i + 1 ser = [0]*i + [1] @@ -80,7 +80,7 @@ class TestArithmetic(TestCase) : pol1 = [0]*i + [1] val1 = leg.legval(self.x, pol1) for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) pol2 = [0]*j + [1] val2 = leg.legval(self.x, pol2) pol3 = leg.legmul(pol1, pol2) @@ -91,7 +91,7 @@ class TestArithmetic(TestCase) : def test_legdiv(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1] cj = [0]*j + [1] tgt = leg.legadd(ci, cj) @@ -115,7 +115,7 @@ class TestEvaluation(TestCase) : assert_equal(leg.legval([], [1]).size, 0) #check normal input) - x = np.linspace(-1,1) + x = np.linspace(-1, 1) y = [polyval(x, c) for c in Llist] for i in range(10) : msg = "At i=%d" % i @@ -129,8 +129,8 @@ class TestEvaluation(TestCase) : dims = [2]*i x = np.zeros(dims) assert_equal(leg.legval(x, [1]).shape, dims) - assert_equal(leg.legval(x, [1,0]).shape, dims) - assert_equal(leg.legval(x, [1,0,0]).shape, dims) + assert_equal(leg.legval(x, [1, 0]).shape, dims) + assert_equal(leg.legval(x, [1, 0, 0]).shape, dims) def test_legval2d(self): x1, x2, x3 = self.x @@ -145,9 +145,9 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = leg.legval2d(z, z, self.c2d) - assert_(res.shape == (2,3)) + assert_(res.shape == (2, 3)) def test_legval3d(self): x1, x2, x3 = self.x @@ -162,7 +162,7 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = leg.legval3d(z, z, z, self.c3d) assert_(res.shape == (2, 3)) @@ -176,7 +176,7 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = leg.leggrid2d(z, z, self.c2d) assert_(res.shape == (2, 3)*2) @@ -190,7 +190,7 @@ class TestEvaluation(TestCase) : assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = leg.leggrid3d(z, z, z, self.c3d) assert_(res.shape == (2, 3)*3) @@ -201,7 +201,7 @@ class TestIntegral(TestCase) : # check exceptions assert_raises(ValueError, leg.legint, [0], .5) assert_raises(ValueError, leg.legint, [0], -1) - assert_raises(ValueError, leg.legint, [0], 1, [0,0]) + assert_raises(ValueError, leg.legint, [0], 1, [0, 0]) # test integration of zero polynomial for i in range(2, 5): @@ -239,7 +239,7 @@ class TestIntegral(TestCase) : # check multiple integrations with default k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -249,7 +249,7 @@ class TestIntegral(TestCase) : # check multiple integrations with defined k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -259,7 +259,7 @@ class TestIntegral(TestCase) : # check multiple integrations with lbnd for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -269,7 +269,7 @@ class TestIntegral(TestCase) : # check multiple integrations with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -309,14 +309,14 @@ class TestDerivative(TestCase) : # check that derivation is the inverse of integration for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = leg.legder(leg.legint(tgt, m=j), m=j) assert_almost_equal(trim(res), trim(tgt)) # check derivation with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = leg.legder(leg.legint(tgt, m=j, scl=2), m=j, scl=.5) assert_almost_equal(trim(res), trim(tgt)) @@ -397,10 +397,10 @@ class TestFitting(TestCase): assert_raises(TypeError, leg.legfit, [1, 2], [1], 0) assert_raises(TypeError, leg.legfit, [1], [1, 2], 0) assert_raises(TypeError, leg.legfit, [1], [1], 0, w=[[1]]) - assert_raises(TypeError, leg.legfit, [1], [1], 0, w=[1,1]) + assert_raises(TypeError, leg.legfit, [1], [1], 0, w=[1, 1]) # Test fit - x = np.linspace(0,2) + x = np.linspace(0, 2) y = f(x) # coef3 = leg.legfit(x, y, 3) @@ -411,8 +411,8 @@ class TestFitting(TestCase): assert_equal(len(coef4), 5) assert_almost_equal(leg.legval(x, coef4), y) # - coef2d = leg.legfit(x, np.array([y,y]).T, 3) - assert_almost_equal(coef2d, np.array([coef3,coef3]).T) + coef2d = leg.legfit(x, np.array([y, y]).T, 3) + assert_almost_equal(coef2d, np.array([coef3, coef3]).T) # test weighting w = np.zeros_like(x) yw = y.copy() @@ -421,8 +421,8 @@ class TestFitting(TestCase): wcoef3 = leg.legfit(x, yw, 3, w=w) assert_almost_equal(wcoef3, coef3) # - wcoef2d = leg.legfit(x, np.array([yw,yw]).T, 3, w=w) - assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) + wcoef2d = leg.legfit(x, np.array([yw, yw]).T, 3, w=w) + assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T) # test scaling with complex values x points whose square # is zero when summed. x = [1, 1j, -1, -1j] @@ -455,7 +455,7 @@ class TestGauss(TestCase): v = leg.legvander(x, 99) vv = np.dot(v.T * w, v) vd = 1/np.sqrt(vv.diagonal()) - vv = vd[:,None] * vv * vd + vv = vd[:, None] * vv * vd assert_almost_equal(vv, np.eye(100)) # check that the integral of 1 is correct @@ -468,7 +468,7 @@ class TestMisc(TestCase) : def test_legfromroots(self) : res = leg.legfromroots([]) assert_almost_equal(trim(res), [1]) - for i in range(1,5) : + for i in range(1, 5) : roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2]) pol = leg.legfromroots(roots) res = leg.legval(roots, pol) @@ -480,7 +480,7 @@ class TestMisc(TestCase) : def test_legroots(self) : assert_almost_equal(leg.legroots([1]), []) assert_almost_equal(leg.legroots([1, 2]), [-.5]) - for i in range(2,5) : + for i in range(2, 5) : tgt = np.linspace(-1, 1, i) res = leg.legroots(leg.legfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt)) @@ -497,7 +497,7 @@ class TestMisc(TestCase) : assert_equal(leg.legtrim(coef, 2), [0]) def test_legline(self) : - assert_equal(leg.legline(3,4), [3, 4]) + assert_equal(leg.legline(3, 4), [3, 4]) def test_leg2poly(self) : for i in range(10) : diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py index 583872978..373045aae 100644 --- a/numpy/polynomial/tests/test_polynomial.py +++ b/numpy/polynomial/tests/test_polynomial.py @@ -46,8 +46,8 @@ class TestArithmetic(TestCase) : def test_polyadd(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] += 1 res = poly.polyadd([0]*i + [1], [0]*j + [1]) @@ -56,8 +56,8 @@ class TestArithmetic(TestCase) : def test_polysub(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - tgt = np.zeros(max(i,j) + 1) + msg = "At i=%d, j=%d" % (i, j) + tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] -= 1 res = poly.polysub([0]*i + [1], [0]*j + [1]) @@ -74,7 +74,7 @@ class TestArithmetic(TestCase) : def test_polymul(self) : for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) + msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) @@ -85,17 +85,17 @@ class TestArithmetic(TestCase) : assert_raises(ZeroDivisionError, poly.polydiv, [1], [0]) # check scalar division - quo, rem = poly.polydiv([2],[2]) + quo, rem = poly.polydiv([2], [2]) assert_equal((quo, rem), (1, 0)) - quo, rem = poly.polydiv([2,2],[2]) - assert_equal((quo, rem), ((1,1), 0)) + quo, rem = poly.polydiv([2, 2], [2]) + assert_equal((quo, rem), ((1, 1), 0)) # check rest. for i in range(5) : for j in range(5) : - msg = "At i=%d, j=%d" % (i,j) - ci = [0]*i + [1,2] - cj = [0]*j + [1,2] + msg = "At i=%d, j=%d" % (i, j) + ci = [0]*i + [1, 2] + cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) quo, rem = poly.polydiv(tgt, ci) res = poly.polyadd(poly.polymul(quo, ci), rem) @@ -118,7 +118,7 @@ class TestEvaluation(TestCase): assert_equal(poly.polyval([], [1]).size, 0) #check normal input) - x = np.linspace(-1,1) + x = np.linspace(-1, 1) y = [x**i for i in range(5)] for i in range(5) : tgt = y[i] @@ -133,8 +133,8 @@ class TestEvaluation(TestCase): dims = [2]*i x = np.zeros(dims) assert_equal(poly.polyval(x, [1]).shape, dims) - assert_equal(poly.polyval(x, [1,0]).shape, dims) - assert_equal(poly.polyval(x, [1,0,0]).shape, dims) + assert_equal(poly.polyval(x, [1, 0]).shape, dims) + assert_equal(poly.polyval(x, [1, 0, 0]).shape, dims) def test_polyval2d(self): x1, x2, x3 = self.x @@ -149,9 +149,9 @@ class TestEvaluation(TestCase): assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = poly.polyval2d(z, z, self.c2d) - assert_(res.shape == (2,3)) + assert_(res.shape == (2, 3)) def test_polyval3d(self): x1, x2, x3 = self.x @@ -166,7 +166,7 @@ class TestEvaluation(TestCase): assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = poly.polyval3d(z, z, z, self.c3d) assert_(res.shape == (2, 3)) @@ -180,7 +180,7 @@ class TestEvaluation(TestCase): assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = poly.polygrid2d(z, z, self.c2d) assert_(res.shape == (2, 3)*2) @@ -194,7 +194,7 @@ class TestEvaluation(TestCase): assert_almost_equal(res, tgt) #test shape - z = np.ones((2,3)) + z = np.ones((2, 3)) res = poly.polygrid3d(z, z, z, self.c3d) assert_(res.shape == (2, 3)*3) @@ -205,7 +205,7 @@ class TestIntegral(TestCase): # check exceptions assert_raises(ValueError, poly.polyint, [0], .5) assert_raises(ValueError, poly.polyint, [0], -1) - assert_raises(ValueError, poly.polyint, [0], 1, [0,0]) + assert_raises(ValueError, poly.polyint, [0], 1, [0, 0]) # test integration of zero polynomial for i in range(2, 5): @@ -238,7 +238,7 @@ class TestIntegral(TestCase): # check multiple integrations with default k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -248,7 +248,7 @@ class TestIntegral(TestCase): # check multiple integrations with defined k for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -258,7 +258,7 @@ class TestIntegral(TestCase): # check multiple integrations with lbnd for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -268,7 +268,7 @@ class TestIntegral(TestCase): # check multiple integrations with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : pol = [0]*i + [1] tgt = pol[:] for k in range(j) : @@ -308,14 +308,14 @@ class TestDerivative(TestCase) : # check that derivation is the inverse of integration for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = poly.polyder(poly.polyint(tgt, m=j), m=j) assert_almost_equal(trim(res), trim(tgt)) # check derivation with scaling for i in range(5) : - for j in range(2,5) : + for j in range(2, 5) : tgt = [0]*i + [1] res = poly.polyder(poly.polyint(tgt, m=j, scl=2), m=j, scl=.5) assert_almost_equal(trim(res), trim(tgt)) @@ -403,16 +403,16 @@ class TestMisc(TestCase) : def test_polyfromroots(self) : res = poly.polyfromroots([]) assert_almost_equal(trim(res), [1]) - for i in range(1,5) : + for i in range(1, 5) : roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2]) tgt = Tlist[i] res = poly.polyfromroots(roots)*2**(i-1) - assert_almost_equal(trim(res),trim(tgt)) + assert_almost_equal(trim(res), trim(tgt)) def test_polyroots(self) : assert_almost_equal(poly.polyroots([1]), []) assert_almost_equal(poly.polyroots([1, 2]), [-.5]) - for i in range(2,5) : + for i in range(2, 5) : tgt = np.linspace(-1, 1, i) res = poly.polyroots(poly.polyfromroots(tgt)) assert_almost_equal(trim(res), trim(tgt)) @@ -429,10 +429,10 @@ class TestMisc(TestCase) : assert_raises(TypeError, poly.polyfit, [1, 2], [1], 0) assert_raises(TypeError, poly.polyfit, [1], [1, 2], 0) assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[[1]]) - assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[1,1]) + assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[1, 1]) # Test fit - x = np.linspace(0,2) + x = np.linspace(0, 2) y = f(x) # coef3 = poly.polyfit(x, y, 3) @@ -443,8 +443,8 @@ class TestMisc(TestCase) : assert_equal(len(coef4), 5) assert_almost_equal(poly.polyval(x, coef4), y) # - coef2d = poly.polyfit(x, np.array([y,y]).T, 3) - assert_almost_equal(coef2d, np.array([coef3,coef3]).T) + coef2d = poly.polyfit(x, np.array([y, y]).T, 3) + assert_almost_equal(coef2d, np.array([coef3, coef3]).T) # test weighting w = np.zeros_like(x) yw = y.copy() @@ -453,8 +453,8 @@ class TestMisc(TestCase) : wcoef3 = poly.polyfit(x, yw, 3, w=w) assert_almost_equal(wcoef3, coef3) # - wcoef2d = poly.polyfit(x, np.array([yw,yw]).T, 3, w=w) - assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T) + wcoef2d = poly.polyfit(x, np.array([yw, yw]).T, 3, w=w) + assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T) # test scaling with complex values x points whose square # is zero when summed. x = [1, 1j, -1, -1j] @@ -473,7 +473,7 @@ class TestMisc(TestCase) : assert_equal(poly.polytrim(coef, 2), [0]) def test_polyline(self) : - assert_equal(poly.polyline(3,4), [3, 4]) + assert_equal(poly.polyline(3, 4), [3, 4]) if __name__ == "__main__": diff --git a/numpy/polynomial/tests/test_polyutils.py b/numpy/polynomial/tests/test_polyutils.py index 93c742abd..11b37aa1a 100644 --- a/numpy/polynomial/tests/test_polyutils.py +++ b/numpy/polynomial/tests/test_polyutils.py @@ -18,8 +18,8 @@ class TestMisc(TestCase) : def test_as_series(self) : # check exceptions assert_raises(ValueError, pu.as_series, [[]]) - assert_raises(ValueError, pu.as_series, [[[1,2]]]) - assert_raises(ValueError, pu.as_series, [[1],['a']]) + assert_raises(ValueError, pu.as_series, [[[1, 2]]]) + assert_raises(ValueError, pu.as_series, [[1], ['a']]) # check common types types = ['i', 'd', 'O'] for i in range(len(types)) : @@ -45,7 +45,7 @@ class TestDomain(TestCase) : def test_getdomain(self) : # test for real values x = [1, 10, 3, -1] - tgt = [-1,10] + tgt = [-1, 10] res = pu.getdomain(x) assert_almost_equal(res, tgt) @@ -57,8 +57,8 @@ class TestDomain(TestCase) : def test_mapdomain(self) : # test for real values - dom1 = [0,4] - dom2 = [1,3] + dom1 = [0, 4] + dom2 = [1, 3] tgt = dom2 res = pu. mapdomain(dom1, dom1, dom2) assert_almost_equal(res, tgt) @@ -72,24 +72,24 @@ class TestDomain(TestCase) : assert_almost_equal(res, tgt) # test for multidimensional arrays - dom1 = [0,4] - dom2 = [1,3] + dom1 = [0, 4] + dom2 = [1, 3] tgt = np.array([dom2, dom2]) x = np.array([dom1, dom1]) res = pu.mapdomain(x, dom1, dom2) assert_almost_equal(res, tgt) # test that subtypes are preserved. - dom1 = [0,4] - dom2 = [1,3] + dom1 = [0, 4] + dom2 = [1, 3] x = np.matrix([dom1, dom1]) res = pu.mapdomain(x, dom1, dom2) assert_(isinstance(res, np.matrix)) def test_mapparms(self) : # test for real values - dom1 = [0,4] - dom2 = [1,3] + dom1 = [0, 4] + dom2 = [1, 3] tgt = [1, .5] res = pu. mapparms(dom1, dom2) assert_almost_equal(res, tgt) diff --git a/numpy/polynomial/tests/test_printing.py b/numpy/polynomial/tests/test_printing.py index 96a2ea7d4..883597cb9 100644 --- a/numpy/polynomial/tests/test_printing.py +++ b/numpy/polynomial/tests/test_printing.py @@ -5,74 +5,74 @@ from numpy.testing import TestCase, run_module_suite, assert_ class test_str(TestCase): def test_polynomial_str(self): - res = str(poly.Polynomial([0,1])) + res = str(poly.Polynomial([0, 1])) tgt = 'poly([0., 1.])' assert_(res, tgt) def test_chebyshev_str(self): - res = str(poly.Chebyshev([0,1])) + res = str(poly.Chebyshev([0, 1])) tgt = 'leg([0., 1.])' assert_(res, tgt) def test_legendre_str(self): - res = str(poly.Legendre([0,1])) + res = str(poly.Legendre([0, 1])) tgt = 'leg([0., 1.])' assert_(res, tgt) def test_hermite_str(self): - res = str(poly.Hermite([0,1])) + res = str(poly.Hermite([0, 1])) tgt = 'herm([0., 1.])' assert_(res, tgt) def test_hermiteE_str(self): - res = str(poly.HermiteE([0,1])) + res = str(poly.HermiteE([0, 1])) tgt = 'herme([0., 1.])' assert_(res, tgt) def test_laguerre_str(self): - res = str(poly.Laguerre([0,1])) + res = str(poly.Laguerre([0, 1])) tgt = 'lag([0., 1.])' assert_(res, tgt) class test_repr(TestCase): def test_polynomial_str(self): - res = repr(poly.Polynomial([0,1])) + res = repr(poly.Polynomial([0, 1])) tgt = 'Polynomial([0., 1.])' assert_(res, tgt) def test_chebyshev_str(self): - res = repr(poly.Chebyshev([0,1])) + res = repr(poly.Chebyshev([0, 1])) tgt = 'Chebyshev([0., 1.], [-1., 1.], [-1., 1.])' assert_(res, tgt) def test_legendre_repr(self): - res = repr(poly.Legendre([0,1])) + res = repr(poly.Legendre([0, 1])) tgt = 'Legendre([0., 1.], [-1., 1.], [-1., 1.])' assert_(res, tgt) def test_hermite_repr(self): - res = repr(poly.Hermite([0,1])) + res = repr(poly.Hermite([0, 1])) tgt = 'Hermite([0., 1.], [-1., 1.], [-1., 1.])' assert_(res, tgt) def test_hermiteE_repr(self): - res = repr(poly.HermiteE([0,1])) + res = repr(poly.HermiteE([0, 1])) tgt = 'HermiteE([0., 1.], [-1., 1.], [-1., 1.])' assert_(res, tgt) def test_laguerre_repr(self): - res = repr(poly.Laguerre([0,1])) + res = repr(poly.Laguerre([0, 1])) tgt = 'Laguerre([0., 1.], [0., 1.], [0., 1.])' assert_(res, tgt) |