示例#1
0
 def test_minimum_multipiece(self):
     x = chebfun('x', np.linspace(-2,3,11))
     y = chebfun(2, x.domain)
     g = (x**y).minimum(1.5)
     t = np.linspace(-2,3,2001)
     f = lambda x: np.minimum(x**2,1.5)
     self.assertLessEqual(infnorm(f(t)-g(t)), 1e1*eps)
示例#2
0
 def test_minimum_multipiece(self):
     x = chebfun('x', np.linspace(-2, 3, 11))
     y = chebfun(2, x.domain)
     g = (x**y).minimum(1.5)
     t = np.linspace(-2, 3, 2001)
     f = lambda x: np.minimum(x**2, 1.5)
     self.assertLessEqual(infnorm(f(t) - g(t)), 1e1 * eps)
示例#3
0
 def test_simplify(self):
     dom = np.linspace(-2, 1.5, 13)
     f = chebfun(cos, dom, 70).simplify()
     g = chebfun(cos, dom)
     self.assertEquals(f.domain, g.domain)
     for n, fun in enumerate(f):
         # we allow one degree of freedom difference
         # TODO: check this
         self.assertLessEqual(fun.size - g.funs[n].size, 1)
示例#4
0
 def test_simplify(self):
     dom = np.linspace(-2,1.5,13)
     f = chebfun(cos, dom, 70).simplify()
     g = chebfun(cos, dom)
     self.assertEquals(f.domain, g.domain)
     for n, fun in enumerate(f):
         # we allow one degree of freedom difference
         # TODO: check this
         self.assertLessEqual(fun.size-g.funs[n].size, 1)
示例#5
0
 def test_restrict(self):
     dom1 = Domain(np.linspace(-2,1.5,13))
     dom2 = Domain(np.linspace(-1.7,0.93,17))
     dom3 = dom1.merge(dom2).restrict(dom2)
     f = chebfun(cos, dom1).restrict(dom2)
     g = chebfun(cos, dom3)
     self.assertEquals(f.domain, g.domain)
     for n, fun in enumerate(f):
         # we allow two degrees of freedom difference either way
         # TODO: once standard chop is fixed, may be able to reduce 4 to 0
         self.assertLessEqual(fun.size-g.funs[n].size, 4)
示例#6
0
 def test_restrict(self):
     dom1 = Domain(np.linspace(-2, 1.5, 13))
     dom2 = Domain(np.linspace(-1.7, 0.93, 17))
     dom3 = dom1.merge(dom2).restrict(dom2)
     f = chebfun(cos, dom1).restrict(dom2)
     g = chebfun(cos, dom3)
     self.assertEquals(f.domain, g.domain)
     for n, fun in enumerate(f):
         # we allow two degrees of freedom difference either way
         # TODO: once standard chop is fixed, may be able to reduce 4 to 0
         self.assertLessEqual(fun.size - g.funs[n].size, 4)
示例#7
0
 def test_roots_cache(self):
     # check that a _cache property is created containing the stored roots
     ff = chebfun(sin, np.linspace(-10, 10, 13))
     self.assertFalse(hasattr(ff, '_cache'))
     ff.roots()
     self.assertTrue(hasattr(ff, '_cache'))
     self.assertTrue(ff.roots.__name__ in ff._cache.keys())
示例#8
0
 def test_roots_cache(self):
     # check that a _cache property is created containing the stored roots
     ff = chebfun(sin, np.linspace(-10,10,13))
     self.assertFalse(hasattr(ff, '_cache'))
     ff.roots()
     self.assertTrue(hasattr(ff, '_cache'))
     self.assertTrue(ff.roots.__name__ in ff._cache.keys())
示例#9
0
def domainBreakOpTester(domainBreakOp, f, g, dom, tol):
    xx = np.linspace(dom[0],dom[-1],1001)
    ff = chebfun(f, dom)
    gg = chebfun(g, dom)
    # convert constant g to to callable
    if isinstance(g, (int, float)):
        ffgg = domainBreakOp(f(xx), g)
    else:
        ffgg = domainBreakOp(f(xx), g(xx))
    fg = getattr(ff, domainBreakOp.__name__)(gg)
    def tester(self):
        vscl = max([ff.vscale, gg.vscale])
        hscl = max([ff.hscale, gg.hscale])
        lscl = max([fun.size for fun in np.append(ff.funs, gg.funs)])
        self.assertLessEqual(infnorm(fg(xx)-ffgg), vscl*hscl*lscl*tol)
    return tester
示例#10
0
    def test_chebfun_alphanum_char(self):
        n = 100
        d = np.array([-2, 0, 1])
        f1 = chebfun('x')
        f2 = chebfun('y', d)
        f3 = chebfun('z', n=n)
        f4 = chebfun('a', d, n)

        # check domains
        self.assertTrue(f1.domain == DefaultPrefs.domain)
        self.assertTrue(f2.domain == d)
        self.assertTrue(f3.domain == DefaultPrefs.domain)
        self.assertTrue(f4.domain == d)

        # check lengths of f3 and f4
        self.assertEqual(np.sum([fun.size for fun in f3]), n)
        self.assertTrue(np.all([fun.size == n for fun in f4]))
