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