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

Function round

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

r"""Element-wise :math:`\operatorname{round}(x)` function. Rounds each element :math:`x_i` of the input tensor :math:`x` to the nearest integer-valued number. Args: x: input tensor. Should have a numeric data type. Returns: a tensor containing the rounded resul

(x)

Source from the content-addressed store, hash-verified

850
851
852def round(x):
853 r"""Element-wise :math:`\operatorname{round}(x)` function.
854
855 Rounds each element :math:`x_i` of the input tensor :math:`x` to the nearest integer-valued number.
856
857 Args:
858 x: input tensor. Should have a numeric data type.
859
860 Returns:
861 a tensor containing the rounded result for each element in :math:`x`.
862 The returned tensor must have the same data type as :math:`x`.
863
864 .. admonition:: Special cases
865
866 If :math:`x_i` is already integer-valued, the result is :math:`x_i`.
867
868 For floating-point operands,
869
870 * If :math:`x_i` is ``+infinity``, the result is ``+infinity``.
871 * If :math:`x_i` is ``-infinity``, the result is ``-infinity``.
872 * If :math:`x_i` is ``+0``, the result is ``+0``.
873 * If :math:`x_i` is ``-0``, the result is ``-0``.
874 * If :math:`x_i` is NaN, the result is NaN.
875 * If two integers are equally close to :math:`x_i`, the result is the even integer closest to :math:`x_i`.
876
877 Examples:
878 >>> F.round(1.5)
879 Tensor(2.0, device=xpux:0)
880
881 Element-wise rounding:
882
883 >>> x = Tensor([1.5, 2.5, 3.5, 4.5])
884 >>> F.round(x)
885 Tensor([2. 3. 4. 5.], device=xpux:0)
886 """
887 return _elwise(x, mode=Elemwise.Mode.ROUND)
888
889
890def ceil(x):

Callers 11

peak_mem_registFunction · 0.50
_get_shapeMethod · 0.50
_get_shapeMethod · 0.50
_get_coordMethod · 0.50
_get_coordMethod · 0.50
fakequant_lowerFunction · 0.50
fakequant_grad_ruleFunction · 0.50
tqt_lowerFunction · 0.50
tqt_grad_ruleFunction · 0.50
lsq_lowerFunction · 0.50
lsq_grad_ruleFunction · 0.50

Calls 1

_elwiseFunction · 0.50

Tested by

no test coverage detected