Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b79d2329
Unverified
提交
b79d2329
authored
5月 07, 2024
作者:
Dhruvanshu-Joshi
提交者:
GitHub
5月 07, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement `ufunc_outer` like `add.outer` for binary `Elemwise` operations
上级
35ae5db4
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
0 行删除
+31
-0
elemwise.py
pytensor/tensor/elemwise.py
+10
-0
test_elemwise.py
tests/tensor/test_elemwise.py
+21
-0
没有找到文件。
pytensor/tensor/elemwise.py
浏览文件 @
b79d2329
...
@@ -1170,6 +1170,16 @@ class Elemwise(OpenMPOp):
...
@@ -1170,6 +1170,16 @@ class Elemwise(OpenMPOp):
else
:
else
:
return
()
return
()
def
outer
(
self
,
x
,
y
):
from
pytensor.tensor.basic
import
expand_dims
if
self
.
scalar_op
.
nin
not
in
(
-
1
,
2
):
raise
NotImplementedError
(
"outer is only available for binary operators"
)
x_
=
expand_dims
(
x
,
tuple
(
range
(
-
y
.
ndim
,
0
)))
y_
=
expand_dims
(
y
,
tuple
(
range
(
x
.
ndim
)))
return
self
(
x_
,
y_
)
class
CAReduce
(
COp
):
class
CAReduce
(
COp
):
"""Reduces a scalar operation along specified axes.
"""Reduces a scalar operation along specified axes.
...
...
tests/tensor/test_elemwise.py
浏览文件 @
b79d2329
...
@@ -8,7 +8,9 @@ import pytest
...
@@ -8,7 +8,9 @@ import pytest
import
pytensor
import
pytensor
import
pytensor.scalar
as
ps
import
pytensor.scalar
as
ps
import
pytensor.tensor
as
pt
import
tests.unittest_tools
as
utt
import
tests.unittest_tools
as
utt
from
pytensor.compile.function
import
function
from
pytensor.compile.mode
import
Mode
from
pytensor.compile.mode
import
Mode
from
pytensor.configdefaults
import
config
from
pytensor.configdefaults
import
config
from
pytensor.graph.basic
import
Apply
,
Variable
from
pytensor.graph.basic
import
Apply
,
Variable
...
@@ -893,6 +895,25 @@ class TestElemwise(unittest_tools.InferShapeTester):
...
@@ -893,6 +895,25 @@ class TestElemwise(unittest_tools.InferShapeTester):
):
):
x
+
y
x
+
y
@pytest.mark.parametrize
(
"shape_x, shape_y, op, np_op"
,
[
((
3
,
5
),
(
7
,
1
,
3
),
pt
.
add
,
np
.
add
),
((
2
,
3
),
(
1
,
4
),
pt
.
mul
,
np
.
multiply
),
],
)
def
test_outer
(
self
,
shape_x
,
shape_y
,
op
,
np_op
):
x
=
tensor
(
dtype
=
np
.
float64
,
shape
=
shape_x
)
y
=
tensor
(
dtype
=
np
.
float64
,
shape
=
shape_y
)
z
=
op
.
outer
(
x
,
y
)
f
=
function
([
x
,
y
],
z
)
x1
=
np
.
ones
(
shape_x
)
y1
=
np
.
ones
(
shape_y
)
np
.
testing
.
assert_array_equal
(
f
(
x1
,
y1
),
np_op
.
outer
(
x1
,
y1
))
def
test_not_implemented_elemwise_grad
():
def
test_not_implemented_elemwise_grad
():
# Regression test for unimplemented gradient in an Elemwise Op.
# Regression test for unimplemented gradient in an Elemwise Op.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论