Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9352166c
提交
9352166c
authored
11月 19, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
12月 15, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Numba does not output numpy scalars
上级
a602a8ec
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
22 行增加
和
2 行删除
+22
-2
test_basic.py
tests/scalar/test_basic.py
+7
-0
test_basic.py
tests/tensor/test_basic.py
+10
-2
unittest_tools.py
tests/unittest_tools.py
+5
-0
没有找到文件。
tests/scalar/test_basic.py
浏览文件 @
9352166c
...
...
@@ -6,6 +6,7 @@ import pytensor.tensor as pt
from
pytensor.compile.mode
import
Mode
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.link.c.basic
import
DualLinker
from
pytensor.link.numba
import
NumbaLinker
from
pytensor.scalar.basic
import
(
EQ
,
ComplexError
,
...
...
@@ -368,6 +369,8 @@ class TestUpgradeToFloat:
outi
=
fi
(
x_val
)
outf
=
ff
(
x_val
)
if
not
isinstance
(
ff
.
maker
.
linker
,
NumbaLinker
):
# Numba doesn't return numpy scalars
assert
outi
.
dtype
==
outf
.
dtype
,
"incorrect dtype"
assert
np
.
allclose
(
outi
,
outf
),
"insufficient precision"
...
...
@@ -389,6 +392,8 @@ class TestUpgradeToFloat:
outi
=
fi
(
x_val
,
y_val
)
outf
=
ff
(
x_val
,
y_val
)
if
not
isinstance
(
ff
.
maker
.
linker
,
NumbaLinker
):
# Numba doesn't return numpy scalars
assert
outi
.
dtype
==
outf
.
dtype
,
"incorrect dtype"
assert
np
.
allclose
(
outi
,
outf
),
"insufficient precision"
...
...
@@ -414,6 +419,8 @@ class TestUpgradeToFloat:
outi
=
fi
(
x_val
,
y_val
)
outf
=
ff
(
x_val
,
y_val
)
if
not
isinstance
(
ff
.
maker
.
linker
,
NumbaLinker
):
# Numba doesn't return numpy scalars
assert
outi
.
dtype
==
outf
.
dtype
,
"incorrect dtype"
assert
np
.
allclose
(
outi
,
outf
),
"insufficient precision"
...
...
tests/tensor/test_basic.py
浏览文件 @
9352166c
...
...
@@ -18,6 +18,7 @@ from pytensor.gradient import grad, hessian
from
pytensor.graph.basic
import
Apply
,
equal_computations
from
pytensor.graph.op
import
Op
from
pytensor.graph.replace
import
clone_replace
from
pytensor.link.numba
import
NumbaLinker
from
pytensor.raise_op
import
Assert
from
pytensor.scalar
import
autocast_float
,
autocast_float_as
from
pytensor.tensor
import
NoneConst
,
vectorize
...
...
@@ -2193,11 +2194,15 @@ def test_ScalarFromTensor(cast_policy):
assert
ss
.
owner
.
op
is
scalar_from_tensor
assert
ss
.
type
.
dtype
==
tc
.
type
.
dtype
v
=
eval_outputs
([
ss
])
mode
=
get_default_mode
()
v
=
eval_outputs
([
ss
],
mode
=
mode
)
assert
v
==
56
if
isinstance
(
mode
.
linker
,
NumbaLinker
):
# Numba doesn't return numpy scalars
assert
isinstance
(
v
,
int
)
else
:
assert
v
.
shape
==
()
if
cast_policy
==
"custom"
:
assert
isinstance
(
v
,
np
.
int8
)
elif
cast_policy
==
"numpy+floatX"
:
...
...
@@ -2209,6 +2214,9 @@ def test_ScalarFromTensor(cast_policy):
fff
=
function
([
pts
],
ss
)
v
=
fff
(
np
.
asarray
(
5
))
assert
v
==
5
if
isinstance
(
mode
.
linker
,
NumbaLinker
):
assert
isinstance
(
v
,
int
)
else
:
assert
isinstance
(
v
,
np
.
int64
)
assert
v
.
shape
==
()
...
...
tests/unittest_tools.py
浏览文件 @
9352166c
...
...
@@ -3,6 +3,7 @@ import sys
import
warnings
from
copy
import
copy
,
deepcopy
from
functools
import
wraps
from
numbers
import
Number
import
numpy
as
np
import
pytest
...
...
@@ -259,6 +260,10 @@ class InferShapeTester:
numeric_outputs
=
outputs_function
(
*
numeric_inputs
)
numeric_shapes
=
shapes_function
(
*
numeric_inputs
)
for
out
,
shape
in
zip
(
numeric_outputs
,
numeric_shapes
,
strict
=
True
):
if
not
hasattr
(
out
,
"shape"
):
# Numba downcasts scalars to native Python types, which don't have shape
assert
isinstance
(
out
,
Number
)
out
=
np
.
asarray
(
out
)
assert
np
.
all
(
out
.
shape
==
shape
),
(
out
.
shape
,
shape
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论