Example #1
0
File: ui.py Project: chebpy/chebpy
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)
Example #2
0
File: ui.py Project: nbren12/chebpy
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)
Example #3
0
 def test_diff_empty(self):
     df = Chebfun.initempty().diff()
     self.assertIsInstance(df, Chebfun)
     self.assertTrue(df.isempty)
Example #4
0
 def test_dot_empty(self):
     emptyfun = Chebfun.initempty()
     self.assertEqual(self.f1.dot(emptyfun), 0)
     self.assertEqual(emptyfun.dot(self.f1), 0)
Example #5
0
 def test_sum_empty(self):
     f = Chebfun.initempty()
     self.assertEqual(f.sum(), .0)
Example #6
0
 def test_cumsum_empty(self):
     If = Chebfun.initempty().cumsum()
     self.assertIsInstance(If, Chebfun)
     self.assertTrue(If.isempty)
Example #7
0
 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])
Example #8
0
 def test_initempty(self):
     emptyfun = Chebfun.initempty()
     self.assertEqual(emptyfun.funs.size, 0)
Example #9
0
 def setUp(self):
     self.emptyfun = Chebfun.initempty()
     self.yy = np.linspace(-1, 1, 2000)
Example #10
0
 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])
Example #11
0
 def test_dot_empty(self):
     emptyfun = Chebfun.initempty()
     self.assertEqual(self.f1.dot(emptyfun), 0)
     self.assertEqual(emptyfun.dot(self.f1), 0)
Example #12
0
 def test_empty(self):
     rts = Chebfun.initempty().roots()
     self.assertIsInstance(rts, np.ndarray)
     self.assertEqual(rts.size, 0)
Example #13
0
 def test_diff_empty(self):
     df = Chebfun.initempty().diff()
     self.assertIsInstance(df, Chebfun)
     self.assertTrue(df.isempty)
Example #14
0
 def test_cumsum_empty(self):
     If = Chebfun.initempty().cumsum()
     self.assertIsInstance(If, Chebfun)
     self.assertTrue(If.isempty)
Example #15
0
 def test_sum_empty(self):
     f = Chebfun.initempty()
     self.assertEqual(f.sum(), .0)
Example #16
0
 def test_empty(self):
     rts = Chebfun.initempty().roots()
     self.assertIsInstance(rts, np.ndarray)
     self.assertEqual(rts.size, 0)
Example #17
0
 def setUp(self):
     self.emptyfun = Chebfun.initempty()
     self.yy = np.linspace(-1,1,2000)
Example #18
0
 def setUp(self):
     self.emptyfun = Chebfun.initempty()
     self.yy = -1 + 2*rand(1000)
Example #19
0
 def test_initempty(self):
     emptyfun = Chebfun.initempty()
     self.assertEqual(emptyfun.funs.size, 0)