提交 7c5bfadc authored 作者: Caglar's avatar Caglar

Fixed typos and scan_ops in debugmode.

上级 451f7b8f
...@@ -494,7 +494,8 @@ def char_from_number(number): ...@@ -494,7 +494,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, file=sys.stdout, print_destroy_map=False,
print_view_map=False, order=None, ids='CHAR', print_view_map=False, order=None, ids='CHAR',
stop_on_name=False, prefix_child=None): stop_on_name=False, prefix_child=None,
scan_ops=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
...@@ -502,10 +503,10 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -502,10 +503,10 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
:param depth: maximum recursion depth (Default -1 for unlimited). :param depth: maximum recursion depth (Default -1 for unlimited).
:param done: dict of Apply instances that have already been printed :param done: dict of Apply instances that have already been printed
and their associated printed ids and their associated printed ids
:param print_type: wether to print the Variable type after the other infos :param print_type: whether to print the Variable type after the other infos
:param file: file-like object to which to print :param file: file-like object to which to print
:param print_destroy_map: wether to print the op destroy_map after ofther info :param print_destroy_map: whether to print the op destroy_map after other info
:param print_view_map: wether to print the op view_map after ofther info :param print_view_map: whether to print the op view_map after other info
:param order: If not empty will print the index in the toposort. :param order: If not empty will print the index in the toposort.
:param ids: How do we print the identifier of the variable :param ids: How do we print the identifier of the variable
id - print the python id value id - print the python id value
...@@ -514,6 +515,8 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -514,6 +515,8 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
"" - don't print an identifier "" - don't print an identifier
:param stop_on_name: When True, if a node in the graph has a name, :param stop_on_name: When True, if a node in the graph has a name,
we don't print anything below it. we don't print anything below it.
:param scan_ops: Scan ops in the graph will be added inside this list
for later printing purposes.
""" """
if depth == 0: if depth == 0:
...@@ -525,6 +528,9 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -525,6 +528,9 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
if done is None: if done is None:
done = dict() done = dict()
if scan_ops is None:
scan_ops = []
if print_type: if print_type:
type_str = ' <%s>' % r.type type_str = ' <%s>' % r.type
else: else:
...@@ -547,7 +553,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -547,7 +553,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
done[obj] = id_str done[obj] = id_str
return id_str return id_str
if hasattr(r.owner, 'op'): if hasattr(r, 'owner') and hasattr(r.owner, 'op'):
# this variable is the output of computation, # this variable is the output of computation,
# so just print out the apply # so just print out the apply
a = r.owner a = r.owner
...@@ -575,6 +581,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -575,6 +581,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
o = '' o = ''
if order: if order:
o = str(order.index(r.owner)) o = str(order.index(r.owner))
already_printed = a in done # get_id_str put it in the dict already_printed = a in done # get_id_str put it in the dict
id_str = get_id_str(a) id_str = get_id_str(a)
...@@ -602,10 +609,16 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -602,10 +609,16 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
if idx == len(a.inputs) - 1: if idx == len(a.inputs) - 1:
new_prefix_child = prefix_child + ' ' new_prefix_child = prefix_child + ' '
if hasattr(i, 'owner') and hasattr(i.owner, 'op'):
if i.owner.op is not None:
if isinstance(i.owner.op, theano.scan_module.scan_op.Scan):
scan_ops.append(i)
debugprint(i, new_prefix, depth=depth - 1, done=done, 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) prefix_child=new_prefix_child, scan_ops=scan_ops)
else: else:
#this is an input variable #this is an input variable
id_str = get_id_str(r) id_str = get_id_str(r)
...@@ -624,7 +637,6 @@ def _optcheck_fgraph(input_specs, output_specs, accept_inplace=False): ...@@ -624,7 +637,6 @@ def _optcheck_fgraph(input_specs, output_specs, accept_inplace=False):
:type accept_inplace: Bool :type accept_inplace: Bool
:rtype: `FunctionGraph` :rtype: `FunctionGraph`
:returns: a new FunctionGraph with a cloned graph, with debugging `Feature` instances already installed. :returns: a new FunctionGraph with a cloned graph, with debugging `Feature` instances already installed.
""" """
orig_inputs = [spec.variable for spec in input_specs] orig_inputs = [spec.variable for spec in input_specs]
updates = [spec.update for spec in input_specs if spec.update] updates = [spec.update for spec in input_specs if spec.update]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论