Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
42587563
提交
42587563
authored
12月 05, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
12月 13, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Numba CAReduce: respect acc_dtype
Also fix infinity identities for unsigned integers
上级
0cc6314b
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
48 行增加
和
3 行删除
+48
-3
elemwise.py
pytensor/link/numba/dispatch/elemwise.py
+0
-0
elemwise.py
pytensor/tensor/elemwise.py
+4
-1
math.py
pytensor/tensor/math.py
+4
-1
test_elemwise.py
tests/link/numba/test_elemwise.py
+40
-1
没有找到文件。
pytensor/link/numba/dispatch/elemwise.py
浏览文件 @
42587563
差异被折叠。
点击展开。
pytensor/tensor/elemwise.py
浏览文件 @
42587563
...
...
@@ -1391,7 +1391,10 @@ class CAReduce(COp):
return
f
"axes={list(axis)}"
def
__str__
(
self
):
return
f
"{type(self).__name__}{{{self.scalar_op}, {self._axis_str()}}}"
if
self
.
acc_dtype
!=
self
.
dtype
:
return
f
"{type(self).__name__}{{{self.scalar_op}, {self._axis_str()}, acc={self.acc_dtype}}}"
else
:
return
f
"{type(self).__name__}{{{self.scalar_op}, {self._axis_str()}}}"
def
perform
(
self
,
node
,
inp
,
out
):
(
input
,)
=
inp
...
...
pytensor/tensor/math.py
浏览文件 @
42587563
...
...
@@ -357,7 +357,10 @@ def max_and_argmax(a, axis=None, keepdims=False):
class
FixedOpCAReduce
(
CAReduce
):
def
__str__
(
self
):
return
f
"{type(self).__name__}{{{self._axis_str()}}}"
if
self
.
dtype
!=
self
.
acc_dtype
:
return
f
"{type(self).__name__}{{{self._axis_str()}, acc={self.acc_dtype}}}"
else
:
return
f
"{type(self).__name__}{{{self._axis_str()}}}"
class
NonZeroDimsCAReduce
(
FixedOpCAReduce
):
...
...
tests/link/numba/test_elemwise.py
浏览文件 @
42587563
...
...
@@ -13,7 +13,7 @@ from pytensor.compile.ops import deep_copy_op
from
pytensor.gradient
import
grad
from
pytensor.scalar
import
Composite
,
float64
from
pytensor.scalar
import
add
as
scalar_add
from
pytensor.tensor
import
blas
,
tensor
from
pytensor.tensor
import
blas
,
matrix
,
tensor
,
tensor3
from
pytensor.tensor.elemwise
import
CAReduce
,
DimShuffle
,
Elemwise
from
pytensor.tensor.math
import
All
,
Any
,
Max
,
Min
,
Prod
,
ProdWithoutZeros
,
Sum
from
pytensor.tensor.special
import
LogSoftmax
,
Softmax
,
SoftmaxGrad
...
...
@@ -366,6 +366,45 @@ def test_CAReduce(careduce_fn, axis, v):
assert
isinstance
(
node
.
op
,
CAReduce
)
@pytest.mark.parametrize
(
"axis"
,
(
-
1
,
(
0
,
-
1
),
None
))
def
test_CAReduce_respects_acc_dtype
(
axis
):
x
=
tensor3
(
"x"
,
dtype
=
"int8"
)
out
=
x
.
sum
(
dtype
=
"int8"
,
acc_dtype
=
"int64"
,
axis
=
axis
)
# Choose values that would overflow if accumulated internally in int8
max_int8
=
np
.
iinfo
(
np
.
int8
)
.
max
test_x
=
np
.
array
([
max_int8
,
5
,
max_int8
,
-
max_int8
,
5
,
-
max_int8
],
dtype
=
np
.
int8
)
test_x
=
np
.
broadcast_to
(
test_x
,
(
6
,
2
,
6
))
.
copy
()
_
,
[
res
]
=
compare_numba_and_py
(
[
x
],
[
out
],
[
test_x
],
)
if
axis
==
-
1
:
assert
np
.
all
(
res
==
10
)
elif
axis
==
(
0
,
-
1
):
assert
np
.
all
(
res
==
60
)
elif
axis
is
None
:
assert
res
==
120
@pytest.mark.parametrize
(
"axis"
,
(
1
,
None
))
def
test_CAReduce_acc_complex_out_float
(
axis
):
x
=
matrix
(
"x"
,
dtype
=
"complex128"
)
out
=
x
.
sum
(
dtype
=
"float64"
,
axis
=
axis
)
test_x
=
np
.
array
([[
1
+
0.5
j
,
2
-
0.5
j
],
[
3
+
0.5
j
,
4
-
0.5
j
]],
dtype
=
"complex128"
)
compare_numba_and_py
([
x
],
[
out
],
[
test_x
])
@pytest.mark.parametrize
(
"axis"
,
(
-
1
,
(
0
,
-
1
),
None
))
def
test_CAReduce_discrete_infinity_identity
(
axis
):
rng
=
np
.
random
.
default_rng
(
337
)
x
=
tensor3
(
"x"
,
dtype
=
"int8"
)
out
=
x
.
max
(
axis
)
compare_numba_and_py
(
[
x
],
[
out
],
[
rng
.
integers
(
-
127
,
127
,
size
=
(
6
,
6
,
6
))
.
astype
(
"int8"
)]
)
def
test_scalar_Elemwise_Clip
():
a
=
pt
.
scalar
(
"a"
)
b
=
pt
.
scalar
(
"b"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论