Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1d825dd6
提交
1d825dd6
authored
10月 04, 2025
作者:
Rob Zinkov
提交者:
Ricardo Vieira
10月 07, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add logsumexp to xtensor
上级
4312d8c6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
1 行删除
+29
-1
math.py
pytensor/xtensor/math.py
+5
-0
test_math.py
tests/xtensor/test_math.py
+24
-1
没有找到文件。
pytensor/xtensor/math.py
浏览文件 @
1d825dd6
...
...
@@ -512,6 +512,11 @@ def softmax(x, dim=None):
return
exp_x
/
exp_x
.
sum
(
dim
=
dim
)
def
logsumexp
(
x
,
dim
=
None
):
"""Compute the logsumexp of an XTensorVariable along a specified dimension."""
return
log
(
exp
(
x
)
.
sum
(
dim
=
dim
))
class
Dot
(
XOp
):
"""Matrix multiplication between two XTensorVariables.
...
...
tests/xtensor/test_math.py
浏览文件 @
1d825dd6
...
...
@@ -7,6 +7,7 @@ pytest.importorskip("xarray")
import
inspect
import
numpy
as
np
from
scipy.special
import
logsumexp
as
scipy_logsumexp
from
xarray
import
DataArray
import
pytensor.scalar
as
ps
...
...
@@ -14,7 +15,7 @@ import pytensor.xtensor.math as pxm
from
pytensor
import
function
from
pytensor.scalar
import
ScalarOp
from
pytensor.xtensor.basic
import
rename
from
pytensor.xtensor.math
import
add
,
exp
from
pytensor.xtensor.math
import
add
,
exp
,
logsumexp
from
pytensor.xtensor.type
import
xtensor
from
tests.xtensor.util
import
xr_arange_like
,
xr_assert_allclose
,
xr_function
...
...
@@ -152,6 +153,28 @@ def test_cast():
yc64
.
astype
(
"float64"
)
@pytest.mark.parametrize
(
[
"shape"
,
"dims"
,
"axis"
],
[
((
3
,
4
),
(
"a"
,
"b"
),
None
),
((
3
,
4
),
"a"
,
0
),
((
3
,
4
),
"b"
,
1
),
],
)
def
test_logsumexp
(
shape
,
dims
,
axis
):
scipy_inp
=
np
.
zeros
(
shape
)
scipy_out
=
scipy_logsumexp
(
scipy_inp
,
axis
=
axis
)
pytensor_inp
=
DataArray
(
scipy_inp
,
dims
=
(
"a"
,
"b"
))
f
=
function
([],
logsumexp
(
pytensor_inp
,
dim
=
dims
))
pytensor_out
=
f
()
np
.
testing
.
assert_array_almost_equal
(
pytensor_out
,
scipy_out
,
)
def
test_dot
():
"""Test basic dot product operations."""
# Test matrix-vector dot product (with multiple-letter dim names)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论