예제 #1
0
def derivativeTester(fun, der, n, tol):
    ff = Chebtech2.initfun_fixedlen(fun, n)
    gg = Chebtech2.initfun_fixedlen(der, max(n-1,1))
    def tester(self):
        absdiff = infnorm(ff.diff().coeffs - gg.coeffs)
        self.assertLessEqual(absdiff, tol)
    return tester
예제 #2
0
def derivativeTester(fun, der, n, tol):
    ff = Chebtech2.initfun_fixedlen(fun, n)
    gg = Chebtech2.initfun_fixedlen(der, max(n-1,1))
    def tester(self):
        absdiff = infnorm(ff.diff().coeffs - gg.coeffs)
        self.assertLessEqual(absdiff, tol)
    return tester
예제 #3
0
def indefiniteIntegralTester(fun, dfn, n, tol):
    ff = Chebtech2.initfun_fixedlen(fun, n)
    gg = Chebtech2.initfun_fixedlen(dfn, n+1)
    coeffs = gg.coeffs
    coeffs[0] = coeffs[0] - dfn(np.array([-1]))
    def tester(self):
        absdiff = infnorm(ff.cumsum().coeffs - coeffs)
        self.assertLessEqual(absdiff, tol)
    return tester
예제 #4
0
def indefiniteIntegralTester(fun, dfn, n, tol):
    ff = Chebtech2.initfun_fixedlen(fun, n)
    gg = Chebtech2.initfun_fixedlen(dfn, n+1)
    coeffs = gg.coeffs
    coeffs[0] = coeffs[0] - dfn(np.array([-1]))
    def tester(self):
        absdiff = infnorm(ff.cumsum().coeffs - coeffs)
        self.assertLessEqual(absdiff, tol)
    return tester
예제 #5
0
def binaryOpTester(f, g, binop, nf, ng):
    ff = Chebtech2.initfun_fixedlen(f, nf)
    gg = Chebtech2.initfun_fixedlen(g, ng)
    FG = lambda x: binop(f(x),g(x)) 
    fg = binop(ff, gg)
    def tester(self):
        vscl = max([ff.vscale, gg.vscale])
        lscl = max([ff.size, gg.size])
        self.assertLessEqual(infnorm(fg(self.xx)-FG(self.xx)), 3*vscl*lscl*eps)
        if binop is operator.mul:
            # check simplify is not being called in __mul__
            self.assertEqual(fg.size, ff.size+gg.size-1)
    return tester
예제 #6
0
def binaryOpTester(f, g, binop, nf, ng):
    ff = Chebtech2.initfun_fixedlen(f, nf)
    gg = Chebtech2.initfun_fixedlen(g, ng)
    FG = lambda x: binop(f(x),g(x)) 
    fg = binop(ff, gg)
    def tester(self):
        vscl = max([ff.vscale, gg.vscale])
        lscl = max([ff.size, gg.size])
        self.assertLessEqual(infnorm(fg(self.xx)-FG(self.xx)), 3*vscl*lscl*eps)
        if binop is operator.mul:
            # check simplify is not being called in __mul__
            self.assertEqual(fg.size, ff.size+gg.size-1)
    return tester
예제 #7
0
def unaryOpTester(unaryop, f, nf):
    ff = Chebtech2.initfun_fixedlen(f, nf)
    gg = lambda x: unaryop(f(x))
    GG = unaryop(ff)
    def tester(self):
        self.assertLessEqual(infnorm(gg(self.xx)-GG(self.xx)), 4e1*eps)
    return tester
예제 #8
0
def unaryOpTester(unaryop, f, nf):
    ff = Chebtech2.initfun_fixedlen(f, nf)
    gg = lambda x: unaryop(f(x))
    GG = unaryop(ff)
    def tester(self):
        self.assertLessEqual(infnorm(gg(self.xx)-GG(self.xx)), 4e1*eps)
    return tester
예제 #9
0
def fixedlenTester(fun, n):
    ff = Chebtech2.initfun_fixedlen(fun, n)

    def tester(self):
        self.assertEquals(ff.size, n)

    return tester
예제 #10
0
 def test__add__negself(self):
     xx = self.xx
     for (fun, funlen, _) in testfunctions:
         chebtech = Chebtech2.initfun_fixedlen(fun, funlen)
         chebzero = chebtech - chebtech
         self.assertTrue(chebzero.isconst)
         self.assertEqual(infnorm(chebzero(xx)), 0)
예제 #11
0
 def test_truediv_empty(self):
     for (fun, funlen, _) in testfunctions:
         chebtech = Chebtech2.initfun_fixedlen(fun, funlen)
         self.assertTrue(operator.truediv(self.emptyfun,chebtech).isempty)
         self.assertTrue(operator.truediv(chebtech,self.emptyfun).isempty)
         # __truediv__
         self.assertTrue((self.emptyfun/chebtech).isempty)
         self.assertTrue((chebtech/self.emptyfun).isempty)
