• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utilities.raises函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中symengine.utilities.raises函数的典型用法代码示例。如果您正苦于以下问题:Python raises函数的具体用法?Python raises怎么用?Python raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了raises函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_numpy_array_out_exceptions

def test_numpy_array_out_exceptions():
    if not HAVE_NUMPY:  # nosetests work-around
        return
    import numpy as np
    args, exprs, inp, check = _get_array()
    lmb = se.Lambdify(args, exprs)

    all_right = np.empty(len(exprs))
    lmb(inp, all_right)

    too_short = np.empty(len(exprs) - 1)
    raises(ValueError, lambda: (lmb(inp, too_short)))

    wrong_dtype = np.empty(len(exprs), dtype=int)
    raises(TypeError, lambda: (lmb(inp, wrong_dtype)))

    read_only = np.empty(len(exprs))
    read_only.flags['WRITEABLE'] = False
    raises(ValueError, lambda: (lmb(inp, read_only)))

    all_right_broadcast = np.empty((2, len(exprs)))
    inp_bcast = [[1, 2, 3], [4, 5, 6]]
    lmb(np.array(inp_bcast), all_right_broadcast)

    f_contig_broadcast = np.empty((2, len(exprs)), order='F')
    raises(ValueError, lambda: (lmb(inp_bcast, f_contig_broadcast)))

    improper_bcast = np.empty((3, len(exprs)))
    raises(ValueError, lambda: (lmb(inp_bcast, improper_bcast)))
开发者ID:isuruf,项目名称:symengine.py,代码行数:29,代码来源:test_lambdify.py


示例2: test_var_return

def test_var_return():
    raises(ValueError, lambda: var(''))
    v2 = var('q')
    v3 = var('q p')

    assert v2 == Symbol('q')
    assert v3 == (Symbol('q'), Symbol('p'))
开发者ID:kunal-iitkgp,项目名称:symengine.py,代码行数:7,代码来源:test_var.py


示例3: test_var

def test_var():
    var("a")
    assert a == Symbol("a")

    var("b bb cc zz _x")
    assert b == Symbol("b")
    assert bb == Symbol("bb")
    assert cc == Symbol("cc")
    assert zz == Symbol("zz")
    assert _x == Symbol("_x")

    v = var(['d', 'e', 'fg'])
    assert d == Symbol('d')
    assert e == Symbol('e')
    assert fg == Symbol('fg')

    # check return value
    assert v == [d, e, fg]

    # see if var() really injects into global namespace
    raises(NameError, lambda: z1)
    _make_z1()
    assert z1 == Symbol("z1")

    raises(NameError, lambda: z2)
    _make_z2()
    assert z2 == Symbol("z2")
开发者ID:Upabjojr,项目名称:symengine,代码行数:27,代码来源:test_var.py


示例4: test_var_global_namespace

def test_var_global_namespace():
    # see if var() really injects into global namespace
    raises(NameError, lambda: z1)
    _make_z1()
    assert z1 == Symbol("z1")

    raises(NameError, lambda: z2)
    _make_z2()
    assert z2 == Symbol("z2")
开发者ID:kunal-iitkgp,项目名称:symengine.py,代码行数:9,代码来源:test_var.py


示例5: test_sub

def test_sub():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])
    B = DenseMatrix(2, 2, [0, -1, -2, -3])
    a = Symbol("a")
    assert A - 5 == DenseMatrix(2, 2, [-4, -3, -2, -1])
    assert a - A == DenseMatrix(2, 2, [a - 1, a - 2, a - 3, a - 4])
    assert A - B == DenseMatrix(2, 2, [1, 3, 5, 7])

    C = DenseMatrix(2, 1, [1, 2])
    raises(ShapeError, lambda: A - C)
开发者ID:lk11235,项目名称:symengine.py,代码行数:10,代码来源:test_matrices.py


示例6: test_Lambdify_LLVM

def test_Lambdify_LLVM():
    n = 7
    args = x, y, z = se.symbols('x y z')
    if not se.have_llvm:
        raises(ValueError, lambda: se.Lambdify(args, [x+y+z, x**2, (x-y)/z, x*y*z],
                                                      backend='llvm'))
        return
    l = se.Lambdify(args, [x+y+z, x**2, (x-y)/z, x*y*z], backend='llvm')
    assert allclose(l(range(n, n+len(args))),
                    [3*n+3, n**2, -1/(n+2), n*(n+1)*(n+2)])
开发者ID:symengine,项目名称:symengine.py,代码行数:10,代码来源:test_lambdify.py


