Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4258ebb1
提交
4258ebb1
authored
11月 13, 2014
作者:
Pierre Luc Carrier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support case where vector input is already an output of scan
上级
56d71501
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
32 行增加
和
19 行删除
+32
-19
scan_opt.py
theano/scan_module/scan_opt.py
+32
-19
没有找到文件。
theano/scan_module/scan_opt.py
浏览文件 @
4258ebb1
...
@@ -612,6 +612,11 @@ class PushOutScanOutput(gof.Optimizer):
...
@@ -612,6 +612,11 @@ class PushOutScanOutput(gof.Optimizer):
op
=
node
.
op
op
=
node
.
op
# Use scan_args to parse the inputs and outputs of scan for ease of
# use
args
=
scan_args
(
node
.
inputs
,
node
.
outputs
,
node
.
op
.
inputs
,
node
.
op
.
outputs
,
node
.
op
.
info
)
# Obtain the list containing the indices, in clean_outputs, of the
# Obtain the list containing the indices, in clean_outputs, of the
# scan op's outputs that are nit_sot (not fed back to the inner fct.)
# scan op's outputs that are nit_sot (not fed back to the inner fct.)
nitsot_outs
=
op
.
inner_nitsot_outs
(
node
.
outputs
)
nitsot_outs
=
op
.
inner_nitsot_outs
(
node
.
outputs
)
...
@@ -678,8 +683,7 @@ class PushOutScanOutput(gof.Optimizer):
...
@@ -678,8 +683,7 @@ class PushOutScanOutput(gof.Optimizer):
(
nd
.
inputs
[
0
]
in
inner_non_seqs
or
(
nd
.
inputs
[
0
]
in
inner_non_seqs
or
isinstance
(
nd
.
inputs
[
0
],
tensor
.
Constant
))
and
isinstance
(
nd
.
inputs
[
0
],
tensor
.
Constant
))
and
nd
.
inputs
[
1
]
.
ndim
==
1
and
nd
.
inputs
[
1
]
.
ndim
==
1
and
nd
.
inputs
[
1
]
not
in
clean_inputs
and
nd
.
inputs
[
1
]
not
in
clean_inputs
):
nd
.
inputs
[
1
]
not
in
clean_outputs
):
valid_inputs
=
True
valid_inputs
=
True
idx_matrix_input
=
0
idx_matrix_input
=
0
...
@@ -689,8 +693,7 @@ class PushOutScanOutput(gof.Optimizer):
...
@@ -689,8 +693,7 @@ class PushOutScanOutput(gof.Optimizer):
(
nd
.
inputs
[
1
]
in
inner_non_seqs
or
(
nd
.
inputs
[
1
]
in
inner_non_seqs
or
isinstance
(
nd
.
inputs
[
1
],
tensor
.
Constant
))
and
isinstance
(
nd
.
inputs
[
1
],
tensor
.
Constant
))
and
nd
.
inputs
[
0
]
.
ndim
==
1
and
nd
.
inputs
[
0
]
.
ndim
==
1
and
nd
.
inputs
[
0
]
not
in
clean_inputs
and
nd
.
inputs
[
0
]
not
in
clean_inputs
):
nd
.
inputs
[
0
]
not
in
clean_outputs
):
valid_inputs
=
True
valid_inputs
=
True
idx_matrix_input
=
1
idx_matrix_input
=
1
...
@@ -717,34 +720,44 @@ class PushOutScanOutput(gof.Optimizer):
...
@@ -717,34 +720,44 @@ class PushOutScanOutput(gof.Optimizer):
'this on theano-users list'
),
'this on theano-users list'
),
inner_matrix_input
)
inner_matrix_input
)
# Add the new outputs to the scan (get as output the variables of
# If the vector_input is already a nit_sot output of the
# the outer graph corresponding to the new scan outputs
# scan, get a reference to the corresponding outer output.
new_output_inner
=
nd
.
inputs
[
idx_vector_input
]
# Otherwise, add it as a new nit_sot output and then get a
_new_scan_node
,
idx_old_outputs
,
idx_new_output
=
self
.
add_nitsot_outputs
(
# reference to it
fgraph
,
node
,
if
nd
.
inputs
[
idx_vector_input
]
in
nitsot_outs
:
clean_inputs
,
# Figure out which scan output corresponds the vector
clean_outputs
,
# input
new_output_inner
)
inner_vector_input
=
nd
.
inputs
[
idx_vector_input
]
new_outer_output
=
_new_scan_node
.
outputs
[
idx_new_output
]
vector_input_nitsot_idx
=
args
.
inner_out_nit_sot
.
index
(
inner_vector_input
)
outer_vector_input
=
args
.
outer_out_nit_sot
[
vector_input_nitsot_idx
]
# Perform the Dot on the new scan output.
else
:
# Add the vector_input as a new nitsot output to scan
new_output_inner
=
nd
.
inputs
[
idx_vector_input
]
new_scan_node
,
idx_old_outputs
,
idx_new_output
=
self
.
add_nitsot_outputs
(
fgraph
,
node
,
clean_inputs
,
clean_outputs
,
new_output_inner
)
outer_vector_input
=
new_scan_node
.
outputs
[
idx_new_output
]
# Perform the Dot outside of scan
if
idx_matrix_input
==
0
:
if
idx_matrix_input
==
0
:
outer_dot_inputs
=
[
outer_matrix_input
,
outer_dot_inputs
=
[
outer_matrix_input
,
new_outer_out
put
.
transpose
()]
outer_vector_in
put
.
transpose
()]
outer_dot_output
=
theano
.
tensor
.
dot
(
*
outer_dot_inputs
)
.
transpose
()
outer_dot_output
=
theano
.
tensor
.
dot
(
*
outer_dot_inputs
)
.
transpose
()
else
:
# idx_matrix_input == 1
else
:
# idx_matrix_input == 1
outer_dot_inputs
=
[
new_outer_out
put
,
outer_dot_inputs
=
[
outer_vector_in
put
,
outer_matrix_input
]
outer_matrix_input
]
outer_dot_output
=
theano
.
tensor
.
dot
(
*
outer_dot_inputs
)
outer_dot_output
=
theano
.
tensor
.
dot
(
*
outer_dot_inputs
)
# Modify the outer graph to add the outer Dot
# Modify the outer graph to add the outer Dot
new_idx_dot_output
=
idx_old_outputs
[
idx_dot_output
]
new_idx_dot_output
=
idx_old_outputs
[
idx_dot_output
]
fgraph
.
replace_all
([
fgraph
.
replace_all
([
(
_
new_scan_node
.
outputs
[
new_idx_dot_output
],
(
new_scan_node
.
outputs
[
new_idx_dot_output
],
outer_dot_output
)],
outer_dot_output
)],
reason
=
"scanOp_pushout_output"
)
reason
=
"scanOp_pushout_output"
)
new_scan_node
=
_new_scan_node
break
break
return
new_scan_node
return
new_scan_node
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论