예제 #12
0
 def test_truediv_empty(self):
     for (fun, funlen, _) in testfunctions:
         chebtech = Chebtech2.initfun_fixedlen(fun, funlen)
         self.assertTrue(truediv(self.emptyfun, chebtech).isempty)
         self.assertTrue(truediv(chebtech, self.emptyfun).isempty)
         # __truediv__
         self.assertTrue((self.emptyfun / chebtech).isempty)
         self.assertTrue((chebtech / self.emptyfun).isempty)
예제 #13
0
def definiteIntegralTester(fun, n, vscale):
    ff = Chebtech2.initfun_fixedlen(fun, n)

    def tester(self):
        absdiff = abs(ff.vscale - vscale)
        self.assertLessEqual(absdiff, .1 * vscale)

    return tester
예제 #14
0
def definiteIntegralTester(fun, n, integral, tol):
    ff = Chebtech2.initfun_fixedlen(fun, n)

    def tester(self):
        absdiff = abs(ff.sum() - integral)
        self.assertLessEqual(absdiff, tol)

    return tester
예제 #15
0
 def test_rpow_const(self):
     xx = self.xx
     for (fun, funlen) in [(np.sin, 15), (np.exp,15)]:
         for c in (1, 2):
             techfun = Chebtech2.initfun_fixedlen(fun, funlen)
             g = lambda x: c ** fun(x)
             gg = c ** techfun
             tol = 2e1 * eps * abs(c)
             self.assertLessEqual(infnorm(g(xx)-gg(xx)), tol)
예제 #16
0
 def test_pow_const(self):
     xx = self.xx
     for (fun, funlen) in [(np.sin, 15), (np.exp,15)]:
         for c in (1, 2):
             techfun = Chebtech2.initfun_fixedlen(fun, funlen)
             f = lambda x: fun(x) ** c
             ff = techfun ** c
             tol = 2e1 * eps * abs(c)
             self.assertLessEqual(infnorm(f(xx)-ff(xx)), tol)
예제 #17
0
 def test_rpow_const(self):
     xx = self.xx
     for (fun, funlen) in [(np.sin, 15), (np.exp,15)]:
         for c in (1, 2):
             techfun = Chebtech2.initfun_fixedlen(fun, funlen)
             g = lambda x: c ** fun(x)
             gg = c ** techfun
             tol = 2e1 * eps * abs(c)
             self.assertLessEqual(infnorm(g(xx)-gg(xx)), tol)
예제 #18
0
 def test_pow_const(self):
     xx = self.xx
     for (fun, funlen) in [(np.sin, 15), (np.exp,15)]:
         for c in (1, 2):
             techfun = Chebtech2.initfun_fixedlen(fun, funlen)
             f = lambda x: fun(x) ** c
             ff = techfun ** c
             tol = 2e1 * eps * abs(c)
             self.assertLessEqual(infnorm(f(xx)-ff(xx)), tol)
예제 #19
0
 def test__add__radd__constant(self):
     xx = self.xx
     for (fun, funlen, _) in testfunctions:
         for const in (-1, 1, 10, -1e5):
             f = lambda x: const + fun(x)
             techfun = Chebtech2.initfun_fixedlen(fun, funlen)
             f1 = const + techfun
             f2 = techfun + const
             tol = 5e1 * eps * abs(const)
             self.assertLessEqual(infnorm(f(xx) - f1(xx)), tol)
             self.assertLessEqual(infnorm(f(xx) - f2(xx)), tol)
예제 #20
0
 def test__add__radd__constant(self):
     xx = self.xx
     for (fun, funlen, _) in testfunctions:
         for const in (-1, 1, 10, -1e5):
             f = lambda x: const + fun(x)
             techfun = Chebtech2.initfun_fixedlen(fun, funlen)
             f1 = const + techfun
             f2 = techfun + const
             tol = 5e1 * eps * abs(const)
             self.assertLessEqual(infnorm(f(xx)-f1(xx)), tol)
             self.assertLessEqual(infnorm(f(xx)-f2(xx)), tol)
예제 #21
0
 def test__mul__rmul__constant(self):
     xx = self.xx
     for (fun, funlen, _) in testfunctions:
         for const in (-1, 1, 10, -1e5):
             techfun = Chebtech2.initfun_fixedlen(fun, funlen)
             f = lambda x: const * fun(x)
             g = lambda x: fun(x) * const
             ff = const * techfun
             gg = techfun * const
             tol = 5e1 * eps * abs(const)
             self.assertLessEqual(infnorm(f(xx)-ff(xx)), tol)
             self.assertLessEqual(infnorm(g(xx)-gg(xx)), tol)