示例7: test_add_scalar

def test_add_scalar():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])

    a = Symbol("a")
    assert A.add_scalar(a) == DenseMatrix(2, 2, [1 + a, 2 + a, 3 + a, 4 + a])

    i5 = Integer(5)
    assert A.add_scalar(i5) == DenseMatrix(2, 2, [6, 7, 8, 9])
    
    raises(TypeError, lambda: A + 5)
    raises(TypeError, lambda: 5 + A)
开发者ID:parsoyaarihant,项目名称:symengine.py,代码行数:11,代码来源:test_matrices.py


示例8: test_det

def test_det():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])
    assert A.det() == -2

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    d = Symbol("d")
    A = DenseMatrix(2, 2, [a, b, c, d])
    assert A.det() == a*d - b*c

    A = DenseMatrix(3, 2, [1, 2, 3, 4, 5, 6])
    raises(NonSquareMatrixError, lambda: A.det())
开发者ID:lk11235,项目名称:symengine.py,代码行数:13,代码来源:test_matrices.py


示例9: test_n

def test_n():
    x = Symbol("x")
    raises(RuntimeError, lambda: (x.n()))

    x = 2 + I
    raises(RuntimeError, lambda: (x.n(real=True)))

    x = sqrt(Integer(4))
    y = RealDouble(2.0)
    assert x.n(real=True) == y

    x = 1 + 2*I
    y = 1.0 + 2.0*I
    assert x.n() == y

    try:
        from symengine import RealMPFR
        x = sqrt(Integer(2))
        y = RealMPFR('1.41421356237309504880169', 75)
        assert x.n(75, real=True) == y
    except ImportError:
        x = sqrt(Integer(2))
        raises(ValueError, lambda: (x.n(75, real=True)))

    try:
        from symengine import ComplexMPC
        x = sqrt(Integer(2)) + 3*I
        y = ComplexMPC('1.41421356237309504880169', '3.0', 75)
        assert x.n(75) == y
    except ImportError:
        x = sqrt(Integer(2))
        raises(ValueError, lambda: (x.n(75)))
开发者ID:cbehan,项目名称:symengine,代码行数:32,代码来源:test_eval.py


示例10: test_get_item

def test_get_item():
    A = DenseMatrix(3, 3, [1, 2, 3, 4, 5, 6, 7, 8, 9])

    assert A[5] == 6
    assert A[-1] == 9
    assert A[2, 2] == 9
    assert A[-2, 2] == 6

    assert A[1:2, 0] == DenseMatrix(1, 1, [4])
    assert A[1:3, 0] == DenseMatrix(2, 1, [4, 7])
    assert A[1:3, 0] == DenseMatrix(2, 1, [4, 7])
    assert A[1:3, 1:] == DenseMatrix(2, 2, [5, 6, 8, 9])
    assert A[1:3, :1] == DenseMatrix(2, 1, [4, 7])
    assert A[0, 0:] == DenseMatrix(1, 3, [1, 2, 3])
    assert A[2, :] == DenseMatrix(1, 3, [7, 8, 9])
    assert A[:2, -2:] == DenseMatrix(2, 2, [2, 3, 5, 6])
    assert A[1:, :3] == DenseMatrix(2, 3, [4, 5, 6, 7, 8, 9])
    assert A[1:] == [2, 3, 4, 5, 6, 7, 8, 9]
    assert A[-2:] == [8, 9]

    raises(IndexError, lambda: A[-10])
    raises(IndexError, lambda: A[9])

    raises(IndexError, lambda: A[1:3, 3])
    raises(IndexError, lambda: A[1:3, -4])
开发者ID:lk11235,项目名称:symengine.py,代码行数:25,代码来源:test_matrices.py


示例11: test_add_matrix

def test_add_matrix():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])
    B = DenseMatrix(2, 2, [1, 0, 0, 1])

    assert A.add_matrix(B) == DenseMatrix(2, 2, [2, 2, 3, 5])

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    d = Symbol("d")
    A = DenseMatrix(2, 2, [a + b, a - b, a, b])
    B = DenseMatrix(2, 2, [a - b, a + b, -a, b])

    assert A.add_matrix(B) == DenseMatrix(2, 2, [2*a, 2*a, 0, 2*b])
    assert A + B == DenseMatrix(2, 2, [2*a, 2*a, 0, 2*b])

    C = DenseMatrix(1, 2, [a, b])
    raises(ShapeError, lambda: A + C)
