megengine.functional.log

log(x)[source]

Element-wise \(\operatorname{log}(x)\) function.

Calculates an approximation to the natural (base \(e\)) logarithm for each element \(x_i\) of the input tensor \(x\).

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

Parameters

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

Returns

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

Special cases

For floating-point operands,

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

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

  • If \(x_i\) is either +0 or -0, the result is -infinity.

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

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

Examples

>>> F.log([1, F.exp(1)])
Tensor([0. 1.], device=xpux:0)