Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8b8ba028
提交
8b8ba028
authored
12月 09, 2025
作者:
ricardoV94
提交者:
Ricardo Vieira
12月 09, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Numba tridiagonal: avoid inference error when casting inputs
Numba doesn't infer the right type based on the static tuple, but does so with separate boolean variables
上级
eba75f6f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
46 行增加
和
13 行删除
+46
-13
tridiagonal.py
pytensor/link/numba/dispatch/linalg/solve/tridiagonal.py
+15
-13
test_tridiagonal.py
tests/link/numba/linalg/solve/test_tridiagonal.py
+31
-0
没有找到文件。
pytensor/link/numba/dispatch/linalg/solve/tridiagonal.py
浏览文件 @
8b8ba028
...
...
@@ -356,8 +356,10 @@ def numba_funcify_LUFactorTridiagonal(op: LUFactorTridiagonal, node, **kwargs):
overwrite_du
=
op
.
overwrite_du
out_dtype
=
node
.
outputs
[
1
]
.
type
.
numpy_dtype
must_cast_inputs
=
tuple
(
inp
.
type
.
numpy_dtype
!=
out_dtype
for
inp
in
node
.
inputs
)
if
any
(
must_cast_inputs
)
and
config
.
compiler_verbose
:
cast_inputs
=
(
cast_dl
,
cast_d
,
cast_du
)
=
tuple
(
inp
.
type
.
numpy_dtype
!=
out_dtype
for
inp
in
node
.
inputs
)
if
any
(
cast_inputs
)
and
config
.
compiler_verbose
:
print
(
"LUFactorTridiagonal requires casting at least one input"
)
# noqa: T201
@numba_basic.numba_njit
(
cache
=
False
)
...
...
@@ -371,11 +373,11 @@ def numba_funcify_LUFactorTridiagonal(op: LUFactorTridiagonal, node, **kwargs):
np
.
zeros
(
d
.
shape
,
dtype
=
"int32"
),
)
if
must_cast_inputs
[
0
]
:
if
cast_d
:
d
=
d
.
astype
(
out_dtype
)
if
must_cast_inputs
[
1
]
:
if
cast_dl
:
dl
=
dl
.
astype
(
out_dtype
)
if
must_cast_inputs
[
2
]
:
if
cast_du
:
du
=
du
.
astype
(
out_dtype
)
dl
,
d
,
du
,
du2
,
ipiv
,
_
=
_gttrf
(
dl
,
...
...
@@ -402,7 +404,7 @@ def numba_funcify_SolveLUFactorTridiagonal(
overwrite_b
=
op
.
overwrite_b
transposed
=
op
.
transposed
must_cast_inputs
=
tuple
(
must_cast_inputs
=
(
cast_dl
,
cast_d
,
cast_du
,
cast_du2
,
cast_ipiv
,
cast_b
)
=
tuple
(
inp
.
type
.
numpy_dtype
!=
(
np
.
int32
if
i
==
4
else
out_dtype
)
for
i
,
inp
in
enumerate
(
node
.
inputs
)
)
...
...
@@ -417,17 +419,17 @@ def numba_funcify_SolveLUFactorTridiagonal(
else
:
return
np
.
zeros
((
d
.
shape
[
0
],
b
.
shape
[
1
]),
dtype
=
out_dtype
)
if
must_cast_inputs
[
0
]
:
if
cast_dl
:
dl
=
dl
.
astype
(
out_dtype
)
if
must_cast_inputs
[
1
]
:
if
cast_d
:
d
=
d
.
astype
(
out_dtype
)
if
must_cast_inputs
[
2
]
:
if
cast_du
:
du
=
du
.
astype
(
out_dtype
)
if
must_cast_inputs
[
3
]
:
if
cast_du2
:
du2
=
du2
.
astype
(
out_dtype
)
if
must_cast_inputs
[
4
]
:
ipiv
=
ipiv
.
astype
(
"int32"
)
if
must_cast_inputs
[
5
]
:
if
cast_ipiv
:
ipiv
=
ipiv
.
astype
(
np
.
int32
)
if
cast_b
:
b
=
b
.
astype
(
out_dtype
)
x
,
_
=
_gttrs
(
dl
,
...
...
tests/link/numba/linalg/solve/test_tridiagonal.py
浏览文件 @
8b8ba028
...
...
@@ -112,3 +112,34 @@ def test_tridiagonal_lu_solve(b_ndim, transposed, inplace):
assert
(
res_non_contig
==
res
)
.
all
()
# b must be copied when not contiguous so it can't be inplaced
assert
(
b_test
==
b_test_non_contig
)
.
all
()
def
test_cast_needed
():
dl
=
pt
.
vector
(
"dl"
,
shape
=
(
4
,),
dtype
=
"int16"
)
d
=
pt
.
vector
(
"d"
,
shape
=
(
5
,),
dtype
=
"float32"
)
du
=
pt
.
vector
(
"du"
,
shape
=
(
4
,),
dtype
=
"float64"
)
b
=
pt
.
vector
(
"b"
,
shape
=
(
5
,),
dtype
=
"float32"
)
lu_factor_outs
=
LUFactorTridiagonal
()(
dl
,
d
,
du
)
for
i
,
out
in
enumerate
(
lu_factor_outs
):
if
i
==
4
:
assert
out
.
type
.
dtype
==
"int32"
# ipiv is int32
else
:
assert
out
.
type
.
dtype
==
"float64"
lu_solve_out
=
SolveLUFactorTridiagonal
(
b_ndim
=
1
,
transposed
=
False
)(
*
lu_factor_outs
,
b
)
assert
lu_solve_out
.
type
.
dtype
==
"float64"
compare_numba_and_py
(
[
dl
,
d
,
du
,
b
],
lu_solve_out
,
test_inputs
=
[
np
.
array
([
1
,
2
,
3
,
4
],
dtype
=
"int16"
),
np
.
array
([
1
,
2
,
3
,
4
,
5
],
dtype
=
"float32"
),
np
.
array
([
1
,
2
,
3
,
4
],
dtype
=
"float64"
),
np
.
array
([
1
,
2
,
3
,
4
,
5
],
dtype
=
"float32"
),
],
eval_obj_mode
=
False
,
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论