提交 30a9be00 authored 作者: Frederic's avatar Frederic

Add the trace back to an error message

上级 8da30f6e
......@@ -3,10 +3,12 @@ from __future__ import print_function
import six.moves.builtins as builtins
import logging
import time
import traceback
import warnings
import numpy # for numeric_grad
from six import itervalues
from six.moves import StringIO
import theano
......@@ -515,6 +517,17 @@ def grad(cost, wrt, consider_constant=None,
elif disconnected_inputs == 'warn':
warnings.warn(message, stacklevel=2)
elif disconnected_inputs == 'raise':
# Add the var trace
tr = getattr(var.tag, 'trace', [])
if len(tr) > 0:
message += "\nBacktrace when the node is created:\n"
# Print separate message for each element in the list of batcktraces
sio = StringIO()
for subtr in tr:
traceback.print_list(subtr, sio)
message += str(sio.getvalue())
raise DisconnectedInputError(message)
else:
raise ValueError("Invalid value for keyword "
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论