r"""Element-wise :math:`\operatorname{abs}(x)` function. Calculates the absolute value for each element :math:`x_i` of the input tensor :math:`x`. (i.e., the element-wise result has the same magnitude as the respective element in x but has positive sign). Args: x: input ten
(x)
| 555 | |
| 556 | |
| 557 | def abs(x): |
| 558 | r"""Element-wise :math:`\operatorname{abs}(x)` function. |
| 559 | |
| 560 | Calculates the absolute value for each element :math:`x_i` of the input tensor :math:`x`. |
| 561 | (i.e., the element-wise result has the same magnitude as the respective element in x but has positive sign). |
| 562 | |
| 563 | Args: |
| 564 | x: input tensor. Should have a numeric data type. |
| 565 | |
| 566 | Returns: |
| 567 | |
| 568 | a tensor containing the absolute value of each element in :math:`x`. |
| 569 | The returned tensor must have the same data type as :math:`x`. |
| 570 | |
| 571 | .. admonition:: Special cases |
| 572 | |
| 573 | For floating-point operands, |
| 574 | |
| 575 | * If :math:`x_i` is ``NaN``, the result is ``NaN``. |
| 576 | * If :math:`x_i` is ``-0``, the result is ``+0``. |
| 577 | * If :math:`x_i` is ``-infinity``, the result is ``+infinity``. |
| 578 | |
| 579 | Examples: |
| 580 | >>> F.abs(-2) |
| 581 | Tensor(2, dtype=int32, device=xpux:0) |
| 582 | |
| 583 | Element-wise absolution: |
| 584 | |
| 585 | >>> x = Tensor([1, -2, 3, -4, 5]) |
| 586 | >>> F.abs(x) |
| 587 | Tensor([1 2 3 4 5], dtype=int32, device=xpux:0) |
| 588 | """ |
| 589 | return _elwise(x, mode=Elemwise.Mode.ABS) |
| 590 | |
| 591 | |
| 592 | def exp(x): |