summaryrefslogtreecommitdiff
path: root/numpy/polynomial/tests
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/polynomial/tests')
-rw-r--r--numpy/polynomial/tests/test_chebyshev.py64
-rw-r--r--numpy/polynomial/tests/test_classes.py193
-rw-r--r--numpy/polynomial/tests/test_hermite.py64
-rw-r--r--numpy/polynomial/tests/test_hermite_e.py62
-rw-r--r--numpy/polynomial/tests/test_laguerre.py64
-rw-r--r--numpy/polynomial/tests/test_legendre.py64
-rw-r--r--numpy/polynomial/tests/test_polynomial.py68
7 files changed, 202 insertions, 377 deletions
diff --git a/numpy/polynomial/tests/test_chebyshev.py b/numpy/polynomial/tests/test_chebyshev.py
index 56d720f2d..95d241d94 100644
--- a/numpy/polynomial/tests/test_chebyshev.py
+++ b/numpy/polynomial/tests/test_chebyshev.py
@@ -617,9 +617,6 @@ class TestChebyshevClass(TestCase) :
xx = 2*x - 1
assert_almost_equal(self.p2(x), self.p1(xx))
- def test_degree(self) :
- assert_equal(self.p1.degree(), 2)
-
def test_cutdeg(self) :
assert_raises(ValueError, self.p1.cutdeg, .5)
assert_raises(ValueError, self.p1.cutdeg, -1)
@@ -628,11 +625,6 @@ class TestChebyshevClass(TestCase) :
assert_equal(len(self.p1.cutdeg(1)), 2)
assert_equal(len(self.p1.cutdeg(0)), 1)
- def test_convert(self) :
- x = np.linspace(-1,1)
- p = self.p1.convert(domain=[0,1])
- assert_almost_equal(p(x), self.p1(x))
-
def test_mapparms(self) :
parms = self.p2.mapparms()
assert_almost_equal(parms, [-1, 2])
@@ -652,10 +644,6 @@ class TestChebyshevClass(TestCase) :
assert_equal(len(self.p1.truncate(2)), 2)
assert_equal(len(self.p1.truncate(1)), 1)
- def test_copy(self) :
- p = self.p1.copy()
- assert_(self.p1 == p)
-
def test_integ(self) :
p = self.p2.integ()
assert_almost_equal(p.coef, cheb.chebint([1,2,3], 1, 0, scl=.5))
@@ -666,63 +654,13 @@ class TestChebyshevClass(TestCase) :
p = self.p2.integ(2, [1, 2])
assert_almost_equal(p.coef, cheb.chebint([1,2,3], 2, [1,2], scl=.5))
- def test_deriv(self) :
- p = self.p2.integ(2, [1, 2])
- assert_almost_equal(p.deriv(1).coef, self.p2.integ(1, [1]).coef)
- assert_almost_equal(p.deriv(2).coef, self.p2.coef)
-
- def test_roots(self) :
- p = cheb.Chebyshev(cheb.poly2cheb([0, -1, 0, 1]), [0, 1])
- res = p.roots()
- tgt = [0, .5, 1]
- assert_almost_equal(res, tgt)
-
- def test_linspace(self):
- xdes = np.linspace(0, 1, 20)
- ydes = self.p2(xdes)
- xres, yres = self.p2.linspace(20)
- assert_almost_equal(xres, xdes)
- assert_almost_equal(yres, ydes)
-
- def test_fromroots(self) :
- roots = [0, .5, 1]
- p = cheb.Chebyshev.fromroots(roots, domain=[0, 1])
- res = p.coef
- tgt = cheb.poly2cheb([0, -1, 0, 1])
- assert_almost_equal(res, tgt)
-
- def test_fit(self) :
- def f(x) :
- return x*(x - 1)*(x - 2)
- x = np.linspace(0,3)
- y = f(x)
-
- # test default value of domain
- p = cheb.Chebyshev.fit(x, y, 3)
- assert_almost_equal(p.domain, [0,3])
-
- # test that fit works in given domains
- p = cheb.Chebyshev.fit(x, y, 3, None)
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [0,3])
- p = cheb.Chebyshev.fit(x, y, 3, [])
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [-1, 1])
- # test that fit accepts weights.
- w = np.zeros_like(x)
- yw = y.copy()
- w[1::2] = 1
- yw[0::2] = 0
- p = cheb.Chebyshev.fit(x, yw, 3, w=w)
- assert_almost_equal(p(x), y)
-
def test_identity(self) :
x = np.linspace(0,3)
p = cheb.Chebyshev.identity()
assert_almost_equal(p(x), x)
p = cheb.Chebyshev.identity([1,3])
assert_almost_equal(p(x), x)
-#
+
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/polynomial/tests/test_classes.py b/numpy/polynomial/tests/test_classes.py
new file mode 100644
index 000000000..e0fc28f33
--- /dev/null
+++ b/numpy/polynomial/tests/test_classes.py
@@ -0,0 +1,193 @@
+"""Test inter-conversion of different polynomial classes.
+
+This tests the convert and cast methods of all the polynomial classes.
+
+"""
+from __future__ import division
+
+import numpy as np
+from numpy.polynomial import (
+ Polynomial, Legendre, Chebyshev, Laguerre,
+ Hermite, HermiteE)
+from numpy.testing import (
+ TestCase, assert_almost_equal, assert_raises,
+ assert_equal, assert_, run_module_suite)
+
+classes = (
+ Polynomial, Legendre, Chebyshev, Laguerre,
+ Hermite, HermiteE)
+
+class TestClassConversions(TestCase):
+
+ def test_conversion(self):
+ x = np.linspace(0, 1, 10)
+ window = np.array([0, 1])
+ domain = np.array([0, 1])
+ for Poly1 in classes:
+ d1 = domain + np.random.random((2,))*.25
+ w1 = window + np.random.random((2,))*.25
+ c1 = np.random.random((3,))
+ p1 = Poly1(c1, domain=d1, window=w1)
+ for Poly2 in classes:
+ msg = "-- %s -> %s" % (Poly1.__name__, Poly2.__name__)
+ d2 = domain + np.random.random((2,))*.25
+ w2 = window + np.random.random((2,))*.25
+ p2 = p1.convert(kind=Poly2, domain=d2, window=w2)
+ assert_almost_equal(p2.domain, d2, err_msg=msg)
+ assert_almost_equal(p2.window, w2, err_msg=msg)
+ assert_almost_equal(p2(x), p1(x), err_msg=msg)
+
+ def test_cast(self):
+ x = np.linspace(0, 1, 10)
+ window = np.array([0, 1])
+ domain = np.array([0, 1])
+ for Poly1 in classes:
+ d1 = domain + np.random.random((2,))*.25
+ w1 = window + np.random.random((2,))*.25
+ c1 = np.random.random((3,))
+ p1 = Poly1(c1, domain=d1, window=w1)
+ for Poly2 in classes:
+ msg = "-- %s -> %s" % (Poly1.__name__, Poly2.__name__)
+ d2 = domain + np.random.random((2,))*.25
+ w2 = window + np.random.random((2,))*.25
+ p2 = Poly2.cast(p1, domain=d2, window=w2)
+ assert_almost_equal(p2.domain, d2, err_msg=msg)
+ assert_almost_equal(p2.window, w2, err_msg=msg)
+ assert_almost_equal(p2(x), p1(x), err_msg=msg)
+
+
+class TestClasses(TestCase):
+
+ def test_basis(self):
+ window = np.array([0, 1])
+ domain = np.array([0, 1])
+ for Poly in classes:
+ msg = "-- %s" % (Poly.__name__,)
+ d = domain + np.random.random((2,))*.25
+ w = window + np.random.random((2,))*.25
+ p = Poly.basis(5, domain=d, window=w)
+ assert_equal(p.domain, d, err_msg=msg)
+ assert_equal(p.window, w, err_msg=msg)
+ assert_equal(p.coef, [0]*5 + [1])
+
+ def test_fromroots(self):
+ window = np.array([0, 1])
+ domain = np.array([0, 1])
+ for Poly in classes:
+ msg = "-- %s" % (Poly.__name__,)
+ d = domain + np.random.random((2,))*.25
+ w = window + np.random.random((2,))*.25
+ r = np.random.random((5,))
+ p1 = Poly.fromroots(r, domain=d, window=w)
+ assert_equal(p1.domain, d, err_msg=msg)
+ assert_equal(p1.window, w, err_msg=msg)
+ assert_almost_equal(p1(r), 0, err_msg=msg)
+ # test monic with same domain and window
+ p2 = Polynomial.cast(p1, domain=d, window=w)
+ assert_almost_equal(p2.coef[-1], 1, err_msg=msg)
+
+ def test_roots(self):
+ window = np.array([0, 1])
+ domain = np.array([0, 1])
+ for Poly in classes:
+ msg = "-- %s" % (Poly.__name__,)
+ d = domain + np.random.random((2,))*.25
+ w = window + np.random.random((2,))*.25
+ tgt = np.sort(np.random.random((5,)))
+ res = np.sort(Poly.fromroots(tgt).roots())
+ assert_almost_equal(res, tgt, err_msg=msg)
+
+ def test_degree(self):
+ for Poly in classes:
+ msg = "-- %s" % (Poly.__name__,)
+ p = Poly.basis(5)
+ assert_equal(p.degree(), 5, err_msg=msg)
+
+ def test_copy(self):
+ for Poly in classes:
+ msg = "-- %s" % (Poly.__name__,)
+ p1 = Poly.basis(5)
+ p2 = p1.copy()
+ assert_(p1 == p2, msg)
+ assert_(p1 is not p2, msg)
+ assert_(p1.coef is not p2.coef, msg)
+ assert_(p1.domain is not p2.domain, msg)
+ assert_(p1.window is not p2.window, msg)
+
+ def test_deriv(self):
+ # Check that the derivative is the inverse of integration. It is
+ # assumes that the integration has been tested elsewhere.
+ window = np.array([0, 1])
+ domain = np.array([0, 1])
+ for Poly in classes:
+ msg = "-- %s" % (Poly.__name__,)
+ d = domain + np.random.random((2,))*.25
+ w = window + np.random.random((2,))*.25
+ p1 = Poly([1, 2, 3], domain=d, window=w)
+ p2 = p1.integ(2, k=[1, 2])
+ p3 = p1.integ(1, k=[1])
+ assert_almost_equal(p2.deriv(1).coef, p3.coef, err_msg=msg)
+ assert_almost_equal(p2.deriv(2).coef, p1.coef, err_msg=msg)
+
+ def test_linspace(self):
+ window = np.array([0, 1])
+ domain = np.array([0, 1])
+ for Poly in classes:
+ msg = "-- %s" % (Poly.__name__,)
+ d = domain + np.random.random((2,))*.25
+ w = window + np.random.random((2,))*.25
+ p = Poly([1,2,3], domain=d, window=w)
+ # test default domain
+ xtgt = np.linspace(d[0], d[1], 20)
+ ytgt = p(xtgt)
+ xres, yres = p.linspace(20)
+ assert_almost_equal(xres, xtgt, err_msg=msg)
+ assert_almost_equal(yres, ytgt, err_msg=msg)
+ # test specified domain
+ xtgt = np.linspace(0, 2, 20)
+ ytgt = p(xtgt)
+ xres, yres = p.linspace(20, domain=[0, 2])
+ assert_almost_equal(xres, xtgt, err_msg=msg)
+ assert_almost_equal(yres, ytgt, err_msg=msg)
+
+ def test_fit(self) :
+
+ def f(x) :
+ return x*(x - 1)*(x - 2)
+ x = np.linspace(0,3)
+ y = f(x)
+
+ window = np.array([0, 1])
+ domain = np.array([0, 1])
+ for Poly in classes:
+ msg = "-- %s" % (Poly.__name__,)
+ # test default value of domain
+ p = Poly.fit(x, y, 3)
+ assert_almost_equal(p.domain, [0,3], err_msg=msg)
+ assert_almost_equal(p(x), y, err_msg=msg)
+ assert_equal(p.degree(), 3, err_msg=msg)
+
+ # test with given windows and domains
+ d = domain + np.random.random((2,))*.25
+ w = window + np.random.random((2,))*.25
+ p = Poly.fit(x, y, 3, domain=d, window=w)
+ assert_almost_equal(p(x), y, err_msg=msg)
+ assert_almost_equal(p.domain, d, err_msg=msg)
+ assert_almost_equal(p.window, w, err_msg=msg)
+
+ # test with class domain default
+ p = Poly.fit(x, y, 3, [])
+ assert_equal(p.domain, Poly.domain, err_msg=msg)
+ assert_equal(p.window, Poly.window, err_msg=msg)
+
+ # test that fit accepts weights.
+ w = np.zeros_like(x)
+ z = y + np.random.random(y.shape)*.25
+ w[::2] = 1
+ p1 = Poly.fit(x[::2], z[::2], 3)
+ p2 = Poly.fit(x, z, 3, w=w)
+ assert_almost_equal(p1(x), p2(x), err_msg=msg)
+
+
+if __name__ == "__main__":
+ run_module_suite()
diff --git a/numpy/polynomial/tests/test_hermite.py b/numpy/polynomial/tests/test_hermite.py
index b40d3b944..8fe0da652 100644
--- a/numpy/polynomial/tests/test_hermite.py
+++ b/numpy/polynomial/tests/test_hermite.py
@@ -582,9 +582,6 @@ class TestHermiteClass(TestCase) :
xx = 2*x - 1
assert_almost_equal(self.p2(x), self.p1(xx))
- def test_degree(self) :
- assert_equal(self.p1.degree(), 2)
-
def test_cutdeg(self) :
assert_raises(ValueError, self.p1.cutdeg, .5)
assert_raises(ValueError, self.p1.cutdeg, -1)
@@ -593,11 +590,6 @@ class TestHermiteClass(TestCase) :
assert_equal(len(self.p1.cutdeg(1)), 2)
assert_equal(len(self.p1.cutdeg(0)), 1)
- def test_convert(self) :
- x = np.linspace(-1,1)
- p = self.p1.convert(domain=[0,1])
- assert_almost_equal(p(x), self.p1(x))
-
def test_mapparms(self) :
parms = self.p2.mapparms()
assert_almost_equal(parms, [-1, 2])
@@ -617,10 +609,6 @@ class TestHermiteClass(TestCase) :
assert_equal(len(self.p1.truncate(2)), 2)
assert_equal(len(self.p1.truncate(1)), 1)
- def test_copy(self) :
- p = self.p1.copy()
- assert_(self.p1 == p)
-
def test_integ(self) :
p = self.p2.integ()
assert_almost_equal(p.coef, herm.hermint([1,2,3], 1, 0, scl=.5))
@@ -631,63 +619,13 @@ class TestHermiteClass(TestCase) :
p = self.p2.integ(2, [1, 2])
assert_almost_equal(p.coef, herm.hermint([1,2,3], 2, [1,2], scl=.5))
- def test_deriv(self) :
- p = self.p2.integ(2, [1, 2])
- assert_almost_equal(p.deriv(1).coef, self.p2.integ(1, [1]).coef)
- assert_almost_equal(p.deriv(2).coef, self.p2.coef)
-
- def test_roots(self) :
- p = herm.Hermite(herm.poly2herm([0, -1, 0, 1]), [0, 1])
- res = p.roots()
- tgt = [0, .5, 1]
- assert_almost_equal(res, tgt)
-
- def test_linspace(self):
- xdes = np.linspace(0, 1, 20)
- ydes = self.p2(xdes)
- xres, yres = self.p2.linspace(20)
- assert_almost_equal(xres, xdes)
- assert_almost_equal(yres, ydes)
-
- def test_fromroots(self) :
- roots = [0, .5, 1]
- p = herm.Hermite.fromroots(roots, domain=[0, 1])
- res = p.coef
- tgt = herm.poly2herm([0, -1, 0, 1])
- assert_almost_equal(res, tgt)
-
- def test_fit(self) :
- def f(x) :
- return x*(x - 1)*(x - 2)
- x = np.linspace(0,3)
- y = f(x)
-
- # test default value of domain
- p = herm.Hermite.fit(x, y, 3)
- assert_almost_equal(p.domain, [0,3])
-
- # test that fit works in given domains
- p = herm.Hermite.fit(x, y, 3, None)
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [0,3])
- p = herm.Hermite.fit(x, y, 3, [])
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [-1, 1])
- # test that fit accepts weights.
- w = np.zeros_like(x)
- yw = y.copy()
- w[1::2] = 1
- yw[0::2] = 0
- p = herm.Hermite.fit(x, yw, 3, w=w)
- assert_almost_equal(p(x), y)
-
def test_identity(self) :
x = np.linspace(0,3)
p = herm.Hermite.identity()
assert_almost_equal(p(x), x)
p = herm.Hermite.identity([1,3])
assert_almost_equal(p(x), x)
-#
+
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/polynomial/tests/test_hermite_e.py b/numpy/polynomial/tests/test_hermite_e.py
index 18e42416c..552f21ae0 100644
--- a/numpy/polynomial/tests/test_hermite_e.py
+++ b/numpy/polynomial/tests/test_hermite_e.py
@@ -579,9 +579,6 @@ class TestHermiteEClass(TestCase) :
xx = 2*x - 1
assert_almost_equal(self.p2(x), self.p1(xx))
- def test_degree(self) :
- assert_equal(self.p1.degree(), 2)
-
def test_cutdeg(self) :
assert_raises(ValueError, self.p1.cutdeg, .5)
assert_raises(ValueError, self.p1.cutdeg, -1)
@@ -590,11 +587,6 @@ class TestHermiteEClass(TestCase) :
assert_equal(len(self.p1.cutdeg(1)), 2)
assert_equal(len(self.p1.cutdeg(0)), 1)
- def test_convert(self) :
- x = np.linspace(-1,1)
- p = self.p1.convert(domain=[0,1])
- assert_almost_equal(p(x), self.p1(x))
-
def test_mapparms(self) :
parms = self.p2.mapparms()
assert_almost_equal(parms, [-1, 2])
@@ -614,10 +606,6 @@ class TestHermiteEClass(TestCase) :
assert_equal(len(self.p1.truncate(2)), 2)
assert_equal(len(self.p1.truncate(1)), 1)
- def test_copy(self) :
- p = self.p1.copy()
- assert_(self.p1 == p)
-
def test_integ(self) :
p = self.p2.integ()
assert_almost_equal(p.coef, herme.hermeint([1,2,3], 1, 0, scl=.5))
@@ -628,56 +616,6 @@ class TestHermiteEClass(TestCase) :
p = self.p2.integ(2, [1, 2])
assert_almost_equal(p.coef, herme.hermeint([1,2,3], 2, [1,2], scl=.5))
- def test_deriv(self) :
- p = self.p2.integ(2, [1, 2])
- assert_almost_equal(p.deriv(1).coef, self.p2.integ(1, [1]).coef)
- assert_almost_equal(p.deriv(2).coef, self.p2.coef)
-
- def test_roots(self) :
- p = herme.HermiteE(herme.poly2herme([0, -1, 0, 1]), [0, 1])
- res = p.roots()
- tgt = [0, .5, 1]
- assert_almost_equal(res, tgt)
-
- def test_linspace(self):
- xdes = np.linspace(0, 1, 20)
- ydes = self.p2(xdes)
- xres, yres = self.p2.linspace(20)
- assert_almost_equal(xres, xdes)
- assert_almost_equal(yres, ydes)
-
- def test_fromroots(self) :
- roots = [0, .5, 1]
- p = herme.HermiteE.fromroots(roots, domain=[0, 1])
- res = p.coef
- tgt = herme.poly2herme([0, -1, 0, 1])
- assert_almost_equal(res, tgt)
-
- def test_fit(self) :
- def f(x) :
- return x*(x - 1)*(x - 2)
- x = np.linspace(0,3)
- y = f(x)
-
- # test default value of domain
- p = herme.HermiteE.fit(x, y, 3)
- assert_almost_equal(p.domain, [0,3])
-
- # test that fit works in given domains
- p = herme.HermiteE.fit(x, y, 3, None)
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [0,3])
- p = herme.HermiteE.fit(x, y, 3, [])
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [-1, 1])
- # test that fit accepts weights.
- w = np.zeros_like(x)
- yw = y.copy()
- w[1::2] = 1
- yw[0::2] = 0
- p = herme.HermiteE.fit(x, yw, 3, w=w)
- assert_almost_equal(p(x), y)
-
def test_identity(self) :
x = np.linspace(0,3)
p = herme.HermiteE.identity()
diff --git a/numpy/polynomial/tests/test_laguerre.py b/numpy/polynomial/tests/test_laguerre.py
index a95466aed..0c411820e 100644
--- a/numpy/polynomial/tests/test_laguerre.py
+++ b/numpy/polynomial/tests/test_laguerre.py
@@ -577,9 +577,6 @@ class TestLaguerreClass(TestCase) :
xx = 2*x - 1
assert_almost_equal(self.p2(x), self.p1(xx))
- def test_degree(self) :
- assert_equal(self.p1.degree(), 2)
-
def test_cutdeg(self) :
assert_raises(ValueError, self.p1.cutdeg, .5)
assert_raises(ValueError, self.p1.cutdeg, -1)
@@ -588,11 +585,6 @@ class TestLaguerreClass(TestCase) :
assert_equal(len(self.p1.cutdeg(1)), 2)
assert_equal(len(self.p1.cutdeg(0)), 1)
- def test_convert(self) :
- x = np.linspace(-1,1)
- p = self.p1.convert(domain=[0,1])
- assert_almost_equal(p(x), self.p1(x))
-
def test_mapparms(self) :
parms = self.p2.mapparms()
assert_almost_equal(parms, [-1, 2])
@@ -612,10 +604,6 @@ class TestLaguerreClass(TestCase) :
assert_equal(len(self.p1.truncate(2)), 2)
assert_equal(len(self.p1.truncate(1)), 1)
- def test_copy(self) :
- p = self.p1.copy()
- assert_(self.p1 == p)
-
def test_integ(self) :
p = self.p2.integ()
assert_almost_equal(p.coef, lag.lagint([1,2,3], 1, 0, scl=.5))
@@ -626,63 +614,13 @@ class TestLaguerreClass(TestCase) :
p = self.p2.integ(2, [1, 2])
assert_almost_equal(p.coef, lag.lagint([1,2,3], 2, [1,2], scl=.5))
- def test_deriv(self) :
- p = self.p2.integ(2, [1, 2])
- assert_almost_equal(p.deriv(1).coef, self.p2.integ(1, [1]).coef)
- assert_almost_equal(p.deriv(2).coef, self.p2.coef)
-
- def test_roots(self) :
- p = lag.Laguerre(lag.poly2lag([0, -1, 0, 1]), [0, 1])
- res = p.roots()
- tgt = [0, .5, 1]
- assert_almost_equal(res, tgt)
-
- def test_linspace(self):
- xdes = np.linspace(0, 1, 20)
- ydes = self.p2(xdes)
- xres, yres = self.p2.linspace(20)
- assert_almost_equal(xres, xdes)
- assert_almost_equal(yres, ydes)
-
- def test_fromroots(self) :
- roots = [0, .5, 1]
- p = lag.Laguerre.fromroots(roots, domain=[0, 1])
- res = p.coef
- tgt = lag.poly2lag([0, -1, 0, 1])
- assert_almost_equal(res, tgt)
-
- def test_fit(self) :
- def f(x) :
- return x*(x - 1)*(x - 2)
- x = np.linspace(0,3)
- y = f(x)
-
- # test default value of domain
- p = lag.Laguerre.fit(x, y, 3)
- assert_almost_equal(p.domain, [0,3])
-
- # test that fit works in given domains
- p = lag.Laguerre.fit(x, y, 3, None)
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [0,3])
- p = lag.Laguerre.fit(x, y, 3, [])
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [-1, 1])
- # test that fit accepts weights.
- w = np.zeros_like(x)
- yw = y.copy()
- w[1::2] = 1
- yw[0::2] = 0
- p = lag.Laguerre.fit(x, yw, 3, w=w)
- assert_almost_equal(p(x), y)
-
def test_identity(self) :
x = np.linspace(0,3)
p = lag.Laguerre.identity()
assert_almost_equal(p(x), x)
p = lag.Laguerre.identity([1,3])
assert_almost_equal(p(x), x)
-#
+
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/polynomial/tests/test_legendre.py b/numpy/polynomial/tests/test_legendre.py
index d7bb238a9..4dc4f9a25 100644
--- a/numpy/polynomial/tests/test_legendre.py
+++ b/numpy/polynomial/tests/test_legendre.py
@@ -580,9 +580,6 @@ class TestLegendreClass(TestCase) :
xx = 2*x - 1
assert_almost_equal(self.p2(x), self.p1(xx))
- def test_degree(self) :
- assert_equal(self.p1.degree(), 2)
-
def test_cutdeg(self) :
assert_raises(ValueError, self.p1.cutdeg, .5)
assert_raises(ValueError, self.p1.cutdeg, -1)
@@ -591,11 +588,6 @@ class TestLegendreClass(TestCase) :
assert_equal(len(self.p1.cutdeg(1)), 2)
assert_equal(len(self.p1.cutdeg(0)), 1)
- def test_convert(self) :
- x = np.linspace(-1,1)
- p = self.p1.convert(domain=[0,1])
- assert_almost_equal(p(x), self.p1(x))
-
def test_mapparms(self) :
parms = self.p2.mapparms()
assert_almost_equal(parms, [-1, 2])
@@ -615,10 +607,6 @@ class TestLegendreClass(TestCase) :
assert_equal(len(self.p1.truncate(2)), 2)
assert_equal(len(self.p1.truncate(1)), 1)
- def test_copy(self) :
- p = self.p1.copy()
- assert_(self.p1 == p)
-
def test_integ(self) :
p = self.p2.integ()
assert_almost_equal(p.coef, leg.legint([1,2,3], 1, 0, scl=.5))
@@ -629,63 +617,13 @@ class TestLegendreClass(TestCase) :
p = self.p2.integ(2, [1, 2])
assert_almost_equal(p.coef, leg.legint([1,2,3], 2, [1,2], scl=.5))
- def test_deriv(self) :
- p = self.p2.integ(2, [1, 2])
- assert_almost_equal(p.deriv(1).coef, self.p2.integ(1, [1]).coef)
- assert_almost_equal(p.deriv(2).coef, self.p2.coef)
-
- def test_roots(self) :
- p = leg.Legendre(leg.poly2leg([0, -1, 0, 1]), [0, 1])
- res = p.roots()
- tgt = [0, .5, 1]
- assert_almost_equal(res, tgt)
-
- def test_linspace(self):
- xdes = np.linspace(0, 1, 20)
- ydes = self.p2(xdes)
- xres, yres = self.p2.linspace(20)
- assert_almost_equal(xres, xdes)
- assert_almost_equal(yres, ydes)
-
- def test_fromroots(self) :
- roots = [0, .5, 1]
- p = leg.Legendre.fromroots(roots, domain=[0, 1])
- res = p.coef
- tgt = leg.poly2leg([0, -1, 0, 1])
- assert_almost_equal(res, tgt)
-
- def test_fit(self) :
- def f(x) :
- return x*(x - 1)*(x - 2)
- x = np.linspace(0,3)
- y = f(x)
-
- # test default value of domain
- p = leg.Legendre.fit(x, y, 3)
- assert_almost_equal(p.domain, [0,3])
-
- # test that fit works in given domains
- p = leg.Legendre.fit(x, y, 3, None)
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [0,3])
- p = leg.Legendre.fit(x, y, 3, [])
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [-1, 1])
- # test that fit accepts weights.
- w = np.zeros_like(x)
- yw = y.copy()
- w[1::2] = 1
- yw[0::2] = 0
- p = leg.Legendre.fit(x, yw, 3, w=w)
- assert_almost_equal(p(x), y)
-
def test_identity(self) :
x = np.linspace(0,3)
p = leg.Legendre.identity()
assert_almost_equal(p(x), x)
p = leg.Legendre.identity([1,3])
assert_almost_equal(p(x), x)
-#
+
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py
index 09028686f..5715d8b2d 100644
--- a/numpy/polynomial/tests/test_polynomial.py
+++ b/numpy/polynomial/tests/test_polynomial.py
@@ -5,7 +5,9 @@ from __future__ import division
import numpy as np
import numpy.polynomial.polynomial as poly
-from numpy.testing import *
+from numpy.testing import (
+ TestCase, assert_almost_equal, assert_raises,
+ assert_equal, assert_, run_module_suite)
def trim(x) :
return poly.polytrim(x, tol=1e-6)
@@ -533,9 +535,6 @@ class TestPolynomialClass(TestCase) :
xx = 2*x - 1
assert_almost_equal(self.p2(x), self.p1(xx))
- def test_degree(self) :
- assert_equal(self.p1.degree(), 2)
-
def test_cutdeg(self) :
assert_raises(ValueError, self.p1.cutdeg, .5)
assert_raises(ValueError, self.p1.cutdeg, -1)
@@ -544,11 +543,6 @@ class TestPolynomialClass(TestCase) :
assert_equal(len(self.p1.cutdeg(1)), 2)
assert_equal(len(self.p1.cutdeg(0)), 1)
- def test_convert(self) :
- x = np.linspace(-1,1)
- p = self.p1.convert(domain=[0,1])
- assert_almost_equal(p(x), self.p1(x))
-
def test_mapparms(self) :
parms = self.p2.mapparms()
assert_almost_equal(parms, [-1, 2])
@@ -568,10 +562,6 @@ class TestPolynomialClass(TestCase) :
assert_equal(len(self.p1.truncate(2)), 2)
assert_equal(len(self.p1.truncate(1)), 1)
- def test_copy(self) :
- p = self.p1.copy()
- assert_(self.p1 == p)
-
def test_integ(self) :
p = self.p2.integ()
assert_almost_equal(p.coef, poly.polyint([1,2,3], 1, 0, scl=.5))
@@ -582,55 +572,6 @@ class TestPolynomialClass(TestCase) :
p = self.p2.integ(2, [1, 2])
assert_almost_equal(p.coef, poly.polyint([1,2,3], 2, [1, 2], scl=.5))
- def test_deriv(self) :
- p = self.p2.integ(2, [1, 2])
- assert_almost_equal(p.deriv(1).coef, self.p2.integ(1, [1]).coef)
- assert_almost_equal(p.deriv(2).coef, self.p2.coef)
-
- def test_roots(self) :
- p = poly.Polynomial([0, -1, 0, 1], [0, 1])
- res = p.roots()
- tgt = [0, .5, 1]
- assert_almost_equal(res, tgt)
-
- def test_linspace(self):
- xdes = np.linspace(0, 1, 20)
- ydes = self.p2(xdes)
- xres, yres = self.p2.linspace(20)
- assert_almost_equal(xres, xdes)
- assert_almost_equal(yres, ydes)
-
- def test_fromroots(self) :
- roots = [0, .5, 1]
- p = poly.Polynomial.fromroots(roots, domain=[0, 1])
- res = p.coef
- tgt = [0, -1, 0, 1]
- assert_almost_equal(res, tgt)
-
- def test_fit(self) :
- def f(x) :
- return x*(x - 1)*(x - 2)
- x = np.linspace(0,3)
- y = f(x)
-
- # test default value of domain
- p = poly.Polynomial.fit(x, y, 3)
- assert_almost_equal(p.domain, [0,3])
-
- # test that fit works in given domains
- p = poly.Polynomial.fit(x, y, 3, None)
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [0,3])
- p = poly.Polynomial.fit(x, y, 3, [])
- assert_almost_equal(p(x), y)
- assert_almost_equal(p.domain, [-1, 1])
- # test that fit accepts weights.
- w = np.zeros_like(x)
- yw = y.copy()
- w[1::2] = 1
- yw[0::2] = 0
- p = poly.Polynomial.fit(x, yw, 3, w=w)
- assert_almost_equal(p(x), y)
def test_identity(self) :
x = np.linspace(0,3)
@@ -638,7 +579,8 @@ class TestPolynomialClass(TestCase) :
assert_almost_equal(p(x), x)
p = poly.Polynomial.identity([1,3])
assert_almost_equal(p(x), x)
-#
+
+
if __name__ == "__main__":
run_module_suite()