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

Python sympy.julia_code函数代码示例

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

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



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

示例1: test_Pow

def test_Pow():
    assert julia_code(x**3) == "x.^3"
    assert julia_code(x**(y**3)) == "x.^(y.^3)"
    assert julia_code(x**Rational(2, 3)) == 'x.^(2/3)'
    g = implemented_function('g', Lambda(x, 2*x))
    assert julia_code(1/(g(x)*3.5)**(x - y**x)/(x**2 + y)) == \
        "(3.5*2*x).^(-x + y.^x)./(x.^2 + y)"
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:7,代码来源:test_julia.py


示例2: test_julia_matrix_assign_to_more

def test_julia_matrix_assign_to_more():
    # assigning to Symbol or MatrixSymbol requires lhs/rhs match
    A = Matrix([[1, 2, 3]])
    B = MatrixSymbol('B', 1, 3)
    C = MatrixSymbol('C', 2, 3)
    assert julia_code(A, assign_to=B) == "B = [1 2 3]"
    raises(ValueError, lambda: julia_code(A, assign_to=x))
    raises(ValueError, lambda: julia_code(A, assign_to=C))
开发者ID:asmeurer,项目名称:sympy,代码行数:8,代码来源:test_julia.py


示例3: test_julia_matrix_1x1

def test_julia_matrix_1x1():
    A = Matrix([[3]])
    B = MatrixSymbol('B', 1, 1)
    C = MatrixSymbol('C', 1, 2)
    assert julia_code(A, assign_to=B) == "B = [3]"
    # FIXME?
    #assert julia_code(A, assign_to=x) == "x = [3]"
    raises(ValueError, lambda: julia_code(A, assign_to=C))
开发者ID:asmeurer,项目名称:sympy,代码行数:8,代码来源:test_julia.py


示例4: test_julia_matrix_elements

def test_julia_matrix_elements():
    A = Matrix([[x, 2, x*y]])
    assert julia_code(A[0, 0]**2 + A[0, 1] + A[0, 2]) == "x.^2 + x.*y + 2"
    A = MatrixSymbol('AA', 1, 3)
    assert julia_code(A) == "AA"
    assert julia_code(A[0, 0]**2 + sin(A[0,1]) + A[0,2]) == \
           "sin(AA[1,2]) + AA[1,1].^2 + AA[1,3]"
    assert julia_code(sum(A)) == "AA[1,1] + AA[1,2] + AA[1,3]"
开发者ID:asmeurer,项目名称:sympy,代码行数:8,代码来源:test_julia.py


示例5: test_Pow

def test_Pow():
    assert julia_code(x**3) == "x.^3"
    assert julia_code(x**(y**3)) == "x.^(y.^3)"
    assert julia_code(x**Rational(2, 3)) == 'x.^(2/3)'
    g = implemented_function('g', Lambda(x, 2*x))
    assert julia_code(1/(g(x)*3.5)**(x - y**x)/(x**2 + y)) == \
        "(3.5*2*x).^(-x + y.^x)./(x.^2 + y)"
    # For issue 14160
    assert julia_code(Mul(-2, x, Pow(Mul(y,y,evaluate=False), -1, evaluate=False),
                                                evaluate=False)) == '-2*x./(y.*y)'
开发者ID:asmeurer,项目名称:sympy,代码行数:10,代码来源:test_julia.py


示例6: test_MatrixElement_printing

def test_MatrixElement_printing():
    # test cases for issue #11821
    A = MatrixSymbol("A", 1, 3)
    B = MatrixSymbol("B", 1, 3)
    C = MatrixSymbol("C", 1, 3)

    assert(julia_code(A[0, 0]) == "A[1,1]")
    assert(julia_code(3 * A[0, 0]) == "3*A[1,1]")

    F = C[0, 0].subs(C, A - B)
    assert(julia_code(F) == "(A - B)[1,1]")
开发者ID:asmeurer,项目名称:sympy,代码行数:11,代码来源:test_julia.py


示例7: test_julia_not_supported

def test_julia_not_supported():
    assert julia_code(S.ComplexInfinity) == (
        "# Not supported in Julia:\n"
        "# ComplexInfinity\n"
        "zoo"
    )
    f = Function('f')
    assert julia_code(f(x).diff(x)) == (
        "# Not supported in Julia:\n"
        "# Derivative\n"
        "Derivative(f(x), x)"
    )
开发者ID:asmeurer,项目名称:sympy,代码行数:12,代码来源:test_julia.py


