Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
42cf211b
提交
42cf211b
authored
6月 05, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add comment and rename var
上级
32a4afb7
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
27 行增加
和
13 行删除
+27
-13
fg.py
theano/gof/fg.py
+27
-13
没有找到文件。
theano/gof/fg.py
浏览文件 @
42cf211b
...
@@ -375,6 +375,14 @@ class FunctionGraph(utils.object2):
...
@@ -375,6 +375,14 @@ class FunctionGraph(utils.object2):
### prune ###
### prune ###
def
__prune_r__
(
self
,
variables
,
reason
=
None
):
def
__prune_r__
(
self
,
variables
,
reason
=
None
):
"""Should be called for variables that aren't used anymore:
len(var.clients) == 0
This do not mean we will remove it from fgraph.variables. If
the owner stay in the fgraph as other outputs are still used,
the variable will be stay in fgraph.variables.
"""
# Prunes the owners of the variables.
# Prunes the owners of the variables.
for
node
in
set
(
r
.
owner
for
r
in
variables
if
r
.
owner
is
not
None
):
for
node
in
set
(
r
.
owner
for
r
in
variables
if
r
.
owner
is
not
None
):
self
.
__prune__
(
node
,
reason
)
self
.
__prune__
(
node
,
reason
)
...
@@ -383,25 +391,31 @@ class FunctionGraph(utils.object2):
...
@@ -383,25 +391,31 @@ class FunctionGraph(utils.object2):
self
.
variables
.
remove
(
r
)
self
.
variables
.
remove
(
r
)
def
__prune__
(
self
,
apply_node
,
reason
=
None
):
def
__prune__
(
self
,
apply_node
,
reason
=
None
):
node
=
apply_node
"""Always called on owner of pruned variable from the graph.
if
node
not
in
self
.
apply_nodes
:
raise
Exception
(
"
%
s does not belong to this FunctionGraph and cannot be pruned."
%
node
)
This do not mean we will remove it from the graph. If other
assert
node
.
fgraph
is
self
outputs are still used, we will keep the node in the graph.
# If node's outputs have no clients, removes it from the graph
"""
if
apply_node
not
in
self
.
apply_nodes
:
raise
Exception
(
"
%
s does not belong to this FunctionGraph."
%
apply_node
)
assert
apply_node
.
fgraph
is
self
# If apply_node's outputs have no clients, removes it from the graph
# and recursively tries to prune its inputs. If at least one
# and recursively tries to prune its inputs. If at least one
# of the op's outputs is an output to the graph or has a client
# of the op's outputs is an output to the graph or has a client
# then __prune__ is a no-op.
# then __prune__ is a no-op.
for
output
in
node
.
outputs
:
for
output
in
apply_
node
.
outputs
:
# Cannot prune an op which is an output or used somewhere
# Cannot prune an op which is an output or used somewhere
if
self
.
clients
(
output
)
or
output
in
self
.
outputs
:
# output in self.outputs or self.clients(output)
:
if
output
.
clients
or
output
in
self
.
outputs
:
return
return
self
.
apply_nodes
.
remove
(
node
)
self
.
apply_nodes
.
remove
(
apply_
node
)
self
.
variables
.
difference_update
(
node
.
outputs
)
self
.
variables
.
difference_update
(
apply_
node
.
outputs
)
self
.
execute_callbacks
(
'on_prune'
,
node
,
reason
)
self
.
execute_callbacks
(
'on_prune'
,
apply_
node
,
reason
)
for
i
,
input
in
enumerate
(
node
.
inputs
):
for
i
,
input
in
enumerate
(
apply_
node
.
inputs
):
self
.
__remove_clients__
(
input
,
[(
node
,
i
)],
reason
=
reason
)
self
.
__remove_clients__
(
input
,
[(
apply_
node
,
i
)],
reason
=
reason
)
# self.__prune_r__(node.inputs)
# self.__prune_r__(
apply_
node.inputs)
### change input ###
### change input ###
def
change_input
(
self
,
node
,
i
,
new_r
,
reason
=
None
):
def
change_input
(
self
,
node
,
i
,
new_r
,
reason
=
None
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论