Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a8bf731f
提交
a8bf731f
authored
3月 19, 2015
作者:
Pierre Luc Carrier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix scan_op.connection_pattern and add test
上级
5ff8e002
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
22 行删除
+51
-22
scan_op.py
theano/scan_module/scan_op.py
+22
-22
test_scan.py
theano/scan_module/tests/test_scan.py
+29
-0
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
a8bf731f
...
@@ -1349,33 +1349,33 @@ class Scan(PureOp):
...
@@ -1349,33 +1349,33 @@ class Scan(PureOp):
e
+=
1
e
+=
1
return
self
.
outputs
[
s
:
e
]
return
self
.
outputs
[
s
:
e
]
def
_get_inner_inps
(
iidx
):
def
_get_inner_inps
(
outer_iidx
):
if
node
.
inputs
[
iidx
+
1
]
in
self
.
outer_nitsot
(
node
):
"""Given the index of an outer input, return the corresponding
return
None
inner input(s) as a sequence.
if
node
.
inputs
[
iidx
+
1
]
in
self
.
outer_non_seqs
(
node
):
"""
loc_idx
=
self
.
outer_non_seqs
(
node
)
.
index
(
node
.
inputs
[
iidx
+
1
])
return
[
self
.
inner_non_seqs
(
self
.
inputs
)[
loc_idx
]]
s
=
0
outer_iidx_from_inner_iidx
=
self
.
get_outer_iidx_from_inner_iidx_seq
()
if
self
.
n_seqs
>
0
:
e
=
1
# For every inner input, if the corresponding outer input is the
# desired one, store the index
inner_iidxs
=
[]
for
i
in
xrange
(
len
(
outer_iidx_from_inner_iidx
)):
if
outer_iidx_from_inner_iidx
[
i
]
==
outer_iidx
:
inner_iidxs
.
append
(
i
)
# The inner inputs can be selected this way because the indices in
# inner_iidxs are consecutive and in ascending order
if
len
(
inner_iidxs
)
>
0
:
inner_inputs
=
self
.
inputs
[
inner_iidxs
[
0
]:
inner_iidxs
[
-
1
]
+
1
]
else
:
else
:
e
=
len
(
self
.
tap_array
[
0
])
inner_inputs
=
[]
for
p
in
xrange
(
iidx
):
s
=
e
return
inner_inputs
if
p
<
self
.
n_seqs
:
e
+=
1
elif
p
-
self
.
n_seqs
<
len
(
self
.
tap_array
):
e
+=
len
(
self
.
tap_array
[
p
-
self
.
n_seqs
])
else
:
e
+=
1
return
self
.
inputs
[
s
:
e
]
for
oidx
,
out
in
enumerate
(
node
.
outputs
):
for
oidx
,
out
in
enumerate
(
node
.
outputs
):
for
iidx
,
inp
in
enumerate
(
node
.
inputs
[
1
:]):
for
iidx
,
inp
in
enumerate
(
node
.
inputs
[
1
:]):
ols
=
_get_inner_outs
(
oidx
)
ols
=
_get_inner_outs
(
oidx
)
ils
=
_get_inner_inps
(
iidx
)
ils
=
_get_inner_inps
(
iidx
+
1
)
if
ils
is
None
:
if
ils
is
None
:
# The gradient should be disconnected
# The gradient should be disconnected
...
@@ -1439,7 +1439,7 @@ class Scan(PureOp):
...
@@ -1439,7 +1439,7 @@ class Scan(PureOp):
return
connection_pattern
return
connection_pattern
def
get_outer_iidx_from_inner_iidx_seq
(
self
):
def
get_outer_iidx_from_inner_iidx_seq
(
self
):
""" Return a sequence where the value
of
at the i-th position is the
""" Return a sequence where the value at the i-th position is the
index of the outer input corresponding to the i-th inner input
index of the outer input corresponding to the i-th inner input
"""
"""
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
a8bf731f
...
@@ -3333,6 +3333,35 @@ class T_Scan(unittest.TestCase):
...
@@ -3333,6 +3333,35 @@ class T_Scan(unittest.TestCase):
utt
.
assert_allclose
(
outputs
[
4
],
expected_g_out_init
)
utt
.
assert_allclose
(
outputs
[
4
],
expected_g_out_init
)
utt
.
assert_allclose
(
outputs
[
5
],
expected_g_non_seq
)
utt
.
assert_allclose
(
outputs
[
5
],
expected_g_non_seq
)
def
test_grad_duplicate_outputs_connection_pattern
(
self
):
# This test checks for a crash in scan.connection_pattern when taking
# the grad of a scan with certain combinations of outputs.
def
inner_fct
(
inp1
,
inp2
,
inp3
,
inp4
,
inp5
,
inp6
):
total
=
inp1
+
inp2
+
inp3
+
inp4
+
inp5
+
inp6
return
total
,
total
,
total
,
total
,
total
,
total
# Assemble the scan
out_init
=
[
tensor
.
vector
(),
tensor
.
vector
(),
tensor
.
matrix
(),
tensor
.
matrix
()]
outputs_info
=
([
None
,
None
,
out_init
[
0
],
out_init
[
1
],
dict
(
initial
=
out_init
[
2
],
taps
=
[
-
2
,
-
1
]),
dict
(
initial
=
out_init
[
3
],
taps
=
[
-
2
,
-
1
])])
scan_outputs
,
_
=
theano
.
scan
(
fn
=
inner_fct
,
outputs_info
=
outputs_info
,
n_steps
=
10
)
g_output0
=
theano
.
grad
(
scan_outputs
[
0
]
.
sum
(),
out_init
[
1
])
# Validate the connnection pattern is as it should be
node
=
scan_outputs
[
0
]
.
owner
connection_pattern
=
node
.
op
.
connection_pattern
(
node
)
expected_connection_pattern
=
[[(
j
in
[
1
,
2
,
3
,
4
])
for
i
in
range
(
6
)]
for
j
in
range
(
7
)]
assert
connection_pattern
==
expected_connection_pattern
def
test_grad_multiple_seqs_different_nsteps
(
self
):
def
test_grad_multiple_seqs_different_nsteps
(
self
):
# Example provided Michael Forbes
# Example provided Michael Forbes
# This test assures that we clip the sequences to n_steps before
# This test assures that we clip the sequences to n_steps before
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论