Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
117b40c9
提交
117b40c9
authored
10月 29, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
11月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a test for a shape inference issue between Scan and RandomVariable
上级
3d4ef668
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
73 行增加
和
0 行删除
+73
-0
test_basic.py
tests/scan/test_basic.py
+73
-0
没有找到文件。
tests/scan/test_basic.py
浏览文件 @
117b40c9
...
...
@@ -5036,3 +5036,76 @@ def test_mintap_onestep():
_seq
=
np
.
arange
(
20
)
.
astype
(
"int32"
)
_sum
=
f
(
_seq
)
assert
_sum
==
2
def
test_inner_get_vector_length
():
"""Make sure we can handle/preserve fixed shape terms when cloning the body of a `Scan`."""
rng_at
=
RandomStream
()
s1
=
lscalar
(
"s1"
)
s2
=
lscalar
(
"s2"
)
size_at
=
aet
.
as_tensor
([
s1
,
s2
])
def
scan_body
(
size
):
# `size` will be cloned and replaced with an ownerless `TensorVariable`.
# This will cause `RandomVariable.infer_shape` to fail, because it expects
# `get_vector_length` to work on all `size` arguments.
return
rng_at
.
normal
(
0
,
1
,
size
=
size
)
res
,
_
=
scan
(
scan_body
,
non_sequences
=
[
size_at
],
n_steps
=
10
,
strict
=
True
,
)
assert
isinstance
(
res
.
owner
.
op
,
Scan
)
# Make sure the `size` in `scan_body` is a plain `Variable` instance
# carrying no information with which we can derive its length
size_clone
=
res
.
owner
.
op
.
inputs
[
1
]
assert
size_clone
.
owner
is
None
# Make sure the cloned `size` maps to the original `size_at`
inner_outer_map
=
res
.
owner
.
op
.
get_oinp_iinp_iout_oout_mappings
()
outer_input_idx
=
inner_outer_map
[
"outer_inp_from_inner_inp"
][
1
]
original_size
=
res
.
owner
.
inputs
[
outer_input_idx
]
assert
original_size
==
size_at
with
config
.
change_flags
(
on_opt_error
=
"raise"
,
on_shape_error
=
"raise"
):
res_fn
=
function
([
size_at
],
res
.
shape
)
assert
np
.
array_equal
(
res_fn
((
1
,
2
)),
(
10
,
1
,
2
))
# Second case has an empty size non-sequence
size_at
=
aet
.
as_tensor
([],
dtype
=
np
.
int64
)
res
,
_
=
scan
(
scan_body
,
non_sequences
=
[
size_at
],
n_steps
=
10
,
strict
=
True
,
)
assert
isinstance
(
res
.
owner
.
op
,
Scan
)
with
config
.
change_flags
(
on_opt_error
=
"raise"
,
on_shape_error
=
"raise"
):
res_fn
=
function
([],
res
.
shape
)
assert
np
.
array_equal
(
res_fn
(),
(
10
,))
# Third case has a constant size non-sequence
size_at
=
aet
.
as_tensor
([
3
],
dtype
=
np
.
int64
)
res
,
_
=
scan
(
scan_body
,
non_sequences
=
[
size_at
],
n_steps
=
10
,
strict
=
True
,
)
assert
isinstance
(
res
.
owner
.
op
,
Scan
)
with
config
.
change_flags
(
on_opt_error
=
"raise"
,
on_shape_error
=
"raise"
):
res_fn
=
function
([],
res
.
shape
)
assert
np
.
array_equal
(
res_fn
(),
(
10
,
3
))
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论