Example #1
0
def test_rcode_inline_function():
    x = symbols("x")
    g = implemented_function("g", Lambda(x, 2 * x))
    assert rcode(g(x)) == "2*x"
    g = implemented_function("g", Lambda(x, 2 * x / Catalan))
    assert rcode(g(x)) == "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)))
    res = rcode(g(A[i]), assign_to=A[i])
    ref = "for (i in 1:n){\n" "   A[i] = (A[i] + 1)*(A[i] + 2)*A[i];\n" "}"
    assert res == ref
Example #2
0
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" "}"
    )
Example #3
0
def test_rcode_inline_function():
    x = symbols('x')
    g = implemented_function('g', Lambda(x, 2 * x))
    assert rcode(g(x)) == "2*x"
    g = implemented_function('g', Lambda(x, 2 * x / Catalan))
    assert rcode(g(x)) == "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)))
    res = rcode(g(A[i]), assign_to=A[i])
    ref = ("for (i in 1:n){\n" "   A[i] = (A[i] + 1)*(A[i] + 2)*A[i];\n" "}")
    assert res == ref
Example #4
0
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"
                                      "}")
Example #5
0
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"
        "}"
    )
Example #6
0
def test_ccode_inline_function():
    x = symbols('x')
    g = implemented_function('g', Lambda(x, 2*x))
    assert ccode(g(x)) == "2*x"
    g = implemented_function('g', Lambda(x, 2*x/Catalan))
    assert ccode(g(x)) == "double const 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 ccode(g(A[i]), assign_to=A[i]) == (
            "for (int i=0; i<n; i++){\n"
            "   A[i] = A[i]*(1 + A[i])*(2 + A[i]);\n"
            "}"
            )
Example #7
0
def test_ccode_inline_function():
    x = symbols('x')
    g = implemented_function('g', Lambda(x, 2 * x))
    assert ccode(g(x)) == "2*x"
    g = implemented_function('g', Lambda(x, 2 * x / Catalan))
    assert ccode(
        g(x)) == "double const 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 ccode(g(A[i]),
                 assign_to=A[i]) == ("for (int i=0; i<n; i++){\n"
                                     "   A[i] = A[i]*(1 + A[i])*(2 + A[i]);\n"
                                     "}")
Example #8
0
def test_inline_function():
    x = symbols('x')
    g = implemented_function('g', Lambda(x, 2*x))
    assert rust_code(g(x)) == "2*x"

    g = implemented_function('g', Lambda(x, 2*x/Catalan))
    assert rust_code(g(x)) == (
        "const Catalan: f64 = %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 rust_code(g(A[i]), assign_to=A[i]) == (
        "for i in 0..n {\n"
        "    A[i] = (A[i] + 1)*(A[i] + 2)*A[i];\n"
        "}")
Example #9
0
def test_inline_function():
    x = symbols('x')
    g = implemented_function('g', Lambda(x, 2 * x))
    assert rust_code(g(x)) == "2*x"

    g = implemented_function('g', Lambda(x, 2 * x / Catalan))
    assert rust_code(g(x)) == ("const Catalan: f64 = %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 rust_code(g(
        A[i]), assign_to=A[i]) == ("for i in 0..n {\n"
                                   "    A[i] = (A[i] + 1)*(A[i] + 2)*A[i];\n"
                                   "}")
Example #10
0
def test_rcode_inline_function():
    x = symbols('x')
    g = implemented_function('g', Lambda(x, 2*x))
    assert rcode(g(x)) == "2*x"
    g = implemented_function('g', Lambda(x, 2*x/Catalan))
    assert rcode(
        g(x)) == "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)))
    res=rcode(g(A[i]), assign_to=A[i])
    ref=(
        "for (i in 1:n){\n"
        "   A[i] = (A[i] + 1)*(A[i] + 2)*A[i];\n"
        "}"
    )
    assert res == ref