예제 #1
0
    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)
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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)
예제 #5
0
파일: vectorize.py 프로젝트: pausz/flypy
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)
예제 #6
0
    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)
예제 #7
0
파일: interface.py 프로젝트: pombreda/flypy
    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)
예제 #8
0
    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)
예제 #9
0
    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))
예제 #10
0
    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))
예제 #11
0
    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)
예제 #12
0
    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)
예제 #13
0
 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)
예제 #14
0
파일: test_ffi.py 프로젝트: filmackay/flypy
 def apply(signature, arg):
     return jit(signature)(func)(arg)
예제 #15
0
def run(f, expected, args):
    interpreter.expect(jit(f), phase.frontend, args, expected)
예제 #16
0
def run(f, expected, args):
    interpreter.expect(jit(f), phase.frontend, args, expected)