Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
945e9799
提交
945e9799
authored
1月 08, 2026
作者:
jessegrabowski
提交者:
Ricardo Vieira
1月 08, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Respond to feedback
上级
2ea17e72
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
16 行增加
和
20 行删除
+16
-20
linalg.py
pytensor/tensor/rewriting/linalg.py
+1
-3
test_linalg.py
tests/tensor/rewriting/test_linalg.py
+15
-17
没有找到文件。
pytensor/tensor/rewriting/linalg.py
浏览文件 @
945e9799
...
@@ -70,9 +70,6 @@ MATRIX_INVERSE_OPS = (MatrixInverse, MatrixPinv)
...
@@ -70,9 +70,6 @@ MATRIX_INVERSE_OPS = (MatrixInverse, MatrixPinv)
def
fuse_blockdiagonal
(
fgraph
,
node
):
def
fuse_blockdiagonal
(
fgraph
,
node
):
"""Fuse nested BlockDiagonal ops into a single BlockDiagonal."""
"""Fuse nested BlockDiagonal ops into a single BlockDiagonal."""
if
not
isinstance
(
node
.
op
,
BlockDiagonal
):
return
None
new_inputs
=
[]
new_inputs
=
[]
changed
=
False
changed
=
False
...
@@ -86,6 +83,7 @@ def fuse_blockdiagonal(fgraph, node):
...
@@ -86,6 +83,7 @@ def fuse_blockdiagonal(fgraph, node):
if
changed
:
if
changed
:
fused_op
=
BlockDiagonal
(
len
(
new_inputs
))
fused_op
=
BlockDiagonal
(
len
(
new_inputs
))
new_output
=
fused_op
(
*
new_inputs
)
new_output
=
fused_op
(
*
new_inputs
)
copy_stack_trace
(
node
.
outputs
[
0
],
new_output
)
return
[
new_output
]
return
[
new_output
]
return
None
return
None
...
...
tests/tensor/rewriting/test_linalg.py
浏览文件 @
945e9799
...
@@ -10,7 +10,7 @@ from pytensor import function
...
@@ -10,7 +10,7 @@ from pytensor import function
from
pytensor
import
tensor
as
pt
from
pytensor
import
tensor
as
pt
from
pytensor.compile
import
get_default_mode
from
pytensor.compile
import
get_default_mode
from
pytensor.configdefaults
import
config
from
pytensor.configdefaults
import
config
from
pytensor.graph
import
ancestors
from
pytensor.graph
import
FunctionGraph
,
ancestors
from
pytensor.graph.rewriting.utils
import
rewrite_graph
from
pytensor.graph.rewriting.utils
import
rewrite_graph
from
pytensor.tensor
import
swapaxes
from
pytensor.tensor
import
swapaxes
from
pytensor.tensor.blockwise
import
Blockwise
,
BlockwiseWithCoreShape
from
pytensor.tensor.blockwise
import
Blockwise
,
BlockwiseWithCoreShape
...
@@ -52,23 +52,22 @@ def test_nested_blockdiag_fusion():
...
@@ -52,23 +52,22 @@ def test_nested_blockdiag_fusion():
inner
=
BlockDiagonal
(
2
)(
x
,
y
)
inner
=
BlockDiagonal
(
2
)(
x
,
y
)
outer
=
BlockDiagonal
(
2
)(
inner
,
z
)
outer
=
BlockDiagonal
(
2
)(
inner
,
z
)
nodes_before
=
ancestors
([
outer
])
initial_count
=
sum
(
initial_count
=
sum
(
1
1
for
node
in
nodes_before
for
node
in
ancestors
([
outer
])
if
getattr
(
node
,
"owner"
,
None
)
and
isinstance
(
node
.
owner
.
op
,
BlockDiagonal
)
if
getattr
(
node
,
"owner"
,
None
)
and
isinstance
(
node
.
owner
.
op
,
BlockDiagonal
)
)
)
assert
initial_count
==
2
,
"Setup failed: expected 2 nested BlockDiagonal ops"
assert
initial_count
==
2
,
"Setup failed: expected 2 nested BlockDiagonal ops"
f
=
pytensor
.
function
([
x
,
y
,
z
],
outer
)
f
graph
=
FunctionGraph
(
inputs
=
[
x
,
y
,
z
],
outputs
=
[
outer
]
)
fgraph
=
f
.
maker
.
fgraph
rewrite_graph
(
fgraph
,
include
=
(
"fast_run"
,
"blockdiag_fusion"
))
nodes_after
=
fgraph
.
apply_nodes
fused_nodes
=
[
fused_nodes
=
[
node
for
node
in
nodes_after
if
isinstance
(
node
.
op
,
BlockDiagonal
)]
node
for
node
in
fgraph
.
toposort
()
if
isinstance
(
node
.
op
,
BlockDiagonal
)
]
assert
len
(
fused_nodes
)
==
1
,
"Nested BlockDiagonal ops were not fused"
assert
len
(
fused_nodes
)
==
1
,
"Nested BlockDiagonal ops were not fused"
fused_op
=
fused_nodes
[
0
]
.
op
fused_op
=
fused_nodes
[
0
]
.
op
assert
fused_op
.
n_inputs
==
3
,
f
"Expected n_inputs=3, got {fused_op.n_inputs}"
assert
fused_op
.
n_inputs
==
3
,
f
"Expected n_inputs=3, got {fused_op.n_inputs}"
out_shape
=
fgraph
.
outputs
[
0
]
.
type
.
shape
out_shape
=
fgraph
.
outputs
[
0
]
.
type
.
shape
...
@@ -85,21 +84,20 @@ def test_deeply_nested_blockdiag_fusion():
...
@@ -85,21 +84,20 @@ def test_deeply_nested_blockdiag_fusion():
inner2
=
BlockDiagonal
(
2
)(
inner1
,
z
)
inner2
=
BlockDiagonal
(
2
)(
inner1
,
z
)
outer
=
BlockDiagonal
(
2
)(
inner2
,
w
)
outer
=
BlockDiagonal
(
2
)(
inner2
,
w
)
f
=
pytensor
.
function
([
x
,
y
,
z
,
w
],
outer
)
f
graph
=
FunctionGraph
(
inputs
=
[
x
,
y
,
z
,
w
],
outputs
=
[
outer
]
)
fgraph
=
f
.
maker
.
fgraph
rewrite_graph
(
fgraph
,
include
=
(
"fast_run"
,
"blockdiag_fusion"
))
fused_nodes
=
[
fused_
block_diag_
nodes
=
[
node
for
node
in
fgraph
.
apply_nodes
if
isinstance
(
node
.
op
,
BlockDiagonal
)
node
for
node
in
fgraph
.
apply_nodes
if
isinstance
(
node
.
op
,
BlockDiagonal
)
]
]
assert
len
(
fused_block_diag_nodes
)
==
1
,
(
assert
len
(
fused_nodes
)
==
1
,
(
f
"Expected 1 fused BlockDiagonal, got {len(fused_block_diag_nodes)}"
f
"Expected 1 fused BlockDiagonal, got {len(fused_nodes)}"
)
)
fused_
op
=
fused
_nodes
[
0
]
.
op
fused_
block_diag_op
=
fused_block_diag
_nodes
[
0
]
.
op
assert
fused_op
.
n_inputs
==
4
,
(
assert
fused_
block_diag_
op
.
n_inputs
==
4
,
(
f
"Expected n_inputs=4 after fusion, got {fused_op.n_inputs}"
f
"Expected n_inputs=4 after fusion, got {fused_
block_diag_
op.n_inputs}"
)
)
out_shape
=
fgraph
.
outputs
[
0
]
.
type
.
shape
out_shape
=
fgraph
.
outputs
[
0
]
.
type
.
shape
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论