Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
50c3fd00
提交
50c3fd00
authored
11月 13, 2015
作者:
carriepl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add equivalency between inner inputs and outer inputs for infer_shape
上级
79597a04
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
29 行增加
和
6 行删除
+29
-6
scan_op.py
theano/scan_module/scan_op.py
+29
-6
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
50c3fd00
...
@@ -1566,23 +1566,46 @@ class Scan(PureOp):
...
@@ -1566,23 +1566,46 @@ class Scan(PureOp):
# Infer Shape
# Infer Shape
def
infer_shape
(
self
,
node
,
input_shapes
):
def
infer_shape
(
self
,
node
,
input_shapes
):
# input_shapes correspond to the shapes of node.inputs
# input_shapes correspond to the shapes of node.inputs
# Here, we build a list inner_ins_shape, such that inner_ins_shape[i]
# is the shape of self.inputs[i]
for
inp
,
inp_shp
in
izip
(
node
.
inputs
,
input_shapes
):
for
inp
,
inp_shp
in
izip
(
node
.
inputs
,
input_shapes
):
assert
inp_shp
is
None
or
len
(
inp_shp
)
==
inp
.
type
.
ndim
assert
inp_shp
is
None
or
len
(
inp_shp
)
==
inp
.
type
.
ndim
# sequences
# Here we build 2 variables;
# We skip iputs_shapes[0] as it is the total or current number
# - A list `inner_ins_shapes`, such that inner_ins_shapes[i] is the
# shape of self.inputs[i]
# - A dictionary `out_equivalent` containing, for every inner input,
# an equivalent variable computed from the outer inputs.
# NOTE : For non-sequences, this equivalence is trivial. For
# sequences and recurrent states, there is no direct equivalence
# between outer and inner inputs. However, because every iteration
# of the Scan needs to give the same output shapes, we can give an
# equivalence between these inner inputs and the subelements of the
# corresponding outer inputs that the Scan would use as input for
# any given iteration. For simplicity, we use iteration 0.
inner_ins_shapes
=
[]
out_equivalent
=
OrderedDict
()
# We skip the first outer input as it is the total or current number
# of iterations.
# of iterations.
# sequences
seqs_shape
=
[
x
[
1
:]
for
x
in
input_shapes
[
1
:
1
+
self
.
n_seqs
]]
seqs_shape
=
[
x
[
1
:]
for
x
in
input_shapes
[
1
:
1
+
self
.
n_seqs
]]
inner_seqs
=
self
.
inputs
[:
self
.
n_seqs
]
outer_seqs
=
node
.
inputs
[
1
:
1
+
self
.
n_seqs
]
for
in_s
,
out_s
in
izip
(
inner_seqs
,
outer_seqs
):
out_equivalent
[
in_s
]
=
out_s
[
0
]
# mit_mot, mit_sot, sit_sot
# mit_mot, mit_sot, sit_sot
outer_inp_idx
=
1
+
self
.
n_seqs
inner_inp_idx
=
self
.
n_seqs
n_outs
=
self
.
n_mit_mot
+
self
.
n_mit_sot
+
self
.
n_sit_sot
n_outs
=
self
.
n_mit_mot
+
self
.
n_mit_sot
+
self
.
n_sit_sot
outs_shape
=
[]
outs_shape
=
[]
for
idx
in
xrange
(
n_outs
):
for
idx
in
xrange
(
n_outs
):
mintap
=
abs
(
min
(
self
.
tap_array
[
idx
]))
for
k
in
self
.
tap_array
[
idx
]:
for
k
in
self
.
tap_array
[
idx
]:
outs_shape
+=
[
input_shapes
[
idx
+
self
.
n_seqs
+
1
][
1
:]]
outs_shape
+=
[
input_shapes
[
idx
+
self
.
n_seqs
+
1
][
1
:]]
corresponding_tap
=
node
.
inputs
[
outer_inp_idx
][
mintap
+
k
]
out_equivalent
[
self
.
inputs
[
inner_inp_idx
]]
=
corresponding_tap
inner_inp_idx
+=
1
outer_inp_idx
+=
1
# shared_outs
# shared_outs
offset
=
1
+
self
.
n_seqs
+
n_outs
offset
=
1
+
self
.
n_seqs
+
n_outs
...
@@ -1597,9 +1620,9 @@ class Scan(PureOp):
...
@@ -1597,9 +1620,9 @@ class Scan(PureOp):
# Non-sequences have a direct equivalent from self.inputs in
# Non-sequences have a direct equivalent from self.inputs in
# node.inputs
# node.inputs
inner_non_sequences
=
self
.
inputs
[
len
(
seqs_shape
)
+
len
(
outs_shape
):]
inner_non_sequences
=
self
.
inputs
[
len
(
seqs_shape
)
+
len
(
outs_shape
):]
out_equivalent
=
OrderedDict
()
for
in_ns
,
out_ns
in
izip
(
inner_non_sequences
,
node
.
inputs
[
offset
:]):
for
in_ns
,
out_ns
in
izip
(
inner_non_sequences
,
node
.
inputs
[
offset
:]):
out_equivalent
[
in_ns
]
=
out_ns
out_equivalent
[
in_ns
]
=
out_ns
if
self
.
as_while
:
if
self
.
as_while
:
self_outs
=
self
.
outputs
[:
-
1
]
self_outs
=
self
.
outputs
[:
-
1
]
else
:
else
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论