Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
07f12948
提交
07f12948
authored
12月 29, 2011
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
better naming convention
上级
b86abee4
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
35 行删除
+34
-35
scan.py
theano/sandbox/scan_module/scan.py
+0
-0
scan_utils.py
theano/sandbox/scan_module/scan_utils.py
+34
-35
没有找到文件。
theano/sandbox/scan_module/scan.py
浏览文件 @
07f12948
差异被折叠。
点击展开。
theano/sandbox/scan_module/scan_utils.py
浏览文件 @
07f12948
...
...
@@ -183,20 +183,19 @@ def canonical_arguments(sequences,
and that the different fields of of a dictionary are set to default
value if the user has not provided any.
"""
us
=
to_list
(
sequences
)
xys_info
=
to_list
(
outputs_info
)
ws
=
[
tensor
.
as_tensor_variable
(
x
)
for
x
in
to_list
(
non_sequences
)]
states_info
=
to_list
(
outputs_info
)
parameters
=
[
tensor
.
as_tensor_variable
(
x
)
for
x
in
to_list
(
non_sequences
)]
u
s
=
[]
for
u
in
to_list
(
sequences
):
input
s
=
[]
for
input
in
to_list
(
sequences
):
if
not
isinstance
(
u
,
dict
):
us
.
append
(
u
)
elif
u
.
get
(
'taps'
,
True
)
is
None
:
us
.
append
(
u
)
elif
u
.
get
(
'taps'
,
None
):
mintap
=
numpy
.
min
(
u
[
'taps'
])
maxtap
=
numpy
.
max
(
u
[
'taps'
])
for
k
in
u
[
'taps'
]:
inputs
.
append
(
input
)
elif
input
.
get
(
'taps'
,
True
)
is
None
:
inputs
.
append
(
input
)
elif
input
.
get
(
'taps'
,
None
):
mintap
=
numpy
.
min
(
input
[
'taps'
])
maxtap
=
numpy
.
max
(
input
[
'taps'
])
for
k
in
input
[
'taps'
]:
# We cut the sequence such that seq[i] to correspond to
# seq[i-k]
if
maxtap
<
0
:
...
...
@@ -204,57 +203,57 @@ def canonical_arguments(sequences,
else
:
offset
=
0
if
maxtap
==
mintap
and
maxtap
!=
0
:
nw_
u
=
u
[
'input'
][:
abs
(
maxtap
)]
nw_
input
=
input
[
'input'
][:
abs
(
maxtap
)]
elif
maxtap
-
k
!=
0
:
nw_
u
=
u
[
'input'
][
offset
+
k
-
mintap
:
-
(
maxtap
-
k
)]
nw_
input
=
input
[
'input'
][
offset
+
k
-
mintap
:
-
(
maxtap
-
k
)]
else
:
nw_
u
=
u
[
'input'
][
offset
+
k
-
mintap
:]
nw_
input
=
input
[
'input'
][
offset
+
k
-
mintap
:]
if
go_backwards
:
nw_
u
=
nw_u
[::
-
1
]
us
.
append
(
nw_u
)
nw_
input
=
nw_input
[::
-
1
]
inputs
.
append
(
nw_input
)
else
:
raise
ValueError
(
'Provided sequence makes no sense'
,
str
(
u
))
raise
ValueError
(
'Provided sequence makes no sense'
,
str
(
input
))
# Since we've added all sequences now we need to level them up based on
# n_steps or their different shapes
if
n_steps
is
None
:
if
len
(
u
s
)
==
0
:
if
len
(
input
s
)
==
0
:
# No information about the number of steps
raise
ValueError
(
'You need to provide either at least '
'one sequence over which scan should loop '
'or a number of steps for scan to loop. '
'Neither of the two had been provided !'
)
T
=
u
s
[
0
]
.
shape
[
0
]
for
u
in
u
s
[
1
:]:
T
=
tensor
.
minimum
(
T
,
u
.
shape
[
0
])
T
=
input
s
[
0
]
.
shape
[
0
]
for
input
in
input
s
[
1
:]:
T
=
tensor
.
minimum
(
T
,
input
.
shape
[
0
])
else
:
T
=
tensor
.
as_tensor
(
n_steps
)
# Level up sequences
us
=
[
u
[:
T
]
for
u
in
u
s
]
inputs
=
[
input
[:
T
]
for
input
in
input
s
]
# wrap outputs info in a dictionary if they are not already in one
for
i
,
xy
in
enumerate
(
xy
s_info
):
if
xy
is
not
None
and
not
isinstance
(
xy
,
dict
):
xys_info
[
i
]
=
dict
(
initial
=
xy
,
taps
=
[
-
1
])
elif
isinstance
(
xy
,
dict
):
if
not
xy
.
get
(
'initial'
,
None
)
and
xy
.
get
(
'taps'
,
None
):
for
i
,
state
in
enumerate
(
state
s_info
):
if
state
is
not
None
and
not
isinstance
(
state
,
dict
):
states_info
[
i
]
=
dict
(
initial
=
state
,
taps
=
[
-
1
])
elif
isinstance
(
state
,
dict
):
if
not
state
.
get
(
'initial'
,
None
)
and
state
.
get
(
'taps'
,
None
):
raise
ValueError
((
'If you are using slices of an output '
'you need to provide a initial state '
'for it'
),
xy
)
elif
xy
.
get
(
'initial'
,
None
)
and
not
xy
.
get
(
'taps'
,
None
):
'for it'
),
state
)
elif
state
.
get
(
'initial'
,
None
)
and
not
state
.
get
(
'taps'
,
None
):
# ^ initial state but taps not provided
if
'taps'
in
xy
:
if
'taps'
in
state
:
# ^ explicitly provided a None for taps
_logger
.
warning
(
'Output
%
s ( index
%
d) has a initial '
'state but taps is explicitly set to None '
,
getattr
(
out
s_info
[
i
][
'initial'
],
'name'
,
'None'
),
getattr
(
state
s_info
[
i
][
'initial'
],
'name'
,
'None'
),
i
)
xy
s_info
[
i
][
'taps'
]
=
[
-
1
]
state
s_info
[
i
][
'taps'
]
=
[
-
1
]
else
:
# if a None is provided as the output info we replace it
# with an empty dict() to simplify handling
xy
s_info
[
i
]
=
dict
()
return
seqs
,
outs_info
,
non_seqs
,
actual_n_steps
state
s_info
[
i
]
=
dict
()
return
inputs
,
staess_info
,
parameters
,
T
def
infer_shape
(
outs
,
inputs
,
input_shapes
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论