Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5db98be1
提交
5db98be1
authored
5月 24, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
5月 25, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Lift broadcast-only DimShuffles through RandomVariable Ops
上级
a95c3f85
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
35 行增加
和
8 行删除
+35
-8
opt.py
aesara/tensor/random/opt.py
+13
-8
test_opt.py
tests/tensor/random/test_opt.py
+22
-0
没有找到文件。
aesara/tensor/random/opt.py
浏览文件 @
5db98be1
...
@@ -146,11 +146,11 @@ def local_dimshuffle_rv_lift(fgraph, node):
...
@@ -146,11 +146,11 @@ def local_dimshuffle_rv_lift(fgraph, node):
ds_reps_new_dims
=
dim_orders
[:
reps_ind_split_idx
]
ds_reps_new_dims
=
dim_orders
[:
reps_ind_split_idx
]
ds_ind_new_dims
=
dim_orders
[
reps_ind_split_idx
:]
ds_ind_new_dims
=
dim_orders
[
reps_ind_split_idx
:]
ds_
only_in_ind
=
ds_ind_new_dims
and
all
(
ds_
in_ind_space
=
ds_ind_new_dims
and
all
(
d
>=
reps_ind_split_idx
for
n
,
d
in
ds_ind_new_dims
d
>=
reps_ind_split_idx
for
n
,
d
in
ds_ind_new_dims
)
)
if
ds_
only_in_ind
:
if
ds_
in_ind_space
or
(
not
ds_ind_new_dims
and
not
ds_reps_new_dims
)
:
# Update the `size` array to reflect the `DimShuffle`d dimensions,
# Update the `size` array to reflect the `DimShuffle`d dimensions,
# since the trailing dimensions in `size` represent the independent
# since the trailing dimensions in `size` represent the independent
...
@@ -163,10 +163,15 @@ def local_dimshuffle_rv_lift(fgraph, node):
...
@@ -163,10 +163,15 @@ def local_dimshuffle_rv_lift(fgraph, node):
# Compute the new axes parameter(s) for the `DimShuffle` that will be
# Compute the new axes parameter(s) for the `DimShuffle` that will be
# applied to the `RandomVariable` parameters (they need to be offset)
# applied to the `RandomVariable` parameters (they need to be offset)
rv_params_new_order
=
[
if
ds_ind_new_dims
:
d
-
reps_ind_split_idx
if
isinstance
(
d
,
int
)
else
d
rv_params_new_order
=
[
for
d
in
ds_new_order
[
ds_ind_new_dims
[
0
][
0
]
:]
d
-
reps_ind_split_idx
if
isinstance
(
d
,
int
)
else
d
]
for
d
in
ds_new_order
[
ds_ind_new_dims
[
0
][
0
]
:]
]
else
:
# This case is reached when, for example, `ds_new_order` only
# consists of new broadcastable dimensions (i.e. `"x"`s)
rv_params_new_order
=
ds_new_order
# Lift the `DimShuffle`s into the parameters
# Lift the `DimShuffle`s into the parameters
# NOTE: The parameters might not be broadcasted against each other, so
# NOTE: The parameters might not be broadcasted against each other, so
...
@@ -192,11 +197,11 @@ def local_dimshuffle_rv_lift(fgraph, node):
...
@@ -192,11 +197,11 @@ def local_dimshuffle_rv_lift(fgraph, node):
return
[
new_node
.
outputs
[
1
]]
return
[
new_node
.
outputs
[
1
]]
ds_
only_in_reps
=
ds_reps_new_dims
and
all
(
ds_
in_reps_space
=
ds_reps_new_dims
and
all
(
d
<
reps_ind_split_idx
for
n
,
d
in
ds_reps_new_dims
d
<
reps_ind_split_idx
for
n
,
d
in
ds_reps_new_dims
)
)
if
ds_
only_in_reps
:
if
ds_
in_reps_space
:
# Update the `size` array to reflect the `DimShuffle`d dimensions.
# Update the `size` array to reflect the `DimShuffle`d dimensions.
# There should be no need to `DimShuffle` now.
# There should be no need to `DimShuffle` now.
new_size
=
[
new_size
=
[
...
...
tests/tensor/random/test_opt.py
浏览文件 @
5db98be1
...
@@ -134,6 +134,28 @@ def test_lift_rv_shapes():
...
@@ -134,6 +134,28 @@ def test_lift_rv_shapes():
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
"ds_order, lifted, dist_op, dist_params, size, rtol"
,
"ds_order, lifted, dist_op, dist_params, size, rtol"
,
[
[
(
(
"x"
,),
True
,
normal
,
(
np
.
array
(
-
10.0
,
dtype
=
np
.
float64
),
np
.
array
(
1e-6
,
dtype
=
np
.
float64
),
),
(),
1e-7
,
),
(
(
"x"
,
"x"
,
"x"
),
True
,
normal
,
(
np
.
array
(
-
10.0
,
dtype
=
np
.
float64
),
np
.
array
(
1e-6
,
dtype
=
np
.
float64
),
),
(),
1e-7
,
),
(
(
(
1
,
0
,
2
),
(
1
,
0
,
2
),
True
,
True
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论