Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f72d7e58
Unverified
提交
f72d7e58
authored
6月 21, 2025
作者:
Jesse Grabowski
提交者:
GitHub
6月 21, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add JAX dispatch for `CholeskySolve` `Op` (#1491)
* Add jax dispatch for CholeskySolve * Better typehints on user-facing `cho_solve` * Rename test
上级
d3bbc20a
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
40 行增加
和
3 行删除
+40
-3
slinalg.py
pytensor/link/jax/dispatch/slinalg.py
+15
-0
slinalg.py
pytensor/tensor/slinalg.py
+9
-3
test_slinalg.py
tests/link/jax/test_slinalg.py
+16
-0
没有找到文件。
pytensor/link/jax/dispatch/slinalg.py
浏览文件 @
f72d7e58
...
...
@@ -7,6 +7,7 @@ from pytensor.tensor.slinalg import (
LU
,
BlockDiagonal
,
Cholesky
,
CholeskySolve
,
Eigvalsh
,
LUFactor
,
PivotToPermutations
,
...
...
@@ -153,3 +154,17 @@ def jax_funcify_LUFactor(op, **kwargs):
)
return
lu_factor
@jax_funcify.register
(
CholeskySolve
)
def
jax_funcify_ChoSolve
(
op
,
**
kwargs
):
lower
=
op
.
lower
check_finite
=
op
.
check_finite
overwrite_b
=
op
.
overwrite_b
def
cho_solve
(
c
,
b
):
return
jax
.
scipy
.
linalg
.
cho_solve
(
(
c
,
lower
),
b
,
check_finite
=
check_finite
,
overwrite_b
=
overwrite_b
)
return
cho_solve
pytensor/tensor/slinalg.py
浏览文件 @
f72d7e58
...
...
@@ -376,14 +376,20 @@ class CholeskySolve(SolveBase):
return
self
def
cho_solve
(
c_and_lower
,
b
,
*
,
check_finite
=
True
,
b_ndim
:
int
|
None
=
None
):
def
cho_solve
(
c_and_lower
:
tuple
[
TensorLike
,
bool
],
b
:
TensorLike
,
*
,
check_finite
:
bool
=
True
,
b_ndim
:
int
|
None
=
None
,
):
"""Solve the linear equations A x = b, given the Cholesky factorization of A.
Parameters
----------
(c, lower) : tuple, (array
, bool)
c_and_lower : tuple of (TensorLike
, bool)
Cholesky factorization of a, as given by cho_factor
b :
array
b :
TensorLike
Right-hand side
check_finite : bool, optional
Whether to check that the input matrices contain only finite numbers.
...
...
tests/link/jax/test_slinalg.py
浏览文件 @
f72d7e58
...
...
@@ -333,3 +333,19 @@ def test_jax_lu_solve(b_shape):
out
=
pt_slinalg
.
lu_solve
(
lu_and_pivots
,
b
)
compare_jax_and_py
([
A
,
b
],
[
out
],
[
A_val
,
b_val
])
@pytest.mark.parametrize
(
"b_shape, lower"
,
[((
5
,),
True
),
((
5
,
5
),
False
)])
def
test_jax_cho_solve
(
b_shape
,
lower
):
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
L_val
=
rng
.
normal
(
size
=
(
5
,
5
))
.
astype
(
config
.
floatX
)
A_val
=
(
L_val
@
L_val
.
T
)
.
astype
(
config
.
floatX
)
b_val
=
rng
.
normal
(
size
=
b_shape
)
.
astype
(
config
.
floatX
)
A
=
pt
.
tensor
(
name
=
"A"
,
shape
=
(
5
,
5
))
b
=
pt
.
tensor
(
name
=
"b"
,
shape
=
b_shape
)
c
=
pt_slinalg
.
cholesky
(
A
,
lower
=
lower
)
out
=
pt_slinalg
.
cho_solve
((
c
,
lower
),
b
,
b_ndim
=
len
(
b_shape
))
compare_jax_and_py
([
A
,
b
],
[
out
],
[
A_val
,
b_val
])
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论