Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d64cceaf
提交
d64cceaf
authored
12月 08, 2025
作者:
ricardoV94
提交者:
Ricardo Vieira
12月 09, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Work-around numba pow failure was not robust enough
上级
695574b9
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
22 行增加
和
13 行删除
+22
-13
scalar.py
pytensor/link/numba/dispatch/scalar.py
+7
-8
test_scalar.py
tests/link/numba/test_scalar.py
+15
-5
没有找到文件。
pytensor/link/numba/dispatch/scalar.py
浏览文件 @
d64cceaf
...
@@ -170,18 +170,17 @@ def {binary_op_name}({input_signature}):
...
@@ -170,18 +170,17 @@ def {binary_op_name}({input_signature}):
@register_funcify_and_cache_key
(
Pow
)
@register_funcify_and_cache_key
(
Pow
)
def
numba_funcify_Pow
(
op
,
node
,
**
kwargs
):
def
numba_funcify_Pow
(
op
,
node
,
**
kwargs
):
pow_dtype
=
node
.
inputs
[
1
]
.
type
.
dtype
pow_dtype
=
node
.
inputs
[
1
]
.
type
.
dtype
if
pow_dtype
.
startswith
(
"int"
):
# Numba power fails when exponents are non 64-bit discrete integers and fasthmath=True
# https://github.com/numba/numba/issues/9554
def
pow
(
x
,
y
):
return
x
**
np
.
asarray
(
y
,
dtype
=
np
.
int64
)
.
item
()
else
:
def
pow
(
x
,
y
):
def
pow
(
x
,
y
):
return
x
**
y
return
x
**
y
return
numba_basic
.
numba_njit
(
pow
),
scalar_op_cache_key
(
op
)
# Numba power fails when exponents are discrete integers and fasthmath=True
# https://github.com/numba/numba/issues/9554
fastmath
=
False
if
np
.
dtype
(
pow_dtype
)
.
kind
in
"ibu"
else
None
return
numba_basic
.
numba_njit
(
pow
,
fastmath
=
fastmath
),
scalar_op_cache_key
(
op
,
cache_version
=
1
)
@register_funcify_and_cache_key
(
Add
)
@register_funcify_and_cache_key
(
Add
)
...
...
tests/link/numba/test_scalar.py
浏览文件 @
d64cceaf
...
@@ -183,13 +183,23 @@ def test_Softplus(dtype):
...
@@ -183,13 +183,23 @@ def test_Softplus(dtype):
)
)
def
test_discrete_power
():
@pytest.mark.parametrize
(
"test_base"
,
[
np
.
bool
(
True
),
np
.
int16
(
3
),
np
.
uint16
(
3
),
np
.
float32
(
0.5
),
np
.
float64
(
0.5
)],
)
@pytest.mark.parametrize
(
"test_exponent"
,
[
np
.
bool
(
True
),
np
.
int16
(
2
),
np
.
uint16
(
2
),
np
.
float32
(
2.0
),
np
.
float64
(
2.0
)],
)
def
test_power_fastmath_bug
(
test_base
,
test_exponent
):
# Test we don't fail to compile power with discrete exponents due to https://github.com/numba/numba/issues/9554
# Test we don't fail to compile power with discrete exponents due to https://github.com/numba/numba/issues/9554
x
=
pt
.
scalar
(
"x"
,
dtype
=
"float64"
)
base
=
pt
.
scalar
(
"base"
,
dtype
=
test_base
.
dtype
)
exponent
=
pt
.
scalar
(
"exponent"
,
dtype
=
"int8"
)
exponent
=
pt
.
scalar
(
"exponent"
,
dtype
=
test_exponent
.
dtype
)
out
=
pt
.
power
(
x
,
exponent
)
out
=
pt
.
power
(
base
,
exponent
)
compare_numba_and_py
(
compare_numba_and_py
(
[
x
,
exponent
],
[
out
],
[
np
.
array
(
0.5
),
np
.
array
(
2
,
dtype
=
"int8"
)]
[
base
,
exponent
],
[
out
],
[
test_base
,
test_exponent
],
)
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论