当前位置: 首页>>代码示例>>Python>>正文


Python model.summary函数代码示例

本文整理汇总了Python中pypy.objspace.flow.model.summary函数的典型用法代码示例。如果您正苦于以下问题:Python summary函数的具体用法?Python summary怎么用?Python summary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了summary函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: xxx_test_later_along_link

def xxx_test_later_along_link():
    S1 = lltype.GcStruct('S1', ('x', lltype.Signed), hints={'immutable': True})
    s1 = lltype.malloc(S1)
    s1.x = 123
    s2 = lltype.malloc(S1)
    s2.x = 60
    def fn(x, y):
        if x:
            x = s1.x
        else:
            x = s2.x
        y *= 2
        return (x+1) - y

    graph, t = get_graph(fn, [int, int])
    assert summary(graph) == {'int_is_true': 1,
                              'getfield': 2,
                              'int_mul': 1,
                              'int_add': 1,
                              'int_sub': 1}
    constant_fold_graph(graph)
    assert summary(graph) == {'int_is_true': 1,
                              'int_mul': 1,
                              'int_sub': 1}
    check_graph(graph, [-1], 124, t)
    check_graph(graph, [0], 61, t)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:26,代码来源:test_constfold.py

示例2: test_access_directly_specialized

    def test_access_directly_specialized(self):
        def g(b):
            return b.v0

        def f(n):
            b = B(n)
            x = g(b)
            y = g(hint(b, access_directly=True))
            return x + y

        t, typer, graph = self.gengraph(f, [int])
        desc = typer.annotator.bookkeeper.getdesc(g)
        g_graphs = desc._cache.items()
        assert len(g_graphs) == 2
        g_graphs.sort()
        assert g_graphs[0][0] is None

        assert get_force_virtualizable_flags(g_graphs[0][1]) == [{}]
        expected =  [{'access_directly': True}]        
        assert get_force_virtualizable_flags(g_graphs[1][1]) == expected

        self.replace_force_virtualizable(typer, [g_graphs[0][1],
                                                 g_graphs[1][1]])
        
        assert summary(g_graphs[0][1]) == {'direct_call': 1, self.GETFIELD: 1}
        assert summary(g_graphs[1][1]) == {self.GETFIELD: 1}        

        res = self.interpret(f, [23]) 
        assert res == 46
开发者ID:alkorzt,项目名称:pypy,代码行数:29,代码来源:test_rvirtualizable2.py

示例3: test_access_directly_escape

    def test_access_directly_escape(self):
        class Global:
            pass
        glob = Global()

        def g(b):
            glob.b = b

        def h(b):
            return b.v0

        def f(n):
            b = B(n)
            g(b)
            g(hint(b, access_directly=True))
            return h(glob.b)

        t, typer, graph = self.gengraph(f, [int])
        desc = typer.annotator.bookkeeper.getdesc(g)
        g_graphs = desc._cache.items()
        assert len(g_graphs) == 2
        g_graphs.sort()
        assert g_graphs[0][0] is None
        assert summary(g_graphs[0][1]) == {self.SETFIELD: 1}
        assert summary(g_graphs[1][1]) == {self.SETFIELD: 1}
        
        h_graph = t._graphof(h)
        assert summary(h_graph) == {'jit_force_virtualizable': 1,
                                    self.GETFIELD: 1}
        assert get_force_virtualizable_flags(h_graph) == [{}]

        res = self.interpret(f, [23])
        assert res == 23
开发者ID:alkorzt,项目名称:pypy,代码行数:33,代码来源:test_rvirtualizable2.py

示例4: test_dont_constfold_debug_print

def test_dont_constfold_debug_print():
    def fn():
        llop.debug_print(lltype.Void, "hello world")

    graph, t = get_graph(fn, [])
    assert summary(graph) == {'debug_print': 1}
    constant_fold_graph(graph)
    assert summary(graph) == {'debug_print': 1}
开发者ID:antoine1fr,项目名称:pygirl,代码行数:8,代码来源:test_constfold.py

示例5: test_simple_melting_away

