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