Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dc36c99b
提交
dc36c99b
authored
6月 17, 2015
作者:
ChienliMa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish draft, it work. Start working on test and improve the code
上级
81f7134f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
23 行删除
+24
-23
function_module.py
theano/compile/function_module.py
+24
-23
没有找到文件。
theano/compile/function_module.py
浏览文件 @
dc36c99b
...
...
@@ -19,7 +19,6 @@ from theano import gof
from
functools
import
partial
from
theano.compat
import
izip
import
theano.compile.mode
from
theano.compile
import
SharedVariable
from
theano.compile.io
import
(
In
,
SymbolicInput
,
SymbolicInputKit
,
SymbolicOutput
)
from
theano.compile.ops
import
deep_copy_op
,
view_op
...
...
@@ -555,11 +554,6 @@ class Function(object):
storages( see method __copy__() ) and same maker. If two functions
share memory and allow_gc=False, this will increase executing speed
and save memory.
swap -- { dict } Default is None. If not None, it should be a
dictionay {String: theano.SharedVariable} that map original
SharedVariable's name(string) to new SharedVariable.
Two SharedVariable should have the same theano type.
---------------------
Returns:
func -- Copied theano.Function
...
...
@@ -571,23 +565,23 @@ class Function(object):
# copy fgraph and get memo
fg_cpy
,
memo
=
maker
.
fgraph
.
clone_get_equiv
(
attach_feature
=
False
)
#
if swap is not None, swap SharedVariable
#
swap SharedVariable if need
if
swap
!=
None
:
assert
type
(
swap
)
is
dict
,
(
"Parameter swap should be a dict."
"Given:"
,
type
(
swap
))
swap
SV
(
swap
,
ins
,
fg_cpy
,
memo
)
self
.
_swapSV
(
swap
,
ins
,
fg_cpy
,
memo
)
#used to prevent
swap
ped_sv
=
swap
.
keys
(
)
storage_map
=
self
.
fn
.
storage_map
new_storage_map
=
{}
# Construct new storage_map that map new variable to old storage,
# so that the ensuing function shares storage with the original one
# TODO: We could share the output storage, but we must make sure
# 2 different function call won't override each other values. This
# is already done elsewhere, so to reuse it the user would need to
# use Out(var, borrow=True) and maybe the mutable=True flag too.
# But to be safe for now as it isn't documented and we aren't sure
# it is well tested, we don't share the part of the storage_map.
if
share_memory
:
# Construct new storage_map that map new variable to old storage,
# so that the ensuing function shares storage with the original one
# TODO: We could share the output storage, but we must make sure
# 2 different function call won't override each other values. This
# is already done elsewhere, so to reuse it the user would need to
# use Out(var, borrow=True) and maybe the mutable=True flag too.
# But to be safe for now as it isn't documented and we aren't sure
# it is well tested, we don't share the part of the storage_map.
for
key
in
storage_map
.
keys
():
if
key
not
in
i_o_vars
:
new_storage_map
[
memo
[
key
]]
=
storage_map
[
key
]
...
...
@@ -624,7 +618,7 @@ class Function(object):
return
f_cpy
def
_swapSV
(
swap
,
ins
,
fg_cpy
,
memo
):
def
_swapSV
(
s
elf
,
s
wap
,
ins
,
fg_cpy
,
memo
):
"""
Hidden auxiliary function, used to swap SharedVariable in maker.inputs
and maker.fgraph.
...
...
@@ -652,6 +646,8 @@ class Function(object):
# Main code start here
exist_name
=
[
i
.
variable
.
name
for
i
in
ins
]
for
name
,
sv
in
swap
.
iteritems
():
assert
type
(
name
)
is
str
,
(
"The SharedVariable need to be replaced"
"should be indicated by its name(string). Given:"
,
type
(
name
))
# check if SharedVariable exist
if
name
not
in
exist_name
:
print
(
"WARNING: SharedVariable named:
%
s not found"
)
%
name
...
...
@@ -661,7 +657,7 @@ class Function(object):
sv
=
sv
.
clone
()
# replace SharedVariable in maker's In instances
for
i
in
maker
.
input
s
:
for
i
in
in
s
:
if
i
.
variable
.
name
==
name
:
checkSV
(
i
.
variable
,
sv
)
i
.
variable
,
i
.
value
=
sv
,
sv
.
container
...
...
@@ -669,14 +665,19 @@ class Function(object):
# replace SharedVariable in fgraph and memo
for
var_ori
,
var_cpy
in
memo
.
iteritems
():
if
isinstance
(
ori_in
,
SharedVariable
)
and
ori_in
.
name
==
name
:
if
isinstance
(
var_ori
,
theano
.
compile
.
SharedVariable
)
and
var_ori
.
name
==
name
:
checkSV
(
var_cpy
,
sv
)
# replace variable in fgraph
fgraph_cpy
.
replace
(
var_cpy
,
sv
)
# modify fg_cpy.iputs
for
i
in
xrange
(
len
(
fg_cpy
.
inputs
)):
if
fg_cpy
.
inputs
[
i
]
.
name
==
name
:
fg_cpy
.
inputs
[
i
]
=
sv
break
fg_cpy
.
replace
(
var_cpy
,
sv
)
# modify memo so that ori_var->this shared var
memo
[
var_ori
]
=
sv
break
def
__call__
(
self
,
*
args
,
**
kwargs
):
profile
=
self
.
profile
t0
=
time
.
time
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论