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: inp: input tensor. Should have a numeric data type. Returns: a tensor containing test results. An element out is
(inp: Tensor)
| 55 | |
| 56 | |
| 57 | def isnan(inp: Tensor) -> Tensor: |
| 58 | r"""Element-wise ``NaN`` check. |
| 59 | |
| 60 | Tests each element :math:`x_i` of the input tensor :math:`x` to determine whether the element is ``NaN``. |
| 61 | |
| 62 | Args: |
| 63 | inp: input tensor. Should have a numeric data type. |
| 64 | |
| 65 | Returns: |
| 66 | a tensor containing test results. |
| 67 | An element out is ``True`` if :math:`x_i` is ``NaN`` and ``False`` otherwise. |
| 68 | The returned array should have a data type of bool. |
| 69 | |
| 70 | Examples: |
| 71 | |
| 72 | >>> F.isnan(Tensor(1)) |
| 73 | Tensor(False, dtype=bool, device=xpux:0) |
| 74 | |
| 75 | .. TODO: Remove these comments when _elemwise_multi_type support scalar input |
| 76 | .. >>> F.isnan(Tensor(float("nan"))) |
| 77 | .. Tensor(True, dtype=bool, device=xpux:0) |
| 78 | |
| 79 | Element-wise isnan: |
| 80 | |
| 81 | >>> x = Tensor([1, float("nan"), 0]) |
| 82 | >>> F.isnan(x) |
| 83 | Tensor([False True False], dtype=bool, device=xpux:0) |
| 84 | """ |
| 85 | if not np.issubdtype(inp.dtype, np.floating): |
| 86 | return broadcast_to(Const(False, np.bool_, inp.device), inp.shape) |
| 87 | return _elemwise_multi_type(inp, mode="isnan", dtype="bool") |
| 88 | |
| 89 | |
| 90 | def isinf(inp: Tensor) -> Tensor: |
nothing calls this directly
no test coverage detected