本文整理汇总了Python中theano.compat.six.StringIO.flush方法的典型用法代码示例。如果您正苦于以下问题:Python StringIO.flush方法的具体用法?Python StringIO.flush怎么用?Python StringIO.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.compat.six.StringIO
的用法示例。
在下文中一共展示了StringIO.flush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: debugprint
# 需要导入模块: from theano.compat.six import StringIO [as 别名]
# 或者: from theano.compat.six.StringIO import flush [as 别名]
#.........这里部分代码省略.........
_file = file
if done is None:
done = dict()
results_to_print = []
profile_list = []
order = []
if isinstance(obj, (list, tuple)):
lobj = obj
else:
lobj = [obj]
for obj in lobj:
if isinstance(obj, gof.Variable):
results_to_print.append(obj)
profile_list.append(None)
elif isinstance(obj, gof.Apply):
results_to_print.extend(obj.outputs)
profile_list.extend([None for item in obj.outputs])
elif isinstance(obj, Function):
results_to_print.extend(obj.maker.fgraph.outputs)
profile_list.extend(
[obj.profile for item in obj.maker.fgraph.outputs])
order = obj.maker.fgraph.toposort()
elif isinstance(obj, gof.FunctionGraph):
results_to_print.extend(obj.outputs)
profile_list.extend([None for item in obj.outputs])
order = obj.toposort()
elif isinstance(obj, (int, long, float, np.ndarray)):
print(obj)
elif isinstance(obj, (theano.In, theano.Out)):
results_to_print.append(obj.variable)
profile_list.append(None)
else:
raise TypeError("debugprint cannot print an object of this type",
obj)
scan_ops = []
for r, p in zip(results_to_print, profile_list):
# Add the parent scan op to the list as well
if (hasattr(r.owner, 'op') and
isinstance(r.owner.op, theano.scan_module.scan_op.Scan)):
scan_ops.append(r)
if p is not None:
print("""
Timing Info
-----------
--> <time> <% time> - <total time> <% total time>'
<time> computation time for this node
<% time> fraction of total computation time for this node
<total time> time for this node + total times for this node's ancestors
<% total time> total time for this node over total computation time
N.B.:
* Times include the node time and the function overhead.
* <total time> and <% total time> may over-count computation times
if inputs to a node share a common ancestor and should be viewed as a
loose upper bound. Their intended use is to help rule out potential nodes
to remove when optimizing a graph because their <total time> is very low.
""", file=_file)
debugmode.debugprint(r, depth=depth, done=done, print_type=print_type,
file=_file, order=order, ids=ids,
scan_ops=scan_ops, stop_on_name=stop_on_name,
profile=p)
if len(scan_ops) > 0:
print("", file=_file)
new_prefix = ' >'
new_prefix_child = ' >'
print("Inner graphs of the scan ops:", file=_file)
for s in scan_ops:
print("", file=_file)
debugmode.debugprint(s, depth=depth, done=done,
print_type=print_type,
file=_file, ids=ids,
scan_ops=scan_ops, stop_on_name=stop_on_name)
if hasattr(s.owner.op, 'fn'):
# If the op was compiled, print the optimized version.
outputs = s.owner.op.fn.maker.fgraph.outputs
else:
outputs = s.owner.op.outputs
for idx, i in enumerate(outputs):
if hasattr(i, 'owner') and hasattr(i.owner, 'op'):
if isinstance(i.owner.op, theano.scan_module.scan_op.Scan):
scan_ops.append(i)
debugmode.debugprint(r=i, prefix=new_prefix,
depth=depth, done=done,
print_type=print_type, file=_file,
ids=ids, stop_on_name=stop_on_name,
prefix_child=new_prefix_child,
scan_ops=scan_ops)
if file is _file:
return file
elif file == 'str':
return _file.getvalue()
else:
_file.flush()
示例2: debugprint
# 需要导入模块: from theano.compat.six import StringIO [as 别名]
# 或者: from theano.compat.six.StringIO import flush [as 别名]
#.........这里部分代码省略.........
:type depth: integer
:param depth: print graph to this depth (-1 for unlimited)
:type print_type: boolean
:param print_type: whether to print the type of printed objects
:type file: None, 'str', or file-like object
:param file: print to this file ('str' means to return a string)
:type ids: str
:param ids: How do we print the identifier of the variable
id - print the python id value
int - print integer character
CHAR - print capital character
"" - don't print an identifier
:param stop_on_name: When True, if a node in the graph has a name,
we don't print anything below it.
:returns: string if `file` == 'str', else file arg
Each line printed represents a Variable in the graph.
The indentation of lines corresponds to its depth in the symbolic graph.
The first part of the text identifies whether it is an input
(if a name or type is printed) or the output of some Apply (in which case
the Op is printed).
The second part of the text is an identifier of the Variable.
If print_type is True, we add a part containing the type of the Variable
If a Variable is encountered multiple times in the depth-first search,
it is only printed recursively the first time. Later, just the Variable
identifier is printed.
If an Apply has multiple outputs, then a '.N' suffix will be appended
to the Apply's identifier, to indicate which output a line corresponds to.
"""
if file == 'str':
_file = StringIO()
elif file is None:
_file = sys.stdout
else:
_file = file
done = dict()
results_to_print = []
order = []
if isinstance(obj, (list, tuple)):
lobj = obj
else:
lobj = [obj]
for obj in lobj:
if isinstance(obj, gof.Variable):
results_to_print.append(obj)
elif isinstance(obj, gof.Apply):
results_to_print.extend(obj.outputs)
elif isinstance(obj, Function):
results_to_print.extend(obj.maker.fgraph.outputs)
order = obj.maker.fgraph.toposort()
elif isinstance(obj, gof.FunctionGraph):
results_to_print.extend(obj.outputs)
order = obj.toposort()
elif isinstance(obj, (int, long, float, numpy.ndarray)):
print obj
else:
raise TypeError("debugprint cannot print an object of this type",
obj)
scan_ops = []
for r in results_to_print:
#Add the parent scan op to the list as well
if hasattr(r.owner, 'op') and isinstance(r.owner.op, theano.scan_module.scan_op.Scan):
scan_ops.append(r)
debugmode.debugprint(r, depth=depth, done=done, print_type=print_type,
file=_file, order=order, ids=ids,
scan_ops=scan_ops, stop_on_name=stop_on_name)
if len(scan_ops) > 0:
print >> file, ""
new_prefix = ' >'
new_prefix_child = ' >'
print >> file, "Inner graphs of the scan ops:"
for s in scan_ops:
print >> file, ""
debugmode.debugprint(s, depth=depth, done=done, print_type=print_type,
file=_file, ids=ids,
scan_ops=scan_ops, stop_on_name=stop_on_name)
for idx, i in enumerate(s.owner.op.outputs):
if hasattr(i, 'owner') and hasattr(i.owner, 'op'):
if isinstance(i.owner.op, theano.scan_module.scan_op.Scan):
scan_ops.append(i)
debugmode.debugprint(r=i, prefix=new_prefix, depth=depth, done=done,
print_type=print_type, file=file,
ids=ids, stop_on_name=stop_on_name,
prefix_child=new_prefix_child, scan_ops=scan_ops)
if file is _file:
return file
elif file == 'str':
return _file.getvalue()
else:
_file.flush()
示例3: debugprint
# 需要导入模块: from theano.compat.six import StringIO [as 别名]
# 或者: from theano.compat.six.StringIO import flush [as 别名]
def debugprint(obj, depth=-1, print_type=False,
file=None, ids='CHAR', stop_on_name=False):
"""Print a computation graph as text to stdout or a file.
:type obj: Variable, Apply, or Function instance
:param obj: symbolic thing to print
:type depth: integer
:param depth: print graph to this depth (-1 for unlimited)
:type print_type: boolean
:param print_type: whether to print the type of printed objects
:type file: None, 'str', or file-like object
:param file: print to this file ('str' means to return a string)
:type ids: str
:param ids: How do we print the identifier of the variable
id - print the python id value
int - print integer character
CHAR - print capital character
"" - don't print an identifier
:param stop_on_name: When True, if a node in the graph has a name,
we don't print anything below it.
:returns: string if `file` == 'str', else file arg
Each line printed represents a Variable in the graph.
The indentation of lines corresponds to its depth in the symbolic graph.
The first part of the text identifies whether it is an input
(if a name or type is printed) or the output of some Apply (in which case
the Op is printed).
The second part of the text is an identifier of the Variable.
If print_type is True, we add a part containing the type of the Variable
If a Variable is encountered multiple times in the depth-first search,
it is only printed recursively the first time. Later, just the Variable
identifier is printed.
If an Apply has multiple outputs, then a '.N' suffix will be appended
to the Apply's identifier, to indicate which output a line corresponds to.
"""
if file == 'str':
_file = StringIO()
elif file is None:
_file = sys.stdout
else:
_file = file
done = dict()
results_to_print = []
order = []
if isinstance(obj, gof.Variable):
results_to_print.append(obj)
elif isinstance(obj, gof.Apply):
results_to_print.extend(obj.outputs)
elif isinstance(obj, Function):
results_to_print.extend(obj.maker.fgraph.outputs)
order = obj.maker.fgraph.toposort()
elif isinstance(obj, (list, tuple)):
results_to_print.extend(obj)
elif isinstance(obj, gof.FunctionGraph):
results_to_print.extend(obj.outputs)
order = obj.toposort()
else:
raise TypeError("debugprint cannot print an object of this type", obj)
for r in results_to_print:
debugmode.debugprint(r, depth=depth, done=done, print_type=print_type,
file=_file, order=order, ids=ids,
stop_on_name=stop_on_name)
if file is _file:
return file
elif file == 'str':
return _file.getvalue()
else:
_file.flush()