开发者ID:lk11235,项目名称:symengine.py,代码行数:18,代码来源:test_matrices.py


示例12: test_mul_matrix

def test_mul_matrix():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])
    B = DenseMatrix(2, 2, [1, 0, 0, 1])

    assert A.mul_matrix(B) == A

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    d = Symbol("d")
    A = DenseMatrix(2, 2, [a, b, c, d])
    B = DenseMatrix(2, 2, [1, 0, 1, 0])

    assert A.mul_matrix(B) == DenseMatrix(2, 2, [a + b, 0, c + d, 0])
    assert A * B == DenseMatrix(2, 2, [a + b, 0, c + d, 0])

    C = DenseMatrix(2, 3, [1, 2, 3, 2, 3, 4])
    D = DenseMatrix(3, 2, [3, 4, 4, 5, 5, 6])

    assert C.mul_matrix(D) == DenseMatrix(2, 2, [26, 32, 38, 47])

    raises(ShapeError, lambda: A*D)
开发者ID:lk11235,项目名称:symengine.py,代码行数:22,代码来源:test_matrices.py


示例13: test_DictBasic

def test_DictBasic():
    x, y, z = symbols("x y z")
    d = DictBasic({x: 2, y: z})

    assert str(d) == "{x: 2, y: z}" or str(d) == "{y: z, x: 2}"
    assert d[x] == 2

    raises(KeyError, lambda: d[2*z])
    if 2*z in d:
        assert False

    d[2*z] = x
    assert d[2*z] == x
    if 2*z not in d:
        assert False
    assert set(d.items()) == set([(2*z, x), (x, Integer(2)), (y, z)])

    del d[x]
    assert set(d.keys()) == set([2*z, y])
    assert set(d.values()) == set([x, z])

    e = y + sin(2*z)
    assert e.subs(d) == z + sin(x)
开发者ID:kunal-iitkgp,项目名称:symengine.py,代码行数:23,代码来源:test_dict_basic.py


示例14: test_sub

def test_sub():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])
    B = DenseMatrix(2, 2, [0, -1, -2, -3])
    a = Symbol("a")
    assert A - B == DenseMatrix(2, 2, [1, 3, 5, 7])

    C = DenseMatrix(2, 1, [1, 2])
    raises(ShapeError, lambda: A - C)
    raises(TypeError, lambda: A - 5)
    raises(TypeError, lambda: 5 - A)
开发者ID:parsoyaarihant,项目名称:symengine.py,代码行数:10,代码来源:test_matrices.py


示例15: test_get

def test_get():
    A = DenseMatrix([[1, 2], [3, 4]])

    assert A.get(0, 0) == 1
    assert A.get(0, 1) == 2
    assert A.get(1, 1) == 4

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    d = Symbol("d")
    A = DenseMatrix(2, 2, [a, b, c, d])

    assert A.get(0, 0) == a
    assert A.get(1, 0) == c
    assert A.get(1, 1) == d

    assert A.get(-1, 0) == c
    assert A.get(-1, -1) == d

    raises(IndexError, lambda: A.get(2, 0))
    raises(IndexError, lambda: A.get(0, 2))
    raises(IndexError, lambda: A.get(-3, 0))
开发者ID:lk11235,项目名称:symengine.py,代码行数:23,代码来源:test_matrices.py


示例16: test_symbols

