提交 15b15332 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

replaced Attribute error catching with call to new get_parents method

上级 4d585874
......@@ -125,13 +125,14 @@ def _contains_cycle(inputs, outputs, orderings):
assert not orderings.get(cur_var_or_node, False)
expand_l = []
else:
try:
if cur_var_or_node.owner:
expand_l = [cur_var_or_node.owner]
else:
expand_l = []
except AttributeError:
expand_l = list(cur_var_or_node.inputs)
expand_l = cur_var_or_node.get_parents()
#try:
# if cur_var_or_node.owner:
# expand_l = [cur_var_or_node.owner]
# else:
# expand_l = []
#except AttributeError:
# expand_l = list(cur_var_or_node.inputs)
expand_l.extend(orderings.get(cur_var_or_node, []))
if expand_l:
......
......@@ -202,6 +202,9 @@ class Apply(utils.object2):
new_node.inputs = new_inputs
return new_node
def get_parents(self):
return list( self.inputs )
#convenience properties
nin = property(lambda self: len(self.inputs), doc='same as len(self.inputs)')
"""property: Number of inputs"""
......@@ -364,6 +367,11 @@ class Variable(utils.object2):
raise NotImplementedError('Subclasses of Variable must provide __ge__',
self.__class__.__name__)
def get_parents(self):
if self.owner is not None:
return [ self.owner ]
return [ ]
def env_getter(self):
warnings.warn("Variable.env is deprecated, it has been renamed 'fgraph'",
stacklevel=2)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论