Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
7fadc16d
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
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看板
提交
7fadc16d
编写于
8月 31, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(mge/functional): support tensor shape in interpolate and split
GitOrigin-RevId: 6430b64f010ea5d0ecb1caa59b6da0a1547552ae
上级
968f74ce
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
27 addition
and
24 deletion
+27
-24
imperative/python/megengine/core/tensor/utils.py
imperative/python/megengine/core/tensor/utils.py
+3
-1
imperative/python/megengine/functional/elemwise.py
imperative/python/megengine/functional/elemwise.py
+12
-5
imperative/python/megengine/functional/nn.py
imperative/python/megengine/functional/nn.py
+2
-5
imperative/python/megengine/functional/tensor.py
imperative/python/megengine/functional/tensor.py
+6
-4
imperative/python/test/unit/functional/test_elemwise.py
imperative/python/test/unit/functional/test_elemwise.py
+4
-4
imperative/python/test/unit/functional/test_functional.py
imperative/python/test/unit/functional/test_functional.py
+0
-3
imperative/python/test/unit/functional/test_tensor.py
imperative/python/test/unit/functional/test_tensor.py
+0
-2
未找到文件。
imperative/python/megengine/core/tensor/utils.py
浏览文件 @
7fadc16d
...
...
@@ -31,6 +31,8 @@ def dtype_promotion(raw_inputs):
]
inputs
=
[
i
for
i
in
raw_inputs
if
hasattr
(
i
,
"dtype"
)]
assert
len
(
scalar_inputs
+
inputs
)
>
0
dtype
=
None
if
len
(
inputs
)
>
0
:
dtype
=
np
.
result_type
(
*
inputs
)
dtype_all
=
np
.
result_type
(
*
(
inputs
+
scalar_inputs
))
assert
(
...
...
imperative/python/megengine/functional/elemwise.py
浏览文件 @
7fadc16d
...
...
@@ -10,8 +10,9 @@
import
functools
from
..core.ops
import
builtin
from
..core.tensor
import
utils
from
..core.tensor
import
megbrain_graph
,
utils
from
..core.tensor.core
import
apply
from
..device
import
get_default_device
from
..tensor
import
Tensor
__all__
=
[
...
...
@@ -76,11 +77,17 @@ __all__ = [
def
_elwise
(
*
args
,
mode
):
op
=
builtin
.
Elemwise
(
mode
=
mode
)
if
mode
in
(
"true_div"
,
"exp"
,
"pow"
,
"log"
,
"expm1"
,
"log1p"
):
args
=
tuple
(
map
(
lambda
x
:
x
.
astype
(
"float32"
)
if
hasattr
(
x
,
"dtype"
)
else
x
,
args
)
tensor_args
=
list
(
filter
(
lambda
x
:
isinstance
(
x
,
(
Tensor
,
megbrain_graph
.
VarNode
)),
args
)
)
if
len
(
tensor_args
)
==
0
:
dtype
=
utils
.
dtype_promotion
(
args
)
first_arg
=
Tensor
(
args
[
0
],
dtype
=
dtype
,
device
=
get_default_device
())
args
=
utils
.
convert_inputs
(
first_arg
,
*
args
[
1
:])
else
:
args
=
utils
.
convert_inputs
(
*
args
)
if
mode
in
(
"true_div"
,
"exp"
,
"pow"
,
"log"
,
"expm1"
,
"log1p"
):
args
=
tuple
(
map
(
lambda
x
:
x
.
astype
(
"float32"
),
args
))
(
result
,)
=
apply
(
op
,
*
args
)
return
result
...
...
imperative/python/megengine/functional/nn.py
浏览文件 @
7fadc16d
...
...
@@ -1126,11 +1126,8 @@ def interpolate(
if
mode
==
"LINEAR"
:
inp
=
add_axis
(
inp
,
3
)
if
not
isinstance
(
inp
.
shape
,
inp
.
__class__
):
if
len
(
inp
.
shape
)
!=
4
:
raise
ValueError
(
"shape of input tensor must correspond to the operartion mode"
)
if
inp
.
ndim
!=
4
:
raise
ValueError
(
"shape of input tensor must correspond to the operartion mode"
)
if
size
is
None
:
if
scale_factor
is
None
:
...
...
imperative/python/megengine/functional/tensor.py
浏览文件 @
7fadc16d
...
...
@@ -317,7 +317,7 @@ def split(inp, nsplits_or_sections, axis=0):
def
swapaxis
(
inp
,
src
,
dst
):
if
src
==
dst
:
return
inp
shape
=
[
i
for
i
in
range
(
len
(
inp
.
shape
)
)]
shape
=
[
i
for
i
in
range
(
inp
.
ndim
)]
shape
[
src
]
=
dst
shape
[
dst
]
=
src
return
inp
.
transpose
(
shape
)
...
...
@@ -325,9 +325,11 @@ def split(inp, nsplits_or_sections, axis=0):
inp
=
swapaxis
(
inp
,
0
,
axis
)
if
isinstance
(
nsplits_or_sections
,
int
):
incr_step
=
math
.
ceil
(
inp
.
shape
[
0
]
/
nsplits_or_sections
)
while
incr_step
<
inp
.
shape
[
0
]:
sections
.
append
(
incr_step
)
incr_step
=
ceil
(
inp
.
shape
[
0
]
/
nsplits_or_sections
)
nsplits
=
nsplits_or_sections
while
nsplits
>
0
:
nsplits
-=
1
sections
.
append
(
incr_step
.
astype
(
"int32"
))
incr_step
+=
nsplits_or_sections
else
:
sections
=
nsplits_or_sections
...
...
imperative/python/test/unit/functional/test_elemwise.py
浏览文件 @
7fadc16d
...
...
@@ -19,13 +19,13 @@ def test_abs():
np
.
abs
(
np
.
array
([
-
3.0
,
-
4.0
,
-
5.0
],
dtype
=
np
.
float32
)),
)
# assertTensorClose(F.abs(-3.0
), np.abs(np.float32(-3.0)))
assertTensorClose
(
F
.
abs
(
-
3.0
).
numpy
(
),
np
.
abs
(
np
.
float32
(
-
3.0
)))
def
test_multiply
():
#
assertTensorClose(
# F.mul(-3.0, -4.0
), np.multiply(np.float32(-3.0), np.float32(-4.0))
#
)
assertTensorClose
(
F
.
mul
(
-
3.0
,
-
4.0
).
numpy
(
),
np
.
multiply
(
np
.
float32
(
-
3.0
),
np
.
float32
(
-
4.0
))
)
assertTensorClose
(
F
.
mul
(
tensor
([
3.0
,
4.0
]),
4.0
).
numpy
(),
...
...
imperative/python/test/unit/functional/test_functional.py
浏览文件 @
7fadc16d
...
...
@@ -194,9 +194,6 @@ def test_matmul():
def
test_interpolate
():
if
use_tensor_shape
():
# XXX: please fix me
return
def
linear_interpolate
():
inp
=
tensor
(
np
.
arange
(
1
,
3
,
dtype
=
np
.
float32
).
reshape
(
1
,
1
,
2
))
...
...
imperative/python/test/unit/functional/test_tensor.py
浏览文件 @
7fadc16d
...
...
@@ -125,8 +125,6 @@ def test_stack():
def
test_split
():
if
use_tensor_shape
():
# XXX: please fix me
return
data
=
np
.
random
.
random
((
2
,
3
,
4
,
5
)).
astype
(
np
.
float32
)
mge_out1
=
F
.
split
(
tensor
(
data
),
2
,
axis
=
3
)
mge_out2
=
F
.
split
(
tensor
(
data
),
[
3
,
5
],
axis
=
3
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录