def test_simple_melting_away():
    def fn(n):
        assert n >= 1
        return n-1
    graph, t = get_graph(fn, [int])
    assert summary(graph) == {'int_ge': 1, 'int_sub': 1}
    remove_asserts(t, [graph])
    assert summary(graph) == {'int_ge': 1, 'debug_assert': 1, 'int_sub': 1}
    check_graph(graph, [1], 0, t)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:9,代码来源:test_removeassert.py

示例6: test_simple

def test_simple():
    S1 = lltype.GcStruct('S1', ('x', lltype.Signed), hints={'immutable': True})
    s1 = lltype.malloc(S1)
    s1.x = 123
    def g(y):
        return y + 1
    def fn():
        return g(s1.x)

    graph, t = get_graph(fn, [])
    assert summary(graph) == {'getfield': 1, 'direct_call': 1}
    constant_fold_graph(graph)
    assert summary(graph) == {'direct_call': 1}
    check_graph(graph, [], 124, t)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:14,代码来源:test_constfold.py

示例7: test_simple_melting_away

def test_simple_melting_away():
    def fn(n):
        assert n >= 1
        return n-1
    graph, t = get_graph(fn, [int])
    assert summary(graph) == {'int_ge': 1, 'int_sub': 1}
    remove_asserts(t, [graph])
    assert summary(graph) == {'int_ge': 1, 'debug_assert': 1, 'int_sub': 1}
    check_graph(graph, [1], 0, t)
    from pypy.translator.backendopt.removenoops import remove_debug_assert
    remove_debug_assert(graph)
    assert summary(graph) == {'int_ge': 1, 'int_sub': 1}
    from pypy.translator.simplify import transform_dead_op_vars
    transform_dead_op_vars(graph)
    assert summary(graph) == {'int_sub': 1}
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:15,代码来源:test_removeassert.py

示例8: check_insns

 def check_insns(self, expected=None, **counts):
     residual_graph = self.get_residual_graph()
     self.insns = summary(residual_graph)
     if expected is not None:
         assert self.insns == expected
     for opname, count in counts.items():
         assert self.insns.get(opname, 0) == count
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:test_portal.py

示例9: test_multiple_incoming_links

def test_multiple_incoming_links():
    S1 = lltype.GcStruct('S1', ('x', lltype.Signed), hints={'immutable': True})
    s1 = lltype.malloc(S1)
    s1.x = 123
    s2 = lltype.malloc(S1)
    s2.x = 60
    s3 = lltype.malloc(S1)
    s3.x = 15
    def fn(x):
        y = x * 10
        if x == 1:
            x = s1.x
        elif x == 2:
            x = s2.x
        elif x == 3:
            x = s3.x
            y = s1.x
        return (x+1) + y

    graph, t = get_graph(fn, [int])
    constant_fold_graph(graph)
    assert summary(graph) == {'int_mul': 1, 'int_eq': 3, 'int_add': 2}
    for link in graph.iterlinks():
        if Constant(139) in link.args:
            break
    else:
        raise AssertionError("139 not found in the graph as a constant")
    for i in range(4):
        check_graph(graph, [i], fn(i), t)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:29,代码来源:test_constfold.py

示例10: test_access_directly_escape

def test_access_directly_escape():
    class Global:
        pass
    glob = Global()

    def g(b):
        glob.b = b

    def h(b):
        return b.v0

    def f(n):
        b = B(n)
        g(b)
        g(hint(b, access_directly=True))
        return h(glob.b)

    interp, graph = get_interpreter(f, [23])
    desc = interp.typer.annotator.bookkeeper.getdesc(g)
    g_graphs = desc._cache.values()
    assert len(g_graphs) == 2
    summaries = map(summary, g_graphs)
    summaries.sort()
    assert summaries == [{'setfield': 1},
                         {'setfield': 1}]
    h_graph = interp.typer.annotator.translator._graphof(h)
    assert summary(h_graph) == {'direct_call': 1}

    res = interp.eval_graph(graph, [23])
    assert res == 23
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:30,代码来源:test_rvirtualizable.py

