Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e73258b4
提交
e73258b4
authored
10月 31, 2024
作者:
ricardoV94
提交者:
Ricardo Vieira
11月 01, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug in `local_reduce_join` rewrite.
The helper `apply_local_dimshuffle_lift` requires a FunctionGraph when elemwise inputs are involved.
上级
e934ac7c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
1 行删除
+20
-1
math.py
pytensor/tensor/rewriting/math.py
+1
-1
test_math.py
tests/tensor/rewriting/test_math.py
+19
-0
没有找到文件。
pytensor/tensor/rewriting/math.py
浏览文件 @
e73258b4
...
@@ -1620,7 +1620,7 @@ def local_reduce_join(fgraph, node):
...
@@ -1620,7 +1620,7 @@ def local_reduce_join(fgraph, node):
if
not
inp
.
type
.
broadcastable
[
join_axis
]:
if
not
inp
.
type
.
broadcastable
[
join_axis
]:
return
None
return
None
# Most times inputs to join have an expand_dims, we eagerly clean up those here
# Most times inputs to join have an expand_dims, we eagerly clean up those here
new_input
=
apply_local_dimshuffle_lift
(
None
,
inp
.
squeeze
(
join_axis
))
new_input
=
apply_local_dimshuffle_lift
(
fgraph
,
inp
.
squeeze
(
join_axis
))
new_inputs
.
append
(
new_input
)
new_inputs
.
append
(
new_input
)
ret
=
Elemwise
(
node
.
op
.
scalar_op
)(
*
new_inputs
)
ret
=
Elemwise
(
node
.
op
.
scalar_op
)(
*
new_inputs
)
...
...
tests/tensor/rewriting/test_math.py
浏览文件 @
e73258b4
...
@@ -103,6 +103,7 @@ from pytensor.tensor.rewriting.math import (
...
@@ -103,6 +103,7 @@ from pytensor.tensor.rewriting.math import (
local_mul_canonizer
,
local_mul_canonizer
,
local_mul_switch_sink
,
local_mul_switch_sink
,
local_reduce_chain
,
local_reduce_chain
,
local_reduce_join
,
local_sum_prod_of_mul_or_div
,
local_sum_prod_of_mul_or_div
,
mul_canonizer
,
mul_canonizer
,
parse_mul_tree
,
parse_mul_tree
,
...
@@ -3415,6 +3416,24 @@ class TestReduceJoin:
...
@@ -3415,6 +3416,24 @@ class TestReduceJoin:
f
(
x
,
y
),
np
.
sum
(
np
.
concatenate
([
x
,
y
],
axis
=
0
),
axis
=
0
)
f
(
x
,
y
),
np
.
sum
(
np
.
concatenate
([
x
,
y
],
axis
=
0
),
axis
=
0
)
)
)
def
test_non_ds_inputs
(
self
):
"""Make sure rewrite works when inputs to join are not the usual DimShuffle.
Sum{axis=1} [id A] <Vector(float64, shape=(3,))>
└─ Join [id B] <Matrix(float64, shape=(3, 3))>
├─ 1 [id C] <Scalar(int8, shape=())>
├─ ExpandDims{axis=1} [id D] <Matrix(float64, shape=(3, 1))>
├─ Sub [id E] <Matrix(float64, shape=(3, 1))>
└─ Sub [id F] <Matrix(float64, shape=(3, 1))>
"""
x
=
vector
(
"x"
)
out
=
join
(
0
,
exp
(
x
[
None
]),
log
(
x
[
None
]))
.
sum
(
axis
=
0
)
fg
=
FunctionGraph
([
x
],
[
out
],
clone
=
False
)
[
rewritten_out
]
=
local_reduce_join
.
transform
(
fg
,
out
.
owner
)
expected_out
=
add
(
exp
(
x
),
log
(
x
))
assert
equal_computations
([
rewritten_out
],
[
expected_out
])
def
test_local_useless_adds
():
def
test_local_useless_adds
():
default_mode
=
get_default_mode
()
default_mode
=
get_default_mode
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论