提交 83316061 authored 作者: Frederic's avatar Frederic

debugprint now stop printing the "|" symbol in a columns after the last input.

上级 ec0e7537
...@@ -24,6 +24,7 @@ New Feature ...@@ -24,6 +24,7 @@ New Feature
as this is more readable. as this is more readable.
* debugprint new param stop_on_name=[False,True]. If True, we don't print * debugprint new param stop_on_name=[False,True]. If True, we don't print
anything bellow an intermediate variable that have a name. Default to False. anything bellow an intermediate variable that have a name. Default to False.
* debugprint now stop printing the "|" symbol in a columns after the last input.
============= =============
Release Notes Release Notes
......
...@@ -502,7 +502,8 @@ def char_from_number(number): ...@@ -502,7 +502,8 @@ def char_from_number(number):
def debugprint(r, prefix='', depth=-1, done=None, print_type=False, def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
file=sys.stdout, print_destroy_map=False, print_view_map=False, file=sys.stdout, print_destroy_map=False, print_view_map=False,
order=[], ids='CHAR', stop_on_name=False): order=[], ids='CHAR', stop_on_name=False,
prefix_child=None):
"""Print the graph leading to `r` to given depth. """Print the graph leading to `r` to given depth.
:param r: Variable instance :param r: Variable instance
...@@ -535,6 +536,9 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -535,6 +536,9 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
else: else:
type_str = '' type_str = ''
if prefix_child is None:
prefix_child = prefix
def get_id_str(obj): def get_id_str(obj):
if obj in done: if obj in done:
id_str = "[@%s]" % done[obj] id_str = "[@%s]" % done[obj]
...@@ -598,10 +602,16 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -598,10 +602,16 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
if not already_printed: if not already_printed:
if (not stop_on_name or if (not stop_on_name or
not (hasattr(r, 'name') and r.name is not None)): not (hasattr(r, 'name') and r.name is not None)):
for i in a.inputs: new_prefix = prefix_child + ' |'
debugprint(i, prefix + ' |', depth=depth - 1, done=done, new_prefix_child = prefix_child + ' |'
for idx, i in enumerate(a.inputs):
if idx == len(a.inputs) - 1:
new_prefix_child = prefix_child + ' '
debugprint(i, new_prefix, depth=depth - 1, done=done,
print_type=print_type, file=file, order=order, print_type=print_type, file=file, order=order,
ids=ids, stop_on_name=stop_on_name) ids=ids, stop_on_name=stop_on_name,
prefix_child=new_prefix_child)
else: else:
#this is an input variable #this is an input variable
id_str = get_id_str(r) id_str = get_id_str(r)
......
...@@ -112,8 +112,8 @@ def test_debugprint(): ...@@ -112,8 +112,8 @@ def test_debugprint():
| |A [@2] | |A [@2]
| |B [@3] | |B [@3]
|Elemwise{add,no_inplace} [@4] '' |Elemwise{add,no_inplace} [@4] ''
| |D [@5] |D [@5]
| |E [@6] |E [@6]
""" """
if s != reference: if s != reference:
...@@ -132,8 +132,8 @@ def test_debugprint(): ...@@ -132,8 +132,8 @@ def test_debugprint():
| |A [@C] | |A [@C]
| |B [@D] | |B [@D]
|Elemwise{add,no_inplace} [@E] '' |Elemwise{add,no_inplace} [@E] ''
| |D [@F] |D [@F]
| |E [@G] |E [@G]
""" """
if s != reference: if s != reference:
...@@ -151,8 +151,8 @@ def test_debugprint(): ...@@ -151,8 +151,8 @@ def test_debugprint():
reference = """Elemwise{add,no_inplace} [@A] '' reference = """Elemwise{add,no_inplace} [@A] ''
|Elemwise{add,no_inplace} [@B] 'C' |Elemwise{add,no_inplace} [@B] 'C'
|Elemwise{add,no_inplace} [@C] '' |Elemwise{add,no_inplace} [@C] ''
| |D [@D] |D [@D]
| |E [@E] |E [@E]
""" """
if s != reference: if s != reference:
...@@ -172,8 +172,8 @@ def test_debugprint(): ...@@ -172,8 +172,8 @@ def test_debugprint():
| |A | |A
| |B | |B
|Elemwise{add,no_inplace} '' |Elemwise{add,no_inplace} ''
| |D |D
| |E |E
""" """
if s != reference: if s != reference:
print '--'+s+'--' print '--'+s+'--'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论