Пример #1
0
def test_cython_wrapper_inoutarg():
    code_gen = CythonCodeWrapper(CCodeGen())
    routine = make_routine('test', Eq(z, x + y + z))
    source = get_string(code_gen.dump_pyx, [routine])
    expected = ("cdef extern from 'file.h':\n"
                '    void test(double x, double y, double *z)\n'
                '\n'
                'def test_c(double x, double y, double z):\n'
                '\n'
                '    test(x, y, &z)\n'
                '    return z')
    assert source == expected
Пример #2
0
def test_cython_wrapper_scalar_function():
    expr = (x + y) * z
    routine = make_routine('test', expr)
    code_gen = CythonCodeWrapper(CCodeGen())
    source = get_string(code_gen.dump_pyx, [routine])
    expected = ("cdef extern from 'file.h':\n"
                '    double test(double x, double y, double z)\n'
                '\n'
                'def test_c(double x, double y, double z):\n'
                '\n'
                '    return test(x, y, z)')
    assert source == expected
Пример #3
0
def test_cython_wrapper_scalar_function():
    x, y, z = symbols('x,y,z')
    expr = (x + y) * z
    routine = make_routine("test", expr)
    code_gen = CythonCodeWrapper(CCodeGen())
    source = get_string(code_gen.dump_pyx, [routine])
    expected = ("cdef extern from 'file.h':\n"
                "    double test(double x, double y, double z)\n"
                "\n"
                "def test_c(double x, double y, double z):\n"
                "\n"
                "    return test(x, y, z)")
    assert source == expected
Пример #4
0
def test_cython_wrapper_outarg():
    code_gen = CythonCodeWrapper(CCodeGen())

    routine = make_routine("test", Eq(z, x + y))
    source = get_string(code_gen.dump_pyx, [routine])
    expected = ("cdef extern from 'file.h':\n"
                "    void test(double x, double y, double *z)\n"
                "\n"
                "def test_c(double x, double y):\n"
                "\n"
                "    cdef double z = 0\n"
                "    test(x, y, &z)\n"
                "    return z")
    assert source == expected
Пример #5
0
def test_cython_wrapper_inoutarg():
    from diofant import Equality
    x, y, z = symbols('x,y,z')
    code_gen = CythonCodeWrapper(CCodeGen())
    routine = make_routine("test", Equality(z, x + y + z))
    source = get_string(code_gen.dump_pyx, [routine])
    expected = ("cdef extern from 'file.h':\n"
                "    void test(double x, double y, double *z)\n"
                "\n"
                "def test_c(double x, double y, double z):\n"
                "\n"
                "    test(x, y, &z)\n"
                "    return z")
    assert source == expected