Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f52d6ee7
提交
f52d6ee7
authored
6月 09, 2015
作者:
--global
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add function to generate all mappings between sets of inputs/outputs
上级
5aca8c8e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
155 行增加
和
0 行删除
+155
-0
scan_op.py
theano/scan_module/scan_op.py
+155
-0
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
f52d6ee7
...
...
@@ -1595,6 +1595,161 @@ class Scan(PureOp):
node
.
tag
.
connection_pattern
=
connection_pattern
return
connection_pattern
def
get_oinp_iinp_iout_oout_mappings
(
self
):
""" Compute and return dictionary mappings between the inputs and
outputs of the inner function and the inputs and outputs of the Scan
node in the outer graph.
The return value is a dictionary in which the keys are the names of
the individual mappings and the values are the mapping dictionaries
themselves. In dictionaries representing mappings to outer variables,
the values are individual integer indices. In dictionaries
representing mappings to inner variables, the values are sequences of
indices because multiple inner variables can be associated with the
same state
"""
# Lists for outer variables contain individual indices, lists for
# inner variables contain sequences of indices because many inner
# variables can be associated with the same outer variable. The list
# and indices are initialized already containing the data associated
# with the timestep index, the first outer input.
outer_input_indices
=
[
0
]
inner_input_indices
=
[[]]
inner_output_indices
=
[[]]
outer_output_indices
=
[
-
1
]
outer_iidx
=
1
inner_iidx
=
0
inner_oidx
=
0
outer_oidx
=
0
# Handle sequences inputs
for
i
in
range
(
self
.
info
[
'n_seqs'
]):
outer_input_indices
.
append
(
outer_iidx
)
inner_input_indices
.
append
([
inner_iidx
])
inner_output_indices
.
append
([])
outer_output_indices
.
append
(
-
1
)
outer_iidx
+=
1
inner_iidx
+=
1
inner_oidx
+=
0
outer_oidx
+=
0
# Handle mitmots, mitsots and sitsots variables
for
i
in
range
(
len
(
self
.
info
[
'tap_array'
])):
nb_input_taps
=
len
(
self
.
info
[
'tap_array'
][
i
])
if
i
<
self
.
n_mit_mot
:
nb_output_taps
=
len
(
self
.
mit_mot_out_slices
[
i
])
else
:
nb_output_taps
=
1
outer_input_indices
.
append
(
outer_iidx
)
inner_input_indices
.
append
(
range
(
inner_iidx
,
inner_iidx
+
nb_input_taps
))
inner_output_indices
.
append
(
range
(
inner_oidx
,
inner_oidx
+
nb_output_taps
))
outer_output_indices
.
append
(
outer_oidx
)
outer_iidx
+=
1
inner_iidx
+=
nb_input_taps
inner_oidx
+=
nb_output_taps
outer_oidx
+=
1
# This is needed because, for outer inputs (and for outer inputs only)
# nitsots come *after* shared variables.
outer_iidx
+=
self
.
info
[
'n_shared_outs'
]
# Handle nitsots variables
for
i
in
range
(
self
.
n_nit_sot
):
outer_input_indices
.
append
(
outer_iidx
)
inner_input_indices
.
append
([])
inner_output_indices
.
append
([
inner_oidx
])
outer_output_indices
.
append
(
outer_oidx
)
outer_iidx
+=
1
inner_iidx
+=
0
inner_oidx
+=
1
outer_oidx
+=
1
# This is needed because, for outer inputs (and for outer inputs only)
# nitsots come *after* shared variables.
outer_iidx
-=
(
self
.
info
[
'n_shared_outs'
]
+
self
.
n_nit_sot
)
# Handle shared states
for
i
in
range
(
self
.
info
[
'n_shared_outs'
]):
outer_input_indices
.
append
(
outer_iidx
)
inner_input_indices
.
append
([
inner_iidx
])
inner_output_indices
.
append
([
inner_oidx
])
outer_output_indices
.
append
(
outer_oidx
)
outer_iidx
+=
1
inner_iidx
+=
1
inner_oidx
+=
1
outer_oidx
+=
1
# This is needed because, for outer inputs (and for outer inputs only)
# nitsots come *after* shared variables.
outer_iidx
+=
self
.
n_nit_sot
# Handle non-sequence inputs
# Note : the number of non-sequence inputs is not stored in self.info
# so it has to be inferred from the number of inner inputs that remain
# to be handled
for
i
in
range
(
len
(
self
.
inputs
)
-
inner_iidx
):
outer_input_indices
.
append
(
outer_iidx
)
inner_input_indices
.
append
([
inner_iidx
])
inner_output_indices
.
append
([])
outer_output_indices
.
append
(
-
1
)
outer_iidx
+=
1
inner_iidx
+=
1
inner_oidx
+=
0
outer_oidx
+=
0
# With the global mapping inferred, the individual mappings
# can be produced
mappings
=
{
"outer_inp_from_outer_out"
:
{},
"inner_inp_from_outer_out"
:
{},
"inner_out_from_outer_out"
:
{},
"inner_inp_from_outer_inp"
:
{},
"inner_out_from_outer_inp"
:
{},
"outer_out_from_outer_inp"
:
{},
"outer_inp_from_inner_inp"
:
{},
"inner_out_from_inner_inp"
:
{},
"outer_out_from_inner_inp"
:
{},
"outer_inp_from_inner_out"
:
{},
"inner_inp_from_inner_out"
:
{},
"outer_out_from_inner_out"
:
{}}
for
(
oinp
,
iinp
,
iout
,
oout
)
in
zip
(
outer_input_indices
,
inner_input_indices
,
inner_output_indices
,
outer_output_indices
):
if
oout
!=
-
1
:
mappings
[
"outer_inp_from_outer_out"
][
oout
]
=
oinp
mappings
[
"inner_inp_from_outer_out"
][
oout
]
=
iinp
mappings
[
"inner_out_from_outer_out"
][
oout
]
=
iout
if
oinp
!=
-
1
:
mappings
[
"inner_inp_from_outer_inp"
][
oinp
]
=
iinp
mappings
[
"inner_out_from_outer_inp"
][
oinp
]
=
iout
mappings
[
"outer_out_from_outer_inp"
][
oinp
]
=
oout
for
idx
in
iinp
:
mappings
[
"outer_inp_from_inner_inp"
][
idx
]
=
oinp
mappings
[
"inner_out_from_inner_inp"
][
idx
]
=
iout
mappings
[
"outer_out_from_inner_inp"
][
idx
]
=
oout
for
idx
in
iout
:
mappings
[
"outer_inp_from_inner_out"
][
idx
]
=
oinp
mappings
[
"inner_inp_from_inner_out"
][
idx
]
=
iinp
mappings
[
"outer_out_from_inner_out"
][
idx
]
=
oout
return
mappings
def
get_inner_oidx_from_outer_oidx
(
self
,
outer_oidx
):
"""Given the index of an outer output, return the indices of the
corresponding inner output(s) in a sequence.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论