Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
165aa19f
提交
165aa19f
authored
3月 18, 2026
作者:
Vybhav
提交者:
Ricardo Vieira
3月 19, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix scalar Pow.impl returning complex for negative base with fractional exponent
上级
30558ba5
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
25 行增加
和
1 行删除
+25
-1
basic.py
pytensor/scalar/basic.py
+1
-1
test_basic.py
tests/scalar/test_basic.py
+24
-0
没有找到文件。
pytensor/scalar/basic.py
浏览文件 @
165aa19f
...
@@ -2282,7 +2282,7 @@ class Pow(BinaryScalarOp):
...
@@ -2282,7 +2282,7 @@ class Pow(BinaryScalarOp):
nfunc_spec
=
(
"power"
,
2
,
1
)
nfunc_spec
=
(
"power"
,
2
,
1
)
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
**
y
return
np
.
power
(
x
,
y
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,
y
)
=
inputs
(
x
,
y
)
=
inputs
...
...
tests/scalar/test_basic.py
浏览文件 @
165aa19f
...
@@ -34,6 +34,7 @@ from pytensor.scalar.basic import (
...
@@ -34,6 +34,7 @@ from pytensor.scalar.basic import (
exp2
,
exp2
,
expm1
,
expm1
,
float32
,
float32
,
float64
,
floats
,
floats
,
int8
,
int8
,
int32
,
int32
,
...
@@ -47,6 +48,7 @@ from pytensor.scalar.basic import (
...
@@ -47,6 +48,7 @@ from pytensor.scalar.basic import (
mul
,
mul
,
neg
,
neg
,
neq
,
neq
,
pow
,
rad2deg
,
rad2deg
,
reciprocal
,
reciprocal
,
sin
,
sin
,
...
@@ -530,3 +532,25 @@ def test_cast_to_complex(inp_type):
...
@@ -530,3 +532,25 @@ def test_cast_to_complex(inp_type):
res_y
=
y
.
eval
({
x
:
np
.
array
(
1.0
,
dtype
=
inp_type
.
dtype
)})
res_y
=
y
.
eval
({
x
:
np
.
array
(
1.0
,
dtype
=
inp_type
.
dtype
)})
assert
res_y
==
1
assert
res_y
==
1
assert
res_y
.
dtype
==
"complex64"
assert
res_y
.
dtype
==
"complex64"
@pytest.mark.parametrize
(
"mode"
,
[
Mode
(
linker
=
"py"
),
None
])
def
test_pow_negative_base_fractional_exponent
(
mode
):
x
=
float64
(
"x"
)
y
=
float64
(
"y"
)
f
=
pytensor
.
function
([
x
,
y
],
pow
(
x
,
y
),
mode
=
mode
)
# Positive base works normally
assert
f
(
2.0
,
3.0
)
==
8.0
# Negative base with integer exponent works
assert
f
(
-
2.0
,
3.0
)
==
-
8.0
# Negative base with fractional exponent returns nan, not complex
result
=
f
(
-
1.0
,
0.01
)
if
not
isinstance
(
f
.
maker
.
linker
,
NumbaLinker
):
# Numba doesn't return numpy scalars
assert
isinstance
(
result
,
np
.
floating
),
(
f
"Expected numpy float, got {type(result)}: {result}"
)
assert
np
.
isnan
(
result
),
f
"Expected nan, got {result}"
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论