Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
69354dd0
提交
69354dd0
authored
7月 06, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
in pydotprint don't have dot merge Theano node with too long name.
上级
aacaa693
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
57 行增加
和
6 行删除
+57
-6
printing.py
theano/printing.py
+29
-6
test_printing.py
theano/tests/test_printing.py
+28
-0
没有找到文件。
theano/printing.py
浏览文件 @
69354dd0
...
@@ -479,10 +479,10 @@ def pydotprint(fct, outfile=None,
...
@@ -479,10 +479,10 @@ def pydotprint(fct, outfile=None,
high_contrast
=
True
,
cond_highlight
=
None
,
colorCodes
=
None
,
high_contrast
=
True
,
cond_highlight
=
None
,
colorCodes
=
None
,
max_label_size
=
50
,
scan_graphs
=
False
,
max_label_size
=
50
,
scan_graphs
=
False
,
var_with_name_simple
=
False
,
var_with_name_simple
=
False
,
print_output_file
=
True
print_output_file
=
True
,
assert_nb_all_strings
=-
1
):
):
"""
"""print to a file in png format the graph of op of a compile theano fct.
print to a file in png format the graph of op of a compile theano fct.
:param fct: the theano fct returned by theano.function.
:param fct: the theano fct returned by theano.function.
:param outfile: the output file where to put the graph.
:param outfile: the output file where to put the graph.
...
@@ -509,6 +509,10 @@ def pydotprint(fct, outfile=None,
...
@@ -509,6 +509,10 @@ def pydotprint(fct, outfile=None,
:param var_with_name_simple: If true and a variable have a name,
:param var_with_name_simple: If true and a variable have a name,
we will print only the variable name.
we will print only the variable name.
Otherwise, we concatenate the type to the var name.
Otherwise, we concatenate the type to the var name.
:param assert_nb_all_strings: Used for tests. This assert the
number of uniq string node in the dot graph. This is
used in tests to verify that dot won't merge Theano
node.
In the graph, ellipses are Apply Nodes (the execution of an op)
In the graph, ellipses are Apply Nodes (the execution of an op)
and boxes are variables. If variables have names they are used as
and boxes are variables. If variables have names they are used as
...
@@ -526,6 +530,7 @@ def pydotprint(fct, outfile=None,
...
@@ -526,6 +530,7 @@ def pydotprint(fct, outfile=None,
grey boxes are variables that are not outputs and are not used
grey boxes are variables that are not outputs and are not used
red ellipses are transfers from/to the gpu (ops with names GpuFromHost,
red ellipses are transfers from/to the gpu (ops with names GpuFromHost,
HostFromGpu)
HostFromGpu)
"""
"""
if
colorCodes
is
None
:
if
colorCodes
is
None
:
colorCodes
=
default_colorCodes
colorCodes
=
default_colorCodes
...
@@ -622,6 +627,13 @@ def pydotprint(fct, outfile=None,
...
@@ -622,6 +627,13 @@ def pydotprint(fct, outfile=None,
varstr
=
varstr
+
idx
varstr
=
varstr
+
idx
elif
len
(
varstr
)
>
max_label_size
:
elif
len
(
varstr
)
>
max_label_size
:
varstr
=
varstr
[:
max_label_size
-
3
]
+
'...'
varstr
=
varstr
[:
max_label_size
-
3
]
+
'...'
idx
=
1
while
varstr
in
all_strings
:
idx
+=
1
suffix
=
' id='
+
str
(
idx
)
varstr
=
(
varstr
[:
max_label_size
-
3
-
len
(
suffix
)]
+
'...'
+
suffix
)
var_str
[
var
]
=
varstr
var_str
[
var
]
=
varstr
all_strings
.
add
(
varstr
)
all_strings
.
add
(
varstr
)
...
@@ -656,6 +668,13 @@ def pydotprint(fct, outfile=None,
...
@@ -656,6 +668,13 @@ def pydotprint(fct, outfile=None,
applystr
=
applystr
+
idx
applystr
=
applystr
+
idx
elif
len
(
applystr
)
>
max_label_size
:
elif
len
(
applystr
)
>
max_label_size
:
applystr
=
applystr
[:
max_label_size
-
3
]
+
'...'
applystr
=
applystr
[:
max_label_size
-
3
]
+
'...'
idx
=
1
while
applystr
in
all_strings
:
idx
+=
1
suffix
=
' id='
+
str
(
idx
)
applystr
=
(
applystr
[:
max_label_size
-
3
-
len
(
suffix
)]
+
'...'
+
suffix
)
all_strings
.
add
(
applystr
)
all_strings
.
add
(
applystr
)
apply_name_cache
[
node
]
=
applystr
apply_name_cache
[
node
]
=
applystr
...
@@ -698,10 +717,10 @@ def pydotprint(fct, outfile=None,
...
@@ -698,10 +717,10 @@ def pydotprint(fct, outfile=None,
for
id
,
var
in
enumerate
(
node
.
inputs
):
for
id
,
var
in
enumerate
(
node
.
inputs
):
varstr
=
var_name
(
var
)
varstr
=
var_name
(
var
)
label
=
str
(
var
.
type
)
label
=
str
(
var
.
type
)
if
len
(
label
)
>
max_label_size
:
label
=
label
[:
max_label_size
-
3
]
+
'...'
if
len
(
node
.
inputs
)
>
1
:
if
len
(
node
.
inputs
)
>
1
:
label
=
str
(
id
)
+
' '
+
label
label
=
str
(
id
)
+
' '
+
label
if
len
(
label
)
>
max_label_size
:
label
=
label
[:
max_label_size
-
3
]
+
'...'
if
var
.
owner
is
None
:
if
var
.
owner
is
None
:
if
high_contrast
:
if
high_contrast
:
g
.
add_node
(
pd
.
Node
(
varstr
,
g
.
add_node
(
pd
.
Node
(
varstr
,
...
@@ -751,10 +770,14 @@ def pydotprint(fct, outfile=None,
...
@@ -751,10 +770,14 @@ def pydotprint(fct, outfile=None,
if
not
outfile
.
endswith
(
'.'
+
format
):
if
not
outfile
.
endswith
(
'.'
+
format
):
outfile
+=
'.'
+
format
outfile
+=
'.'
+
format
g
.
write
(
outfile
,
prog
=
'dot'
,
format
=
format
)
g
.
write
(
outfile
,
prog
=
'dot'
,
format
=
format
)
if
print_output_file
:
if
print_output_file
:
print
'The output file is available at'
,
outfile
print
'The output file is available at'
,
outfile
if
assert_nb_all_strings
!=
-
1
:
assert
len
(
all_strings
)
==
assert_nb_all_strings
if
scan_graphs
:
if
scan_graphs
:
scan_ops
=
[(
idx
,
x
)
for
idx
,
x
in
enumerate
(
fct_env
.
toposort
())
scan_ops
=
[(
idx
,
x
)
for
idx
,
x
in
enumerate
(
fct_env
.
toposort
())
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
...
...
theano/tests/test_printing.py
浏览文件 @
69354dd0
...
@@ -47,6 +47,34 @@ def test_pydotprint_cond_highlight():
...
@@ -47,6 +47,34 @@ def test_pydotprint_cond_highlight():
' is no IfElse node in the graph
\n
'
)
' is no IfElse node in the graph
\n
'
)
def
test_pydotprint_long_name
():
"""This is a REALLY PARTIAL TEST.
It print a graph where there is variable and apply node that
there too long name is different, but not the shortened name.
We should not merge those node in the dot graph.
"""
# Skip test if pydot is not available.
if
not
theano
.
printing
.
pydot_imported
:
raise
SkipTest
(
'pydot not available'
)
x
=
tensor
.
dvector
()
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
"fusion"
)
f
=
theano
.
function
([
x
],
[
x
*
2
,
x
+
x
],
mode
=
mode
)
f
([
1
,
2
,
3
,
4
])
s
=
StringIO
.
StringIO
()
new_handler
=
logging
.
StreamHandler
(
s
)
new_handler
.
setLevel
(
logging
.
DEBUG
)
orig_handler
=
theano
.
logging_default_handler
theano
.
printing
.
pydotprint
(
f
,
max_label_size
=
5
,
print_output_file
=
False
,
assert_nb_all_strings
=
6
)
def
test_pydotprint_profile
():
def
test_pydotprint_profile
():
"""Just check that pydotprint does not crash with ProfileMode."""
"""Just check that pydotprint does not crash with ProfileMode."""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论