megengine.functional.pow#

pow(x, y)[source]#

Element-wise power.

Calculates an implementation-dependent approximation of exponentiation by raising each element \(x_i\) (the base) of the input tensor \(x\) to the power of \(y_i\) (the exponent), where \(y_i\) is the corresponding element of the input tensor \(y\).

Parameters:
  • x (Tensor) – first input tensor whose elements correspond to the exponentiation base. Should have a numeric data type.

  • y (Tensor) – second input tensor whose elements correspond to the exponentiation exponent. Must be compatible with x (see Broadcasting mechanism and rules ). Should have a numeric data type.

Return type:

Tensor

Returns:

A tensor containing the element-wise results. The returned tensor must have a data type determined by Type promotion rules.

Note

The unary ** operator can be used as a shorthand for pow on tensors.

Special cases

For floating-point operands,

  • If \(x_i\) is not equal to 1 and \(y_i\) is NaN, the result is NaN.

  • If \(y_i\) is +0, the result is 1, even if \(x_i\) is NaN.

  • If \(y_i\) is -0, the result is 1, even if \(x_i\) is NaN.

  • If \(x_i\) is NaN and \(y_i\) is not equal to 0, the result is NaN.

  • If \(\abs{x_i}\) is greater than 1 and \(y_i\) is +infinity, the result is +infinity.

  • If \(\abs{x_i}\) is greater than 1 and \(y_i\) is -infinity, the result is +0.

  • If \(\abs{x_i}\) is 1 and \(y_i\) is +infinity, the result is 1.

  • If \(\abs{x_i}\) is 1 and \(y_i\) is -infinity, the result is 1.

  • If \(x_i\) is 1 and \(y_i\) is not NaN, the result is 1.

  • If \(\abs{x_i}\) is less than 1 and \(y_i\) is +infinity, the result is +0.

  • If \(\abs{x_i}\) is less than 1 and \(y_i\) is -infinity, the result is +infinity.

  • If \(x_i\) is +infinity and \(y_i\) is greater than 0, the result is +infinity.

  • If \(x_i\) is +infinity and \(y_i\) is less than 0, the result is +0.

  • If \(x_i\) is -infinity, \(y_i\) is greater than 0, and \(y_i\) is an odd integer value, the result is -infinity.

  • If \(x_i\) is -infinity, \(y_i\) is greater than 0, and \(y_i\) is not an odd integer value, the result is +infinity.

  • If \(x_i\) is -infinity, \(y_i\) is less than 0, and \(y_i\) is an odd integer value, the result is -0.

  • If \(x_i\) is -infinity, \(y_i\) is less than 0, and \(y_i\) is not an odd integer value, the result is +0.

  • If \(x_i\) is +0 and \(y_i\) is greater than 0, the result is +0.

  • If \(x_i\) is +0 and \(y_i\) is less than 0, the result is +infinity.

  • If \(x_i\) is -0, \(y_i\) is greater than 0, and \(y_i\) is an odd integer value, the result is -0.

  • If \(x_i\) is -0, \(y_i\) is greater than 0, and \(y_i\) is not an odd integer value, the result is +0.

  • If \(x_i\) is -0, \(y_i\) is less than 0, and \(y_i\) is an odd integer value, the result is -infinity.

  • If \(x_i\) is -0, \(y_i\) is less than 0, and \(y_i\) is not an odd integer value, the result is +infinity.

  • If \(x_i\) is less than 0, \(x_i\) is a finite number, \(y_i\) is a finite number, and \(y_i\) is not an integer value, the result is NaN.

Examples

>>> F.pow(2.0, 3.0)
Tensor(8.0, device=xpux:0)

Element-wise power:

>>> x = Tensor([1, 2, 3, 4, 5])
>>> y = Tensor([1, 2, 1, 2, 1])
>>> F.pow(x, y)
Tensor([ 1.  4.  3. 16.  5.], device=xpux:0)

Broadcasting:

>>> F.pow(x, 2)
Tensor([ 1.  4.  9. 16. 25.], device=xpux:0)