Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c82d0161
提交
c82d0161
authored
9月 15, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
9月 17, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update aesara.printing.debugprint and _debugprint docstrings
上级
84265eb9
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
86 行增加
和
75 行删除
+86
-75
printing.py
aesara/printing.py
+86
-75
没有找到文件。
aesara/printing.py
浏览文件 @
c82d0161
...
...
@@ -10,16 +10,18 @@ import os
import
sys
from
copy
import
copy
from
functools
import
reduce
from
io
import
StringIO
from
io
import
IOBase
,
StringIO
from
typing
import
Dict
,
List
,
Optional
,
Union
import
numpy
as
np
from
aesara.compile
import
Function
,
SharedVariable
from
aesara.compile.io
import
In
,
Out
from
aesara.compile.profiling
import
ProfileStats
from
aesara.configdefaults
import
config
from
aesara.graph.basic
import
Apply
,
Constant
,
Variable
,
graph_inputs
,
io_toposort
from
aesara.graph.fg
import
FunctionGraph
from
aesara.graph.op
import
Op
from
aesara.graph.op
import
Op
,
StorageMapType
from
aesara.graph.utils
import
Scratchpad
...
...
@@ -80,47 +82,20 @@ def char_from_number(number):
def
debugprint
(
obj
,
depth
=-
1
,
print_type
=
False
,
file
=
None
,
ids
=
"CHAR"
,
stop_on_name
=
False
,
done
=
None
,
print_storage
=
False
,
used_ids
=
None
,
):
obj
:
Union
[
Union
[
Variable
,
Apply
,
Function
],
List
[
Union
[
Variable
,
Apply
,
Function
]]
],
depth
:
int
=
-
1
,
print_type
:
bool
=
False
,
file
:
Optional
[
Union
[
str
,
IOBase
]]
=
None
,
ids
:
str
=
"CHAR"
,
stop_on_name
:
bool
=
False
,
done
:
Optional
[
Dict
[
Apply
,
str
]]
=
None
,
print_storage
:
bool
=
False
,
used_ids
:
Optional
[
Dict
[
Variable
,
str
]]
=
None
,
)
->
Union
[
str
,
IOBase
]:
"""Print a computation graph as text to stdout or a file.
:type obj: :class:`~aesara.graph.basic.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.
:type done: None or dict
:param done: A dict where we store the ids of printed node.
Useful to have multiple call to debugprint share the same ids.
:type print_storage: bool
:param print_storage: If True, this will print the storage map
for Aesara functions. Combined with allow_gc=False, after the
execution of an Aesara function, we see the intermediate result.
:type used_ids: dict or None
:param used_ids: the id to use for some object, but maybe we only
referred to it yet.
: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
...
...
@@ -136,6 +111,43 @@ def debugprint(
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.
Parameters
----------
obj
The `Variable`, `Apply`, or `Function` instance to print (or a list
thereof).
depth
Print graph to this depth (``-1`` for unlimited).
print_type
Whether to print the type of printed objects
file
When `file` is extends `IOBase`, print to this file; when `file` is
equal to ``"str"``, return a string; when `file` is ``None``, print to
stdout.
ids
Determines the type of identifier used for variables.
- ``"id"``: print the python id value,
- ``"int"``: print integer character,
- ``"CHAR"``: print capital character,
- ``"auto"``: print the ``auto_name`` value,
- ``""``: don't print an identifier.
stop_on_name
When ``True``, if a node in the graph has a name, we don't print anything
below it.
done
A ``dict`` where we store the ids of printed nodes.
Useful to have multiple call to `debugprint` share the same ids.
print_storage
If ``True``, this will print the storage map for Aesara functions. When
combined with ``allow_gc=False``, after the execution of an Aesara
function, the output will show the intermediate results.
used_ids
A map between nodes and their printed ids.
Returns
-------
A string representing the printed graph, if `file` is a string, else `file`.
"""
from
aesara.scan.op
import
Scan
...
...
@@ -309,46 +321,46 @@ N.B.:
def
_debugprint
(
r
,
prefix
=
""
,
depth
=
-
1
,
done
=
None
,
print_type
=
False
,
file
=
sys
.
stdout
,
print_destroy_map
=
False
,
print_view_map
=
False
,
order
=
None
,
ids
=
"CHAR"
,
stop_on_name
=
False
,
prefix_child
=
None
,
scan_ops
=
None
,
profile
=
None
,
scan_inner_to_outer_inputs
=
None
,
smap
=
None
,
used_ids
=
None
,
):
"""Print the graph leading to `r`.
r
:
Variable
,
prefix
:
str
=
""
,
depth
:
int
=
-
1
,
done
:
Optional
[
Dict
[
Apply
,
str
]]
=
None
,
print_type
:
bool
=
False
,
file
:
IOBase
=
sys
.
stdout
,
print_destroy_map
:
bool
=
False
,
print_view_map
:
bool
=
False
,
order
:
Optional
[
List
[
Variable
]]
=
None
,
ids
:
str
=
"CHAR"
,
stop_on_name
:
bool
=
False
,
prefix_child
:
Optional
[
str
]
=
None
,
scan_ops
:
Optional
[
List
[
Variable
]]
=
None
,
profile
:
Optional
[
ProfileStats
]
=
None
,
scan_inner_to_outer_inputs
:
Optional
[
Dict
[
Variable
,
Variable
]]
=
None
,
smap
:
Optional
[
StorageMapType
]
=
None
,
used_ids
:
Optional
[
Dict
[
Variable
,
str
]]
=
None
,
)
->
IOBase
:
r
"""Print the graph leading to `r`.
Parameters
----------
r
Variable
instance.
A `Variable`
instance.
prefix
Prefix to each line (typically some number of spaces).
depth
Maximum recursion depth (Default -1
for unlimited).
Print graph to this depth (``-1``
for unlimited).
done
A ``dict`` of `Apply` instances that have already been printed and
their associated printed ids.
Internal. Used to pass information when recursing.
Dict of Apply instances that have already been printed and their
associated printed ids.
print_type
Whether to print the
Variable type after the other infos
.
Whether to print the
`Variable`'s type
.
file
File-like object to which to print.
print_destroy_map
Whether to print
the op destroy_map after other info
.
Whether to print
`Op` ``destroy_map``\s
.
print_view_map
Whether to print
the op view_map after other info
.
Whether to print
`Op` ``view_map``\s
.
order
If not empty will print the index in the toposort.
ids
...
...
@@ -359,20 +371,19 @@ def _debugprint(
- ``"auto"``: print the ``auto_name`` value,
- ``""``: don't print an identifier.
stop_on_name
When
True
, if a node in the graph has a name, we don't print anything
When
``True``
, if a node in the graph has a name, we don't print anything
below it.
scan_ops
Scan ops in the graph will be added inside this list for later printing
purposes.
`Scan` `Op`\s in the graph will be added inside this list for later
p
rinting p
urposes.
scan_inner_to_outer_inputs
A dictionary mapping a scan ops inner function inputs to the scan op
inputs (outer inputs) for printing purposes.
A dictionary mapping a `Scan` `Op`'s inner-inputs to its outer-inputs.
smap
None or the storage_map
when printing an Aesara function.
``None`` or the ``storage_map``
when printing an Aesara function.
used_ids
Internal. Used to pass information when recursing.
It is a dict from obj to the id used for it.
A map between nodes and their printed ids.
It wasn't always printed, but at least a reference to it was printed.
Internal. Used to pass information when recursing.
"""
if
depth
==
0
:
return
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论