예제 #22
0
 def test__mul__rmul__constant(self):
     xx = self.xx
     for (fun, funlen, _) in testfunctions:
         for const in (-1, 1, 10, -1e5):
             techfun = Chebtech2.initfun_fixedlen(fun, funlen)
             f = lambda x: const * fun(x)
             g = lambda x: fun(x) * const
             ff = const * techfun
             gg = techfun * const
             tol = 5e1 * eps * abs(const)
             self.assertLessEqual(infnorm(f(xx) - ff(xx)), tol)
             self.assertLessEqual(infnorm(g(xx) - gg(xx)), tol)
예제 #23
0
 def test_truediv_constant(self):
     xx = self.xx
     for (fun, funlen, hasRoots) in testfunctions:
         for const in (-1, 1, 10, -1e5):
             tol = eps*abs(const)
             techfun = Chebtech2.initfun_fixedlen(fun, funlen)
             g = lambda x: fun(x) / const
             gg = techfun / const
             self.assertLessEqual(infnorm(g(xx)-gg(xx)), 2*gg.size*tol)
             # don't do the following test for functions with roots
             if not hasRoots:
                 f = lambda x: const / fun(x)
                 ff = const / techfun
                 self.assertLessEqual(infnorm(f(xx)-ff(xx)), 3*ff.size*tol)
예제 #24
0
 def test_truediv_constant(self):
     xx = self.xx
     for (fun, funlen, hasRoots) in testfunctions:
         for const in (-1, 1, 10, -1e5):
             tol = eps*abs(const)
             techfun = Chebtech2.initfun_fixedlen(fun, funlen)
             g = lambda x: fun(x) / const
             gg = techfun / const
             self.assertLessEqual(infnorm(g(xx)-gg(xx)), 2*gg.size*tol)
             # don't do the following test for functions with roots
             if not hasRoots:
                 f = lambda x: const / fun(x)
                 ff = const / techfun
                 self.assertLessEqual(infnorm(f(xx)-ff(xx)), 3*ff.size*tol)
예제 #25
0
 def test__mul__rmul__empty(self):
     for (fun, funlen, _) in testfunctions:
         chebtech = Chebtech2.initfun_fixedlen(fun, funlen)
         self.assertTrue((self.emptyfun * chebtech).isempty)
         self.assertTrue((chebtech * self.emptyfun).isempty)
예제 #26
0
 def setUp(self):
     f = lambda x: sin(3*x) + 5e-1*cos(30*x)
     self.f0 = Chebtech2.initfun_fixedlen(f, 100)
     self.f1 = Chebtech2.initfun_adaptive(f)
예제 #27
0
 def setUp(self):
     f = lambda x: sin(3 * x) + 5e-1 * cos(30 * x)
     self.f0 = Chebtech2.initfun_fixedlen(f, 100)
     self.f1 = Chebtech2.initfun_adaptive(f)
예제 #28
0
 def setUp(self):
     self.ff = Chebtech2.initfun_fixedlen(lambda x: sin(30 * x), 100)
     self.xx = -1 + 2 * rand(100)
예제 #29
0
def definiteIntegralTester(fun, n, integral, tol):
    ff = Chebtech2.initfun_fixedlen(fun, n)
    def tester(self):
        absdiff = abs(ff.sum()-integral)
        self.assertLessEqual(absdiff, tol)
    return tester
예제 #30
0
 def test__mul__rmul__empty(self):
     for (fun, funlen, _) in testfunctions:
         chebtech = Chebtech2.initfun_fixedlen(fun, funlen)
         self.assertTrue((self.emptyfun*chebtech).isempty)
         self.assertTrue((chebtech*self.emptyfun).isempty)
예제 #31
0
def definiteIntegralTester(fun, n, vscale):
    ff = Chebtech2.initfun_fixedlen(fun, n)
    def tester(self):
        absdiff = abs(ff.vscale-vscale)
        self.assertLessEqual(absdiff, .1*vscale)
    return tester
예제 #32
0
 def setUp(self):
     f = lambda x: sin(3 * x) + 5e-1 * cos(30 * x)
     u = lambda x: np.exp(2 * np.pi * 1j * x)
     self.f0 = Chebtech2.initfun_fixedlen(f, 100)
     self.f1 = Chebtech2.initfun_adaptive(f)
     self.f2 = Chebtech2.initfun_adaptive(u)
예제 #33
0
 def setUp(self):
     self.ff = Chebtech2.initfun_fixedlen(lambda x: np.sin(30*x), 100)
     self.xx = -1 + 2*np.random.rand(100)
예제 #34
0
def fixedlenTester(fun, n):
    ff = Chebtech2.initfun_fixedlen(fun, n)
    def tester(self):
        self.assertEquals(ff.size, n)
    return tester