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
- 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 forpowon tensors.Special cases
For floating-point operands,
If \(x_i\) is not equal to
1and \(y_i\) isNaN, the result isNaN.If \(y_i\) is
+0, the result is1, even if \(x_i\) isNaN.If \(y_i\) is
-0, the result is1, even if \(x_i\) isNaN.If \(x_i\) is
NaNand \(y_i\) is not equal to0, the result isNaN.If \(\abs{x_i}\) is greater than
1and \(y_i\) is+infinity, the result is+infinity.If \(\abs{x_i}\) is greater than
1and \(y_i\) is-infinity, the result is+0.If \(\abs{x_i}\) is
1and \(y_i\) is+infinity, the result is1.If \(\abs{x_i}\) is
1and \(y_i\) is-infinity, the result is1.If \(x_i\) is
1and \(y_i\) is notNaN, the result is1.If \(\abs{x_i}\) is less than
1and \(y_i\) is+infinity, the result is+0.If \(\abs{x_i}\) is less than
1and \(y_i\) is-infinity, the result is+infinity.If \(x_i\) is
+infinityand \(y_i\) is greater than0, the result is+infinity.If \(x_i\) is
+infinityand \(y_i\) is less than0, the result is+0.If \(x_i\) is
-infinity, \(y_i\) is greater than0, and \(y_i\) is an odd integer value, the result is-infinity.If \(x_i\) is
-infinity, \(y_i\) is greater than0, and \(y_i\) is not an odd integer value, the result is+infinity.If \(x_i\) is
-infinity, \(y_i\) is less than0, and \(y_i\) is an odd integer value, the result is-0.If \(x_i\) is
-infinity, \(y_i\) is less than0, and \(y_i\) is not an odd integer value, the result is+0.If \(x_i\) is
+0and \(y_i\) is greater than0, the result is+0.If \(x_i\) is
+0and \(y_i\) is less than0, the result is+infinity.If \(x_i\) is
-0, \(y_i\) is greater than0, and \(y_i\) is an odd integer value, the result is-0.If \(x_i\) is
-0, \(y_i\) is greater than0, and \(y_i\) is not an odd integer value, the result is+0.If \(x_i\) is
-0, \(y_i\) is less than0, and \(y_i\) is an odd integer value, the result is-infinity.If \(x_i\) is
-0, \(y_i\) is less than0, 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)