Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
e034874a
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
404
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看板
提交
e034874a
编写于
10月 09, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mge): rename clamp -> clip
GitOrigin-RevId: 2b594a611ebc158c85b86f05c2307e0b9685548c
上级
912d733e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
14 addition
and
14 deletion
+14
-14
imperative/python/megengine/functional/elemwise.py
imperative/python/megengine/functional/elemwise.py
+6
-6
imperative/python/megengine/functional/math.py
imperative/python/megengine/functional/math.py
+5
-5
imperative/python/test/unit/functional/test_elemwise.py
imperative/python/test/unit/functional/test_elemwise.py
+3
-3
未找到文件。
imperative/python/megengine/functional/elemwise.py
浏览文件 @
e034874a
...
...
@@ -26,7 +26,7 @@ __all__ = [
"acosh"
,
"atanh"
,
"ceil"
,
"cl
am
p"
,
"cl
i
p"
,
"cos"
,
"cosh"
,
"div"
,
...
...
@@ -547,7 +547,7 @@ def sigmoid(x):
return
_elwise
(
x
,
mode
=
"sigmoid"
)
def
cl
am
p
(
x
:
Tensor
,
lower
=
None
,
upper
=
None
)
->
Tensor
:
def
cl
i
p
(
x
:
Tensor
,
lower
=
None
,
upper
=
None
)
->
Tensor
:
r
"""Clamps all elements in input tensor into the range `[` :attr:`lower`, :attr:`upper` `]` and returns
a resulting tensor:
...
...
@@ -572,9 +572,9 @@ def clamp(x: Tensor, lower=None, upper=None) -> Tensor:
import megengine.functional as F
a = tensor(np.arange(5).astype(np.int32))
print(F.cl
am
p(a, 2, 4).numpy())
print(F.cl
am
p(a, lower=3).numpy())
print(F.cl
am
p(a, upper=3).numpy())
print(F.cl
i
p(a, 2, 4).numpy())
print(F.cl
i
p(a, lower=3).numpy())
print(F.cl
i
p(a, upper=3).numpy())
Outputs:
...
...
@@ -590,7 +590,7 @@ def clamp(x: Tensor, lower=None, upper=None) -> Tensor:
),
"At least one of 'lower' or 'upper' must not be None"
if
lower
is
not
None
:
if
upper
is
not
None
:
assert
lower
<=
upper
,
"cl
am
p lower bound is bigger that upper bound"
assert
lower
<=
upper
,
"cl
i
p lower bound is bigger that upper bound"
return
minimum
(
maximum
(
x
,
lower
),
upper
)
else
:
return
maximum
(
x
,
lower
)
...
...
imperative/python/megengine/functional/math.py
浏览文件 @
e034874a
...
...
@@ -18,7 +18,7 @@ from ..core.ops.special import Const
from
..core.tensor
import
utils
from
..core.tensor.core
import
TensorBase
,
TensorWrapperBase
,
apply
from
..tensor
import
Tensor
from
.elemwise
import
cl
am
p
,
exp
,
log
,
log1p
from
.elemwise
import
cl
i
p
,
exp
,
log
,
log1p
from
.tensor
import
add_axis
,
remove_axis
,
reshape
__all__
=
[
...
...
@@ -557,9 +557,9 @@ def normalize(
:return: normalized output tensor.
"""
if
axis
is
None
:
return
inp
/
cl
am
p
(
norm
(
inp
,
p
,
axis
),
lower
=
eps
)
return
inp
/
cl
i
p
(
norm
(
inp
,
p
,
axis
),
lower
=
eps
)
else
:
return
inp
/
cl
am
p
(
norm
(
inp
,
p
,
axis
,
keepdims
=
True
),
lower
=
eps
)
return
inp
/
cl
i
p
(
norm
(
inp
,
p
,
axis
,
keepdims
=
True
),
lower
=
eps
)
def
argsort
(
inp
:
Tensor
,
descending
:
bool
=
False
)
->
Tensor
:
...
...
imperative/python/test/unit/functional/test_elemwise.py
浏览文件 @
e034874a
...
...
@@ -47,14 +47,14 @@ def test_multiply():
def
test_clamp
():
"""Fix an issue when `lower` or `upper` is 0, it will be recognized as `False` and
`F.cl
am
p` will fall into wrong conditions unexpectedly.
`F.cl
i
p` will fall into wrong conditions unexpectedly.
"""
x
=
np
.
linspace
(
-
6
,
6
,
dtype
=
"float32"
)
np
.
testing
.
assert_allclose
(
F
.
cl
am
p
(
tensor
(
x
)
+
3
,
0
,
6
).
numpy
(),
np
.
clip
(
x
+
3
,
0
,
6
)
F
.
cl
i
p
(
tensor
(
x
)
+
3
,
0
,
6
).
numpy
(),
np
.
clip
(
x
+
3
,
0
,
6
)
)
np
.
testing
.
assert_allclose
(
F
.
cl
am
p
(
tensor
(
x
)
-
3
,
-
6
,
0
).
numpy
(),
np
.
clip
(
x
-
3
,
-
6
,
0
)
F
.
cl
i
p
(
tensor
(
x
)
-
3
,
-
6
,
0
).
numpy
(),
np
.
clip
(
x
-
3
,
-
6
,
0
)
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录