提交 b86b4389 authored 作者: delallea's avatar delallea

Merge pull request #33 from goodfeli/add_verbosity_config

added a config variable to control the verbosity of exceptions
......@@ -475,3 +475,19 @@ import theano and print the config variable, as in:
``'warn'`` will result in a UserWarning being raised when some Op inputs
do not contain an appropriate test value. ``'raise'`` will instead raise
an Exception when a problem is encountered during this debugging phase.
.. attribute:: config.exception_verbosity
String Value: ``'low'``, ``'high'``.
Default: ``'low'``
If ``'low'``, the text of exceptions will generally refer to apply nodes
with short names such as ``'Elemwise{add_no_inplace}'``. If ``'high'``,
some exceptions will also refer to apply nodes with long descriptions like:
::
A. Elemwise{add_no_inplace}
B. log_likelihood_v_given_h
C. log_likelihood_h
......@@ -259,3 +259,22 @@ AddConfigVar('compute_test_value',
"If 'True', Theano will run each op at graph build time, using Constants, SharedVariables and the tag 'test_value' as inputs to the function. This helps the user track down problems in the graph before it gets optimized.",
EnumStr('off', 'ignore', 'warn', 'raise'),
in_c_key=False)
"""Note to developers:
Generally your exceptions should use an apply node's __str__
method when exception_verbosity == 'low'. When exception_verbosity
== 'high', you should include a call to printing.min_informative_str
on all important apply nodes.
"""
AddConfigVar('exception_verbosity',
"If 'low', the text of exceptions will generally refer " \
+ "to apply nodes with short names such as " \
+ "Elemwise{add_no_inplace}. If 'high', some exceptions " \
+ "will also refer to apply nodes with long descriptions " \
+ """ like:
A. Elemwise{add_no_inplace}
B. log_likelihood_v_given_h
C. log_likelihood_h""",
EnumStr('low','high'),
in_c_key=False)
......@@ -21,7 +21,7 @@ import elemwise
from theano import scalar as scal
from theano.gof.python25 import partial, any, all
from theano import compile, printing
from theano.printing import pprint
from theano.printing import pprint, min_informative_str
# We use these exceptions as well.
from theano.scalar import ComplexError, IntegerDivisionError
......@@ -2492,9 +2492,15 @@ class Alloc(gof.Op):
v = as_tensor_variable(value)
sh = [as_tensor_variable(s) for s in shape]
bcast = []
for s in sh:
for i, s in enumerate(sh):
if s.type.dtype[:3] not in ('int', 'uin'):
raise TypeError('Shape arguments must be integers', s)
if config.exception_verbosity == 'high':
s_as_str = '\n' + min_informative_str(s)
else:
s_as_str = str(s)
raise TypeError('Shape arguments to Alloc must be integers, '
'but argument %s is not for apply node: %s' %
(i, s_as_str))
# if s is constant 1, then we're broadcastable in that dim
try:
const_shp = get_constant_value(s)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论