def test_symbols():
    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    assert symbols('x') == x
    assert symbols('x ') == x
    assert symbols(' x ') == x
    assert symbols('x,') == (x,)
    assert symbols('x, ') == (x,)
    assert symbols('x ,') == (x,)

    assert symbols('x , y') == (x, y)

    assert symbols('x,y,z') == (x, y, z)
    assert symbols('x y z') == (x, y, z)

    assert symbols('x,y,z,') == (x, y, z)
    assert symbols('x y z ') == (x, y, z)

    xyz = Symbol('xyz')
    abc = Symbol('abc')

    assert symbols('xyz') == xyz
    assert symbols('xyz,') == (xyz,)
    assert symbols('xyz,abc') == (xyz, abc)

    assert symbols(('xyz',)) == (xyz,)
    assert symbols(('xyz,',)) == ((xyz,),)
    assert symbols(('x,y,z,',)) == ((x, y, z),)
    assert symbols(('xyz', 'abc')) == (xyz, abc)
    assert symbols(('xyz,abc',)) == ((xyz, abc),)
    assert symbols(('xyz,abc', 'x,y,z')) == ((xyz, abc), (x, y, z))

    assert symbols(('x', 'y', 'z')) == (x, y, z)
    assert symbols(['x', 'y', 'z']) == [x, y, z]
    assert symbols(set(['x', 'y', 'z'])) == set([x, y, z])

    raises(ValueError, lambda: symbols(''))
    raises(ValueError, lambda: symbols(','))
    raises(ValueError, lambda: symbols('x,,y,,z'))
    raises(ValueError, lambda: symbols(('x', '', 'y', '', 'z')))

    x0 = Symbol('x0')
    x1 = Symbol('x1')
    x2 = Symbol('x2')

    y0 = Symbol('y0')
    y1 = Symbol('y1')

    assert symbols('x0:0') == ()
    assert symbols('x0:1') == (x0,)
    assert symbols('x0:2') == (x0, x1)
    assert symbols('x0:3') == (x0, x1, x2)

    assert symbols('x:0') == ()
    assert symbols('x:1') == (x0,)
    assert symbols('x:2') == (x0, x1)
    assert symbols('x:3') == (x0, x1, x2)

    assert symbols('x1:1') == ()
    assert symbols('x1:2') == (x1,)
    assert symbols('x1:3') == (x1, x2)

    assert symbols('x1:3,x,y,z') == (x1, x2, x, y, z)

    assert symbols('x:3,y:2') == (x0, x1, x2, y0, y1)
    assert symbols(('x:3', 'y:2')) == ((x0, x1, x2), (y0, y1))

    a = Symbol('a')
    b = Symbol('b')
    c = Symbol('c')
    d = Symbol('d')

    assert symbols('x:z') == (x, y, z)
    assert symbols('a:d,x:z') == (a, b, c, d, x, y, z)
    assert symbols(('a:d', 'x:z')) == ((a, b, c, d), (x, y, z))

    aa = Symbol('aa')
    ab = Symbol('ab')
    ac = Symbol('ac')
    ad = Symbol('ad')

    assert symbols('aa:d') == (aa, ab, ac, ad)
    assert symbols('aa:d,x:z') == (aa, ab, ac, ad, x, y, z)
    assert symbols(('aa:d','x:z')) == ((aa, ab, ac, ad), (x, y, z))

    def sym(s):
        return str(symbols(s))
    assert sym('a0:4') == '(a0, a1, a2, a3)'
    assert sym('a2:4,b1:3') == '(a2, a3, b1, b2)'
    assert sym('a1(2:4)') == '(a12, a13)'
    assert sym(('a0:2.0:2')) == '(a0.0, a0.1, a1.0, a1.1)'
    assert sym(('aa:cz')) == '(aaz, abz, acz)'
    assert sym('aa:c0:2') == '(aa0, aa1, ab0, ab1, ac0, ac1)'
    assert sym('aa:ba:b') == '(aaa, aab, aba, abb)'
    assert sym('a:3b') == '(a0b, a1b, a2b)'
    assert sym('a-1:3b') == '(a-1b, a-2b)'
    assert sym('a:2\,:2' + chr(0)) == '(a0,0%s, a0,1%s, a1,0%s, a1,1%s)' % (
        (chr(0),)*4)
#.........这里部分代码省略.........
开发者ID:kunal-iitkgp,项目名称:symengine.py,代码行数:101,代码来源:test_symbol.py


示例17: test_eval_double2

def test_eval_double2():
    x = Symbol("x")
    y = Symbol("y")
    e = sin(x)**2 + cos(x)**2
    raises(RuntimeError, lambda: (abs(eval_double(e) - 1) < 1e-9))
开发者ID:Upabjojr,项目名称:symengine,代码行数:5,代码来源:test_eval.py


示例18: test_fibonacci_error

def test_fibonacci_error():
    raises(NotImplementedError, lambda: fibonacci(-3))
开发者ID:kunal-iitkgp,项目名称:symengine.py,代码行数:2,代码来源:test_ntheory.py


示例19: test_mod_error

def test_mod_error():
    raises(ZeroDivisionError, lambda: mod(2, 0))
开发者ID:kunal-iitkgp,项目名称:symengine.py,代码行数:2,代码来源:test_ntheory.py


示例20: test_arit3

def test_arit3():
    x = Symbol("x")
    y = Symbol("y")
    raises(TypeError, lambda: ("x"*x))
开发者ID:kunal-iitkgp,项目名称:symengine.py,代码行数:4,代码来源:test_arit.py



注:本文中的symengine.utilities.raises函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python symfit.parameters函数代码示例发布时间:2022-05-27
下一篇:
Python symengine_wrapper.DenseMatrix类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap