当前位置: 首页>>代码示例>>Python>>正文


Python sympy.jscode函数代码示例

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


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

示例1: test_jscode_Pow

def test_jscode_Pow():
    g = implemented_function('g', Lambda(x, 2*x))
    assert jscode(x**3) == "Math.pow(x, 3)"
    assert jscode(x**(y**3)) == "Math.pow(x, Math.pow(y, 3))"
    assert jscode(1/(g(x)*3.5)**(x - y**x)/(x**2 + y)) == \
        "Math.pow(3.5*2*x, -x + Math.pow(y, x))/(Math.pow(x, 2) + y)"
    assert jscode(x**-1.0) == '1/x'
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:7,代码来源:test_jscode.py

示例2: test_jscode_Pow

def test_jscode_Pow():
    assert jscode(x ** 3) == "Math.pow(x, 3)"
    assert jscode(x ** (y ** 3)) == "Math.pow(x, Math.pow(y, 3))"
    assert (
        jscode(1 / (g(x) * 3.5) ** (x - y ** x) / (x ** 2 + y))
        == "Math.pow(3.5*g(x), -x + Math.pow(y, x))/(Math.pow(x, 2) + y)"
    )
    assert jscode(x ** -1.0) == "1/x"
开发者ID:cbr-washington-edu,项目名称:branch,代码行数:8,代码来源:test_jscode.py

示例3: 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(jscode(A[0, 0]) == "A[0]")
    assert(jscode(3 * A[0, 0]) == "3*A[0]")

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

示例4: test_jscode_inline_function

def test_jscode_inline_function():
    x = symbols("x")
    g = implemented_function("g", Lambda(x, 2 * x))
    assert jscode(g(x)) == "2*x"
    g = implemented_function("g", Lambda(x, 2 * x / Catalan))
    assert jscode(g(x)) == "var Catalan = %s;\n2*x/Catalan" % Catalan.n()
    A = IndexedBase("A")
    i = Idx("i", symbols("n", integer=True))
    g = implemented_function("g", Lambda(x, x * (1 + x) * (2 + x)))
    assert jscode(g(A[i]), assign_to=A[i]) == (
        "for (var i=0; i<n; i++){\n" "   A[i] = A[i]*(1 + A[i])*(2 + A[i]);\n" "}"
    )
开发者ID:cbr-washington-edu,项目名称:branch,代码行数:12,代码来源:test_jscode.py

示例5: test_jscode_inline_function

def test_jscode_inline_function():
    x = symbols('x')
    g = implemented_function('g', Lambda(x, 2*x))
    assert jscode(g(x)) == "2*x"
    g = implemented_function('g', Lambda(x, 2*x/Catalan))
    assert jscode(g(x)) == "var Catalan = %s;\n2*x/Catalan" % Catalan.n()
    A = IndexedBase('A')
    i = Idx('i', symbols('n', integer=True))
    g = implemented_function('g', Lambda(x, x*(1 + x)*(2 + x)))
    assert jscode(g(A[i]), assign_to=A[i]) == (
        "for (var i=0; i<n; i++){\n"
        "   A[i] = (A[i] + 1)*(A[i] + 2)*A[i];\n"
        "}"
    )
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:14,代码来源:test_jscode.py

示例6: test_jscode_loops_addfactor

def test_jscode_loops_addfactor():
    from sympy.tensor import IndexedBase, Idx
    from sympy import symbols

    n, m, o, p = symbols("n m o p", integer=True)
    a = IndexedBase("a")
    b = IndexedBase("b")
    c = IndexedBase("c")
    y = IndexedBase("y")
    i = Idx("i", m)
    j = Idx("j", n)
    k = Idx("k", o)
    l = Idx("l", p)

    s = (
        "for (var i=0; i<m; i++){\n"
        "   y[i] = 0;\n"
        "}\n"
        "for (var i=0; i<m; i++){\n"
        "   for (var j=0; j<n; j++){\n"
        "      for (var k=0; k<o; k++){\n"
        "         for (var l=0; l<p; l++){\n"
        "            y[i] = (a[i*n*o*p + j*o*p + k*p + l] + b[i*n*o*p + j*o*p + k*p + l])*c[j*o*p + k*p + l] + y[i];\n"
        "         }\n"
        "      }\n"
        "   }\n"
        "}"
    )
    c = jscode((a[i, j, k, l] + b[i, j, k, l]) * c[j, k, l], assign_to=y[i])
    assert c == s
开发者ID:cbr-washington-edu,项目名称:branch,代码行数:30,代码来源:test_jscode.py

示例7: jsify_expr

def jsify_expr(expr):
    clamp = Function("clamp")
    bottom_clamp = Function("bottom")
    x = Wild("x")
    # Prevent NaNs on inverse trig functions
    expr = expr.replace(asin, lambda x: asin(clamp(x, -1, 1)))
    expr = expr.replace(acos, lambda x: acos(clamp(x, -1, 1)))
    # Prevent NaNs on sqrts
    expr = expr.replace(sqrt(x + 1),
                        sqrt(bottom_clamp(x + 1, 0)))
    js_expr = jscode(expr, user_functions = {
            "clamp": "THREE.Math.clamp",
            "bottom": "THREE.Math.clampBottom"
        })
    # Convert all matrix references for compatibility with
    # three.js
    atoms = expr.atoms(Symbol)
    matrices = set([])
    for atom in atoms:
        matrix_name = re.findall("([a-zA-Z]+)_\d,\d", atom.name)
        if len(matrix_name) > 0:
            matrices.add(matrix_name[0])
    for matrix in matrices:
        js_expr = subs_matrix_elements(js_expr, matrix)
    return js_expr
开发者ID:TJSomething,项目名称:ncb,代码行数:25,代码来源:build_motion.py

示例8: test_jscode_loops_multiple_contractions

def test_jscode_loops_multiple_contractions():
    from sympy.tensor import IndexedBase, Idx
    from sympy import symbols
    n, m, o, p = symbols('n m o p', integer=True)
    a = IndexedBase('a')
    b = IndexedBase('b')
    y = IndexedBase('y')
    i = Idx('i', m)
    j = Idx('j', n)
    k = Idx('k', o)
    l = Idx('l', p)

    s = (
        'for (var i=0; i<m; i++){\n'
        '   y[i] = 0;\n'
        '}\n'
        'for (var i=0; i<m; i++){\n'
        '   for (var j=0; j<n; j++){\n'
        '      for (var k=0; k<o; k++){\n'
        '         for (var l=0; l<p; l++){\n'
        '            y[i] = y[i] + b[j*o*p + k*p + l]*a[i*n*o*p + j*o*p + k*p + l];\n'
        '         }\n'
        '      }\n'
        '   }\n'
        '}'
    )
    c = jscode(b[j, k, l]*a[i, j, k, l], assign_to=y[i])
    assert c == s
开发者ID:Acebulf,项目名称:sympy,代码行数:28,代码来源:test_jscode.py

示例9: eval_graph

def eval_graph(evaluator, variable):
    from sympy.plotting.plot import LineOver1DRangeSeries
    func = evaluator.eval("input_evaluated")

    free_symbols = sympy.sympify(func).free_symbols
    if len(free_symbols) != 1 or variable not in free_symbols:
        raise ValueError("Cannot graph function of multiple variables")

    try:
        series = LineOver1DRangeSeries(func, (variable, -10, 10), nb_of_points=200)
        # returns a list of [[x,y], [next_x, next_y]] pairs
        series = series.get_segments()
    except TypeError:
        raise ValueError("Cannot graph function")

    xvalues = []
    yvalues = []
    for point in series:
        xvalues.append(point[0][0])
        yvalues.append(point[0][1])
    xvalues.append(series[-1][1][0])
    yvalues.append(series[-1][1][1])
    return {
        'function': sympy.jscode(sympy.sympify(func)),
        'variable': repr(variable),
        'xvalues': json.dumps(xvalues),
        'yvalues': json.dumps(yvalues)
    }
