diff options
Diffstat (limited to 'numpy/polynomial/tests/test_polynomial.py')
| -rw-r--r-- | numpy/polynomial/tests/test_polynomial.py | 72 |
1 files changed, 36 insertions, 36 deletions
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__": |
