Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
45642af3
提交
45642af3
authored
6月 03, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
6月 03, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow newlines in __str__ output printed by fgraph_to_python
上级
c028e387
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
54 行增加
和
3 行删除
+54
-3
utils.py
aesara/link/utils.py
+3
-3
test_utils.py
tests/link/test_utils.py
+51
-0
没有找到文件。
aesara/link/utils.py
浏览文件 @
45642af3
...
...
@@ -760,9 +760,9 @@ def fgraph_to_python(
node_output_names
=
[
unique_name
(
v
)
for
v
in
node
.
outputs
]
body_assigns
.
append
(
f
"# {node}
\n
{', '.join(node_output_names)} = {local_compiled_func_name}({', '.join(node_input_names)})"
)
assign_comment_str
=
f
"{indent(str(node), '# ')}"
assign_str
=
f
"
{', '.join(node_output_names)} = {local_compiled_func_name}({', '.join(node_input_names)})"
body_assigns
.
append
(
f
"{assign_comment_str}
\n
{assign_str}"
)
fgraph_input_names
=
[
unique_name
(
v
)
for
v
in
fgraph
.
inputs
]
fgraph_output_names
=
[
unique_name
(
v
)
for
v
in
fgraph
.
outputs
]
...
...
tests/link/test_utils.py
浏览文件 @
45642af3
import
inspect
from
functools
import
singledispatch
import
numpy
as
np
...
...
@@ -108,6 +109,56 @@ def test_fgraph_to_python_once():
assert
op2
.
called
==
2
def
test_fgraph_to_python_multiline_str
():
"""Make sure that multiline `__str__` values are supported by `fgraph_to_python`."""
x
=
vector
(
"x"
)
y
=
vector
(
"y"
)
class
TestOp
(
Op
):
def
__init__
(
self
):
super
()
.
__init__
()
def
make_node
(
self
,
*
args
):
return
Apply
(
self
,
list
(
args
),
[
x
.
type
()
for
x
in
args
])
def
perform
(
self
,
inputs
,
outputs
):
for
i
,
inp
in
enumerate
(
inputs
):
outputs
[
i
][
0
]
=
inp
[
0
]
def
__str__
(
self
):
return
"Test
\n
Op()"
@to_python.register
(
TestOp
)
def
to_python_TestOp
(
op
,
**
kwargs
):
def
func
(
*
args
,
op
=
op
):
return
list
(
args
)
return
func
op1
=
TestOp
()
op2
=
TestOp
()
q
,
r
=
op1
(
x
,
y
)
outs
=
op2
(
q
+
r
,
q
+
r
)
out_fg
=
FunctionGraph
([
x
,
y
],
outs
,
clone
=
False
)
assert
len
(
out_fg
.
outputs
)
==
2
out_py
=
fgraph_to_python
(
out_fg
,
to_python
)
out_py_src
=
inspect
.
getsource
(
out_py
)
assert
(
"""
# Elemwise{add,no_inplace}(Test
# Op().0, Test
# Op().1)
"""
in
out_py_src
)
def
test_unique_name_generator
():
unique_names
=
unique_name_generator
([
"blah"
],
suffix_sep
=
"_"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论