Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ef5bcb50
提交
ef5bcb50
authored
12月 01, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
12月 15, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test SVD and Eig(h): allow benign sign change
上级
ebe518fa
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
37 行增加
和
11 行删除
+37
-11
test_nlinalg.py
tests/tensor/test_nlinalg.py
+37
-11
没有找到文件。
tests/tensor/test_nlinalg.py
浏览文件 @
ef5bcb50
...
...
@@ -165,10 +165,33 @@ class TestSvd(utt.InferShapeTester):
pt_outputs
=
fn
(
a
)
np_outputs
=
np_outputs
if
isinstance
(
np_outputs
,
tuple
)
else
[
np_outputs
]
if
compute_uv
:
# In this case we sometimes get a sign flip on some columns in one impl and not the thore
# The results are both correct, and we test that by reconstructing the original input
U
,
S
,
Vh
=
pt_outputs
S_diag
=
np
.
expand_dims
(
S
,
-
2
)
*
np
.
eye
(
S
.
shape
[
-
1
])
diff
=
a
.
shape
[
-
2
]
-
a
.
shape
[
-
1
]
if
full_matrix
:
if
diff
>
0
:
# tall
S_diag
=
np
.
pad
(
S_diag
,
[(
0
,
0
),
(
0
,
diff
),
(
0
,
0
)][
-
a
.
ndim
:])
elif
diff
<
0
:
# wide
S_diag
=
np
.
pad
(
S_diag
,
[(
0
,
0
),
(
0
,
0
),
(
0
,
-
diff
)][
-
a
.
ndim
:])
a_r
=
U
@
S_diag
@
Vh
rtol
=
1e-3
if
config
.
floatX
==
"float32"
else
1e-7
np
.
testing
.
assert_allclose
(
a_r
,
a
,
rtol
=
rtol
)
for
np_val
,
pt_val
in
zip
(
np_outputs
,
pt_outputs
,
strict
=
True
):
# Check values are equivalent up to sign change
np
.
testing
.
assert_allclose
(
np
.
abs
(
np_val
),
np
.
abs
(
pt_val
),
rtol
=
rtol
)
rtol
=
1e-5
if
config
.
floatX
==
"float32"
else
1e-7
for
np_val
,
pt_val
in
zip
(
np_outputs
,
pt_outputs
,
strict
=
True
):
np
.
testing
.
assert_allclose
(
np_val
,
pt_val
,
rtol
=
rtol
)
else
:
rtol
=
1e-5
if
config
.
floatX
==
"float32"
else
1e-7
for
np_val
,
pt_val
in
zip
(
np_outputs
,
pt_outputs
,
strict
=
True
):
np
.
testing
.
assert_allclose
(
np_val
,
pt_val
,
rtol
=
rtol
)
def
test_svd_infer_shape
(
self
):
self
.
validate_shape
((
4
,
4
),
full_matrices
=
True
,
compute_uv
=
True
)
...
...
@@ -428,8 +451,8 @@ class TestEig(utt.InferShapeTester):
w
,
v
=
fn
(
A_val
)
w_np
,
v_np
=
np
.
linalg
.
eig
(
A_val
)
np
.
testing
.
assert_allclose
(
w
,
w_np
)
np
.
testing
.
assert_allclose
(
v
,
v_np
)
np
.
testing
.
assert_allclose
(
np
.
abs
(
w
),
np
.
abs
(
w_np
)
)
np
.
testing
.
assert_allclose
(
np
.
abs
(
v
),
np
.
abs
(
v_np
)
)
assert_array_almost_equal
(
np
.
dot
(
A_val
,
v
),
w
*
v
)
# Asymmetric input (real eigenvalues)
...
...
@@ -438,16 +461,16 @@ class TestEig(utt.InferShapeTester):
w
,
v
=
fn
(
A_val
)
w_np
,
v_np
=
np
.
linalg
.
eig
(
A_val
)
np
.
testing
.
assert_allclose
(
w
,
w_np
)
np
.
testing
.
assert_allclose
(
v
,
v_np
)
np
.
testing
.
assert_allclose
(
np
.
abs
(
w
),
np
.
abs
(
w_np
)
)
np
.
testing
.
assert_allclose
(
np
.
abs
(
v
),
np
.
abs
(
v_np
)
)
assert_array_almost_equal
(
np
.
dot
(
A_val
,
v
),
w
*
v
)
# Asymmetric input (complex eigenvalues)
A_val
=
self
.
rng
.
normal
(
size
=
(
5
,
5
))
w
,
v
=
fn
(
A_val
)
w_np
,
v_np
=
np
.
linalg
.
eig
(
A_val
)
np
.
testing
.
assert_allclose
(
w
,
w_np
)
np
.
testing
.
assert_allclose
(
v
,
v_np
)
np
.
testing
.
assert_allclose
(
np
.
abs
(
w
),
np
.
abs
(
w_np
)
)
np
.
testing
.
assert_allclose
(
np
.
abs
(
v
),
np
.
abs
(
v_np
)
)
assert_array_almost_equal
(
np
.
dot
(
A_val
,
v
),
w
*
v
)
...
...
@@ -464,11 +487,14 @@ class TestEigh(TestEig):
w
,
v
=
fn
(
A_val
)
w_np
,
v_np
=
np
.
linalg
.
eigh
(
A_val
)
np
.
testing
.
assert_allclose
(
w
,
w_np
)
np
.
testing
.
assert_allclose
(
v
,
v_np
)
# There are multiple valid results up to some sign changes
# Check we can reconstruct input
rtol
=
1e-2
if
self
.
dtype
==
"float32"
else
1e-7
np
.
testing
.
assert_allclose
(
np
.
dot
(
A_val
,
v
),
w
*
v
,
rtol
=
rtol
)
np
.
testing
.
assert_allclose
(
np
.
abs
(
w
),
np
.
abs
(
w_np
),
rtol
=
rtol
)
np
.
testing
.
assert_allclose
(
np
.
abs
(
v
),
np
.
abs
(
v_np
),
rtol
=
rtol
)
def
test_uplo
(
self
):
S
=
self
.
S
a
=
matrix
(
dtype
=
self
.
dtype
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论