def test(): for argtype in [object_, float_, double]: # f_ = autojit(f) f_ = jit(numba.function(None, [argtype]))(f) for v in range(-10, 10): assert f_(v) == f(v) assert f_(float(v)) == f(float(v))
def test_math_funcs(): functions = get_functions() exceptions = 0 for func_name in functions: # func_name = 'sqrt' func = functions[func_name] for dest_type in dest_types: signature = numba.function(None, [dest_type, dest_type]) print(("executing...", func_name, signature)) try: numba_func = jit(signature)(func) except error.NumbaError as e: exceptions += 1 print((func_name, dest_type, e)) continue x, y = 5.2, 6.9 if dest_type.is_int: x, y = 5, 6 r1 = numba_func(x, y) r2 = func(x, y) assert np.allclose(r1, r2), (r1, r2, signature, func_name) if exceptions: raise Exception
def test(): for argtype in [object_, float_, double]: # f_ = autojit(f) f_ = jit(numba.function(None, [argtype]))(f) for v in range(-10,10): assert f_(v)==f(v) assert f_(float(v))==f(float(v))
def map_type(cffi_type): "Map CFFI type to numba type" if cffi_type.kind in ('struct', 'union'): if cffi_type.kind == 'union': result = None else: result = struct([(name, map_type(field_type)) for name, field_type in cffi_type.fields]) elif cffi_type.kind == 'function': restype = map_type(cffi_type.result) argtypes = [map_type(arg) for arg in cffi_type.args] result = numba.function(restype, argtypes, is_vararg=cffi_type.ellipsis).pointer() else: result = type_map.get(cffi_type) if result is None: raise TypeError(cffi_type) return result
def signature(self): return numba.function(return_type=self.return_type, args=self.arg_types, is_vararg=self.is_vararg)
def sep201_signature_string(functype, name): functype = numba.function(functype.return_type, functype.args, name) return str(functype)