Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
90d490c1
提交
90d490c1
authored
5月 27, 2015
作者:
ChienliMa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish draft of Function.copy()
上级
98127db0
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
68 行增加
和
1 行删除
+68
-1
function_module.py
theano/compile/function_module.py
+68
-1
没有找到文件。
theano/compile/function_module.py
浏览文件 @
90d490c1
...
@@ -22,8 +22,9 @@ import theano.compile.mode
...
@@ -22,8 +22,9 @@ import theano.compile.mode
from
theano.compile.io
import
(
from
theano.compile.io
import
(
In
,
SymbolicInput
,
SymbolicInputKit
,
SymbolicOutput
)
In
,
SymbolicInput
,
SymbolicInputKit
,
SymbolicOutput
)
from
theano.compile.ops
import
deep_copy_op
,
view_op
from
theano.compile.ops
import
deep_copy_op
,
view_op
from
theano.gof.graph
import
is_same_graph
from
theano.gof.graph
import
is_same_graph
,
clone_get_equiv
from
theano.gof.op
import
ops_with_inner_function
from
theano.gof.op
import
ops_with_inner_function
from
theano.gof.fg
import
FunctionGraph
import
logging
import
logging
_logger
=
logging
.
getLogger
(
'theano.compile.function_module'
)
_logger
=
logging
.
getLogger
(
'theano.compile.function_module'
)
...
@@ -535,6 +536,10 @@ class Function(object):
...
@@ -535,6 +536,10 @@ class Function(object):
self
.
value
[
item
]
=
value
self
.
value
[
item
]
=
value
def
__copy__
(
self
):
def
__copy__
(
self
):
"""
Copy a function. Copied function have separate intermediate
storages and output storages with original function
"""
defaults
=
[
default
for
_1
,
_2
,
default
in
self
.
defaults
]
defaults
=
[
default
for
_1
,
_2
,
default
in
self
.
defaults
]
cpy
=
self
.
maker
.
create
(
defaults
,
trustme
=
True
)
cpy
=
self
.
maker
.
create
(
defaults
,
trustme
=
True
)
for
(
input
,
_1
,
_2
),
here
,
there
in
zip
(
self
.
indices
,
for
(
input
,
_1
,
_2
),
here
,
there
in
zip
(
self
.
indices
,
...
@@ -546,6 +551,68 @@ class Function(object):
...
@@ -546,6 +551,68 @@ class Function(object):
there
.
data
=
here
.
data
there
.
data
=
here
.
data
return
cpy
return
cpy
def
copy
(
self
,
share_memory
=
False
):
"""
Copy this function. Copied function will have separated maker and fgraph
with original function. User can choose whether to separate storage by
changing the share_memory arguments
---------------------
Params:
share_memory -- { boolean } Default is False. When True, two function
share intermediate storages(storages except input and output storages)
---------------------
Returns:
func -- Copied theano.Function
"""
if
not
share_memory
:
return
self
.
__copy__
()
else
:
# copy SymbolocKits
ins
,
outs
=
copy
.
deepcopy
([
self
.
maker
.
inputs
,
self
.
maker
.
outputs
])
# get copied input, output variables
in_vars
=
[
i
.
variabls
for
i
in
ins
]
out_vars
=
[
o
.
variabls
for
o
in
outs
]
# contruct memo that map old variables to new variables
memo
=
{}
for
old_i
,
new_i
in
zip
([
i
.
variable
for
i
in
self
.
maker
.
inputs
],
in_vars
):
memo
[
old_i
]
=
new_i
for
old_o
,
new_o
in
zip
([
o
.
variable
for
o
in
self
.
maker
.
outputs
],
out_vars
):
memo
[
old_o
]
=
new_o
# contruct new fgraph with new vars and complete the memo
memo
=
clone_get_equiv
(
in_vars
,
out_vars
,
memo
)
new_fgraph
=
FunctionGraph
(
in_vars
,
out_vars
)
# re-initialize new FunctionMaker
maker
=
self
.
maker
kwargs
=
dict
(
inputs
=
ins
,
outputs
=
outs
,
fgraph
=
new_fgraph
,
mode
=
maker
.
mode
,
profile
=
maker
.
profile
,
accept_inplace
=
maker
.
accept_inplace
,
function_builder
=
maker
.
function_builder
,
on_unused_input
=
maker
.
on_unused_input
)
new_maker
=
FunctionMaker
(
kwargs
)
# construct new storage_map that map new variable to old storage
# so that the ensuing function shares storage with the original one
new_storage_map
=
{}
storage_map
=
self
.
fn
.
storage_map
for
key
in
storage_map
.
keys
():
if
not
isinstance
(
key
,
theano
.
tensor
.
constant
)
and
\
equiv
.
has_key
(
key
):
new_storage_map
[
memo
[
key
]]
=
storage_map
[
key
]
# copy input storages and use new storage_map to link function
input_storage
=
copy
.
copy
([
getattr
(
input
,
'value'
,
None
)
for
input
in
ins
])
new_func
=
new_maker
.
create
(
input_storage
,
storage_map
=
new_storage_map
)
return
new_func
def
__call__
(
self
,
*
args
,
**
kwargs
):
def
__call__
(
self
,
*
args
,
**
kwargs
):
profile
=
self
.
profile
profile
=
self
.
profile
t0
=
time
.
time
()
t0
=
time
.
time
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论