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
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
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)