Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
07c70749
提交
07c70749
authored
5月 27, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debugging, testing of WrapLinker
上级
20267813
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
58 行增加
和
17 行删除
+58
-17
_test_link.py
gof/_test_link.py
+34
-0
link.py
gof/link.py
+24
-17
没有找到文件。
gof/_test_link.py
浏览文件 @
07c70749
...
...
@@ -122,6 +122,40 @@ class _test_PerformLinker(unittest.TestCase):
fn
=
perform_linker
(
Env
(
*
graph
.
clone
([
x
,
y
,
r
],
[
e
])))
.
make_function
()
self
.
failUnless
(
fn
(
1.0
,
2.0
,
4.5
)
==
7.5
)
def
wrap_linker
(
env
,
linkers
,
wrapper
):
lnk
=
WrapLinker
(
linkers
,
wrapper
)
.
accept
(
env
)
return
lnk
class
_test_WrapLinker
(
unittest
.
TestCase
):
def
test0
(
self
):
nodes
=
[]
def
wrap
(
i
,
node
,
th
):
nodes
.
append
(
node
.
op
)
x
,
y
,
z
=
inputs
()
e
=
mul
(
add
(
x
,
y
),
div
(
x
,
y
))
fn
,
i
,
o
=
wrap_linker
(
Env
([
x
,
y
,
z
],
[
e
]),
[
PerformLinker
()],
wrap
)
.
make_thunk
()
i
[
0
]
.
data
=
1
i
[
1
]
.
data
=
2
fn
()
self
.
failUnless
(
nodes
==
[
div
,
add
,
mul
],
nodes
)
self
.
failUnless
(
o
[
0
]
.
data
is
None
)
def
test1
(
self
):
nodes
=
[]
def
wrap
(
i
,
node
,
th
):
nodes
.
append
(
node
.
op
)
th
()
x
,
y
,
z
=
inputs
()
e
=
mul
(
add
(
x
,
y
),
div
(
x
,
y
))
fn
,
i
,
o
=
wrap_linker
(
Env
([
x
,
y
,
z
],
[
e
]),
[
PerformLinker
()],
wrap
)
.
make_thunk
()
i
[
0
]
.
data
=
1
i
[
1
]
.
data
=
2
fn
()
self
.
failUnless
(
nodes
==
[
div
,
add
,
mul
],
nodes
)
self
.
failUnless
(
o
[
0
]
.
data
==
1.5
,
o
[
0
]
.
data
)
# def test_disconnected_input_output(self):
...
...
gof/link.py
浏览文件 @
07c70749
...
...
@@ -260,19 +260,23 @@ class WrapLinker(Linker):
This class makes it easier to run several L{LocalLinker}s in parallel, and
offers some control over how each thunk is run.
and they should all return the same order. A wrapper function must
be provided to execute the thunks, inspect the nodes
, etc.
A wrapper function must be provided, and it can be used to execute the
thunks, inspect the nodes, print stuff out
, etc.
@note:
The outputs of the first linker will be returned.
@note:
This linker ensures that each linker has its own storage for
inputs and outputs and intermediate results. There is no interference
between linkers.
"""
def
__init__
(
self
,
env
,
linkers
,
wrapper
,
no_recycling
=
[]
):
def
__init__
(
self
,
linkers
,
wrapper
):
"""
Initialize a WrapLinker.
@type env: gof.Env
@param env: the env which we will link
@type linkers: list of L{LocalLinker} subclasses, whose make_all()
method returns thunks in the same order.
...
...
@@ -287,22 +291,27 @@ class WrapLinker(Linker):
want to run the program, make sure to call the necessary thunks in this
function.)
"""
self
.
linkers
=
linkers
self
.
wrapper
=
wrapper
def
accept
(
self
,
env
,
no_recycling
=
[]):
"""
@type env: gof.Env
@param env: the env which we will link
@type no_recycling: a list of Results that belong to env.
@param no_recycling: If a Result is in no_recycling, L{WrapLinker} will clear
the output storage associated to it (for each linker in linkers) during
the computation to avoid reusing it.
@note:
This linker ensures that each linker has its own storage for
inputs and outputs and intermediate results. There is no interference
between linkers.
"""
self
.
env
=
env
self
.
linkers
=
linkers
self
.
wrapper
=
wrapper
self
.
no_recycling
=
no_recycling
for
l
in
self
.
linkers
:
l
.
accept
(
env
,
no_recycling
)
return
self
def
pre
(
self
,
f
,
inputs
,
order
,
thunk_groups
):
pass
...
...
@@ -310,12 +319,10 @@ class WrapLinker(Linker):
def
make_thunk
(
self
,
**
kwargs
):
no_recycling
=
self
.
no_recycling
instantiated_linkers
=
[
linker
(
self
.
env
,
no_recycling
=
no_recycling
)
\
.
make_all
(
**
kwargs
)
for
linker
in
self
.
linkers
]
make_all
=
[
l
.
make_all
(
**
kwargs
)
for
l
in
self
.
linkers
]
fns
,
input_lists
,
output_lists
,
thunk_lists
,
order_lists
\
=
zip
(
*
instantiated_linkers
)
=
zip
(
*
make_all
)
order_list0
=
order_lists
[
0
]
for
order_list
in
order_lists
[
1
:]:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论