Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
09fe88b9
提交
09fe88b9
authored
6月 23, 2015
作者:
ChienliMa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8 coding style fix and return 'del a' line in test_leak2
上级
0c1cdd89
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
14 行删除
+14
-14
function_module.py
theano/compile/function_module.py
+13
-13
test_vm.py
theano/gof/tests/test_vm.py
+1
-1
没有找到文件。
theano/compile/function_module.py
浏览文件 @
09fe88b9
...
@@ -546,7 +546,7 @@ class Function(object):
...
@@ -546,7 +546,7 @@ class Function(object):
"""
"""
Copy this function. Copied function will have separated maker and
Copy this function. Copied function will have separated maker and
fgraph with original function. User can choose whether to separate
fgraph with original function. User can choose whether to separate
storage by changing the share_memory arguments.
storage by changing the share_memory arguments.
Note:
Note:
We reuse original Out instances but In instances, therefore variables
We reuse original Out instances but In instances, therefore variables
in Ins and Outs are not in the same graph. Please avoid using variables
in Ins and Outs are not in the same graph. Please avoid using variables
...
@@ -565,7 +565,7 @@ class Function(object):
...
@@ -565,7 +565,7 @@ class Function(object):
None.
None.
delete_updates -- { boolean } Default is False. If True, Copied
delete_updates -- { boolean } Default is False. If True, Copied
function will not have update.
function will not have update.
---------------------
---------------------
Returns:
Returns:
func -- Copied theano.Function
func -- Copied theano.Function
...
@@ -597,14 +597,14 @@ class Function(object):
...
@@ -597,14 +597,14 @@ class Function(object):
update_i
=
len
(
outs
)
update_i
=
len
(
outs
)
for
i
,
in_var
in
zip
(
ins
,
fg_cpy
.
inputs
):
for
i
,
in_var
in
zip
(
ins
,
fg_cpy
.
inputs
):
i
.
variable
=
in_var
i
.
variable
=
in_var
if
not
delete_updates
and
i
.
update
!=
None
:
if
not
delete_updates
and
i
.
update
is
not
None
:
i
.
update
=
fg_cpy
.
outputs
[
update_i
]
i
.
update
=
fg_cpy
.
outputs
[
update_i
]
update_i
+=
1
update_i
+=
1
else
:
else
:
i
.
update
=
None
i
.
update
=
None
# swap SharedVariable
# swap SharedVariable
if
swap
!=
None
:
if
swap
is
not
None
:
self
.
__swapSV
(
swap
,
ins
,
fg_cpy
)
self
.
__swapSV
(
swap
,
ins
,
fg_cpy
)
# the name of SV we swapped
# the name of SV we swapped
swapped_sv
=
swap
.
keys
()
swapped_sv
=
swap
.
keys
()
...
@@ -627,7 +627,7 @@ class Function(object):
...
@@ -627,7 +627,7 @@ class Function(object):
if
key
not
in
i_o_vars
:
if
key
not
in
i_o_vars
:
new_storage_map
[
memo
[
key
]]
=
storage_map
[
key
]
new_storage_map
[
memo
[
key
]]
=
storage_map
[
key
]
input_storage
=
[
i
.
value
for
i
in
ins
]
input_storage
=
[
i
.
value
for
i
in
ins
]
# reinitialize new maker and create new function
# reinitialize new maker and create new function
f_cpy
=
maker
.
__class__
(
inputs
=
ins
,
outputs
=
outs
,
f_cpy
=
maker
.
__class__
(
inputs
=
ins
,
outputs
=
outs
,
fgraph
=
fg_cpy
,
fgraph
=
fg_cpy
,
...
@@ -643,7 +643,7 @@ class Function(object):
...
@@ -643,7 +643,7 @@ class Function(object):
f_cpy
.
input_storage
):
f_cpy
.
input_storage
):
is_const
=
isinstance
(
in_ori
.
variable
,
theano
.
tensor
.
Constant
)
is_const
=
isinstance
(
in_ori
.
variable
,
theano
.
tensor
.
Constant
)
# In instances' name default to vairables' name
# In instances' name default to vairables' name
swapped
=
swap
!=
None
and
in_ori
.
name
in
swapped_sv
swapped
=
swap
is
not
None
and
in_ori
.
name
in
swapped_sv
if
(
is_const
or
not
in_ori
.
mutable
)
and
not
swapped
:
if
(
is_const
or
not
in_ori
.
mutable
)
and
not
swapped
:
cpy
.
data
=
ori
.
data
cpy
.
data
=
ori
.
data
...
@@ -652,7 +652,7 @@ class Function(object):
...
@@ -652,7 +652,7 @@ class Function(object):
# Reconstruct Function.finder.
# Reconstruct Function.finder.
# Function.value and Function.data work
# Function.value and Function.data work
for
ori
,
cpy
in
zip
(
maker
.
inputs
,
f_cpy
.
maker
.
inputs
):
for
ori
,
cpy
in
zip
(
maker
.
inputs
,
f_cpy
.
maker
.
inputs
):
swapped
=
swap
!=
None
and
ori
.
name
in
swapped_sv
swapped
=
swap
is
not
None
and
ori
.
name
in
swapped_sv
if
not
swapped
:
if
not
swapped
:
f_cpy
.
finder
[
ori
.
variable
]
=
f_cpy
.
finder
.
pop
(
cpy
.
variable
)
f_cpy
.
finder
[
ori
.
variable
]
=
f_cpy
.
finder
.
pop
(
cpy
.
variable
)
else
:
else
:
...
@@ -666,14 +666,14 @@ class Function(object):
...
@@ -666,14 +666,14 @@ class Function(object):
and maker.fgraph.
and maker.fgraph.
--------------------
--------------------
Params:
Params:
swap -- { dict } The same as docs in copy()
swap -- { dict } The same as docs in copy()
ins -- { list } List of In instances to be modified.
ins -- { list } List of In instances to be modified.
fg_cpy -- { FounctionGraph } Copied FunctionGraph.
fg_cpy -- { FounctionGraph } Copied FunctionGraph.
--------------------
--------------------
Returns:
Returns:
None
None
"""
"""
def
checkSV
(
sv_ori
,
sv_rpl
):
def
checkSV
(
sv_ori
,
sv_rpl
):
"""
"""
Assert two SharedVariable follow some restirctions:
Assert two SharedVariable follow some restirctions:
1. same type
1. same type
...
@@ -682,7 +682,7 @@ class Function(object):
...
@@ -682,7 +682,7 @@ class Function(object):
assert
sv_ori
.
type
==
sv_rpl
.
type
,
(
assert
sv_ori
.
type
==
sv_rpl
.
type
,
(
"Type of given SharedVariable conflicts with origianl one"
,
"Type of given SharedVariable conflicts with origianl one"
,
"Type of given SharedVariable:"
,
sv_rpl
.
type
,
"Type of given SharedVariable:"
,
sv_rpl
.
type
,
"Type of original SharedVariable:"
,
sv_ori
.
type
)
"Type of original SharedVariable:"
,
sv_ori
.
type
)
exist_names
=
[
i
.
variable
.
name
for
i
in
ins
]
exist_names
=
[
i
.
variable
.
name
for
i
in
ins
]
swap_names
=
swap
.
keys
()
swap_names
=
swap
.
keys
()
...
@@ -690,7 +690,7 @@ class Function(object):
...
@@ -690,7 +690,7 @@ class Function(object):
# Check if given names exist
# Check if given names exist
for
name
in
swap_names
:
for
name
in
swap_names
:
if
name
not
in
exist_names
:
if
name
not
in
exist_names
:
warnings
.
warn
(
"Given name:
%
s wasn't found"
%
(
name
)
)
warnings
.
warn
(
"Given name:
%
s wasn't found"
%
(
name
)
)
# Swap SharedVairable in fgraph and ins
# Swap SharedVairable in fgraph and ins
for
index
,
(
i
,
in_v
)
in
enumerate
(
zip
(
ins
,
fg_cpy
.
inputs
)):
for
index
,
(
i
,
in_v
)
in
enumerate
(
zip
(
ins
,
fg_cpy
.
inputs
)):
...
@@ -699,11 +699,11 @@ class Function(object):
...
@@ -699,11 +699,11 @@ class Function(object):
if
in_v
.
name
in
swap_names
:
if
in_v
.
name
in
swap_names
:
# In the fgraph we use the cloned SharedVariable
# In the fgraph we use the cloned SharedVariable
swap_sv
=
swap
[
in_v
.
name
]
.
clone
()
swap_sv
=
swap
[
in_v
.
name
]
.
clone
()
checkSV
(
in_v
,
swap_sv
)
checkSV
(
in_v
,
swap_sv
)
# Swap SharedVariable in fgraph
# Swap SharedVariable in fgraph
fg_cpy
.
inputs
[
index
]
=
swap_sv
fg_cpy
.
inputs
[
index
]
=
swap_sv
fg_cpy
.
replace
(
in_v
,
swap_sv
,
reason
=
"Swap SV"
)
fg_cpy
.
replace
(
in_v
,
swap_sv
,
reason
=
"Swap SV"
)
# swap variable and value of In instances
# swap variable and value of In instances
i
.
variable
=
swap_sv
i
.
variable
=
swap_sv
...
...
theano/gof/tests/test_vm.py
浏览文件 @
09fe88b9
...
@@ -230,7 +230,7 @@ if run_memory_usage_tests:
...
@@ -230,7 +230,7 @@ if run_memory_usage_tests:
a
=
cuda
.
CudaNdarray
(
n
)
a
=
cuda
.
CudaNdarray
(
n
)
a
.
sum
()
a
.
sum
()
assert
c
==
sys
.
getrefcount
(
n
)
assert
c
==
sys
.
getrefcount
(
n
)
del
a
if
not
i
%
1000
:
if
not
i
%
1000
:
print
(
'.'
,
end
=
' '
)
print
(
'.'
,
end
=
' '
)
print
(
gc
.
collect
(),
end
=
' '
)
print
(
gc
.
collect
(),
end
=
' '
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论