提交 a4643310 authored 作者: abergeron's avatar abergeron

Merge pull request #1926 from nouiz/err

Better error when missing inputs.
......@@ -584,13 +584,15 @@ class Function(object):
# done by raise_with_op is not implemented in C.
if hasattr(self.fn, 'thunks'):
# For the CVM
gof.vm.raise_with_op(self.fn.nodes[self.fn.position_of_error],
self.fn.thunks[self.fn.position_of_error])
gof.vm.raise_with_op(
self.fn.nodes[self.fn.position_of_error],
self.fn.thunks[self.fn.position_of_error])
else:
# For the c linker
# We don't have access from python to all the temps values
# So for now, we just don't print the extra shapes/strides info
gof.vm.raise_with_op(self.fn.nodes[self.fn.position_of_error])
# For the c linker We don't have access from
# python to all the temps values So for now, we
# just don't print the extra shapes/strides info
gof.vm.raise_with_op(
self.fn.nodes[self.fn.position_of_error])
else:
# old-style linkers raise their own exceptions
raise
......
......@@ -4,8 +4,10 @@ fg.py: fg stands for FunctionGraph
Contains the FunctionGraph class and exception
types that it can raise
"""
import StringIO
import sys
import time
import traceback
import theano
from theano.gof import graph
......@@ -328,18 +330,29 @@ class FunctionGraph(utils.object2):
#if there is no path then r isn't really a graph input so we shouldn't be running error
#handler code in the first place
assert path is not None
raise MissingInputError((
tr = getattr(r.tag, 'trace', None)
detailed_err_msg = ""
if tr:
sio = StringIO.StringIO()
traceback.print_list(tr, sio)
tr = sio.getvalue()
detailed_err_msg += "\nBacktrace when the variable is created:\n"
detailed_err_msg += str(tr)
raise MissingInputError(
'A variable that is an input to the graph was '
'neither provided as an input to the function '
'nor given a value. A chain of variables '
'leading from this input to an output is %s. '
'This chain may not be unique' % str(path)))
'This chain may not be unique' % str(path) +
detailed_err_msg)
#Standard error message
raise MissingInputError((
"An input of the graph, used to compute %s, "
"was not provided and not given a value"
"was not provided and not given a value."
"Use the Theano flag exception_verbosity='high',"
"for more information on this error."
% str(node)),
r)
......
......@@ -13,7 +13,7 @@ __excepthook = sys.excepthook
def log_thunk_trace(value, f=sys.stderr):
"""Log theano's diagnostic stack trace for an exception
"""Log Theano's diagnostic stack trace for an exception
raised by raise_with_op.
"""
# in future, consider accepting `write` as arg rather than file
......@@ -149,7 +149,7 @@ def raise_with_op(node, thunk=None, exc_info=None):
sio = StringIO.StringIO()
traceback.print_list(tr, sio)
tr = sio.getvalue()
detailed_err_msg += "\nBacktrace when the node is created:"
detailed_err_msg += "\nBacktrace when the node is created:\n"
detailed_err_msg += str(tr)
else:
hints.append(
......
......@@ -19,17 +19,18 @@ import theano.gof.cmodule
logger = logging.getLogger(__name__)
AddConfigVar('profile',
"If VM should collect profile information",
BoolParam(False),
in_c_key=False)
"If VM should collect profile information",
BoolParam(False),
in_c_key=False)
AddConfigVar('profile_optimizer',
"If VM should collect optimizer profile information",
BoolParam(False),
in_c_key=False)
"If VM should collect optimizer profile information",
BoolParam(False),
in_c_key=False)
AddConfigVar('profile_memory',
"If VM should collect memory profile information and print it",
BoolParam(False),
in_c_key=False)
"If VM should collect memory profile information and print it",
BoolParam(False),
in_c_key=False)
def filter_vm_lazy(val):
if val == 'False' or val is False:
......@@ -40,7 +41,7 @@ def filter_vm_lazy(val):
return None
else:
raise ValueError('Valid values for an vm.lazy parameter '
'should be None, False or True, not `%s`.' % val)
'should be None, False or True, not `%s`.' % val)
AddConfigVar('vm.lazy',
"Useful only for the vm linkers. When lazy is None,"
......
......@@ -11,7 +11,6 @@ from theano.tensor.utils import hash_from_ndarray
from theano.tensor.type import TensorType
class AsTensorError(TypeError):
"""Raised when as_tensor_variable isn't able to create a
TensorVariable.
......@@ -560,13 +559,16 @@ class _tensor_py_operators:
def swapaxes(self, axis1, axis2):
"""Return 'tensor.swapaxes(self, axis1, axis2)
If a matrix is provided with the right axes, its transpose will be returned.
If a matrix is provided with the right axes, its transpose
will be returned.
"""
return theano.tensor.basic.swapaxes(self, axis1, axis2)
def fill(self, value):
"""Fill inputted tensor with the assigned value"""
return theano.tensor.basic.fill(self, value)
"""Fill inputted tensor with the assigned value"""
return theano.tensor.basic.fill(self, value)
class TensorVariable(_tensor_py_operators, Variable):
"""Subclass to add the tensor operators to the basic `Variable` class."""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论