Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
43fb2c4a
MegEngine
项目概览
MegEngine 天元
/
MegEngine
9 个月 前同步成功
通知
392
Star
4702
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看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
43fb2c4a
编写于
9月 14, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(opr): let roll support empty IO
GitOrigin-RevId: b9a59b623a8b16ca0a6af1340cfc226b73128321
上级
b2827cb1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
5 deletion
+31
-5
imperative/python/megengine/functional/tensor.py
imperative/python/megengine/functional/tensor.py
+4
-3
imperative/python/test/unit/functional/test_tensor.py
imperative/python/test/unit/functional/test_tensor.py
+23
-0
src/opr/impl/tensor_manip.cpp
src/opr/impl/tensor_manip.cpp
+4
-2
未找到文件。
imperative/python/megengine/functional/tensor.py
浏览文件 @
43fb2c4a
...
@@ -1352,10 +1352,11 @@ def roll(
...
@@ -1352,10 +1352,11 @@ def roll(
if
shift_
==
0
:
if
shift_
==
0
:
continue
continue
size
=
shp
[
axis_normalized_
]
size
=
shp
[
axis_normalized_
]
if
shift_
>
0
:
shift_normalized_
=
0
if
size
==
0
else
shift_
%
size
a
,
b
=
split
(
out
,
[
size
-
shift_
,],
axis
=
axis_normalized_
)
if
shift_normalized_
>
0
:
a
,
b
=
split
(
out
,
[
size
-
shift_normalized_
,],
axis
=
axis_normalized_
)
else
:
else
:
a
,
b
=
split
(
out
,
[
-
shift_
,],
axis
=
axis_normalized_
)
a
,
b
=
split
(
out
,
[
-
shift_
normalized_
,],
axis
=
axis_normalized_
)
out
=
concat
((
b
,
a
),
axis
=
axis_normalized_
)
out
=
concat
((
b
,
a
),
axis
=
axis_normalized_
)
if
shp_bak
is
not
None
:
if
shp_bak
is
not
None
:
out
=
out
.
reshape
(
shp_bak
)
out
=
out
.
reshape
(
shp_bak
)
...
...
imperative/python/test/unit/functional/test_tensor.py
浏览文件 @
43fb2c4a
...
@@ -806,6 +806,8 @@ def test_tile(shape, reps, is_varnode):
...
@@ -806,6 +806,8 @@ def test_tile(shape, reps, is_varnode):
[
[
((
2
,
3
),
0
,
None
),
((
2
,
3
),
0
,
None
),
((
2
,
3
),
1
,
0
),
((
2
,
3
),
1
,
0
),
((
2
,
3
),
100
,
0
),
((
2
,
3
),
-
100
,
0
),
((
2
,
3
,
4
,
5
),
(
-
1
,
1
),
(
0
,
1
)),
((
2
,
3
,
4
,
5
),
(
-
1
,
1
),
(
0
,
1
)),
((
2
,
3
,
4
,
5
),
(
-
2
,
1
,
2
),
(
1
,
2
,
3
)),
((
2
,
3
,
4
,
5
),
(
-
2
,
1
,
2
),
(
1
,
2
,
3
)),
],
],
...
@@ -829,3 +831,24 @@ def test_roll(shape, shifts, axis, is_varnode):
...
@@ -829,3 +831,24 @@ def test_roll(shape, shifts, axis, is_varnode):
opr_test
(
opr_test
(
cases
,
func
,
ref_fn
=
lambda
inp
:
np
.
roll
(
inp
,
shifts
,
axis
),
network
=
network
cases
,
func
,
ref_fn
=
lambda
inp
:
np
.
roll
(
inp
,
shifts
,
axis
),
network
=
network
)
)
@
pytest
.
mark
.
parametrize
(
"shape, shifts, axis"
,
[((
10
,
0
),
5
,
1
),
((
10
,
0
),
-
10
,
1
),],
)
@
pytest
.
mark
.
parametrize
(
"is_symbolic"
,
[
None
,
True
,
False
])
def
test_roll_empty_tensor
(
shape
,
shifts
,
axis
,
is_symbolic
):
inp
=
tensor
(
np
.
random
.
randn
(
*
shape
).
astype
(
"float32"
))
def
func
(
inp
):
return
F
.
roll
(
inp
,
shifts
,
axis
)
if
is_symbolic
is
not
None
:
func
=
trace
(
symbolic
=
is_symbolic
)(
func
)
out_ref
=
np
.
roll
(
inp
.
numpy
(),
shifts
,
axis
)
for
_
in
range
(
3
):
out
=
F
.
roll
(
inp
,
shifts
,
axis
)
np
.
testing
.
assert_equal
(
out
.
numpy
(),
out_ref
)
if
is_symbolic
is
None
:
break
src/opr/impl/tensor_manip.cpp
浏览文件 @
43fb2c4a
...
@@ -1339,8 +1339,10 @@ void Concat::scn_do_execute() {
...
@@ -1339,8 +1339,10 @@ void Concat::scn_do_execute() {
if
(
real_axis
<
0
)
if
(
real_axis
<
0
)
real_axis
+=
in
.
shape
().
ndim
;
real_axis
+=
in
.
shape
().
ndim
;
end
=
begin
+
in
.
shape
().
shape
[
real_axis
];
end
=
begin
+
in
.
shape
().
shape
[
real_axis
];
out
.
sub
(
Slice
(
begin
,
end
).
apply
(
out
.
layout
(),
real_axis
)).
if
(
!
in
.
layout
().
is_empty
())
{
copy_from_fixlayout
(
in
);
out
.
sub
(
Slice
(
begin
,
end
).
apply
(
out
.
layout
(),
real_axis
)).
copy_from_fixlayout
(
in
);
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录