示例11: test_access_directly_method

    def test_access_directly_method(self):
        class A:
            _virtualizable2_ = ['v0']

            def __init__(self, v):
                self.v0 = v
            
            def meth1(self, x):
                return self.g(x+1)

            def g(self, y):
                return self.v0 * y

        def f(n):
            a = A(n)
            a = hint(a, access_directly=True)
            return a.meth1(100)

        t, typer, graph = self.gengraph(f, [int])
        g_graph = t._graphof(A.g.im_func)

        self.replace_force_virtualizable(typer, [g_graph])
        
        assert summary(g_graph) == {self.GETFIELD: 1, 'int_mul': 1}

        res = self.interpret(f, [23])
        assert res == 2323
开发者ID:alkorzt,项目名称:pypy,代码行数:27,代码来源:test_rvirtualizable2.py

示例12: test_coalesce_exitswitchs

def test_coalesce_exitswitchs():
    def g(n):
        return n > 5 and n < 20
    def fn(n):
        if g(n):
            return 100
        else:
            return 0

    graph, t = get_graph(fn, [int])
    from pypy.translator.backendopt import removenoops, inline
    inline.auto_inline_graphs(t, t.graphs, threshold=999)
    removenoops.remove_same_as(graph)
    constant_fold_graph(graph)
    if conftest.option.view:
        t.view()
    # check that the graph starts with a condition (which should be 'n > 5')
    # and that if this condition is false, it goes directly to 'return 0'.
    assert summary(graph) == {'int_gt': 1, 'int_lt': 1}
    assert len(graph.startblock.exits) == 2
    assert graph.startblock.exits[0].exitcase == False
    assert graph.startblock.exits[0].target is graph.returnblock
    check_graph(graph, [2], 0, t)
    check_graph(graph, [10], 100, t)
    check_graph(graph, [42], 0, t)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:25,代码来源:test_constfold.py

示例13: test_substitute_graph

def test_substitute_graph():
    class MetaG:
        pass    # the details are only used by the timeshifter

    def g(m):
        return m * 17

    def f(n, m):
        x = g(n)
        y = g(m)
        hint(y, concrete=True)
        return g(m)

    class MyPolicy(HintAnnotatorPolicy):
        entrypoint_returns_red = False
        def look_inside_graph(self, graph):
            if graph.func is g:
                return MetaG   # replaces g with a meta-call to metafunc()
            else:
                return True

    hs, hannotator = hannotate(f, [int, int], policy=MyPolicy(),
                               annotator=True)
    assert hs.is_green()
    for graph in hannotator.translator.graphs:
        assert 'int_mul' not in flowmodel.summary(graph)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:26,代码来源:test_annotator.py

示例14: test_keepalive_const_fieldptr

def test_keepalive_const_fieldptr():
    S1 = lltype.GcStruct('S1', ('x', lltype.Signed))
    s1 = lltype.malloc(S1)
    s1.x = 1234
    def fn():
        p1 = lltype.direct_fieldptr(s1, 'x')
        return p1[0]
    graph, t = get_graph(fn, [])
    assert summary(graph) == {'direct_fieldptr': 1, 'getarrayitem': 1}
    constant_fold_graph(graph)

    # kill all references to 's1'
    s1 = fn = None
    del graph.func
    import gc; gc.collect()

    assert summary(graph) == {'getarrayitem': 1}
    check_graph(graph, [], 1234, t)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:18,代码来源:test_constfold.py

示例15: test_keepalive_const_substruct

def test_keepalive_const_substruct():
    py.test.skip("do we want partial folding of getinteriorfield?")
    S2 = lltype.Struct('S2', ('x', lltype.Signed))
    S1 = lltype.GcStruct('S1', ('sub', S2))
    s1 = lltype.malloc(S1)
    s1.sub.x = 1234
    def fn():
        return s1.sub.x
    graph, t = get_graph(fn, [])
    assert summary(graph) == {'getinteriorfield': 1}
    constant_fold_graph(graph)

    # kill all references to 's1'
    s1 = fn = None
    del graph.func
    import gc; gc.collect()

    assert summary(graph) == {'getfield': 1}
    check_graph(graph, [], 1234, t)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:19,代码来源:test_constfold.py


注:本文中的pypy.objspace.flow.model.summary函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。