提交 92b60da5 authored 作者: Frederic Bastien's avatar Frederic Bastien

Better error message and simplicy code,doc.

上级 401cdef9
...@@ -105,7 +105,7 @@ class change_flags(object): ...@@ -105,7 +105,7 @@ class change_flags(object):
for k in args: for k in args:
l = [v for v in theano.configparser._config_var_list l = [v for v in theano.configparser._config_var_list
if v.fullname == k] if v.fullname == k]
assert len(l) == 1 assert len(l) == 1, l
confs[k] = l[0] confs[k] = l[0]
self.confs = confs self.confs = confs
self.new_vals = args self.new_vals = args
......
...@@ -482,7 +482,8 @@ class FunctionGraph(utils.object2): ...@@ -482,7 +482,8 @@ class FunctionGraph(utils.object2):
print_type=True, print_type=True,
used_ids=used_ids).getvalue() used_ids=used_ids).getvalue()
raise toolbox.BadOptimization( raise toolbox.BadOptimization(
r, new_r, None, None, reason, old, new) r, new_r, None, None, str(reason) +
". The type of the replacement must be the same.", old, new)
new_r = new_r2 new_r = new_r2
if r not in self.variables: if r not in self.variables:
# this variable isn't in the graph... don't raise an # this variable isn't in the graph... don't raise an
......
...@@ -41,7 +41,8 @@ class BadOptimization(Exception): ...@@ -41,7 +41,8 @@ class BadOptimization(Exception):
Exception: some variable and its substitute take different runtime values. Exception: some variable and its substitute take different runtime values.
Note: If there is only 1 parameter and it is a string, we will use Note: If there is only 1 parameter and it is a string, we will use
it as the error message. it as the error message. This is needed when we catch, extend and
reraise an error.
""" """
...@@ -103,6 +104,8 @@ class BadOptimization(Exception): ...@@ -103,6 +104,8 @@ class BadOptimization(Exception):
self.reason = reason self.reason = reason
self.old_graph = old_graph self.old_graph = old_graph
self.new_graph = new_graph self.new_graph = new_graph
# To allow extending the error message of an existing error.
self.full_err = None self.full_err = None
if isinstance(old_r, str): if isinstance(old_r, str):
assert (new_r is None and old_r_val is None and new_r_val is None and assert (new_r is None and old_r_val is None and new_r_val is None and
...@@ -110,8 +113,6 @@ class BadOptimization(Exception): ...@@ -110,8 +113,6 @@ class BadOptimization(Exception):
self.full_err = old_r self.full_err = old_r
def __str__(self): def __str__(self):
if getattr(self, 'full_err', None) is not None:
return self.full_err
return self.str_diagnostic() return self.str_diagnostic()
def str_diagnostic(self): def str_diagnostic(self):
...@@ -120,6 +121,9 @@ class BadOptimization(Exception): ...@@ -120,6 +121,9 @@ class BadOptimization(Exception):
of the exception. of the exception.
""" """
# We have a pre-made message
if getattr(self, 'full_err', None) is not None:
return self.full_err
sio = StringIO() sio = StringIO()
val_str_len_limit = 800 val_str_len_limit = 800
print("BadOptimization Error", super(BadOptimization, print("BadOptimization Error", super(BadOptimization,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论