示例8: test_haramard

def test_haramard():
    A = MatrixSymbol('A', 3, 3)
    B = MatrixSymbol('B', 3, 3)
    v = MatrixSymbol('v', 3, 1)
    h = MatrixSymbol('h', 1, 3)
    C = HadamardProduct(A, B)
    assert julia_code(C) == "A.*B"
    assert julia_code(C*v) == "(A.*B)*v"
    assert julia_code(h*C*v) == "h*(A.*B)*v"
    assert julia_code(C*A) == "(A.*B)*A"
    # mixing Hadamard and scalar strange b/c we vectorize scalars
    assert julia_code(C*x*y) == "(x.*y)*(A.*B)"
开发者ID:asmeurer,项目名称:sympy,代码行数:12,代码来源:test_julia.py


示例9: test_julia_noninline

def test_julia_noninline():
    source = julia_code((x+y)/Catalan, assign_to='me', inline=False)
    expected = (
        "const Catalan = %s\n"
        "me = (x + y)/Catalan"
    ) % Catalan.evalf(17)
    assert source == expected
开发者ID:asmeurer,项目名称:sympy,代码行数:7,代码来源:test_julia.py


示例10: test_julia_noninline

def test_julia_noninline():
    source = julia_code((x+y)/Catalan, assign_to='me', inline=False)
    expected = (
        "const Catalan = 0.915965594177219\n"
        "me = (x + y)/Catalan"
    )
    assert source == expected
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:7,代码来源:test_julia.py


示例11: test_Matrices_entries_not_hadamard

def test_Matrices_entries_not_hadamard():
    # For Matrix with col >= 2, row >= 2, they need to be scalars
    # FIXME: is it worth worrying about this?  Its not wrong, just
    # leave it user's responsibility to put scalar data for x.
    A = Matrix([[1, sin(2/x), 3*pi/x/5], [1, 2, x*y]])
    expected = ("[1 sin(2/x) 3*pi/(5*x);\n"
                "1        2        x*y]") # <- we give x.*y
    assert julia_code(A) == expected
开发者ID:asmeurer,项目名称:sympy,代码行数:8,代码来源:test_julia.py


示例12: test_julia_piecewise

def test_julia_piecewise():
    expr = Piecewise((x, x < 1), (x**2, True))
    assert julia_code(expr) == "((x < 1) ? (x) : (x.^2))"
    assert julia_code(expr, assign_to="r") == (
        "r = ((x < 1) ? (x) : (x.^2))")
    assert julia_code(expr, assign_to="r", inline=False) == (
        "if (x < 1)\n"
        "    r = x\n"
        "else\n"
        "    r = x.^2\n"
        "end")
    expr = Piecewise((x**2, x < 1), (x**3, x < 2), (x**4, x < 3), (x**5, True))
    expected = ("((x < 1) ? (x.^2) :\n"
                "(x < 2) ? (x.^3) :\n"
                "(x < 3) ? (x.^4) : (x.^5))")
    assert julia_code(expr) == expected
    assert julia_code(expr, assign_to="r") == "r = " + expected
    assert julia_code(expr, assign_to="r", inline=False) == (
        "if (x < 1)\n"
        "    r = x.^2\n"
        "elseif (x < 2)\n"
        "    r = x.^3\n"
        "elseif (x < 3)\n"
        "    r = x.^4\n"
        "else\n"
        "    r = x.^5\n"
        "end")
    # Check that Piecewise without a True (default) condition error
    expr = Piecewise((x, x < 1), (x**2, x > 1), (sin(x), x > 0))
    raises(ValueError, lambda: julia_code(expr))
开发者ID:asmeurer,项目名称:sympy,代码行数:30,代码来源:test_julia.py


示例13: test_boolean

def test_boolean():
    assert julia_code(x & y) == "x && y"
    assert julia_code(x | y) == "x || y"
    assert julia_code(~x) == "!x"
    assert julia_code(x & y & z) == "x && y && z"
    assert julia_code(x | y | z) == "x || y || z"
    assert julia_code((x & y) | z) == "z || x && y"
    assert julia_code((x | y) & z) == "z && (x || y)"
开发者ID:asmeurer,项目名称:sympy,代码行数:8,代码来源:test_julia.py


示例14: test_constants

def test_constants():
    assert julia_code(pi) == "pi"
    assert julia_code(oo) == "Inf"
    assert julia_code(-oo) == "-Inf"
    assert julia_code(S.NegativeInfinity) == "-Inf"
    assert julia_code(S.NaN) == "NaN"
    assert julia_code(S.Exp1) == "e"
    assert julia_code(exp(1)) == "e"
