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

Function pow

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

r"""Element-wise power. Calculates an implementation-dependent approximation of exponentiation by raising each element :math:`x_i` (the base) of the input tensor :math:`x` to the power of :math:`y_i` (the exponent), where :math:`y_i` is the corresponding element of the input tenso

(x: Tensor, y: Tensor)

Source from the content-addressed store, hash-verified

416
417
418def pow(x: Tensor, y: Tensor) -> Tensor:
419 r"""Element-wise power.
420
421 Calculates an implementation-dependent approximation of exponentiation by
422 raising each element :math:`x_i` (the base) of the input tensor :math:`x` to
423 the power of :math:`y_i` (the exponent), where :math:`y_i` is the corresponding element of the input tensor :math:`y`.
424
425 Args:
426 x: first input tensor whose elements correspond to the exponentiation base. Should have a numeric data type.
427 y: second input tensor whose elements correspond to the exponentiation exponent.
428 Must be compatible with `x` (see :ref:`broadcasting-rule` ). Should have a numeric data type.
429
430 Returns:
431 A tensor containing the element-wise results.
432 The returned tensor must have a data type determined by :ref:`dtype-promotion`.
433
434 .. note::
435
436 The unary ``**`` operator can be used as a shorthand for ``pow`` on tensors.
437
438 .. admonition:: Special cases
439
440 For floating-point operands,
441
442 * If :math:`x_i` is not equal to ``1`` and :math:`y_i` is ``NaN``, the result is ``NaN``.
443 * If :math:`y_i` is ``+0``, the result is ``1``, even if :math:`x_i` is ``NaN``.
444 * If :math:`y_i` is ``-0``, the result is ``1``, even if :math:`x_i` is ``NaN``.
445 * If :math:`x_i` is ``NaN`` and :math:`y_i` is not equal to ``0``, the result is ``NaN``.
446 * If :math:`\abs{x_i}` is greater than ``1`` and :math:`y_i` is ``+infinity``, the result is ``+infinity``.
447 * If :math:`\abs{x_i}` is greater than ``1`` and :math:`y_i` is ``-infinity``, the result is ``+0``.
448 * If :math:`\abs{x_i}` is ``1`` and :math:`y_i` is ``+infinity``, the result is ``1``.
449 * If :math:`\abs{x_i}` is ``1`` and :math:`y_i` is ``-infinity``, the result is ``1``.
450 * If :math:`x_i` is ``1`` and :math:`y_i` is not ``NaN``, the result is ``1``.
451 * If :math:`\abs{x_i}` is less than ``1`` and :math:`y_i` is ``+infinity``, the result is ``+0``.
452 * If :math:`\abs{x_i}` is less than ``1`` and :math:`y_i` is ``-infinity``, the result is ``+infinity``.
453 * If :math:`x_i` is ``+infinity`` and :math:`y_i` is greater than ``0``, the result is ``+infinity``.
454 * If :math:`x_i` is ``+infinity`` and :math:`y_i` is less than ``0``, the result is ``+0``.
455 * If :math:`x_i` is ``-infinity``, :math:`y_i` is greater than ``0``, and :math:`y_i` is an odd integer value, the result is ``-infinity``.
456 * If :math:`x_i` is ``-infinity``, :math:`y_i` is greater than ``0``, and :math:`y_i` is not an odd integer value, the result is ``+infinity``.
457 * If :math:`x_i` is ``-infinity``, :math:`y_i` is less than ``0``, and :math:`y_i` is an odd integer value, the result is ``-0``.
458 * If :math:`x_i` is ``-infinity``, :math:`y_i` is less than ``0``, and :math:`y_i` is not an odd integer value, the result is ``+0``.
459 * If :math:`x_i` is ``+0`` and :math:`y_i` is greater than ``0``, the result is ``+0``.
460 * If :math:`x_i` is ``+0`` and :math:`y_i` is less than ``0``, the result is ``+infinity``.
461 * If :math:`x_i` is ``-0``, :math:`y_i` is greater than ``0``, and :math:`y_i` is an odd integer value, the result is ``-0``.
462 * If :math:`x_i` is ``-0``, :math:`y_i` is greater than ``0``, and :math:`y_i` is not an odd integer value, the result is ``+0``.
463 * If :math:`x_i` is ``-0``, :math:`y_i` is less than ``0``, and :math:`y_i` is an odd integer value, the result is ``-infinity``.
464 * If :math:`x_i` is ``-0``, :math:`y_i` is less than ``0``, and :math:`y_i` is not an odd integer value, the result is ``+infinity``.
465 * If :math:`x_i` is less than 0, :math:`x_i` is a finite number, :math:`y_i` is a finite number, and :math:`y_i` is not an integer value, the result is ``NaN``.
466
467 Examples:
468 >>> F.pow(2.0, 3.0)
469 Tensor(8.0, device=xpux:0)
470
471 Element-wise power:
472
473 >>> x = Tensor([1, 2, 3, 4, 5])
474 >>> y = Tensor([1, 2, 1, 2, 1])
475 >>> F.pow(x, y)

Callers 4

__pow__Method · 0.50
tqt_lowerFunction · 0.50
tqt_grad_ruleFunction · 0.50
eval_funcMethod · 0.50

Calls 1

_elwiseFunction · 0.50

Tested by

no test coverage detected