Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ad8dca48
提交
ad8dca48
authored
1月 24, 2026
作者:
jessegrabowski
提交者:
Jesse Grabowski
1月 29, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement QZ Op
上级
9834e96c
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
101 行增加
和
0 行删除
+101
-0
slinalg.py
pytensor/tensor/slinalg.py
+0
-0
test_slinalg.py
tests/tensor/test_slinalg.py
+101
-0
没有找到文件。
pytensor/tensor/slinalg.py
浏览文件 @
ad8dca48
差异被折叠。
点击展开。
tests/tensor/test_slinalg.py
浏览文件 @
ad8dca48
...
@@ -37,6 +37,7 @@ from pytensor.tensor.slinalg import (
...
@@ -37,6 +37,7 @@ from pytensor.tensor.slinalg import (
lu_solve
,
lu_solve
,
pivot_to_permutation
,
pivot_to_permutation
,
qr
,
qr
,
qz
,
schur
,
schur
,
solve
,
solve
,
solve_triangular
,
solve_triangular
,
...
@@ -1366,3 +1367,103 @@ class TestSchur:
...
@@ -1366,3 +1367,103 @@ class TestSchur:
assert
Z_out
.
size
==
0
assert
Z_out
.
size
==
0
assert
T_out
.
dtype
==
config
.
floatX
assert
T_out
.
dtype
==
config
.
floatX
assert
Z_out
.
dtype
==
config
.
floatX
assert
Z_out
.
dtype
==
config
.
floatX
class
TestQZ
:
@pytest.mark.parametrize
(
"shape, output"
,
[((
5
,
5
),
"real"
),
((
5
,
5
),
"complex"
),
((
2
,
4
,
4
),
"real"
)],
ids
=
[
"not_batched_real"
,
"not_batched_complex"
,
"batched_real"
],
)
@pytest.mark.parametrize
(
"complex"
,
[
False
,
True
],
ids
=
[
"real"
,
"complex"
])
@pytest.mark.parametrize
(
"sort"
,
[
None
,
"lhp"
,
"rhp"
,
"iuc"
,
"ouc"
])
def
test_qz_decomposition
(
self
,
shape
,
output
,
complex
,
sort
):
dtype
=
(
config
.
floatX
if
not
complex
else
f
"complex{int(config.floatX[-2:]) * 2}"
)
A
=
tensor
(
"A"
,
shape
=
shape
,
dtype
=
dtype
)
B
=
tensor
(
"B"
,
shape
=
shape
,
dtype
=
dtype
)
outputs
=
qz
(
A
,
B
,
output
=
output
,
sort
=
sort
,
return_eigenvalues
=
sort
is
not
None
)
f
=
function
([
A
,
B
],
outputs
)
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
A_val
,
B_val
=
rng
.
normal
(
size
=
(
2
,
*
shape
))
A_val
=
A_val
.
astype
(
config
.
floatX
)
B_val
=
B_val
.
astype
(
config
.
floatX
)
if
complex
:
A_val
=
A_val
+
1
j
*
rng
.
normal
(
size
=
shape
)
.
astype
(
config
.
floatX
)
B_val
=
B_val
+
1
j
*
rng
.
normal
(
size
=
shape
)
.
astype
(
config
.
floatX
)
output_values
=
f
(
A_val
,
B_val
)
if
sort
is
None
:
AA_val
,
BB_val
,
Q_val
,
Z_val
=
output_values
else
:
AA_val
,
BB_val
,
alpha_val
,
beta_val
,
Q_val
,
Z_val
=
output_values
# Verify reconstruction
A_rebuilt
=
np
.
einsum
(
"...ij,...jk,...lk->...il"
,
Q_val
,
AA_val
,
Z_val
.
conj
())
B_rebuilt
=
np
.
einsum
(
"...ij,...jk,...lk->...il"
,
Q_val
,
BB_val
,
Z_val
.
conj
())
np
.
testing
.
assert_allclose
(
A_val
,
A_rebuilt
,
atol
=
1e-6
if
config
.
floatX
==
"float64"
else
1e-3
,
rtol
=
1e-6
if
config
.
floatX
==
"float64"
else
1e-3
,
)
np
.
testing
.
assert_allclose
(
B_val
,
B_rebuilt
,
atol
=
1e-6
if
config
.
floatX
==
"float64"
else
1e-3
,
rtol
=
1e-6
if
config
.
floatX
==
"float64"
else
1e-3
,
)
scipy_fn
=
(
scipy_linalg
.
qz
if
sort
is
None
else
functools
.
partial
(
scipy_linalg
.
ordqz
,
sort
=
sort
)
)
scipy_signature
=
(
"(m,m),(m,m)->(m,m),(m,m),(m,m),(m,m)"
if
sort
is
None
else
(
"(m,m),(m,m)->(m,m),(m,m),(m),(m),(m,m),(m,m)"
)
)
vec_qz
=
np
.
vectorize
(
lambda
a
,
b
:
scipy_fn
(
a
,
b
,
output
=
output
),
signature
=
scipy_signature
,
)
scipy_result
=
vec_qz
(
A_val
,
B_val
)
if
sort
is
None
:
scipy_AA
,
scipy_BB
,
scipy_Q
,
scipy_Z
=
scipy_result
else
:
scipy_AA
,
scipy_BB
,
scipy_alpha
,
scipy_beta
,
scipy_Q
,
scipy_Z
=
scipy_result
np
.
testing
.
assert_allclose
(
AA_val
,
scipy_AA
,
atol
=
1e-6
,
rtol
=
1e-6
)
np
.
testing
.
assert_allclose
(
BB_val
,
scipy_BB
,
atol
=
1e-6
,
rtol
=
1e-6
)
np
.
testing
.
assert_allclose
(
Q_val
,
scipy_Q
,
atol
=
1e-6
,
rtol
=
1e-6
)
np
.
testing
.
assert_allclose
(
Z_val
,
scipy_Z
,
atol
=
1e-6
,
rtol
=
1e-6
)
if
sort
is
not
None
:
np
.
testing
.
assert_allclose
(
alpha_val
,
scipy_alpha
,
atol
=
1e-6
,
rtol
=
1e-6
)
np
.
testing
.
assert_allclose
(
beta_val
,
scipy_beta
,
atol
=
1e-6
,
rtol
=
1e-6
)
if
len
(
shape
)
==
2
and
(
output
==
"complex"
)
==
complex
:
A_f
=
np
.
asfortranarray
(
A_val
.
copy
())
B_f
=
np
.
asfortranarray
(
B_val
.
copy
())
f_mut
=
function
(
[
In
(
A
,
mutable
=
True
),
In
(
B
,
mutable
=
True
)],
outputs
,
mode
=
get_default_mode
()
.
including
(
"inplace"
),
)
f_mut
(
A_f
,
B_f
)
np
.
testing
.
assert_allclose
(
A_f
,
scipy_AA
,
atol
=
1e-6
,
rtol
=
1e-6
)
np
.
testing
.
assert_allclose
(
B_f
,
scipy_BB
,
atol
=
1e-6
,
rtol
=
1e-6
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论