Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
f62f2615
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看板
提交
f62f2615
编写于
9月 14, 2022
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs(mge/functional): enhance functional elemwise docstring
GitOrigin-RevId: 5987ed3b5980af6a2949cc5225c9bf0bb56ef587
上级
07d94c41
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
1550 addition
and
187 deletion
+1550
-187
imperative/python/megengine/functional/elemwise.py
imperative/python/megengine/functional/elemwise.py
+1509
-172
imperative/python/megengine/functional/math.py
imperative/python/megengine/functional/math.py
+41
-15
未找到文件。
imperative/python/megengine/functional/elemwise.py
浏览文件 @
f62f2615
此差异已折叠。
点击以展开。
imperative/python/megengine/functional/math.py
浏览文件 @
f62f2615
...
@@ -38,55 +38,81 @@ __all__ = [
...
@@ -38,55 +38,81 @@ __all__ = [
]
]
# TODO: Should be moved to elemwise - logical functions
def
isnan
(
inp
:
Tensor
)
->
Tensor
:
def
isnan
(
inp
:
Tensor
)
->
Tensor
:
r
"""Returns a new tensor representing if each element is ``NaN`` or not.
r
"""Element-wise ``NaN`` check.
Tests each element :math:`x_i` of the input tensor :math:`x` to determine whether the element is ``NaN``.
Args:
Args:
inp: input tensor.
inp: input tensor.
Should have a numeric data type.
Returns:
Returns:
result tensor.
a tensor containing test results.
An element out is ``True`` if :math:`x_i` is ``NaN`` and ``False`` otherwise.
The returned array should have a data type of bool.
Examples:
Examples:
>>> x = Tensor([1, float("nan"), 0])
>>> x = Tensor([1, float("nan"), 0])
>>> F.isnan(x)
.numpy()
>>> F.isnan(x)
array([False, True, False]
)
Tensor([False True False], dtype=bool, device=xpux:0
)
"""
"""
return
_elemwise_multi_type
(
inp
,
mode
=
"isnan"
,
dtype
=
"bool"
)
return
_elemwise_multi_type
(
inp
,
mode
=
"isnan"
,
dtype
=
"bool"
)
def
isinf
(
inp
:
Tensor
)
->
Tensor
:
def
isinf
(
inp
:
Tensor
)
->
Tensor
:
r
"""Returns a new tensor representing if each element is ``Inf`` or not.
r
"""Element-wise ``infinity`` check.
Tests each element :math:`x_i` of the input tensor :math:`x` to determine
whether the element is if equal to positive or negative infinity.
Args:
Args:
inp: input tensor.
inp: input tensor.
Should have a numeric data type.
Returns:
Returns:
result tensor.
a tensor containing test results.
An element out is ``True`` if :math:`x_i` is either positive or negative infinity and ``False`` otherwise.
The returned array should have a data type of bool.
Examples:
Examples:
>>> x = Tensor([1, float("inf"), 0])
>>> x = Tensor([1, float("inf"), 0])
>>> F.isinf(x)
.numpy()
>>> F.isinf(x)
array([False, True, False]
)
Tensor([False True False], dtype=bool, device=xpux:0
)
"""
"""
return
_elemwise_multi_type
(
inp
,
mode
=
"isinf"
,
dtype
=
"bool"
)
return
_elemwise_multi_type
(
inp
,
mode
=
"isinf"
,
dtype
=
"bool"
)
def
sign
(
inp
:
Tensor
):
# TODO: Should be moved to elemwise - arithmetic operations
r
"""Returns a new tensor representing the sign of each element in input tensor.
def
sign
(
x
:
Tensor
):
r
"""Element-wise sign.
Returns an indication of the sign of a number for each element :math:`x_i` of the input tensor :math:`x`.
Args:
Args:
inp:
Tensor:
inp:
input tensor. Should have a numeric data type.
Returns:
Returns:
the sign of input tensor.
a tensor containing the evaluated result for each element in :math:`x`.
The returned array must have the same data type as :math:`x`.
Examples:
Examples:
Element-wise sign:
>>> x = Tensor([1, -1, 0])
>>> x = Tensor([1, -1, 0])
>>> F.sign(x)
>>> F.sign(x)
Tensor([ 1 -1 0], dtype=int32, device=xpux:0)
Tensor([ 1 -1 0], dtype=int32, device=xpux:0)
"""
"""
return
(
inp
>
0
).
astype
(
inp
.
dtype
)
-
(
inp
<
0
).
astype
(
inp
.
dtype
)
return
(
x
>
0
).
astype
(
x
.
dtype
)
-
(
x
<
0
).
astype
(
x
.
dtype
)
# statistical functions
def
sum
(
def
sum
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录