提交 73df2d61 authored 作者: Roy Xue's avatar Roy Xue

Using frozenset and dict

上级 bcedcd7c
...@@ -798,8 +798,7 @@ class ProfileStats(object): ...@@ -798,8 +798,7 @@ class ProfileStats(object):
# This take only the inputs/outputs dependencies. # This take only the inputs/outputs dependencies.
dependencies = fgraph.profile.dependencies dependencies = fgraph.profile.dependencies
DONE_SET = set([]) DONE_SET = set([])
list_set = [] done_dict = {}
list_mem = []
# Initial compute_map which is used to check if a node is valid # Initial compute_map which is used to check if a node is valid
compute_map = defaultdict(lambda: [0]) compute_map = defaultdict(lambda: [0])
...@@ -913,15 +912,13 @@ class ProfileStats(object): ...@@ -913,15 +912,13 @@ class ProfileStats(object):
mem_count -= mem_freed mem_count -= mem_freed
DONE_SET.add(node) DONE_SET.add(node)
if DONE_SET not in list_set: if DONE_SET not in done_dict.keys():
set_copy = DONE_SET.copy() froze_set = frozenset(DONE_SET)
list_set.append(set_copy) done_dict[frozenset] = mem_count
list_mem.append(mem_count)
else: else:
set_idx = list_set.index(DONE_SET) past_mem = done_dict[DONE_SET]
past_mem = list_mem[set_idx] if past_mem > mem_count:
if past_mem >= mem_count: done_dict[DONE_SET] = mem_count
list_mem[set_idx] = mem_count
else: else:
DONE_SET.remove(node) DONE_SET.remove(node)
mem_count -= mem_created mem_count -= mem_created
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论