示例#1
0
def test_find_all_graphs_without_floats():
    def g(x):
        return int(x * 12.5)

    def f(x):
        return g(x) + 1

    rtyper = support.annotate(f, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    res = cw.find_all_graphs(translator.graphs[0],
                             None,
                             jitpolicy,
                             supports_floats=True)
    funcs = set([graph.func for graph in res])
    assert funcs == set([f, g])

    cw = CodeWriter(rtyper)
    res = cw.find_all_graphs(translator.graphs[0],
                             None,
                             jitpolicy,
                             supports_floats=False)
    funcs = [graph.func for graph in res]
    assert funcs == [f]
示例#2
0
def test_find_all_graphs_str_join():
    def i(x, y):
        return "hello".join([str(x), str(y), "bye"])

    rtyper = support.annotate(i, [7, 100])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    # does not explode
    cw.find_all_graphs(translator.graphs[0], None, jitpolicy, True)
示例#3
0
def test_find_all_graphs_str_join():
    def i(x, y):
        return "hello".join([str(x), str(y), "bye"])

    rtyper = support.annotate(i, [7, 100])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    # does not explode
    cw.find_all_graphs(translator.graphs[0], None, jitpolicy, True)
示例#4
0
def test_find_all_graphs_loops():
    def g(x):
        i = 0
        while i < x:
            i += 1
        return i
    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i

    def f(x):
        i = 0
        while i < x*x:
            i += g(x) + h(x)
        return i

    rtyper = support.annotate(f, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    res = cw.find_all_graphs(translator.graphs[0], None, jitpolicy,
                             supports_floats=True)
    funcs = set([graph.func for graph in res])
    assert funcs == set([f, h])
示例#5
0
def test_find_all_graphs_loops():
    def g(x):
        i = 0
        while i < x:
            i += 1
        return i

    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i

    def f(x):
        i = 0
        while i < x * x:
            i += g(x) + h(x)
        return i

    rtyper = support.annotate(f, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    res = cw.find_all_graphs(translator.graphs[0],
                             None,
                             jitpolicy,
                             supports_floats=True)
    funcs = set([graph.func for graph in res])
    assert funcs == set([f, h])
示例#6
0
def test_find_all_graphs():
    def f(x):
        if x < 0:
            return f(-x)
        return x + 1

    @jit.purefunction
    def g(x):
        return x + 2

    @jit.dont_look_inside
    def h(x):
        return x + 3

    def i(x):
        return f(x) * g(x) * h(x)

    rtyper = support.annotate(i, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    res = cw.find_all_graphs(rtyper.annotator.translator.graphs[0], None,
                             jitpolicy, True)
    translator = rtyper.annotator.translator

    funcs = set([graph.func for graph in res])
    assert funcs == set([i, f])
示例#7
0
def test_find_all_graphs():
    def f(x):
        if x < 0:
            return f(-x)
        return x + 1

    @jit.purefunction
    def g(x):
        return x + 2

    @jit.dont_look_inside
    def h(x):
        return x + 3

    def i(x):
        return f(x) * g(x) * h(x)

    rtyper = support.annotate(i, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    res = cw.find_all_graphs(rtyper.annotator.translator.graphs[0], None, jitpolicy, True)
    translator = rtyper.annotator.translator

    funcs = set([graph.func for graph in res])
    assert funcs == set([i, f])
示例#8
0
def test_find_all_graphs_without_floats():
    def g(x):
        return int(x * 12.5)
    def f(x):
        return g(x) + 1
    rtyper = support.annotate(f, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    res = cw.find_all_graphs(translator.graphs[0], None, jitpolicy,
                             supports_floats=True)
    funcs = set([graph.func for graph in res])
    assert funcs == set([f, g])

    cw = CodeWriter(rtyper)        
    res = cw.find_all_graphs(translator.graphs[0], None, jitpolicy,
                             supports_floats=False)
    funcs = [graph.func for graph in res]
    assert funcs == [f]
示例#9
0
def test_unroll_safe_and_inline():
    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i

    h._always_inline_ = True

    def g(x):
        return h(x)

    rtyper = support.annotate(g, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    res = cw.find_all_graphs(translator.graphs[0], None, jitpolicy, supports_floats=True)
    funcs = set([graph.func for graph in res])
    assert funcs == set([g, h])
示例#10
0
def test_unroll_safe_and_inline():
    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i

    h._always_inline_ = True

    def g(x):
        return h(x)

    rtyper = support.annotate(g, [7])
    cw = CodeWriter(rtyper)
    jitpolicy = JitPolicy()
    translator = rtyper.annotator.translator
    res = cw.find_all_graphs(translator.graphs[0],
                             None,
                             jitpolicy,
                             supports_floats=True)
    funcs = set([graph.func for graph in res])
    assert funcs == set([g, h])