提交 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, ...@@ -764,7 +764,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
outer_id_str = get_id_str(outer_r.owner) outer_id_str = get_id_str(outer_r.owner)
else: else:
outer_id_str = get_id_str(outer_r) 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) outer_id_str), file=file)
else: else:
# this is an input variable # this is an input variable
...@@ -772,7 +772,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -772,7 +772,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
if smap: if smap:
data = " " + str(smap.get(r, '')) data = " " + str(smap.get(r, ''))
id_str = get_id_str(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), type_str, data),
file=file) file=file)
......
...@@ -644,6 +644,14 @@ AddConfigVar( ...@@ -644,6 +644,14 @@ AddConfigVar(
in_c_key=False) 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', AddConfigVar('compute_test_value_opt',
("For debugging Theano optimization only." ("For debugging Theano optimization only."
" Same as compute_test_value, but is used" " Same as compute_test_value, but is used"
......
...@@ -12,6 +12,7 @@ from copy import copy ...@@ -12,6 +12,7 @@ from copy import copy
from itertools import count from itertools import count
import theano import theano
from theano import config
from theano.gof import utils from theano.gof import utils
from six import string_types, integer_types, iteritems from six import string_types, integer_types, iteritems
from theano.misc.ordered_set import OrderedSet from theano.misc.ordered_set import OrderedSet
...@@ -394,6 +395,17 @@ class Variable(Node): ...@@ -394,6 +395,17 @@ class Variable(Node):
""" """
WRITEME 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: if self.name is not None:
return self.name return self.name
...@@ -406,6 +418,12 @@ class Variable(Node): ...@@ -406,6 +418,12 @@ class Variable(Node):
else: else:
return "<%s>" % str(self.type) return "<%s>" % str(self.type)
def __get_test_value__(self):
try:
return repr(self.tag.test_value)
except AttributeError:
return None
def __repr__(self): def __repr__(self):
return str(self) return str(self)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论