提交 9a3f089b authored 作者: Frederic Bastien's avatar Frederic Bastien 提交者: Reyhane Askari

Don't merge ordering when there is only 1 ordering.

上级 aa546d11
...@@ -655,7 +655,10 @@ class FunctionGraph(utils.object2): ...@@ -655,7 +655,10 @@ class FunctionGraph(utils.object2):
""" """
ords = OrderedDict() ords = OrderedDict()
first_ordering = None # first non empty ordering
assert isinstance(self._features, list) assert isinstance(self._features, list)
non_empty_ordering = 0
for feature in self._features: for feature in self._features:
if hasattr(feature, 'orderings'): if hasattr(feature, 'orderings'):
orderings = feature.orderings(self) orderings = feature.orderings(self)
...@@ -664,6 +667,22 @@ class FunctionGraph(utils.object2): ...@@ -664,6 +667,22 @@ class FunctionGraph(utils.object2):
str(feature.orderings) + str(feature.orderings) +
". Nondeterministic object is " + ". Nondeterministic object is " +
str(orderings)) str(orderings))
if len(orderings) > 0:
non_empty_ordering += 1
# If we get only 1 ordering, we reuse it directly.
if non_empty_ordering == 1:
ords = orderings
for node, prereqs in iteritems(orderings):
if not isinstance(prereqs, (list, OrderedSet)):
raise TypeError(
"prereqs must be a type with a "
"deterministic iteration order, or toposort "
" will be non-deterministic.")
# If we get more then 1 orderings, we need to
# combine them.
elif non_empty_ordering == 2:
ords = OrderedDict()
if non_empty_ordering > 1:
for node, prereqs in iteritems(orderings): for node, prereqs in iteritems(orderings):
if not isinstance(prereqs, (list, OrderedSet)): if not isinstance(prereqs, (list, OrderedSet)):
raise TypeError( raise TypeError(
...@@ -671,7 +690,9 @@ class FunctionGraph(utils.object2): ...@@ -671,7 +690,9 @@ class FunctionGraph(utils.object2):
"deterministic iteration order, or toposort " "deterministic iteration order, or toposort "
" will be non-deterministic.") " will be non-deterministic.")
ords.setdefault(node, []).extend(prereqs) ords.setdefault(node, []).extend(prereqs)
# eliminate duplicate prereqs if non_empty_ordering > 1:
# eliminate duplicate prereqs if there is more then one
# empty ordering
for (node, prereqs) in iteritems(ords): for (node, prereqs) in iteritems(ords):
ords[node] = list(OrderedSet(prereqs)) ords[node] = list(OrderedSet(prereqs))
return ords return ords
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论