Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1efa92fd
提交
1efa92fd
authored
3月 15, 2026
作者:
jessegrabowski
提交者:
Ricardo Vieira
3月 15, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow complex inputs to numba cholesky
上级
6499a2c1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
7 行删除
+17
-7
cholesky.py
...nsor/link/numba/dispatch/linalg/decomposition/cholesky.py
+5
-3
test_slinalg.py
tests/link/numba/test_slinalg.py
+12
-4
没有找到文件。
pytensor/link/numba/dispatch/linalg/decomposition/cholesky.py
浏览文件 @
1efa92fd
import
numpy
as
np
import
numpy
as
np
from
numba.core.extending
import
overload
from
numba.core.extending
import
overload
from
numba.core.types
import
Complex
,
Float
from
numba.np.linalg
import
_copy_to_fortran_order
,
ensure_lapack
from
numba.np.linalg
import
_copy_to_fortran_order
,
ensure_lapack
from
numba.types
import
Float
from
scipy
import
linalg
from
scipy
import
linalg
from
pytensor.link.numba.dispatch.linalg._LAPACK
import
(
from
pytensor.link.numba.dispatch.linalg._LAPACK
import
(
...
@@ -19,7 +19,7 @@ def _cholesky(a, lower=False, overwrite_a=False):
...
@@ -19,7 +19,7 @@ def _cholesky(a, lower=False, overwrite_a=False):
@overload
(
_cholesky
)
@overload
(
_cholesky
)
def
cholesky_impl
(
A
,
lower
=
0
,
overwrite_a
=
False
):
def
cholesky_impl
(
A
,
lower
=
0
,
overwrite_a
=
False
):
ensure_lapack
()
ensure_lapack
()
_check_linalg_matrix
(
A
,
ndim
=
2
,
dtype
=
Float
,
func_name
=
"cholesky"
)
_check_linalg_matrix
(
A
,
ndim
=
2
,
dtype
=
(
Float
,
Complex
)
,
func_name
=
"cholesky"
)
dtype
=
A
.
dtype
dtype
=
A
.
dtype
numba_potrf
=
_LAPACK
()
.
numba_xpotrf
(
dtype
)
numba_potrf
=
_LAPACK
()
.
numba_xpotrf
(
dtype
)
...
@@ -33,7 +33,9 @@ def cholesky_impl(A, lower=0, overwrite_a=False):
...
@@ -33,7 +33,9 @@ def cholesky_impl(A, lower=0, overwrite_a=False):
if
overwrite_a
and
A
.
flags
.
f_contiguous
:
if
overwrite_a
and
A
.
flags
.
f_contiguous
:
A_copy
=
A
A_copy
=
A
elif
overwrite_a
and
A
.
flags
.
c_contiguous
:
elif
overwrite_a
and
A
.
flags
.
c_contiguous
:
# We can work on the transpose of A directly
# c_contiguous A reinterpreted as f_contiguous is A^T.
# potrf(A^T, UPLO='U') produces U where U.T == L (the correct lower factor),
# even for complex Hermitian matrices. The .T return corrects the result.
A_copy
=
A
.
T
A_copy
=
A
.
T
transposed
=
True
transposed
=
True
lower
=
not
lower
lower
=
not
lower
...
...
tests/link/numba/test_slinalg.py
浏览文件 @
1efa92fd
...
@@ -465,12 +465,20 @@ class TestDecompositions:
...
@@ -465,12 +465,20 @@ class TestDecompositions:
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
"overwrite_a"
,
[
False
,
True
],
ids
=
[
"no_overwrite"
,
"overwrite_a"
]
"overwrite_a"
,
[
False
,
True
],
ids
=
[
"no_overwrite"
,
"overwrite_a"
]
)
)
def
test_cholesky
(
self
,
lower
:
bool
,
overwrite_a
:
bool
):
@pytest.mark.parametrize
(
"is_complex"
,
[
True
,
False
],
ids
=
[
"complex"
,
"real"
])
cov
=
pt
.
matrix
(
"cov"
)
def
test_cholesky
(
self
,
lower
:
bool
,
overwrite_a
:
bool
,
is_complex
:
bool
):
complex_dtype
=
"complex64"
if
floatX
.
endswith
(
"32"
)
else
"complex128"
dtype
=
complex_dtype
if
is_complex
else
floatX
cov
=
pt
.
matrix
(
"cov"
,
dtype
=
dtype
)
chol
=
pt
.
linalg
.
cholesky
(
cov
,
lower
=
lower
)
chol
=
pt
.
linalg
.
cholesky
(
cov
,
lower
=
lower
)
x
=
np
.
array
([
0.1
,
0.2
,
0.3
])
.
astype
(
floatX
)
rng
=
np
.
random
.
default_rng
(
42
)
val
=
np
.
eye
(
3
)
.
astype
(
floatX
)
+
x
[
None
,
:]
*
x
[:,
None
]
x
=
rng
.
normal
(
size
=
(
3
,
3
))
if
is_complex
:
x
=
x
+
1
j
*
rng
.
normal
(
size
=
(
3
,
3
))
x
=
x
.
astype
(
dtype
)
val
=
np
.
eye
(
3
,
dtype
=
dtype
)
+
x
@
x
.
conj
()
.
T
fn
,
res
=
compare_numba_and_py
(
fn
,
res
=
compare_numba_and_py
(
[
In
(
cov
,
mutable
=
overwrite_a
)],
[
In
(
cov
,
mutable
=
overwrite_a
)],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论