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

Function abs

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

r"""Element-wise :math:`\operatorname{abs}(x)` function. Calculates the absolute value for each element :math:`x_i` of the input tensor :math:`x`. (i.e., the element-wise result has the same magnitude as the respective element in x but has positive sign). Args: x: input ten

(x)

Source from the content-addressed store, hash-verified

555
556
557def abs(x):
558 r"""Element-wise :math:`\operatorname{abs}(x)` function.
559
560 Calculates the absolute value for each element :math:`x_i` of the input tensor :math:`x`.
561 (i.e., the element-wise result has the same magnitude as the respective element in x but has positive sign).
562
563 Args:
564 x: input tensor. Should have a numeric data type.
565
566 Returns:
567
568 a tensor containing the absolute value of each element in :math:`x`.
569 The returned tensor must have the same data type as :math:`x`.
570
571 .. admonition:: Special cases
572
573 For floating-point operands,
574
575 * If :math:`x_i` is ``NaN``, the result is ``NaN``.
576 * If :math:`x_i` is ``-0``, the result is ``+0``.
577 * If :math:`x_i` is ``-infinity``, the result is ``+infinity``.
578
579 Examples:
580 >>> F.abs(-2)
581 Tensor(2, dtype=int32, device=xpux:0)
582
583 Element-wise absolution:
584
585 >>> x = Tensor([1, -2, 3, -4, 5])
586 >>> F.abs(x)
587 Tensor([1 2 3 4 5], dtype=int32, device=xpux:0)
588 """
589 return _elwise(x, mode=Elemwise.Mode.ABS)
590
591
592def exp(x):

Callers 10

l1_lossFunction · 0.70
_assert_equalFunction · 0.70
normFunction · 0.70
sizeof_fmtFunction · 0.50
sampleMethod · 0.50
logsigmoidFunction · 0.50
softplusFunction · 0.50
softplus_gradFunction · 0.50
test_correlationFunction · 0.50
deduce_layoutFunction · 0.50

Calls 1

_elwiseFunction · 0.50

Tested by 1

test_correlationFunction · 0.40