Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
8563f514
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
8563f514
编写于
6月 06, 2022
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(imperative): fix buildin reduce keepdim
GitOrigin-RevId: 38d90ab38adeaa139c420109a558b630125bcace
上级
96d90be1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
2 deletion
+19
-2
imperative/python/test/unit/functional/test_math.py
imperative/python/test/unit/functional/test_math.py
+17
-0
imperative/src/impl/ops/reduce.cpp
imperative/src/impl/ops/reduce.cpp
+1
-1
src/core/include/megbrain/ir/ops.td
src/core/include/megbrain/ir/ops.td
+1
-1
未找到文件。
imperative/python/test/unit/functional/test_math.py
浏览文件 @
8563f514
...
...
@@ -7,6 +7,8 @@ from utils import opr_test
import
megengine.functional
as
F
from
megengine
import
jit
,
tensor
from
megengine.core._imperative_rt.core2
import
apply
from
megengine.core.ops
import
builtin
def
common_test_reduce
(
opr
,
ref_opr
):
...
...
@@ -182,6 +184,21 @@ def test_sum_neg_axis():
F
.
sum
(
tensor
(
data
),
axis
=
(
-
1
,
1
))
def
test_builtin_reduce
():
shape
=
(
2
,
3
,
3
,
2
)
data
=
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
for
axis
in
(
-
1
,
-
2
,
0
,
1
):
for
keepdims
in
(
True
,
False
):
op
=
builtin
.
Reduce
(
mode
=
"sum"
,
axis
=
axis
,
keepdim
=
keepdims
)
get
=
apply
(
op
,
tensor
(
data
))[
0
]
def_op
=
builtin
.
Reduce
(
mode
=
"sum"
,
axis
=
axis
)
def_get
=
apply
(
def_op
,
tensor
(
data
))[
0
]
ref
=
np
.
sum
(
data
,
axis
=
axis
,
keepdims
=
keepdims
)
np
.
testing
.
assert_allclose
(
get
.
numpy
(),
ref
,
rtol
=
1e-6
)
if
keepdims
==
True
:
np
.
testing
.
assert_allclose
(
def_get
.
numpy
(),
ref
,
rtol
=
1e-6
)
def
test_non_finite
():
shape
=
(
32
,
3
,
32
,
32
)
data
=
[]
...
...
imperative/src/impl/ops/reduce.cpp
浏览文件 @
8563f514
...
...
@@ -222,7 +222,7 @@ std::tuple<SmallVector<LogicalTensorDesc>, bool> infer_output_attrs_fallible(
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
dests
[
i
].
comp_node
=
inputs
[
i
].
comp_node
;
dests
[
i
].
layout
=
inputs
[
i
].
layout
;
if
(
not
keepdim
&&
dests
[
i
].
layout
.
ndim
>
1
)
{
if
(
!
keepdim
&&
dests
[
i
].
layout
.
ndim
>
1
)
{
dests
[
i
].
layout
.
remove_axis_inplace
(
axis
);
}
else
{
dests
[
i
].
layout
.
shape
[
axis
]
=
1
;
...
...
src/core/include/megbrain/ir/ops.td
浏览文件 @
8563f514
...
...
@@ -16,7 +16,7 @@ def Elemwise : MgbHashableOp<"Elemwise", [ElemwiseParam], [NoSideEffect]> {
def Reduce: MgbHashableOp<"Reduce", [ReduceParam]>{
let extraArguments = (ins
Mgb
BoolAttr
:$keepdim
Mgb
DefaultValuedAttr<MgbBoolAttr, "true">
:$keepdim
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录