megengine.functional.log1p#

log1p(x)[source]#

Element-wise \(\log(1 + x)\) function.

Calculates an approximation to \(\log(1 + x)\):

\[y_i = \log(1 + x_i)\]

where log refers to the natural (base \(e\)) logarithm, for each element \(x_i\) of the input tensor \(x\).

This function has domain [-1, +infinity] and codomain [-infinity, +infinity].

Parameters:

x – input tensor. Should have a floating-point data type.

Returns:

a tensor containing the evaluated result for each element in \(x\). The returned tensor must have a floating-point data type determined by Type promotion rules.

Note

This function is more accurate than \(\log(1+x)\) for small values of input. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.

Special cases

For floating-point operands,

  • If \(x_i\) is NaN, the result is NaN.

  • If \(x_i\) is less than -1, the result is NaN.

  • If \(x_i\) is -1, the result is -infinity.

  • If \(x_i\) is -0, the result is -0.

  • If \(x_i\) is +0, the result is +0.

  • If \(x_i\) is +infinity, the result is +infinity.

Examples

>>> F.log(1e-10 + 1)
Tensor(0.0, device=xpux:0)
>>> F.log1p(1e-10)
Tensor(1e-10, device=xpux:0)