开发者ID:asmeurer,项目名称:sympy,代码行数:8,代码来源:test_julia.py


示例15: test_MatrixSymbol

def test_MatrixSymbol():
    n = Symbol('n', integer=True)
    A = MatrixSymbol('A', n, n)
    B = MatrixSymbol('B', n, n)
    assert julia_code(A*B) == "A*B"
    assert julia_code(B*A) == "B*A"
    assert julia_code(2*A*B) == "2*A*B"
    assert julia_code(B*2*A) == "2*B*A"
    assert julia_code(A*(B + 3*Identity(n))) == "A*(3*eye(n) + B)"
    assert julia_code(A**(x**2)) == "A^(x.^2)"
    assert julia_code(A**3) == "A^3"
    assert julia_code(A**(S.Half)) == "A^(1/2)"
开发者ID:asmeurer,项目名称:sympy,代码行数:12,代码来源:test_julia.py


示例16: test_sparse

def test_sparse():
    M = SparseMatrix(5, 6, {})
    M[2, 2] = 10;
    M[1, 2] = 20;
    M[1, 3] = 22;
    M[0, 3] = 30;
    M[3, 0] = x*y;
    assert julia_code(M) == (
        "sparse([4, 2, 3, 1, 2], [1, 3, 3, 4, 4], [x.*y, 20, 10, 30, 22], 5, 6)"
    )
开发者ID:asmeurer,项目名称:sympy,代码行数:10,代码来源:test_julia.py


示例17: test_containers

def test_containers():
    assert julia_code([1, 2, 3, [4, 5, [6, 7]], 8, [9, 10], 11]) == \
        "Any[1, 2, 3, Any[4, 5, Any[6, 7]], 8, Any[9, 10], 11]"
    assert julia_code((1, 2, (3, 4))) == "(1, 2, (3, 4))"
    assert julia_code([1]) == "Any[1]"
    assert julia_code((1,)) == "(1,)"
    assert julia_code(Tuple(*[1, 2, 3])) == "(1, 2, 3)"
    assert julia_code((1, x*y, (3, x**2))) == "(1, x.*y, (3, x.^2))"
    # scalar, matrix, empty matrix and empty list
    assert julia_code((1, eye(3), Matrix(0, 0, []), [])) == "(1, [1 0 0;\n0 1 0;\n0 0 1], zeros(0, 0), Any[])"
开发者ID:asmeurer,项目名称:sympy,代码行数:10,代码来源:test_julia.py


示例18: test_mix_number_pow_symbols

def test_mix_number_pow_symbols():
    assert julia_code(pi**3) == 'pi^3'
    assert julia_code(x**2) == 'x.^2'
    assert julia_code(x**(pi**3)) == 'x.^(pi^3)'
    assert julia_code(x**y) == 'x.^y'
    assert julia_code(x**(y**z)) == 'x.^(y.^z)'
    assert julia_code((x**y)**z) == '(x.^y).^z'
开发者ID:asmeurer,项目名称:sympy,代码行数:7,代码来源:test_julia.py


示例19: test_Rational

def test_Rational():
    assert julia_code(Rational(3, 7)) == "3/7"
    assert julia_code(Rational(18, 9)) == "2"
    assert julia_code(Rational(3, -7)) == "-3/7"
    assert julia_code(Rational(-3, -7)) == "3/7"
    assert julia_code(x + Rational(3, 7)) == "x + 3/7"
    assert julia_code(Rational(3, 7)*x) == "3*x/7"
开发者ID:asmeurer,项目名称:sympy,代码行数:7,代码来源:test_julia.py


示例20: test_trick_indent_with_end_else_words

def test_trick_indent_with_end_else_words():
    # words starting with "end" or "else" do not confuse the indenter
    t1 = S('endless');
    t2 = S('elsewhere');
    pw = Piecewise((t1, x < 0), (t2, x <= 1), (1, True))
    assert julia_code(pw, inline=False) == (
        "if (x < 0)\n"
        "    endless\n"
        "elseif (x <= 1)\n"
        "    elsewhere\n"
        "else\n"
        "    1\n"
        "end")
开发者ID:asmeurer,项目名称:sympy,代码行数:13,代码来源:test_julia.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python sympy.lambdify函数代码示例发布时间:2022-05-27
下一篇:
Python sympy.jscode函数代码示例发布时间: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