def test_return_generator(self): raise unittest.SkipTest( "Inline function with generator return types without yield " "before fusion") def f(x): result = 0 for x in g(x): result += x * 2 return result def g(x): return h(x * 2) def h(x): for i in range(10): yield x * i expected = f(10) f = jit(f) g = jit(g) h = jit(h) result = f(10) self.assertEqual(result, expected)
def get(f, argtypes): f = jit(f) env = environment.fresh_env(f, argtypes, "cpu") func, env = phase.typing(f, env) context = env['flypy.typing.context'] signature = env['flypy.typing.signature'] return func, context, signature
def vectorize(py_func, signatures, **kwds): signature = parse(signatures[0]) nargs = len(signature.argtypes) py_func = make_ndmap(py_func, nargs) func = jit(py_func, signatures[0], **kwds) for signature in signatures[1:]: func.overload(py_func, signature, **kwds)
def decorator(cls): assert isinstance(cls, type), cls interface_compatibility(interfaces) for i in interfaces: verify_interface(cls, i) for i in interfaces: copy_methods(cls, i) return jit(signature)(cls)
def test_nested_generators(self): def f(x): result = 0 for x in g(x): for y in x: result += y * 2 return result def g(x): for i in range(10): yield h(i) def h(x): for i in range(10): yield x * i expected = f(10) f = jit(f); g = jit(g); h = jit(h) result = f(10) self.assertEqual(result, expected)
def test_cache_code(self): def py_func(x, y): return x + y nb_func = jit(py_func) argtypes = (float64, float64) e = environment.fresh_env(nb_func, argtypes) lfunc, env = phase.llvm(nb_func, e) self.db.insert(py_func, argtypes, 'llvm', lfunc, env, now) cached_module, cached_lfunc, cached_env = self.db.lookup( py_func, argtypes, 'llvm') self.assertEqual(str(lfunc), str(cached_lfunc))
def test_return_generator(self): raise unittest.SkipTest( "Inline function with generator return types without yield " "before fusion") def f(x): result = 0 for x in g(x): result += x * 2 return result def g(x): return h(x * 2) def h(x): for i in range(10): yield x * i expected = f(10) f = jit(f); g = jit(g); h = jit(h) result = f(10) self.assertEqual(result, expected)
def test_nested_generators(self): def f(x): result = 0 for x in g(x): for y in x: result += y * 2 return result def g(x): for i in range(10): yield h(i) def h(x): for i in range(10): yield x * i expected = f(10) f = jit(f) g = jit(g) h = jit(h) result = f(10) self.assertEqual(result, expected)
def decorator(f): @wraps(f) def wrapper(self, *args): args = [self.unwrap()] + [x.unwrap() for x in args] return self.wrap(f(*args)) return jit(signature, opaque=True, inline=True, eval_if_const=True)(wrapper)
def apply(signature, arg): return jit(signature)(func)(arg)
def run(f, expected, args): interpreter.expect(jit(f), phase.frontend, args, expected)