提交 be939078 authored 作者: Francesco Visin's avatar Francesco Visin

Add print_test_value_by_default option

Add option to print the tag.test_value with the variable name by default.
上级 30cc6380
......@@ -764,7 +764,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
outer_id_str = get_id_str(outer_r.owner)
else:
outer_id_str = get_id_str(outer_r)
print('%s%s %s%s -> %s' % (prefix, r, id_str, type_str,
print('%s%s %s%s -> %s' % (prefix, r.__str_name__(), id_str, type_str,
outer_id_str), file=file)
else:
# this is an input variable
......@@ -772,7 +772,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
if smap:
data = " " + str(smap.get(r, ''))
id_str = get_id_str(r)
print('%s%s %s%s%s' % (prefix, r, id_str,
print('%s%s %s%s%s' % (prefix, r.__str_name__(), id_str,
type_str, data),
file=file)
......
......@@ -644,6 +644,14 @@ AddConfigVar(
in_c_key=False)
AddConfigVar(
'print_test_value_by_default',
("If 'True', Theano will override the '__str__' method of its "
"variables to also print the tag.test_value when this is available."),
BoolParam(False),
in_c_key=False)
AddConfigVar('compute_test_value_opt',
("For debugging Theano optimization only."
" Same as compute_test_value, but is used"
......
......@@ -12,6 +12,7 @@ from copy import copy
from itertools import count
import theano
from theano import config
from theano.gof import utils
from six import string_types, integer_types, iteritems
from theano.misc.ordered_set import OrderedSet
......@@ -394,6 +395,17 @@ class Variable(Node):
"""
WRITEME
"""
if config.print_test_value_by_default:
if self.__get_test_value__() is not None:
return '\n'.join([self.__str_name__(),
self.__get_test_value__()])
return self.__str_name__()
def __str_name__(self):
"""
WRITEME
"""
if self.name is not None:
return self.name
......@@ -406,6 +418,12 @@ class Variable(Node):
else:
return "<%s>" % str(self.type)
def __get_test_value__(self):
try:
return repr(self.tag.test_value)
except AttributeError:
return None
def __repr__(self):
return str(self)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论