示例#11
0
    def test_chebfun_callable(self):
        n = 100
        d = np.array([-2, 0, 1])
        f1 = chebfun(np.sin)
        f2 = chebfun(np.sin, d)
        f3 = chebfun(np.sin, n=n)
        f4 = chebfun(np.sin, d, n)

        # check domains
        self.assertTrue(f1.domain == DefaultPrefs.domain)
        self.assertTrue(f2.domain == d)
        self.assertTrue(f3.domain == DefaultPrefs.domain)
        self.assertTrue(f4.domain == d)

        # check lengths of f3 and f4
        self.assertEqual(f3.funs[0].size, n)
        self.assertTrue(np.all([fun.size == n for fun in f4]))
示例#12
0
文件: test_ui.py 项目: chebpy/chebpy
 def test_chebfun_alphanum_char(self):
     n = 100
     d = np.array([-2,0,1])
     f1 = chebfun('x')
     f2 = chebfun('y', d)
     f3 = chebfun('z', n=n)
     f4 = chebfun('a', d, n)
     
     # check domains
     self.assertTrue(f1.domain==DefaultPrefs.domain)
     self.assertTrue(f2.domain==d)
     self.assertTrue(f3.domain==DefaultPrefs.domain)
     self.assertTrue(f4.domain==d)
     
     # check lengths of f3 and f4
     self.assertEqual(np.sum([fun.size for fun in f3]), n)
     self.assertTrue(np.all([fun.size==n for fun in f4]))
示例#13
0
def domainBreakOpTester(domainBreakOp, f, g, dom, tol):
    a, b = dom
    xx = linspace(a,b,1001)
    ff = chebfun(f, dom)
    gg = chebfun(g, dom)
    # convert constant g to to callable
    if isinstance(g, (int, float)):
        ffgg = domainBreakOp(f(xx), g)
    else:
        ffgg = domainBreakOp(f(xx), g(xx))
    fg = getattr(ff, domainBreakOp.__name__)(gg)
    def tester(self):
        vscl = max([ff.vscale, gg.vscale])
        hscl = max([ff.hscale, gg.hscale])
        lscl = max([fun.size for fun in append(ff.funs, gg.funs)])
        self.assertLessEqual(infnorm(fg(xx)-ffgg), vscl*hscl*lscl*tol)
    return tester
示例#14
0
文件: test_ui.py 项目: chebpy/chebpy
 def test_chebfun_callable(self):
     n = 100
     d = np.array([-2,0,1])
     f1 = chebfun(np.sin)
     f2 = chebfun(np.sin, d)
     f3 = chebfun(np.sin, n=n)
     f4 = chebfun(np.sin, d, n)
     
     # check domains
     self.assertTrue(f1.domain==DefaultPrefs.domain)
     self.assertTrue(f2.domain==d)
     self.assertTrue(f3.domain==DefaultPrefs.domain)
     self.assertTrue(f4.domain==d)
     
     # check lengths of f3 and f4
     self.assertEqual(f3.funs[0].size, n)
     self.assertTrue(np.all([fun.size==n for fun in f4]))
示例#15
0
文件: test_ui.py 项目: chebpy/chebpy
 def test_chebfun_float_arg(self):
     d = np.array([-2,0,1])
     f1 = chebfun(3.14)
     f2 = chebfun('3.14')
     f3 = chebfun(2.72, d)
     f4 = chebfun('2.72', d)
     
     # check domains
     self.assertTrue(f1.domain==DefaultPrefs.domain)
     self.assertTrue(f2.domain==DefaultPrefs.domain)
     self.assertTrue(f3.domain==d)
     self.assertTrue(f4.domain==d)
     
     # check all are constant
     self.assertTrue(f1.isconst)
     self.assertTrue(f2.isconst)
     self.assertTrue(f3.isconst)
     self.assertTrue(f4.isconst)
示例#16
0
    def test_chebfun_float_arg(self):
        d = np.array([-2, 0, 1])
        f1 = chebfun(3.14)
        f2 = chebfun('3.14')
        f3 = chebfun(2.72, d)
        f4 = chebfun('2.72', d)

        # check domains
        self.assertTrue(f1.domain == DefaultPrefs.domain)
        self.assertTrue(f2.domain == DefaultPrefs.domain)
        self.assertTrue(f3.domain == d)
        self.assertTrue(f4.domain == d)

        # check all are constant
        self.assertTrue(f1.isconst)
        self.assertTrue(f2.isconst)
        self.assertTrue(f3.isconst)
        self.assertTrue(f4.isconst)
示例#17
0
 def test_from_chebfun(self):
     ff = chebfun(lambda x: np.cos(x), np.linspace(-10, 10, 11))
     Domain.from_chebfun(ff)
示例#18
0
文件: test_ui.py 项目: chebpy/chebpy
 def test_chebfun_null_args(self):
     self.assertTrue(chebfun().isempty)
示例#19
0
 def setUp(self):
     self.f0 = chebfun(np.sin, [-2, 0, 1])
     self.f1 = pickle.loads(pickle.dumps(self.f0))
示例#20
0
 def test_from_chebfun(self):
     ff = chebfun(lambda x: np.cos(x), np.linspace(-10,10,11))
     Domain.from_chebfun(ff)
示例#21
0
 def test_chebfun_null_args(self):
     self.assertTrue(chebfun().isempty)