def setUp(self): npts = 15 self.xk = Chebtech2._chebpts(npts) self.vk = Chebtech2._barywts(npts) self.fk = np.random.rand(npts) self.ak = np.random.rand(11) self.xx = -1 + 2 * np.random.rand(9) self.pts = -1 + 2 * np.random.rand(1001)
def setUp(self): npts = 15 self.xk = Chebtech2._chebpts(npts) self.vk = Chebtech2._barywts(npts) self.fk = np.random.rand(npts) self.ak = np.random.rand(11) self.xx = -1 + 2*np.random.rand(9) self.pts = -1 + 2*np.random.rand(1001)
def test_chebpts_0(self): self.assertEquals(Chebtech2._chebpts(0).size, 0)
def asserter(self): pts = Chebtech2._chebpts(k) self.assertEquals(pts.size, k) self.assertEquals(pts[0], -1.) self.assertEquals(pts[-1], 1.) self.assertTrue(all(diff(pts)) > 0)
# vals2coeffs2vals _testfun_ = vals2coeffs2valsTester(n) _testfun_.__name__ = "test_vals2coeffs2vals_{:02}".format(k) setattr(ChebyshevPoints, _testfun_.__name__, _testfun_) # coeffs2vals2coeffs _testfun_ = coeffs2vals2coeffsTester(n) _testfun_.__name__ = "test_coeffs2vals2coeffs_{:02}".format(k) setattr(ChebyshevPoints, _testfun_.__name__, _testfun_) # ------------------------------------------------------------------------ # ------------------------------------------------------------------------ # Add second-kind Chebyshev points test cases to ChebyshevPoints # ------------------------------------------------------------------------ chebpts2_testlist = ( (Chebtech2._chebpts(1), array([0.]), eps), (Chebtech2._chebpts(2), array([-1., 1.]), eps), (Chebtech2._chebpts(3), array([-1., 0., 1.]), eps), (Chebtech2._chebpts(4), array([-1., -.5, .5, 1.]), 2 * eps), (Chebtech2._chebpts(5), array([-1., -2.**(-.5), 0., 2.**(-.5), 1.]), eps), ) for k, (a, b, tol) in enumerate(chebpts2_testlist): _testfun_ = infNormLessThanTol(a, b, tol) _testfun_.__name__ = "test_chebpts_{:02}".format(k + 1) setattr(ChebyshevPoints, _testfun_.__name__, _testfun_) # check the output is of the correct length, the endpoint values are -1 # and 1, respectively, and that the sequence is monotonically increasing def chebptsLenTester(k): def asserter(self):
# Check that we get consistent output from bary and clenshaw # TODO: Move these tests elsewhere? def test_bary_clenshaw_consistency(self): coeffs = np.random.rand(3) evalpts = (0.5, np.array([]), np.array([.5]), np.array([.5, .6])) for n in range(len(coeffs)): ff = Chebtech2(coeffs[:n]) for xx in evalpts: fb = ff(xx, "bary") fc = ff(xx, "clenshaw") self.assertEquals(type(fb), type(fc)) evalpts = [np.linspace(-1, 1, int(n)) for n in np.array([1e2, 1e3, 1e4, 1e5])] ptsarry = [Chebtech2._chebpts(n) for n in np.array([100, 200])] methods = [bary, clenshaw] def evalTester(method, fun, evalpts, chebpts): x = evalpts xk = chebpts fvals = fun(xk) if method is bary: vk = Chebtech2._barywts(fvals.size) a = bary(x, fvals, xk, vk) tol_multiplier = 1e0 elif method is clenshaw:
self.assertTrue(isinstance(gg(0, "clenshaw"), float)) # Check that we get consistent output from bary and clenshaw # TODO: Move these tests elsewhere? def test_bary_clenshaw_consistency(self): coeffs = np.random.rand(3) evalpts = (0.5, np.array([]), np.array([.5]), np.array([.5, .6])) for n in range(len(coeffs)): ff = Chebtech2(coeffs[:n]) for xx in evalpts: fb = ff(xx, "bary") fc = ff(xx, "clenshaw") self.assertEquals(type(fb), type(fc)) evalpts = [np.linspace(-1,1,n) for n in np.array([1e2, 1e3, 1e4, 1e5])] ptsarry = [Chebtech2._chebpts(n) for n in np.array([100, 200])] methods = [bary, clenshaw] def evalTester(method, fun, evalpts, chebpts): x = evalpts xk = chebpts fvals = fun(xk) if method is bary: vk = Chebtech2._barywts(fvals.size) a = bary(x, fvals, xk, vk) tol_multiplier = 1e0 elif method is clenshaw: ak = Chebtech2._vals2coeffs(fvals)
# vals2coeffs2vals _testfun_ = vals2coeffs2valsTester(n) _testfun_.__name__ = "test_vals2coeffs2vals_{:02}".format(k) setattr(ChebyshevPoints, _testfun_.__name__, _testfun_) # coeffs2vals2coeffs _testfun_ = coeffs2vals2coeffsTester(n) _testfun_.__name__ = "test_coeffs2vals2coeffs_{:02}".format(k) setattr(ChebyshevPoints, _testfun_.__name__, _testfun_) # ------------------------------------------------------------------------ # ------------------------------------------------------------------------ # Add second-kind Chebyshev points test cases to ChebyshevPoints # ------------------------------------------------------------------------ chebpts2_testlist = ( (Chebtech2._chebpts(1), np.array([0.0]), eps), (Chebtech2._chebpts(2), np.array([-1.0, 1.0]), eps), (Chebtech2._chebpts(3), np.array([-1.0, 0.0, 1.0]), eps), (Chebtech2._chebpts(4), np.array([-1.0, -0.5, 0.5, 1.0]), 2 * eps), ( Chebtech2._chebpts(5), np.array([-1.0, -(2.0**(-0.5)), 0.0, 2.0**(-0.5), 1.0]), eps, ), ) for k, (a, b, tol) in enumerate(chebpts2_testlist): _testfun_ = infNormLessThanTol(a, b, tol) _testfun_.__name__ = "test_chebpts_{:02}".format(k + 1) setattr(ChebyshevPoints, _testfun_.__name__, _testfun_)
def asserter(self): pts = Chebtech2._chebpts(k) self.assertEquals(pts.size, k) self.assertEquals(pts[0], -1.) self.assertEquals(pts[-1], 1.) self.assertTrue(np.all(np.diff(pts))>0)
# vals2coeffs2vals _testfun_ = vals2coeffs2valsTester(n) _testfun_.__name__ = "test_vals2coeffs2vals_{:02}".format(k) setattr(ChebyshevPoints, _testfun_.__name__, _testfun_) # coeffs2vals2coeffs _testfun_ = coeffs2vals2coeffsTester(n) _testfun_.__name__ = "test_coeffs2vals2coeffs_{:02}".format(k) setattr(ChebyshevPoints, _testfun_.__name__, _testfun_) # ------------------------------------------------------------------------ # ------------------------------------------------------------------------ # Add second-kind Chebyshev points test cases to ChebyshevPoints # ------------------------------------------------------------------------ chebpts2_testlist = ( (Chebtech2._chebpts(1), np.array([0.]), eps), (Chebtech2._chebpts(2), np.array([-1., 1.]), eps), (Chebtech2._chebpts(3), np.array([-1., 0., 1.]), eps), (Chebtech2._chebpts(4), np.array([-1., -.5, .5, 1.]), 2*eps), (Chebtech2._chebpts(5), np.array([-1., -2.**(-.5), 0., 2.**(-.5), 1.]), eps), ) for k, (a,b,tol) in enumerate(chebpts2_testlist): _testfun_ = infNormLessThanTol(a,b,tol) _testfun_.__name__ = "test_chebpts_{:02}".format(k+1) setattr(ChebyshevPoints, _testfun_.__name__, _testfun_) # check the output is of the correct length, the endpoint values are -1 # and 1, respectively, and that the sequence is monotonically increasing def chebptsLenTester(k): def asserter(self): pts = Chebtech2._chebpts(k)