Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
000663c3
MegEngine
项目概览
MegEngine 天元
/
MegEngine
12 个月 前同步成功
通知
393
Star
4704
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,发现更多精彩内容 >>
提交
000663c3
编写于
4月 21, 2020
作者:
M
Megvii Engine Team
提交者:
Xinran Xu
5月 06, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mge/functional): add isnan and isinf oprs
GitOrigin-RevId: b4a347751c2022a2b0b2eca5a7e62c625b5e8c27
上级
ccc95ad2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
0 deletion
+60
-0
python_module/megengine/functional/__init__.py
python_module/megengine/functional/__init__.py
+2
-0
python_module/megengine/functional/elemwise.py
python_module/megengine/functional/elemwise.py
+48
-0
python_module/test/unit/functional/test_elemwise.py
python_module/test/unit/functional/test_elemwise.py
+10
-0
未找到文件。
python_module/megengine/functional/__init__.py
浏览文件 @
000663c3
...
...
@@ -21,6 +21,8 @@ from .elemwise import (
floor
,
greater
,
greater_equal
,
isinf
,
isnan
,
less
,
less_equal
,
log
,
...
...
python_module/megengine/functional/elemwise.py
浏览文件 @
000663c3
...
...
@@ -27,6 +27,8 @@ __all__ = [
"greater"
,
"greater_equal"
,
"floor"
,
"isinf"
,
"isnan"
,
"less"
,
"less_equal"
,
"log"
,
...
...
@@ -244,3 +246,49 @@ def clamp(inp: Tensor, lower=None, upper=None) -> Tensor:
return
maximum
(
inp
,
lower
)
else
:
return
minimum
(
inp
,
upper
)
def
isnan
(
inp
:
Tensor
)
->
Tensor
:
r
"""Returns a new tensor representing if each element is NaN or not.
:param: inp
:return: a new tensor representing if each element in :attr:`inp` is NaN or not.
Examples:
.. testcode::
from megengine import tensor
import megengine.functional as F
x = tensor([1, float("nan"), 0])
print(F.isnan(x))
.. testoutput::
Tensor([0 1 0], dtype=uint8)
"""
return
(
inp
!=
inp
).
astype
(
"uint8"
)
def
isinf
(
inp
:
Tensor
)
->
Tensor
:
r
"""Returns a new tensor representing if each element is Inf or not.
:param: inp
:return: a new tensor representing if each element in :attr:`inp` is Inf or not.
Examples:
.. testcode::
from megengine import tensor
import megengine.functional as F
x = tensor([1, float("inf"), 0])
print(F.isinf(x))
.. testoutput::
Tensor([0 1 0], dtype=uint8)
"""
return
(
abs
(
inp
)
==
float
(
"inf"
)).
astype
(
"uint8"
)
python_module/test/unit/functional/test_elemwise.py
浏览文件 @
000663c3
...
...
@@ -53,3 +53,13 @@ def test_clamp():
x
=
np
.
linspace
(
-
6
,
6
,
dtype
=
"float32"
)
assertTensorClose
(
F
.
clamp
(
tensor
(
x
)
+
3
,
0
,
6
).
numpy
(),
np
.
clip
(
x
+
3
,
0
,
6
))
assertTensorClose
(
F
.
clamp
(
tensor
(
x
)
-
3
,
-
6
,
0
).
numpy
(),
np
.
clip
(
x
-
3
,
-
6
,
0
))
def
test_isnan
():
for
case
in
[[
1
,
float
(
"nan"
),
0
]]:
assertTensorClose
(
F
.
isnan
(
tensor
(
case
)),
np
.
isnan
(
case
).
astype
(
"uint8"
))
def
test_isinf
():
for
case
in
[[
1
,
float
(
"inf"
),
0
]]:
assertTensorClose
(
F
.
isinf
(
tensor
(
case
)),
np
.
isinf
(
case
).
astype
(
"uint8"
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录