提交 f62f2615 编写于 作者: M Megvii Engine Team

docs(mge/functional): enhance functional elemwise docstring

GitOrigin-RevId: 5987ed3b5980af6a2949cc5225c9bf0bb56ef587
上级 07d94c41
...@@ -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.
先完成此消息的编辑!
想要评论请 注册