Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fd8323fe
提交
fd8323fe
authored
4月 17, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
4月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove use of OrderedDict in aesara.scan.basic
上级
c70ef127
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
20 行增加
和
21 行删除
+20
-21
basic.py
aesara/scan/basic.py
+20
-21
没有找到文件。
aesara/scan/basic.py
浏览文件 @
fd8323fe
import
logging
import
logging
from
collections
import
OrderedDict
import
numpy
as
np
import
numpy
as
np
...
@@ -351,11 +350,11 @@ def scan(
...
@@ -351,11 +350,11 @@ def scan(
n_seqs
=
len
(
seqs
)
n_seqs
=
len
(
seqs
)
n_outs
=
len
(
outs_info
)
n_outs
=
len
(
outs_info
)
return_steps
=
OrderedDict
()
return_steps
=
{}
# wrap sequences in a dictionary if they are not already dictionaries
# wrap sequences in a dictionary if they are not already dictionaries
for
i
in
range
(
n_seqs
):
for
i
in
range
(
n_seqs
):
if
not
isinstance
(
seqs
[
i
],
dict
):
if
not
isinstance
(
seqs
[
i
],
dict
):
seqs
[
i
]
=
OrderedD
ict
([(
"input"
,
seqs
[
i
]),
(
"taps"
,
[
0
])])
seqs
[
i
]
=
d
ict
([(
"input"
,
seqs
[
i
]),
(
"taps"
,
[
0
])])
elif
seqs
[
i
]
.
get
(
"taps"
,
None
)
is
not
None
:
elif
seqs
[
i
]
.
get
(
"taps"
,
None
)
is
not
None
:
seqs
[
i
][
"taps"
]
=
wrap_into_list
(
seqs
[
i
][
"taps"
])
seqs
[
i
][
"taps"
]
=
wrap_into_list
(
seqs
[
i
][
"taps"
])
elif
seqs
[
i
]
.
get
(
"taps"
,
None
)
is
None
:
elif
seqs
[
i
]
.
get
(
"taps"
,
None
)
is
None
:
...
@@ -377,7 +376,7 @@ def scan(
...
@@ -377,7 +376,7 @@ def scan(
if
not
isinstance
(
outs_info
[
i
],
dict
):
if
not
isinstance
(
outs_info
[
i
],
dict
):
# by default any output has a tap value of -1
# by default any output has a tap value of -1
outs_info
[
i
]
=
OrderedD
ict
([(
"initial"
,
outs_info
[
i
]),
(
"taps"
,
[
-
1
])])
outs_info
[
i
]
=
d
ict
([(
"initial"
,
outs_info
[
i
]),
(
"taps"
,
[
-
1
])])
elif
(
elif
(
outs_info
[
i
]
.
get
(
"initial"
,
None
)
is
None
outs_info
[
i
]
.
get
(
"initial"
,
None
)
is
None
and
outs_info
[
i
]
.
get
(
"taps"
,
None
)
is
not
None
and
outs_info
[
i
]
.
get
(
"taps"
,
None
)
is
not
None
...
@@ -417,7 +416,7 @@ def scan(
...
@@ -417,7 +416,7 @@ def scan(
else
:
else
:
# if a None is provided as the output info we replace it
# if a None is provided as the output info we replace it
# with an empty OrdereDict() to simplify handling
# with an empty OrdereDict() to simplify handling
outs_info
[
i
]
=
OrderedDict
()
outs_info
[
i
]
=
{}
##
##
# Step 2. Generate inputs and outputs of the inner functions
# Step 2. Generate inputs and outputs of the inner functions
...
@@ -564,7 +563,7 @@ def scan(
...
@@ -564,7 +563,7 @@ def scan(
mit_sot_inner_inputs
=
[]
mit_sot_inner_inputs
=
[]
mit_sot_inner_slices
=
[]
mit_sot_inner_slices
=
[]
mit_sot_inner_outputs
=
[]
mit_sot_inner_outputs
=
[]
mit_sot_return_steps
=
OrderedDict
()
mit_sot_return_steps
=
{}
mit_sot_tap_array
=
[]
mit_sot_tap_array
=
[]
mit_sot_rightOrder
=
[]
mit_sot_rightOrder
=
[]
...
@@ -573,7 +572,7 @@ def scan(
...
@@ -573,7 +572,7 @@ def scan(
sit_sot_inner_inputs
=
[]
sit_sot_inner_inputs
=
[]
sit_sot_inner_slices
=
[]
sit_sot_inner_slices
=
[]
sit_sot_inner_outputs
=
[]
sit_sot_inner_outputs
=
[]
sit_sot_return_steps
=
OrderedDict
()
sit_sot_return_steps
=
{}
sit_sot_rightOrder
=
[]
sit_sot_rightOrder
=
[]
# go through outputs picking up time slices as needed
# go through outputs picking up time slices as needed
...
@@ -764,9 +763,7 @@ def scan(
...
@@ -764,9 +763,7 @@ def scan(
if
condition
is
not
None
:
if
condition
is
not
None
:
outputs
.
append
(
condition
)
outputs
.
append
(
condition
)
fake_nonseqs
=
[
x
.
type
()
for
x
in
non_seqs
]
fake_nonseqs
=
[
x
.
type
()
for
x
in
non_seqs
]
fake_outputs
=
clone_replace
(
fake_outputs
=
clone_replace
(
outputs
,
replace
=
dict
(
zip
(
non_seqs
,
fake_nonseqs
)))
outputs
,
replace
=
OrderedDict
(
zip
(
non_seqs
,
fake_nonseqs
))
)
all_inputs
=
filter
(
all_inputs
=
filter
(
lambda
x
:
(
lambda
x
:
(
isinstance
(
x
,
Variable
)
isinstance
(
x
,
Variable
)
...
@@ -820,7 +817,7 @@ def scan(
...
@@ -820,7 +817,7 @@ def scan(
n_outs
=
len
(
dummy_outputs
)
n_outs
=
len
(
dummy_outputs
)
if
as_while
:
if
as_while
:
n_outs
=
n_outs
-
1
n_outs
=
n_outs
-
1
outs_info
=
[
OrderedDict
()
for
x
in
range
(
n_outs
)]
outs_info
=
[
{}
for
x
in
range
(
n_outs
)]
# Step 5.1 Outputs with taps different then -1
# Step 5.1 Outputs with taps different then -1
...
@@ -834,7 +831,7 @@ def scan(
...
@@ -834,7 +831,7 @@ def scan(
sit_sot_inner_outputs
.
append
(
outputs
[
i
])
sit_sot_inner_outputs
.
append
(
outputs
[
i
])
# Step 5.3 Outputs that correspond to update rules of shared variables
# Step 5.3 Outputs that correspond to update rules of shared variables
givens
=
OrderedDict
()
inner_replacements
=
{}
n_shared_outs
=
0
n_shared_outs
=
0
shared_scan_inputs
=
[]
shared_scan_inputs
=
[]
shared_inner_inputs
=
[]
shared_inner_inputs
=
[]
...
@@ -843,8 +840,10 @@ def scan(
...
@@ -843,8 +840,10 @@ def scan(
for
input
in
dummy_inputs
:
for
input
in
dummy_inputs
:
if
isinstance
(
input
.
variable
,
SharedVariable
)
and
input
.
update
:
if
isinstance
(
input
.
variable
,
SharedVariable
)
and
input
.
update
:
new_var
=
safe_new
(
input
.
variable
)
new_var
=
safe_new
(
input
.
variable
)
if
getattr
(
input
.
variable
,
"name"
,
None
)
is
not
None
:
if
getattr
(
input
.
variable
,
"name"
,
None
)
is
not
None
:
new_var
.
name
=
input
.
variable
.
name
+
"_copy"
new_var
.
name
=
input
.
variable
.
name
+
"_copy"
if
isinstance
(
new_var
.
type
,
TensorType
):
if
isinstance
(
new_var
.
type
,
TensorType
):
sit_sot_inner_inputs
.
append
(
new_var
)
sit_sot_inner_inputs
.
append
(
new_var
)
sit_sot_scan_inputs
.
append
(
sit_sot_scan_inputs
.
append
(
...
@@ -864,13 +863,13 @@ def scan(
...
@@ -864,13 +863,13 @@ def scan(
# refers to the update rule with index `-1 - pos`.
# refers to the update rule with index `-1 - pos`.
sit_sot_rightOrder
.
append
(
-
1
-
len
(
sit_sot_shared
))
sit_sot_rightOrder
.
append
(
-
1
-
len
(
sit_sot_shared
))
sit_sot_shared
.
append
(
input
.
variable
)
sit_sot_shared
.
append
(
input
.
variable
)
given
s
[
input
.
variable
]
=
new_var
inner_replacement
s
[
input
.
variable
]
=
new_var
else
:
else
:
shared_inner_inputs
.
append
(
new_var
)
shared_inner_inputs
.
append
(
new_var
)
shared_scan_inputs
.
append
(
input
.
variable
)
shared_scan_inputs
.
append
(
input
.
variable
)
shared_inner_outputs
.
append
(
input
.
update
)
shared_inner_outputs
.
append
(
input
.
update
)
given
s
[
input
.
variable
]
=
new_var
inner_replacement
s
[
input
.
variable
]
=
new_var
n_shared_outs
+=
1
n_shared_outs
+=
1
n_sit_sot
=
len
(
sit_sot_inner_inputs
)
n_sit_sot
=
len
(
sit_sot_inner_inputs
)
...
@@ -878,7 +877,7 @@ def scan(
...
@@ -878,7 +877,7 @@ def scan(
# Step 5.4 Outputs with no taps used in the input
# Step 5.4 Outputs with no taps used in the input
n_nit_sot
=
0
n_nit_sot
=
0
nit_sot_inner_outputs
=
[]
nit_sot_inner_outputs
=
[]
nit_sot_return_steps
=
OrderedDict
()
nit_sot_return_steps
=
{}
nit_sot_rightOrder
=
[]
nit_sot_rightOrder
=
[]
for
i
,
out
in
enumerate
(
outs_info
):
for
i
,
out
in
enumerate
(
outs_info
):
if
"taps"
not
in
out
:
if
"taps"
not
in
out
:
...
@@ -905,7 +904,7 @@ def scan(
...
@@ -905,7 +904,7 @@ def scan(
if
(
not
isinstance
(
arg
,
SharedVariable
)
and
not
isinstance
(
arg
,
Constant
))
if
(
not
isinstance
(
arg
,
SharedVariable
)
and
not
isinstance
(
arg
,
Constant
))
]
]
givens
.
update
(
OrderedD
ict
(
zip
(
other_scan_args
,
other_inner_args
)))
inner_replacements
.
update
(
d
ict
(
zip
(
other_scan_args
,
other_inner_args
)))
if
strict
:
if
strict
:
non_seqs_set
=
set
(
non_sequences
if
non_sequences
is
not
None
else
[])
non_seqs_set
=
set
(
non_sequences
if
non_sequences
is
not
None
else
[])
...
@@ -939,11 +938,13 @@ def scan(
...
@@ -939,11 +938,13 @@ def scan(
for
arg
in
dummy_inputs
for
arg
in
dummy_inputs
if
(
isinstance
(
arg
.
variable
,
SharedVariable
)
and
not
arg
.
update
)
if
(
isinstance
(
arg
.
variable
,
SharedVariable
)
and
not
arg
.
update
)
]
]
givens
.
update
(
OrderedDict
(
zip
(
other_shared_scan_args
,
other_shared_inner_args
)))
inner_replacements
.
update
(
dict
(
zip
(
other_shared_scan_args
,
other_shared_inner_args
))
)
##
##
# Step 6. Re-order the outputs and clone them replacing things
# Step 6. Re-order the outputs and clone them replacing things
# using
the givens
# using
`inner_replacements`
##
##
inner_inputs
=
(
inner_inputs
=
(
inner_seqs
inner_seqs
...
@@ -964,10 +965,8 @@ def scan(
...
@@ -964,10 +965,8 @@ def scan(
)
)
if
condition
is
not
None
:
if
condition
is
not
None
:
inner_outs
.
append
(
condition
)
inner_outs
.
append
(
condition
)
# NOTE: legacy code traversed GPU types
new_givens
=
givens
new_outs
=
clone_replace
(
inner_outs
,
replace
=
new_given
s
)
new_outs
=
clone_replace
(
inner_outs
,
replace
=
inner_replacement
s
)
##
##
# Step 7. Create the Scan Op
# Step 7. Create the Scan Op
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论