megengine.functional.round#

round(x)[source]#

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

Rounds each element \(x_i\) of the input tebsor \(x\) to the nearest integer-valued number.

Parameters:

x – input tensor. Should have a numeric data type.

Returns:

a tensor containing the rounded result for each element in \(x\). The returned tensor must have the same data type as \(x\).

Special cases

If \(x_i\) is already integer-valued, the result is \(x_i\).

For floating-point operands,

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

  • If \(x_i\) is -infinity, 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 NaN, the result is NaN.

  • If two integers are equally close to \(x_i\), the result is the even integer closest to \(x_i\).

Examples

>>> F.round(1.5)
Tensor(2.0, device=xpux:0)

Element-wise rounding:

>>> x = Tensor([1.5, 2.5, 3.5, 4.5])
>>> F.round(x)
Tensor([2. 3. 4. 5.], device=xpux:0)