Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d71a80f6
提交
d71a80f6
authored
8月 11, 2015
作者:
ChienliMa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test for sharedvar
上级
51ff4318
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
22 行增加
和
13 行删除
+22
-13
function_module.py
theano/compile/function_module.py
+8
-8
test_function_module.py
theano/compile/tests/test_function_module.py
+14
-5
没有找到文件。
theano/compile/function_module.py
浏览文件 @
d71a80f6
...
@@ -637,22 +637,22 @@ class Function(object):
...
@@ -637,22 +637,22 @@ class Function(object):
# Variables in maker.inputs are defined by user, therefore we
# Variables in maker.inputs are defined by user, therefore we
# use them to make comparision and do the mapping.
# use them to make comparision and do the mapping.
# Otherwise we don't touch them.
# Otherwise we don't touch them.
swap_sv
=
maker
.
inputs
[
index
]
.
variable
var
=
maker
.
inputs
[
index
]
.
variable
if
swap_sv
in
swap_svs_ori
:
if
var
in
swap_svs_ori
:
swap_sv
=
swap
[
var
]
checkSV
(
i
.
variable
,
swap_sv
)
checkSV
(
i
.
variable
,
swap_sv
)
# swap variable and value of In instances
i
.
variable
=
swap_sv
# In the fgraph we use the cloned SharedVariable
# In the fgraph we use the cloned SharedVariable
swap_sv
=
swap_sv
.
clone
()
swap_sv
=
swap_sv
.
clone
()
# 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
i
.
variable
=
swap_sv
i
.
value
=
swap_sv
.
container
# Construct new storage_map that map new variable to old storage,
# Construct new storage_map that map new variable to old storage,
# so that the ensuing function shares storage with the original one
# so that the ensuing function shares storage with the original one
storage_map
=
self
.
fn
.
storage_map
storage_map
=
self
.
fn
.
storage_map
...
...
theano/compile/tests/test_function_module.py
浏览文件 @
d71a80f6
...
@@ -284,7 +284,7 @@ class T_function(unittest.TestCase):
...
@@ -284,7 +284,7 @@ class T_function(unittest.TestCase):
# SharedVariable to replace
# SharedVariable to replace
y_rpl
=
theano
.
shared
(
value
=
3
,
name
=
'y_rpl'
)
y_rpl
=
theano
.
shared
(
value
=
3
,
name
=
'y_rpl'
)
z_rpl
=
theano
.
shared
(
value
=
4
,
name
=
'z_rpl'
)
z_rpl
=
theano
.
shared
(
value
=
4
,
name
=
'z_rpl'
)
swap
=
{
y
:
y_rpl
,
y
:
z_rpl
}
swap
=
{
y
:
y_rpl
,
z
:
z_rpl
}
map_SV
=
{
'y_rpl'
:
y_rpl
,
'z_rpl'
:
z_rpl
}
map_SV
=
{
'y_rpl'
:
y_rpl
,
'z_rpl'
:
z_rpl
}
out
=
x
+
y
+
z
+
m
out
=
x
+
y
+
z
+
m
...
@@ -301,9 +301,21 @@ class T_function(unittest.TestCase):
...
@@ -301,9 +301,21 @@ class T_function(unittest.TestCase):
# assert same SharedVariable are update in different function
# assert same SharedVariable are update in different function
if
not
second_time
:
if
not
second_time
:
# m should be updated 3 times
assert
m
.
get_value
()
==
6
assert
m
.
get_value
()
==
6
# z should be updated once
assert
z
.
get_value
()
==
3
# z_rpl should be updated twice
assert
z_rpl
.
get_value
()
==
6
# y and y_rpl should not be updated
assert
y_rpl
.
get_value
()
==
3
assert
y
.
get_value
()
==
1
elif
second_time
:
elif
second_time
:
# doule update for sharedvariable
assert
m
.
get_value
()
==
12
assert
m
.
get_value
()
==
12
assert
z
.
get_value
()
==
3
assert
z_rpl
.
get_value
()
==
8
assert
y_rpl
.
get_value
()
==
3
# test cpy function:
# test cpy function:
# 2. SharedVariable is updatable -> values did update(z == 5)
# 2. SharedVariable is updatable -> values did update(z == 5)
...
@@ -313,10 +325,7 @@ class T_function(unittest.TestCase):
...
@@ -313,10 +325,7 @@ class T_function(unittest.TestCase):
if
key
.
name
in
names
:
if
key
.
name
in
names
:
assert
map_SV
[
key
.
name
]
.
container
.
storage
[
0
]
==
\
assert
map_SV
[
key
.
name
]
.
container
.
storage
[
0
]
==
\
cpy
.
fn
.
storage_map
[
key
][
0
]
cpy
.
fn
.
storage_map
[
key
][
0
]
if
key
.
name
==
'z_rpl'
and
not
second_time
:
assert
cpy
.
fn
.
storage_map
[
key
][
0
]
==
6
elif
key
.
name
==
'z_rpl'
and
second_time
:
assert
cpy
.
fn
.
storage_map
[
key
][
0
]
==
8
second_time
=
True
second_time
=
True
def
test_copy_delete_updates
(
self
):
def
test_copy_delete_updates
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论