MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / log1p

Function log1p

imperative/python/megengine/functional/elemwise.py:712–759  ·  view source on GitHub ↗

r"""Element-wise :math:`\log(1 + x)` function. Calculates an approximation to :math:`\log(1 + x)`: .. math:: y_i = \log(1 + x_i) where log refers to the natural (base :math:`e`) logarithm, for each element :math:`x_i` of the input tensor :math:`x`. This functio

(x)

Source from the content-addressed store, hash-verified

710
711
712def log1p(x):
713 r"""Element-wise :math:`\log(1 + x)` function.
714
715 Calculates an approximation to :math:`\log(1 + x)`:
716
717 .. math::
718
719 y_i = \log(1 + x_i)
720
721 where log refers to the natural (base :math:`e`) logarithm,
722 for each element :math:`x_i` of the input tensor :math:`x`.
723
724 This function has domain ``[-1, +infinity]`` and codomain ``[-infinity, +infinity]``.
725
726 Args:
727 x: input tensor. Should have a floating-point data type.
728
729 Returns:
730
731 a tensor containing the evaluated result for each element in :math:`x`.
732 The returned tensor must have a floating-point data type determined by :ref:`dtype-promotion`.
733
734 .. note::
735
736 This function is more accurate than :math:`\log(1+x)` for small values of input.
737 See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.
738
739
740 .. admonition:: Special cases
741
742 For floating-point operands,
743
744 * If :math:`x_i` is ``NaN``, the result is ``NaN``.
745 * If :math:`x_i` is less than ``-1``, the result is ``NaN``.
746 * If :math:`x_i` is ``-1``, the result is ``-infinity``.
747 * If :math:`x_i` is ``-0``, the result is ``-0``.
748 * If :math:`x_i` is ``+0``, the result is ``+0``.
749 * If :math:`x_i` is ``+infinity``, the result is ``+infinity``.
750
751 Examples:
752
753 >>> F.log(1e-10 + 1)
754 Tensor(0.0, device=xpux:0)
755 >>> F.log1p(1e-10)
756 Tensor(1e-10, device=xpux:0)
757
758 """
759 return _elwise(x, mode=Elemwise.Mode.LOG1P)
760
761
762def sqrt(x: Tensor) -> Tensor:

Callers 3

log_add_expFunction · 0.50
logsigmoidFunction · 0.50
softplusFunction · 0.50

Calls 1

_elwiseFunction · 0.50

Tested by

no test coverage detected