Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ebea5e22
提交
ebea5e22
authored
4月 18, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
4月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a tests.link.test_utils module
上级
bf8307dd
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
101 行增加
和
0 行删除
+101
-0
test_utils.py
tests/link/test_utils.py
+101
-0
没有找到文件。
tests/link/test_utils.py
0 → 100644
浏览文件 @
ebea5e22
from
functools
import
singledispatch
import
numpy
as
np
from
aesara
import
config
from
aesara.graph.basic
import
Apply
from
aesara.graph.fg
import
FunctionGraph
from
aesara.graph.op
import
Op
from
aesara.link.utils
import
fgraph_to_python
from
aesara.scalar.basic
import
Add
from
aesara.tensor.elemwise
import
Elemwise
from
aesara.tensor.type
import
scalar
,
vector
from
aesara.tensor.type_other
import
NoneConst
@singledispatch
def
to_python
(
op
,
**
kwargs
):
raise
NotImplementedError
()
@to_python.register
(
Elemwise
)
def
to_python_Elemwise
(
op
,
**
kwargs
):
scalar_op
=
op
.
scalar_op
return
to_python
(
scalar_op
,
**
kwargs
)
@to_python.register
(
Add
)
def
to_python_Add
(
op
,
**
kwargs
):
def
add
(
*
args
):
return
np
.
add
(
*
args
)
return
add
def
test_fgraph_to_python_names
():
import
inspect
x
=
scalar
(
"1x"
)
y
=
scalar
(
"_"
)
z
=
scalar
()
q
=
scalar
(
"def"
)
r
=
NoneConst
out_fg
=
FunctionGraph
([
x
,
y
,
z
,
q
,
r
],
[
x
,
y
,
z
,
q
,
r
],
clone
=
False
)
out_jx
=
fgraph_to_python
(
out_fg
,
to_python
)
sig
=
inspect
.
signature
(
out_jx
)
assert
(
x
.
auto_name
,
"_"
,
z
.
auto_name
,
q
.
auto_name
,
r
.
name
)
==
tuple
(
sig
.
parameters
.
keys
()
)
assert
(
1
,
2
,
3
,
4
,
5
)
==
out_jx
(
1
,
2
,
3
,
4
,
5
)
def
test_fgraph_to_python_once
():
"""Make sure that an output is only computed once when it's referenced multiple times."""
x
=
vector
(
"x"
)
y
=
vector
(
"y"
)
class
TestOp
(
Op
):
def
__init__
(
self
):
self
.
called
=
0
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
]
@to_python.register
(
TestOp
)
def
to_python_TestOp
(
op
,
**
kwargs
):
def
func
(
*
args
,
op
=
op
):
op
.
called
+=
1
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
)
x_val
=
np
.
r_
[
1
,
2
]
.
astype
(
config
.
floatX
)
y_val
=
np
.
r_
[
2
,
3
]
.
astype
(
config
.
floatX
)
res
=
out_py
(
x_val
,
y_val
)
assert
len
(
res
)
==
2
assert
op1
.
called
==
1
assert
op2
.
called
==
1
res
=
out_py
(
x_val
,
y_val
)
assert
len
(
res
)
==
2
assert
op1
.
called
==
2
assert
op2
.
called
==
2
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论