Esempio n. 1
0
def test_link_complex(ctx):
    ctx.mkbyref('mycsinf', sinname, ltypes.l_complex64)
    ctx.mkbyref('mycsin',  sinname, ltypes.l_complex128)
    ctx.mkbyref('mycsinl', sinname, ltypes.l_complex256)
    # print(ctx.module)
    ctx.link()
    print(ctx.module)

    m = support.make_mod(ctx)
    input = 10+2j

    result = cmath.sin(input)
    call = support.call_complex_byref

    typeof = lambda f: _base_type(f.argtypes[0])
    assert typeof(m.mycsinf) == ctypes.c_float
    assert typeof(m.mycsin) == ctypes.c_double, typeof(m.mycsin)
    assert typeof(m.mycsinl) in (ctypes.c_double, ctypes.c_longdouble)

    r1 = call(m.mycsinf, input)
    r2 = call(m.mycsin,  input)
    r3 = call(m.mycsinl, input)

    print("expect:", result)
    print("got:", r1, r2, r3)
    assert np.allclose([result] * 3, [r1, r2, r3])
Esempio n. 2
0
def test_link_complex(ctx):
    ctx.mkbyref('mycsinf', sinname, ltypes.l_complex64)
    ctx.mkbyref('mycsin', sinname, ltypes.l_complex128)
    ctx.mkbyref('mycsinl', sinname, ltypes.l_complex256)
    # print(ctx.module)
    ctx.link()
    print(ctx.module)

    m = support.make_mod(ctx)
    input = 10 + 2j

    result = cmath.sin(input)
    call = support.call_complex_byref

    typeof = lambda f: _base_type(f.argtypes[0])
    assert typeof(m.mycsinf) == ctypes.c_float
    assert typeof(m.mycsin) == ctypes.c_double, typeof(m.mycsin)
    assert typeof(m.mycsinl) in (ctypes.c_double, ctypes.c_longdouble)

    r1 = call(m.mycsinf, input)
    r2 = call(m.mycsin, input)
    r3 = call(m.mycsinl, input)

    print("expect:", result)
    print("got:", r1, r2, r3)
    assert np.allclose([result] * 3, [r1, r2, r3])
Esempio n. 3
0
def run(wrap, call_wrapped, ty):
    engine, mod, pm = ctx = support.make_llvm_context()
    double_func = make_double_func(mod, ty)
    wrap(double_func, 'wrapper')

    pymod = support.make_mod(ctx)
    result = call_wrapped(pymod.wrapper, 5 + 6j)
    assert result == 10 + 12j, result
Esempio n. 4
0
def run(wrap, call_wrapped, ty):
    engine, mod, pm = ctx = support.make_llvm_context()
    double_func = make_double_func(mod, ty)
    wrap(double_func, 'wrapper')

    pymod = support.make_mod(ctx)
    result = call_wrapped(pymod.wrapper, 5+6j)
    assert result == 10+12j, result
Esempio n. 5
0
def test_link_real(ctx):
    ctx.mkbyval('mysinf', sinname, ltypes.l_float)
    ctx.mkbyval('mysin',  sinname, ltypes.l_double)
    ctx.mkbyval('mysinl', sinname, ltypes.l_longdouble)

    # print(ctx.module)
    ctx.link()

    m = support.make_mod(ctx)
    our_result = m.mysinf(10.0), m.mysin(10.0), m.mysinl(10.0)
    exp_result = [math.sin(10.0)] * 3
    assert np.allclose(our_result, exp_result)
Esempio n. 6
0
def test_link_real(ctx):
    ctx.mkbyval('mysinf', sinname, ltypes.l_float)
    ctx.mkbyval('mysin', sinname, ltypes.l_double)
    ctx.mkbyval('mysinl', sinname, ltypes.l_longdouble)

    # print(ctx.module)
    ctx.link()

    m = support.make_mod(ctx)
    our_result = m.mysinf(10.0), m.mysin(10.0), m.mysinl(10.0)
    exp_result = [math.sin(10.0)] * 3
    assert np.allclose(our_result, exp_result)
Esempio n. 7
0
def test_link_binary(ctx):
    ty = ltypes.l_complex128
    make_func(ctx, 'mypow', mkname(powname, ty), ty, nargs=2, byref=True)
    ctx.link()
    m = support.make_mod(ctx)
    print(ctx.module)

    assert list(map(_base_type, m.mypow.argtypes)) == [ctypes.c_double] * 3
    assert m.mypow.restype is None

    inputs = 2+2j, 3+3j
    result = support.call_complex_byref(m.mypow, *inputs)
    expect = pow(*inputs)

    print(result, expect)
    assert np.allclose([result], [expect]), (result, expect)
Esempio n. 8
0
def test_link_binary(ctx):
    ty = ltypes.l_complex128
    make_func(ctx, 'mypow', mkname(powname, ty), ty, nargs=2, byref=True)
    ctx.link()
    m = support.make_mod(ctx)
    print(ctx.module)

    assert list(map(_base_type, m.mypow.argtypes)) == [ctypes.c_double] * 3
    assert m.mypow.restype is None

    inputs = 2 + 2j, 3 + 3j
    result = support.call_complex_byref(m.mypow, *inputs)
    expect = pow(*inputs)

    print(result, expect)
    assert np.allclose([result], [expect]), (result, expect)