提交 82db3cfa authored 作者: Ian Goodfellow's avatar Ian Goodfellow

updated check_for_bad_grad to use list comprehension of ancestors

上级 5a523b34
......@@ -282,6 +282,24 @@ def check_for_bad_grad( variables ):
an expression involving a BadGradOp
"""
#preprocess variables to make sure it is a list and make
#sure everything is really a variable and not a
#theano.compile.io.SymbolicOutput
if not isinstance(variables, list):
variables = [ variables ]
for i in xrange(len(variables)):
if not isinstance(variables[i],gof.Variable):
if hasattr(variables[i],'variable') and \
isinstance(variables[i].variable,gof.Variable):
variables[i] = variables[i].variable
for v in gof.graph.ancestors(variables):
if v.owner is not None and isinstance(v.owner.op,BadGradOp):
v.owner.op.raise_exc()
"""
#implemented using a deque rather than recursion because python recursion
#limit is set low by default
......@@ -327,6 +345,7 @@ def check_for_bad_grad( variables ):
#end if node is not None
#end if not already_checked
#end while
"""
########################
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论