コード例 #1
0
ファイル: test_libs.py プロジェクト: B-Rich/llvmmath
def test_abs():
    "Test abs() with negative numbers"
    lib = libs.get_mathlib_so()

    def get_syms(rtypes, types):
        for rty, ty in zip(rtypes, types):
            yield lib.get_ctypes_symbol('abs', ltypes.Signature(rty, [ty]))

    iabs, labs, llabs = get_syms(ltypes.integral, ltypes.integral)
    fabsf, fabs, fabsl = get_syms(ltypes.floating, ltypes.floating)
    cabsf, cabs, cabsl = get_syms(ltypes.floating, ltypes.complexes)

    # Integral
    assert iabs(-2) == labs(-2) == llabs(-2) == 2

    # Floating
    result = fabsf(-2.2), fabs(-2.2), fabsl(-2.2)
    assert np.allclose(result, [2.2] * 3)

    # Complex
    call = support.call_complex_byref
    x = -2.2 - 3.3j
    result = call(cabsf, x), call(cabs, x), call(cabsl, x)
    result = [r.value for r in result]
    assert np.allclose(result, [abs(x)] * 3), result
コード例 #2
0
ファイル: test_libs.py プロジェクト: toobaz/llvmmath
def test_abs():
    "Test abs() with negative numbers"
    lib = libs.get_mathlib_so()

    def get_syms(rtypes, types):
        for rty, ty in zip(rtypes, types):
            yield lib.get_ctypes_symbol('abs', ltypes.Signature(rty, [ty]))

    iabs, labs, llabs = get_syms(ltypes.integral, ltypes.integral)
    fabsf, fabs, fabsl = get_syms(ltypes.floating, ltypes.floating)
    cabsf, cabs, cabsl = get_syms(ltypes.floating, ltypes.complexes)

    # Integral
    assert iabs(-2) == labs(-2) == llabs(-2) == 2

    # Floating
    result = fabsf(-2.2), fabs(-2.2), fabsl(-2.2)
    assert np.allclose(result, [2.2] * 3)

    # Complex
    call = support.call_complex_byref
    x = -2.2 - 3.3j
    result = call(cabsf, x), call(cabs, x), call(cabsl, x)
    result = [r.value for r in result]
    assert np.allclose(result, [abs(x)] * 3), result
コード例 #3
0
ファイル: test_linking.py プロジェクト: B-Rich/llvmmath
def make_contexts():
    "Create LLVM contexts (_Ctx) for the .so and .s lib"
    so = libs.get_mathlib_so()
    so_linker = linking.ExternalLibraryLinker()
    ctx1 = new_ctx(lib=so, linker=so_linker)
    contexts = [ctx1]

    if have_llvm_asm():
        asm = libs.get_llvm_mathlib()
        asm_linker = linking.LLVMLinker()
        ctx2 = new_ctx(lib=asm, linker=asm_linker)
        contexts.append(ctx2)

    return contexts
コード例 #4
0
ファイル: test_linking.py プロジェクト: toobaz/llvmmath
def make_contexts():
    "Create LLVM contexts (_Ctx) for the .so and .s lib"
    so = libs.get_mathlib_so()
    so_linker = linking.ExternalLibraryLinker()
    ctx1 = new_ctx(lib=so, linker=so_linker)
    contexts = [ctx1]

    if have_llvm_asm():
        asm = libs.get_llvm_mathlib()
        asm_linker = linking.LLVMLinker()
        ctx2 = new_ctx(lib=asm, linker=asm_linker)
        contexts.append(ctx2)

    return contexts
コード例 #5
0
ファイル: test_libs.py プロジェクト: B-Rich/llvmmath
def test_math():
    lib = libs.get_mathlib_so()
    assert not lib.missing, lib.missing
    run_from_types(lib, ltypes.integral)
    run_from_types(lib, ltypes.floating)
    run_from_types(lib, ltypes.complexes)
コード例 #6
0
ファイル: test_libs.py プロジェクト: toobaz/llvmmath
def test_math():
    lib = libs.get_mathlib_so()
    assert not lib.missing, lib.missing
    run_from_types(lib, ltypes.integral)
    run_from_types(lib, ltypes.floating)
    run_from_types(lib, ltypes.complexes)