def chebfun(f=None, domain=None, n=None): """Chebfun constructor """ # chebfun() if f is None: return Chebfun.initempty() domain = DefaultPrefs.domain if domain is None else domain # chebfun(lambda x: f(x), ... ) if hasattr(f, "__call__"): return Chebfun.initfun(f, domain, n) # chebfun('x', ... ) if isinstance(f, str) and len(f) is 1 and f.isalpha(): if n: return Chebfun.initfun(lambda x: x, domain, n) else: return Chebfun.initidentity(domain) try: # chebfun(3.14, ... ), chebfun('3.14', ... ) return Chebfun.initconst(float(f), domain) except: raise ValueError(f)
def chebfun(f=None, domain=None, n=None): """Chebfun constructor """ # chebfun() if f is None: return Chebfun.initempty() domain = DefaultPrefs.domain if domain is None else domain # chebfun(lambda x: f(x), ... ) if hasattr(f, "__call__"): return _initfun(f, domain, n) # chebfun('x', ... ) if isinstance(f, str) and len(f) is 1 and f.isalpha(): if n: return _initfun(lambda x: x, domain, n) else: return Chebfun.initidentity(domain) try: # chebfun(3.14, ... ), chebfun('3.14', ... ) return Chebfun.initconst(float(f), domain) except: raise ValueError(f)
def test_diff_empty(self): df = Chebfun.initempty().diff() self.assertIsInstance(df, Chebfun) self.assertTrue(df.isempty)
def test_dot_empty(self): emptyfun = Chebfun.initempty() self.assertEqual(self.f1.dot(emptyfun), 0) self.assertEqual(emptyfun.dot(self.f1), 0)
def test_sum_empty(self): f = Chebfun.initempty() self.assertEqual(f.sum(), .0)
def test_cumsum_empty(self): If = Chebfun.initempty().cumsum() self.assertIsInstance(If, Chebfun) self.assertTrue(If.isempty)
def setUp(self): self.f0 = Chebfun.initempty() self.f1 = Chebfun.initfun_adaptive(lambda x: x**2, [-1,1]) self.f2 = Chebfun.initfun_adaptive(lambda x: x**2, [-1,0,1,2])
def test_initempty(self): emptyfun = Chebfun.initempty() self.assertEqual(emptyfun.funs.size, 0)
def setUp(self): self.emptyfun = Chebfun.initempty() self.yy = np.linspace(-1, 1, 2000)
def setUp(self): self.f0 = Chebfun.initempty() self.f1 = Chebfun.initfun_adaptive(lambda x: x**2, [-1, 1]) self.f2 = Chebfun.initfun_adaptive(lambda x: x**2, [-1, 0, 1, 2])
def test_empty(self): rts = Chebfun.initempty().roots() self.assertIsInstance(rts, np.ndarray) self.assertEqual(rts.size, 0)
def setUp(self): self.emptyfun = Chebfun.initempty() self.yy = np.linspace(-1,1,2000)
def setUp(self): self.emptyfun = Chebfun.initempty() self.yy = -1 + 2*rand(1000)