r"""Element-wise :math:`\operatorname{log}(x)` function. Calculates an approximation to the natural (base :math:`e`) logarithm for each element :math:`x_i` of the input tensor :math:`x`. This function has domain ``[+0, +infinity]`` and codomain ``[-infinity, +infinity]``. Args
(x)
| 677 | |
| 678 | |
| 679 | def log(x): |
| 680 | r"""Element-wise :math:`\operatorname{log}(x)` function. |
| 681 | |
| 682 | Calculates an approximation to the natural (base :math:`e`) logarithm for each element :math:`x_i` of the input tensor :math:`x`. |
| 683 | |
| 684 | This function has domain ``[+0, +infinity]`` and codomain ``[-infinity, +infinity]``. |
| 685 | |
| 686 | Args: |
| 687 | x: input tensor. Should have a floating-point data type. |
| 688 | |
| 689 | Returns: |
| 690 | a tensor containing the evaluated natural logarithm result for each element in :math:`x`. |
| 691 | The returned tensor must have a floating-point data type determined by :ref:`dtype-promotion`. |
| 692 | |
| 693 | .. admonition:: Special cases |
| 694 | |
| 695 | For floating-point operands, |
| 696 | |
| 697 | * If :math:`x_i` is ``NaN``, the result is ``NaN``. |
| 698 | * If :math:`x_i` is less than ``0``, the result is ``NaN``. |
| 699 | * If :math:`x_i` is either ``+0`` or ``-0``, the result is ``-infinity``. |
| 700 | * If :math:`x_i` is ``1``, the result is ``+0``. |
| 701 | * If :math:`x_i` is ``+infinity``, the result is ``+infinity``. |
| 702 | |
| 703 | Examples: |
| 704 | |
| 705 | >>> F.log([1, F.exp(1)]) |
| 706 | Tensor([0. 1.], device=xpux:0) |
| 707 | |
| 708 | """ |
| 709 | return _elwise(x, mode=Elemwise.Mode.LOG) |
| 710 | |
| 711 | |
| 712 | def log1p(x): |