提交 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,16 +667,34 @@ class FunctionGraph(utils.object2): ...@@ -664,16 +667,34 @@ class FunctionGraph(utils.object2):
str(feature.orderings) + str(feature.orderings) +
". Nondeterministic object is " + ". Nondeterministic object is " +
str(orderings)) str(orderings))
for node, prereqs in iteritems(orderings): if len(orderings) > 0:
if not isinstance(prereqs, (list, OrderedSet)): non_empty_ordering += 1
raise TypeError( # If we get only 1 ordering, we reuse it directly.
"prereqs must be a type with a " if non_empty_ordering == 1:
"deterministic iteration order, or toposort " ords = orderings
" will be non-deterministic.") for node, prereqs in iteritems(orderings):
ords.setdefault(node, []).extend(prereqs) if not isinstance(prereqs, (list, OrderedSet)):
# eliminate duplicate prereqs raise TypeError(
for (node, prereqs) in iteritems(ords): "prereqs must be a type with a "
ords[node] = list(OrderedSet(prereqs)) "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):
if not isinstance(prereqs, (list, OrderedSet)):
raise TypeError(
"prereqs must be a type with a "
"deterministic iteration order, or toposort "
" will be non-deterministic.")
ords.setdefault(node, []).extend(prereqs)
if non_empty_ordering > 1:
# eliminate duplicate prereqs if there is more then one
# empty ordering
for (node, prereqs) in iteritems(ords):
ords[node] = list(OrderedSet(prereqs))
return ords return ords
def check_integrity(self): def check_integrity(self):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论