开发者ID:joaomfranco,项目名称:sympy_gamma,代码行数:28,代码来源:resultsets.py

示例10: test_jscode_loops_addfactor

def test_jscode_loops_addfactor():
    from sympy.tensor import IndexedBase, Idx
    from sympy import symbols
    n, m, o, p = symbols('n m o p', integer=True)
    a = IndexedBase('a')
    b = IndexedBase('b')
    c = IndexedBase('c')
    y = IndexedBase('y')
    i = Idx('i', m)
    j = Idx('j', n)
    k = Idx('k', o)
    l = Idx('l', p)

    s = (
        'for (var i=0; i<m; i++){\n'
        '   y[i] = 0;\n'
        '}\n'
        'for (var i=0; i<m; i++){\n'
        '   for (var j=0; j<n; j++){\n'
        '      for (var k=0; k<o; k++){\n'
        '         for (var l=0; l<p; l++){\n'
        '            y[i] = (a[%s] + b[%s])*c[%s] + y[i];\n' % (i*n*o*p + j*o*p + k*p + l, i*n*o*p + j*o*p + k*p + l, j*o*p + k*p + l) +\
        '         }\n'
        '      }\n'
        '   }\n'
        '}'
    )
    c = jscode((a[i, j, k, l] + b[i, j, k, l])*c[j, k, l], assign_to=y[i])
    assert c == s
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:29,代码来源:test_jscode.py

示例11: test_jscode_boolean

def test_jscode_boolean():
    assert jscode(x & y) == "x && y"
    assert jscode(x | y) == "x || y"
    assert jscode(~x) == "!x"
    assert jscode(x & y & z) == "x && y && z"
    assert jscode(x | y | z) == "x || y || z"
    assert jscode((x & y) | z) == "z || x && y"
    assert jscode((x | y) & z) == "z && (x || y)"
开发者ID:cbr-washington-edu,项目名称:branch,代码行数:8,代码来源:test_jscode.py

示例12: test_jscode_Piecewise

def test_jscode_Piecewise():
    p = jscode(Piecewise((x, x < 1), (x ** 2, True)))
    s = """\
if (x < 1) {
   x
}
else {
   Math.pow(x, 2)
}\
"""
    assert p == s
开发者ID:cbr-washington-edu,项目名称:branch,代码行数:11,代码来源:test_jscode.py

示例13: eval_graph

def eval_graph(evaluator, variable):
    from sympy.plotting.plot import LineOver1DRangeSeries
    func = evaluator.eval("input_evaluated")
    series = LineOver1DRangeSeries(func, (variable, -10, 10), nb_of_points=200)
    series = series.get_points()
    return {
        'function': sympy.jscode(sympy.sympify(func)),
        'variable': repr(variable),
        'xvalues': json.dumps(series[0].tolist()),
        'yvalues': json.dumps(series[1].tolist())
    }
开发者ID:catchmrbharath,项目名称:sympy_gamma,代码行数:11,代码来源:resultsets.py

示例14: test_jscode_Piecewise_deep

def test_jscode_Piecewise_deep():
    p = jscode(2*Piecewise((x, x < 1), (x**2, True)))
    s = \
"""\
2*((x < 1) ? (
   x
)
: (
   Math.pow(x, 2)
))\
"""
    assert p == s
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:12,代码来源:test_jscode.py

示例15: test_jscode_Piecewise_deep

def test_jscode_Piecewise_deep():
    p = jscode(2*Piecewise((x, x < 1), (x**2, True)))
    s = \
"""\
2*if (x < 1) {
   x
}
else {
   Math.pow(x, 2)
}\
"""
    assert p == s
开发者ID:Acebulf,项目名称:sympy,代码行数:12,代码来源:test_jscode.py


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