Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5d1ecb0b
提交
5d1ecb0b
authored
6月 11, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #685 from jaberg/clone_get_equiv
Clone get equiv
上级
8bb23735
9c765de2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
44 行增加
和
31 行删除
+44
-31
graph.py
theano/gof/graph.py
+44
-31
没有找到文件。
theano/gof/graph.py
浏览文件 @
5d1ecb0b
...
...
@@ -575,54 +575,67 @@ def clone(i, o, copy_inputs = True):
return
[
equiv
[
input
]
for
input
in
i
],
[
equiv
[
output
]
for
output
in
o
]
def
clone_get_equiv
(
i
,
o
,
copy_inputs_and_orphans
=
True
):
""" WRITEME
def
clone_get_equiv
(
inputs
,
outputs
,
copy_inputs_and_orphans
=
True
,
memo
=
None
):
"""
Return a dictionary that maps from Variable and Apply nodes in the
original graph to a new node (a clone) in a new graph.
This function works by recursively cloning inputs... rebuilding a directed
graph from the bottom (inputs) up to eventually building new outputs.
Parameters
----------
inputs: a list of Variables
outputs: a list of Variables
copy_inputs_and_orphans: bool
True means to create the cloned graph from new input and constant
nodes (the bottom of a feed-upward graph),
False means to clone a graph that is rooted at the original input
nodes.
memo: None or dict
Optionally start with a partly-filled dictionary for the return value.
If a dictionary is passed, this function will work in-place on that
dictionary and return it.
:type i: list
:param i: input L{Variable}s
:type o: list
:param o: output L{Variable}s
:type copy_inputs_and_orphans: bool
:param copy_inputs_and_orphans:
if True, the inputs and the orphans will be replaced in the cloned graph by copies
available in the equiv dictionary returned by the function (copy_inputs_and_orphans
defaults to True)
:rtype: a dictionary
:return:
equiv mapping each L{Variable} and L{Op} in the graph delimited by i and o to a copy
(akin to deepcopy's memo).
"""
d
=
{}
for
input
in
i
:
if
memo
is
None
:
memo
=
{}
# clone the inputs if necessary
for
input
in
inputs
:
if
copy_inputs_and_orphans
:
cpy
=
input
.
clone
()
cpy
.
owner
=
None
cpy
.
index
=
None
d
[
input
]
=
cpy
memo
.
setdefault
(
input
,
cpy
)
else
:
d
[
input
]
=
input
memo
.
setdefault
(
input
,
input
)
for
apply
in
io_toposort
(
i
,
o
):
# go through the inputs -> outputs graph cloning as we go
for
apply
in
io_toposort
(
inputs
,
outputs
):
for
input
in
apply
.
inputs
:
if
input
not
in
d
:
if
input
not
in
memo
:
if
copy_inputs_and_orphans
:
cpy
=
input
.
clone
()
d
[
input
]
=
cpy
memo
[
input
]
=
cpy
else
:
d
[
input
]
=
input
memo
[
input
]
=
input
new_apply
=
apply
.
clone_with_new_inputs
([
d
[
i
]
for
i
in
apply
.
inputs
])
d
[
apply
]
=
new_apply
new_apply
=
apply
.
clone_with_new_inputs
([
memo
[
i
]
for
i
in
apply
.
inputs
])
memo
.
setdefault
(
apply
,
new_apply
)
for
output
,
new_output
in
zip
(
apply
.
outputs
,
new_apply
.
outputs
):
d
[
output
]
=
new_output
memo
.
setdefault
(
output
,
new_output
)
for
output
in
o
:
if
output
not
in
d
:
d
[
output
]
=
output
.
clone
()
# finish up by cloning any remaining outputs (it can happen)
for
output
in
outputs
:
if
output
not
in
memo
:
memo
[
output
]
=
output
.
clone
()
return
memo
return
d
def
general_toposort
(
r_out
,
deps
,
debug_print
=
False
):
"""WRITEME
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论