Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fcd46689
提交
fcd46689
authored
6月 21, 2021
作者:
Ricardo
提交者:
Brandon T. Willard
6月 21, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add `logaddexp`
Closes #467
上级
ecd6a1e9
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
60 行增加
和
0 行删除
+60
-0
math.py
aesara/tensor/math.py
+20
-0
test_math.py
tests/tensor/test_math.py
+40
-0
没有找到文件。
aesara/tensor/math.py
浏览文件 @
fcd46689
...
...
@@ -2764,6 +2764,25 @@ def power(x, y):
return
x
**
y
def
logaddexp
(
*
xs
):
"""Logarithm of the sum of exponentiations of the inputs.
See ``numpy.logaddexp``.
Parameters
----------
xs : symbolic tensors
Input
Returns
-------
tensor
"""
return
log
(
add
(
*
[
exp
(
x
)
for
x
in
xs
]))
def
logsumexp
(
x
,
axis
=
None
,
keepdims
=
False
):
"""Compute the log of the sum of exponentials of input elements.
...
...
@@ -2913,5 +2932,6 @@ __all__ = [
"all"
,
"ptp"
,
"power"
,
"logaddexp"
,
"logsumexp"
,
]
tests/tensor/test_math.py
浏览文件 @
fcd46689
...
...
@@ -76,6 +76,7 @@ from aesara.tensor.math import (
log1p
,
log2
,
log10
,
logaddexp
,
logsumexp
,
max
,
max_and_argmax
,
...
...
@@ -125,6 +126,7 @@ from aesara.tensor.type import (
matrices
,
matrix
,
scalar
,
scalars
,
tensor
,
tensor3
,
tensor4
,
...
...
@@ -3277,6 +3279,44 @@ def test_tanh_grad_broadcast():
grad
(
tanh
(
x
+
y
)
.
sum
(),
[
x
,
y
])
def
test_logaddexp
():
# Test more than two multidimensional inputs
x
,
y
,
z
=
matrices
(
"x"
,
"y"
,
"z"
)
out
=
logaddexp
(
x
,
y
,
z
)
f
=
function
([
x
,
y
,
z
],
out
)
inp
=
np
.
zeros
((
3
,
3
),
dtype
=
config
.
floatX
)
np
.
testing
.
assert_allclose
(
f
(
inp
,
inp
,
inp
),
np
.
full
((
3
,
3
),
np
.
log
(
3
)),
)
# Test scalar inputs
x
,
y
=
scalars
(
"x"
,
"y"
)
out
=
logaddexp
(
x
,
y
)
f
=
function
([
x
,
y
],
out
)
res
=
f
(
0
,
0
)
assert
np
.
ndim
(
res
)
==
0
assert
np
.
isclose
(
res
,
np
.
log
(
2
))
# Test scalar and matrix inputs
x
=
scalar
(
"x"
)
y
=
matrix
(
"y"
)
out
=
logaddexp
(
x
,
y
)
f
=
function
([
x
,
y
],
out
)
res
=
f
(
np
.
array
(
0
,
dtype
=
config
.
floatX
),
np
.
zeros
((
3
,
3
),
dtype
=
config
.
floatX
),
)
assert
np
.
shape
(
res
)
==
(
3
,
3
)
np
.
testing
.
assert_allclose
(
res
,
np
.
full
((
3
,
3
),
np
.
log
(
2
)),
)
@pytest.mark.parametrize
(
[
"shape"
,
"axis"
],
[
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论