Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
54a85007
提交
54a85007
authored
1月 11, 2026
作者:
ricardoV94
提交者:
Jesse Grabowski
1月 11, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug in local_block_diag_dot_to_dot_block_diag
上级
ac6dc81b
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
4 行删除
+38
-4
math.py
pytensor/tensor/rewriting/math.py
+14
-4
test_math.py
tests/tensor/rewriting/test_math.py
+24
-0
没有找到文件。
pytensor/tensor/rewriting/math.py
浏览文件 @
54a85007
...
@@ -183,13 +183,23 @@ def local_block_diag_dot_to_dot_block_diag(fgraph, node):
...
@@ -183,13 +183,23 @@ def local_block_diag_dot_to_dot_block_diag(fgraph, node):
try
:
try
:
client_idx
=
client
.
inputs
.
index
(
blockdiag_result
)
client_idx
=
client
.
inputs
.
index
(
blockdiag_result
)
except
ValueError
:
except
ValueError
:
# If the blockdiag result is not an input to the dot, there is at least one Op between them
(usually a
# If the blockdiag result is not an input to the dot, there is at least one Op between them
.
#
DimShuffle). In this case, we need to figure out which of the inputs of the dot eventually leads to the
#
We allow left expand_dims (DimShuffle), which is introduced automatically by Blockwise to equalize number of batch dims,
#
blockdiag result.
#
But does not change the semantics of the graph
for
ancestor
in
client
.
inputs
:
for
ancestor
in
client
.
inputs
:
if
ancestor
.
owner
and
blockdiag_result
in
ancestor
.
owner
.
inputs
:
if
(
ancestor
.
owner
is
not
None
and
(
isinstance
(
ancestor
.
owner
.
op
,
DimShuffle
)
and
ancestor
.
owner
.
op
.
is_left_expand_dims
)
and
blockdiag_result
in
ancestor
.
owner
.
inputs
):
client_idx
=
client
.
inputs
.
index
(
ancestor
)
client_idx
=
client
.
inputs
.
index
(
ancestor
)
break
break
else
:
# no-break
# Not a simple left expand_dims between dot and block_diag
return
None
other_input
=
client
.
inputs
[
1
-
client_idx
]
other_input
=
client
.
inputs
[
1
-
client_idx
]
...
...
tests/tensor/rewriting/test_math.py
浏览文件 @
54a85007
...
@@ -148,6 +148,7 @@ from pytensor.tensor.type import (
...
@@ -148,6 +148,7 @@ from pytensor.tensor.type import (
)
)
from
pytensor.tensor.variable
import
TensorConstant
from
pytensor.tensor.variable
import
TensorConstant
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
tests.unittest_tools
import
assert_equal_computations
rewrite_mode
=
config
.
mode
rewrite_mode
=
config
.
mode
...
@@ -4944,6 +4945,29 @@ class TestBlockDiagDotToDotBlockDiag:
...
@@ -4944,6 +4945,29 @@ class TestBlockDiagDotToDotBlockDiag:
rtol
=
1e-6
if
config
.
floatX
==
"float32"
else
1e-12
,
rtol
=
1e-6
if
config
.
floatX
==
"float32"
else
1e-12
,
)
)
def
test_rewrite_does_not_apply
(
self
):
# Regression test for https://github.com/pymc-devs/pytensor/issues/1836
# Shapes match if either R is tranposed or y is, but not by default
y
=
pt
.
tensor
(
"y"
,
shape
=
(
7
,
9
))
R1
=
pt
.
tensor
(
"R1"
,
shape
=
(
2
,
3
))
R2
=
pt
.
tensor
(
"R2"
,
shape
=
(
5
,
6
))
R
=
pt
.
linalg
.
block_diag
(
R1
,
R2
)
# This could be rewritten in the future, if that's the case remove this condition
original
=
dot
(
R
.
mT
,
y
)
rewritten
=
rewrite_graph
(
original
,
include
=
(
"canonicalize"
,
"stabilize"
,
"specialize"
)
)
assert_equal_computations
([
rewritten
],
[
original
])
# This is unlikely to ever be rewritten
original
=
dot
(
R
.
exp
(),
y
.
mT
)
rewritten
=
rewrite_graph
(
original
,
include
=
(
"canonicalize"
,
"stabilize"
,
"specialize"
)
)
assert_equal_computations
([
rewritten
],
[
original
])
@pytest.mark.parametrize
(
"rewrite"
,
[
True
,
False
],
ids
=
[
"rewrite"
,
"no_rewrite"
])
@pytest.mark.parametrize
(
"rewrite"
,
[
True
,
False
],
ids
=
[
"rewrite"
,
"no_rewrite"
])
@pytest.mark.parametrize
(
"size"
,
[
10
,
100
,
1000
],
ids
=
[
"small"
,
"medium"
,
"large"
])
@pytest.mark.parametrize
(
"size"
,
[
10
,
100
,
1000
],
ids
=
[
"small"
,
"medium"
,
"large"
])
def
test_benchmark
(
self
,
benchmark
,
size
,
rewrite
):
def
test_benchmark
(
self
,
benchmark
,
size
,
rewrite
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论