diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-08-18 11:51:25 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-08-18 11:51:25 -0600 |
commit | fbd6510d58a47ea0d166c48a82793f05425406e4 (patch) | |
tree | 330ce703eb02d20f96099c3fe0fc36ae33d4905b /numpy/polynomial | |
parent | 8ddb0ce0acafe75d78df528b4d2540dfbf4b364d (diff) | |
download | numpy-fbd6510d58a47ea0d166c48a82793f05425406e4.tar.gz |
STY: Giant comma spacing fixup.
Run the 2to3 ws_comma fixer on *.py files. Some lines are now too long
and will need to be broken at some point. OTOH, some lines were already
too long and need to be broken at some point. Now seems as good a time
as any to do this with open PRs at a minimum.
Diffstat (limited to 'numpy/polynomial')
-rw-r--r-- | numpy/polynomial/chebyshev.py | 14 | ||||
-rw-r--r-- | numpy/polynomial/hermite.py | 14 | ||||
-rw-r--r-- | numpy/polynomial/hermite_e.py | 14 | ||||
-rw-r--r-- | numpy/polynomial/laguerre.py | 10 | ||||
-rw-r--r-- | numpy/polynomial/legendre.py | 14 | ||||
-rw-r--r-- | numpy/polynomial/polynomial.py | 16 | ||||
-rw-r--r-- | numpy/polynomial/setup.py | 2 | ||||
-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 |
16 files changed, 288 insertions, 288 deletions
diff --git a/numpy/polynomial/chebyshev.py b/numpy/polynomial/chebyshev.py index db1b637fd..6a2394382 100644 --- a/numpy/polynomial/chebyshev.py +++ b/numpy/polynomial/chebyshev.py @@ -98,7 +98,7 @@ __all__ = ['chebzero', 'chebone', 'chebx', 'chebdomain', 'chebline', 'chebval', 'chebder', 'chebint', 'cheb2poly', 'poly2cheb', 'chebfromroots', 'chebvander', 'chebfit', 'chebtrim', 'chebroots', 'chebpts1', 'chebpts2', 'Chebyshev', 'chebval2d', 'chebval3d', - 'chebgrid2d', 'chebgrid3d', 'chebvander2d','chebvander3d', + 'chebgrid2d', 'chebgrid3d', 'chebvander2d', 'chebvander3d', 'chebcompanion', 'chebgauss', 'chebweight'] chebtrim = pu.trimcoef @@ -439,7 +439,7 @@ def cheb2poly(c) : # # Chebyshev default domain. -chebdomain = np.array([-1,1]) +chebdomain = np.array([-1, 1]) # Chebyshev coefficients representing zero. chebzero = np.array([0]) @@ -448,7 +448,7 @@ chebzero = np.array([0]) chebone = np.array([1]) # Chebyshev coefficients representing the identity x. -chebx = np.array([0,1]) +chebx = np.array([0, 1]) def chebline(off, scl) : @@ -482,7 +482,7 @@ def chebline(off, scl) : """ if scl != 0 : - return np.array([off,scl]) + return np.array([off, scl]) else : return np.array([off]) @@ -1523,7 +1523,7 @@ def chebvander2d(x, y, deg) : vx = chebvander(x, degx) vy = chebvander(y, degy) - v = vx[..., None]*vy[..., None, :] + v = vx[..., None]*vy[..., None,:] return v.reshape(v.shape[:-2] + (-1,)) @@ -1588,7 +1588,7 @@ def chebvander3d(x, y, z, deg) : vx = chebvander(x, degx) vy = chebvander(y, degy) vz = chebvander(z, degz) - v = vx[..., None, None]*vy[..., None, :, None]*vz[..., None, None, :] + v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:] return v.reshape(v.shape[:-3] + (-1,)) @@ -1805,7 +1805,7 @@ def chebcompanion(c): top[0] = np.sqrt(.5) top[1:] = 1/2 bot[...] = top - mat[:,-1] -= (c[:-1]/c[-1])*(scl/scl[-1])*.5 + mat[:, -1] -= (c[:-1]/c[-1])*(scl/scl[-1])*.5 return mat diff --git a/numpy/polynomial/hermite.py b/numpy/polynomial/hermite.py index 13b9e6845..4140acfb7 100644 --- a/numpy/polynomial/hermite.py +++ b/numpy/polynomial/hermite.py @@ -185,7 +185,7 @@ def herm2poly(c) : # # Hermite -hermdomain = np.array([-1,1]) +hermdomain = np.array([-1, 1]) # Hermite coefficients representing zero. hermzero = np.array([0]) @@ -228,7 +228,7 @@ def hermline(off, scl) : """ if scl != 0 : - return np.array([off,scl/2]) + return np.array([off, scl/2]) else : return np.array([off]) @@ -1295,7 +1295,7 @@ def hermvander2d(x, y, deg) : vx = hermvander(x, degx) vy = hermvander(y, degy) - v = vx[..., None]*vy[..., None, :] + v = vx[..., None]*vy[..., None,:] return v.reshape(v.shape[:-2] + (-1,)) @@ -1360,7 +1360,7 @@ def hermvander3d(x, y, z, deg) : vx = hermvander(x, degx) vy = hermvander(y, degy) vz = hermvander(z, degz) - v = vx[..., None, None]*vy[..., None, :, None]*vz[..., None, None, :] + v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:] return v.reshape(v.shape[:-3] + (-1,)) @@ -1577,13 +1577,13 @@ def hermcompanion(c): n = len(c) - 1 mat = np.zeros((n, n), dtype=c.dtype) - scl = np.hstack((1., np.sqrt(2.*np.arange(1,n)))) + scl = np.hstack((1., np.sqrt(2.*np.arange(1, n)))) scl = np.multiply.accumulate(scl) top = mat.reshape(-1)[1::n+1] bot = mat.reshape(-1)[n::n+1] - top[...] = np.sqrt(.5*np.arange(1,n)) + top[...] = np.sqrt(.5*np.arange(1, n)) bot[...] = top - mat[:,-1] -= (c[:-1]/c[-1])*(scl/scl[-1])*.5 + mat[:, -1] -= (c[:-1]/c[-1])*(scl/scl[-1])*.5 return mat diff --git a/numpy/polynomial/hermite_e.py b/numpy/polynomial/hermite_e.py index 9f10403dd..735ca9470 100644 --- a/numpy/polynomial/hermite_e.py +++ b/numpy/polynomial/hermite_e.py @@ -184,7 +184,7 @@ def herme2poly(c) : # # Hermite -hermedomain = np.array([-1,1]) +hermedomain = np.array([-1, 1]) # Hermite coefficients representing zero. hermezero = np.array([0]) @@ -228,7 +228,7 @@ def hermeline(off, scl) : """ if scl != 0 : - return np.array([off,scl]) + return np.array([off, scl]) else : return np.array([off]) @@ -1291,7 +1291,7 @@ def hermevander2d(x, y, deg) : vx = hermevander(x, degx) vy = hermevander(y, degy) - v = vx[..., None]*vy[..., None, :] + v = vx[..., None]*vy[..., None,:] return v.reshape(v.shape[:-2] + (-1,)) @@ -1356,7 +1356,7 @@ def hermevander3d(x, y, z, deg) : vx = hermevander(x, degx) vy = hermevander(y, degy) vz = hermevander(z, degz) - v = vx[..., None, None]*vy[..., None, :, None]*vz[..., None, None, :] + v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:] return v.reshape(v.shape[:-3] + (-1,)) @@ -1574,13 +1574,13 @@ def hermecompanion(c): n = len(c) - 1 mat = np.zeros((n, n), dtype=c.dtype) - scl = np.hstack((1., np.sqrt(np.arange(1,n)))) + scl = np.hstack((1., np.sqrt(np.arange(1, n)))) scl = np.multiply.accumulate(scl) top = mat.reshape(-1)[1::n+1] bot = mat.reshape(-1)[n::n+1] - top[...] = np.sqrt(np.arange(1,n)) + top[...] = np.sqrt(np.arange(1, n)) bot[...] = top - mat[:,-1] -= (c[:-1]/c[-1])*(scl/scl[-1]) + mat[:, -1] -= (c[:-1]/c[-1])*(scl/scl[-1]) return mat diff --git a/numpy/polynomial/laguerre.py b/numpy/polynomial/laguerre.py index ea805e146..b7ffe9b0c 100644 --- a/numpy/polynomial/laguerre.py +++ b/numpy/polynomial/laguerre.py @@ -181,7 +181,7 @@ def lag2poly(c) : # # Laguerre -lagdomain = np.array([0,1]) +lagdomain = np.array([0, 1]) # Laguerre coefficients representing zero. lagzero = np.array([0]) @@ -1294,7 +1294,7 @@ def lagvander2d(x, y, deg) : vx = lagvander(x, degx) vy = lagvander(y, degy) - v = vx[..., None]*vy[..., None, :] + v = vx[..., None]*vy[..., None,:] return v.reshape(v.shape[:-2] + (-1,)) @@ -1359,7 +1359,7 @@ def lagvander3d(x, y, z, deg) : vx = lagvander(x, degx) vy = lagvander(y, degy) vz = lagvander(z, degz) - v = vx[..., None, None]*vy[..., None, :, None]*vz[..., None, None, :] + v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:] return v.reshape(v.shape[:-3] + (-1,)) @@ -1578,10 +1578,10 @@ def lagcompanion(c): top = mat.reshape(-1)[1::n+1] mid = mat.reshape(-1)[0::n+1] bot = mat.reshape(-1)[n::n+1] - top[...] = -np.arange(1,n) + top[...] = -np.arange(1, n) mid[...] = 2.*np.arange(n) + 1. bot[...] = top - mat[:,-1] += (c[:-1]/c[-1])*n + mat[:, -1] += (c[:-1]/c[-1])*n return mat diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py index c7a1f2dd2..8d89c8412 100644 --- a/numpy/polynomial/legendre.py +++ b/numpy/polynomial/legendre.py @@ -92,7 +92,7 @@ from .polytemplate import polytemplate __all__ = ['legzero', 'legone', 'legx', 'legdomain', 'legline', 'legadd', 'legsub', 'legmulx', 'legmul', 'legdiv', 'legpow', 'legval', 'legder', 'legint', 'leg2poly', 'poly2leg', 'legfromroots', - 'legvander', 'legfit', 'legtrim', 'legroots', 'Legendre','legval2d', + 'legvander', 'legfit', 'legtrim', 'legroots', 'Legendre', 'legval2d', 'legval3d', 'leggrid2d', 'leggrid3d', 'legvander2d', 'legvander3d', 'legcompanion', 'leggauss', 'legweight'] @@ -213,7 +213,7 @@ def leg2poly(c) : # # Legendre -legdomain = np.array([-1,1]) +legdomain = np.array([-1, 1]) # Legendre coefficients representing zero. legzero = np.array([0]) @@ -222,7 +222,7 @@ legzero = np.array([0]) legone = np.array([1]) # Legendre coefficients representing the identity x. -legx = np.array([0,1]) +legx = np.array([0, 1]) def legline(off, scl) : @@ -256,7 +256,7 @@ def legline(off, scl) : """ if scl != 0 : - return np.array([off,scl]) + return np.array([off, scl]) else : return np.array([off]) @@ -1324,7 +1324,7 @@ def legvander2d(x, y, deg) : vx = legvander(x, degx) vy = legvander(y, degy) - v = vx[..., None]*vy[..., None, :] + v = vx[..., None]*vy[..., None,:] return v.reshape(v.shape[:-2] + (-1,)) @@ -1389,7 +1389,7 @@ def legvander3d(x, y, z, deg) : vx = legvander(x, degx) vy = legvander(y, degy) vz = legvander(z, degz) - v = vx[..., None, None]*vy[..., None, :, None]*vz[..., None, None, :] + v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:] return v.reshape(v.shape[:-3] + (-1,)) @@ -1605,7 +1605,7 @@ def legcompanion(c): bot = mat.reshape(-1)[n::n+1] top[...] = np.arange(1, n)*scl[:n-1]*scl[1:n] bot[...] = top - mat[:,-1] -= (c[:-1]/c[-1])*(scl/scl[-1])*(n/(2*n - 1)) + mat[:, -1] -= (c[:-1]/c[-1])*(scl/scl[-1])*(n/(2*n - 1)) return mat diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py index 0b044e8e8..9acdcbe52 100644 --- a/numpy/polynomial/polynomial.py +++ b/numpy/polynomial/polynomial.py @@ -58,8 +58,8 @@ from __future__ import division, absolute_import, print_function __all__ = ['polyzero', 'polyone', 'polyx', 'polydomain', 'polyline', 'polyadd', 'polysub', 'polymulx', 'polymul', 'polydiv', 'polypow', 'polyval', 'polyder', 'polyint', 'polyfromroots', 'polyvander', - 'polyfit', 'polytrim', 'polyroots', 'Polynomial','polyval2d', - 'polyval3d', 'polygrid2d', 'polygrid3d', 'polyvander2d','polyvander3d'] + 'polyfit', 'polytrim', 'polyroots', 'Polynomial', 'polyval2d', + 'polyval3d', 'polygrid2d', 'polygrid3d', 'polyvander2d', 'polyvander3d'] import numpy as np import numpy.linalg as la @@ -75,7 +75,7 @@ polytrim = pu.trimcoef # # Polynomial default domain. -polydomain = np.array([-1,1]) +polydomain = np.array([-1, 1]) # Polynomial coefficients representing zero. polyzero = np.array([0]) @@ -84,7 +84,7 @@ polyzero = np.array([0]) polyone = np.array([1]) # Polynomial coefficients representing the identity x. -polyx = np.array([0,1]) +polyx = np.array([0, 1]) # # Polynomial series functions @@ -120,7 +120,7 @@ def polyline(off, scl) : """ if scl != 0 : - return np.array([off,scl]) + return np.array([off, scl]) else : return np.array([off]) @@ -1119,7 +1119,7 @@ def polyvander2d(x, y, deg) : vx = polyvander(x, degx) vy = polyvander(y, degy) - v = vx[..., None]*vy[..., None, :] + v = vx[..., None]*vy[..., None,:] # einsum bug #v = np.einsum("...i,...j->...ij", vx, vy) return v.reshape(v.shape[:-2] + (-1,)) @@ -1186,7 +1186,7 @@ def polyvander3d(x, y, z, deg) : vx = polyvander(x, degx) vy = polyvander(y, degy) vz = polyvander(z, degz) - v = vx[..., None, None]*vy[..., None, :, None]*vz[..., None, None, :] + v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:] # einsum bug #v = np.einsum("...i, ...j, ...k->...ijk", vx, vy, vz) return v.reshape(v.shape[:-3] + (-1,)) @@ -1424,7 +1424,7 @@ def polycompanion(c): mat = np.zeros((n, n), dtype=c.dtype) bot = mat.reshape(-1)[n::n+1] bot[...] = 1 - mat[:,-1] -= c[:-1]/c[-1] + mat[:, -1] -= c[:-1]/c[-1] return mat diff --git a/numpy/polynomial/setup.py b/numpy/polynomial/setup.py index ab2ff2be8..cb59ee1e5 100644 --- a/numpy/polynomial/setup.py +++ b/numpy/polynomial/setup.py @@ -2,7 +2,7 @@ from __future__ import division, print_function def configuration(parent_package='',top_path=None): from numpy.distutils.misc_util import Configuration - config = Configuration('polynomial',parent_package,top_path) + config = Configuration('polynomial', parent_package, top_path) config.add_data_dir('tests') return config 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) |