Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
56501f9d
提交
56501f9d
authored
8月 17, 2017
作者:
abergeron
提交者:
GitHub
8月 17, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6059 from rizar/always_copy_orphas
separate copying inputs and copying orphans
上级
7fabbc7e
e84346eb
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
45 行增加
和
9 行删除
+45
-9
graph.py
theano/gof/graph.py
+25
-9
test_graph.py
theano/gof/tests/test_graph.py
+20
-0
没有找到文件。
theano/gof/graph.py
浏览文件 @
56501f9d
...
@@ -799,9 +799,8 @@ def orphans(i, o):
...
@@ -799,9 +799,8 @@ def orphans(i, o):
return
variables_and_orphans
(
i
,
o
)[
1
]
return
variables_and_orphans
(
i
,
o
)[
1
]
def
clone
(
i
,
o
,
copy_inputs
=
True
):
def
clone
(
i
,
o
,
copy_inputs
=
True
,
copy_orphans
=
None
):
"""
"""Copies the subgraph contained between i and o.
Copies the subgraph contained between i and o.
Parameters
Parameters
----------
----------
...
@@ -811,18 +810,32 @@ def clone(i, o, copy_inputs=True):
...
@@ -811,18 +810,32 @@ def clone(i, o, copy_inputs=True):
Output Variables.
Output Variables.
copy_inputs : bool
copy_inputs : bool
If True, the inputs will be copied (defaults to True).
If True, the inputs will be copied (defaults to True).
copy_orphans:
When None, use the copy_inputs value,
When True, new orphans nodes are created.
When False, original orphans nodes are reused in the new graph.
Returns
Returns
-------
-------
object
object
The inputs and outputs of that copy.
The inputs and outputs of that copy.
Note
----
A constant, if in the ``i`` list is not an orpha. So it will be
copied depending of the ``copy_inputs`` parameter. Otherwise it
will be copied depending of the ``copy_orphans`` parameter.
"""
"""
equiv
=
clone_get_equiv
(
i
,
o
,
copy_inputs
)
if
copy_orphans
is
None
:
copy_orphans
=
copy_inputs
equiv
=
clone_get_equiv
(
i
,
o
,
copy_inputs
,
copy_orphans
)
return
[
equiv
[
input
]
for
input
in
i
],
[
equiv
[
output
]
for
output
in
o
]
return
[
equiv
[
input
]
for
input
in
i
],
[
equiv
[
output
]
for
output
in
o
]
def
clone_get_equiv
(
inputs
,
outputs
,
copy_inputs_and_orphans
=
True
,
memo
=
None
):
def
clone_get_equiv
(
inputs
,
outputs
,
copy_inputs
=
True
,
copy_orphans
=
True
,
memo
=
None
):
"""
"""
Return a dictionary that maps from Variable and Apply nodes in the
Return a dictionary that maps from Variable and Apply nodes in the
original graph to a new node (a clone) in a new graph.
original graph to a new node (a clone) in a new graph.
...
@@ -834,11 +847,14 @@ def clone_get_equiv(inputs, outputs, copy_inputs_and_orphans=True, memo=None):
...
@@ -834,11 +847,14 @@ def clone_get_equiv(inputs, outputs, copy_inputs_and_orphans=True, memo=None):
----------
----------
inputs : a list of Variables
inputs : a list of Variables
outputs : a list of Variables
outputs : a list of Variables
copy_inputs
_and_orphans
: bool
copy_inputs : bool
True means to create the cloned graph from new input
and constant
True means to create the cloned graph from new input
nodes (the bottom of a feed-upward graph).
nodes (the bottom of a feed-upward graph).
False means to clone a graph that is rooted at the original input
False means to clone a graph that is rooted at the original input
nodes.
nodes.
copy_orphans:
When True, new constant nodes are created. When False, original
constant nodes are reused in the new graph.
memo : None or dict
memo : None or dict
Optionally start with a partly-filled dictionary for the return value.
Optionally start with a partly-filled dictionary for the return value.
If a dictionary is passed, this function will work in-place on that
If a dictionary is passed, this function will work in-place on that
...
@@ -850,7 +866,7 @@ def clone_get_equiv(inputs, outputs, copy_inputs_and_orphans=True, memo=None):
...
@@ -850,7 +866,7 @@ def clone_get_equiv(inputs, outputs, copy_inputs_and_orphans=True, memo=None):
# clone the inputs if necessary
# clone the inputs if necessary
for
input
in
inputs
:
for
input
in
inputs
:
if
copy_inputs
_and_orphans
:
if
copy_inputs
:
cpy
=
input
.
clone
()
cpy
=
input
.
clone
()
cpy
.
owner
=
None
cpy
.
owner
=
None
cpy
.
index
=
None
cpy
.
index
=
None
...
@@ -862,7 +878,7 @@ def clone_get_equiv(inputs, outputs, copy_inputs_and_orphans=True, memo=None):
...
@@ -862,7 +878,7 @@ def clone_get_equiv(inputs, outputs, copy_inputs_and_orphans=True, memo=None):
for
apply
in
io_toposort
(
inputs
,
outputs
):
for
apply
in
io_toposort
(
inputs
,
outputs
):
for
input
in
apply
.
inputs
:
for
input
in
apply
.
inputs
:
if
input
not
in
memo
:
if
input
not
in
memo
:
if
copy_
inputs_and_
orphans
:
if
copy_orphans
:
cpy
=
input
.
clone
()
cpy
=
input
.
clone
()
memo
[
input
]
=
cpy
memo
[
input
]
=
cpy
else
:
else
:
...
...
theano/gof/tests/test_graph.py
浏览文件 @
56501f9d
...
@@ -156,6 +156,26 @@ class TestClone(X):
...
@@ -156,6 +156,26 @@ class TestClone(X):
assert
self
.
str
(
inputs
(
new_node
.
outputs
),
new_node
.
outputs
)
==
[
"MyOp(R7, R8)"
]
assert
self
.
str
(
inputs
(
new_node
.
outputs
),
new_node
.
outputs
)
==
[
"MyOp(R7, R8)"
]
assert
self
.
str
(
inputs
(
node
.
outputs
),
node
.
outputs
)
==
[
"MyOp(MyOp(R1, R2), R5)"
]
assert
self
.
str
(
inputs
(
node
.
outputs
),
node
.
outputs
)
==
[
"MyOp(MyOp(R1, R2), R5)"
]
def
test_constant
(
self
):
r1
,
r2
,
r5
=
MyVariable
(
1
),
MyVariable
(
2
),
MyVariable
(
5
)
node
=
MyOp
.
make_node
(
MyOp
.
make_node
(
r1
,
r2
)
.
outputs
[
0
],
r5
)
_
,
new
=
clone
([
r1
,
r2
,
r5
],
node
.
outputs
,
False
)
new_node
=
new
[
0
]
.
owner
new_node
.
inputs
=
MyVariable
(
7
),
MyVariable
(
8
)
c1
=
tensor
.
constant
(
1.5
)
i
,
o
=
clone
([
c1
],
[
c1
])
assert
i
[
0
]
is
not
c1
and
o
[
0
]
is
not
c1
i
,
o
=
clone
([
c1
],
[
c1
],
False
)
assert
i
[
0
]
is
c1
and
o
[
0
]
is
c1
i
,
o
=
clone
([
c1
],
[
c1
],
True
,
False
)
assert
i
[
0
]
is
not
c1
and
o
[
0
]
is
not
c1
i
,
o
=
clone
([
c1
],
[
c1
],
False
,
True
)
assert
i
[
0
]
is
c1
and
o
[
0
]
is
c1
############
############
# toposort #
# toposort #
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论