megengine.functional.pow¶
- pow(x, y)[源代码]¶
Element-wise power.
一种特定实现的近似取幂运算,将张量 \(x\) 中的每一个元素 \(x_i\) (底数) 跟张量 \(y\) 中每一个元素 \(y_i\) (指数)做幂运算。
- 参数
- 返回类型
- 返回
返回一个逐元素运算之后的 Tensor,其数值类型由 类型提升规则 规则决定。
注解
可以使用
**
运算符作为pow
的简写来进行张量计算。特殊的案例
对于浮点数的操作,
如果 \(x_i\) 不为
1
且 \(y_i\) 为NaN
, 则幂运算的结果为NaN
.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
NaN
and \(y_i\) is not equal to0
, the result isNaN
.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 is1
.If \(\abs{x_i}\) is
1
and \(y_i\) is-infinity
, the result is1
.If \(x_i\) is
1
and \(y_i\) is notNaN
, the result is1
.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 than0
, the result is+infinity
.If \(x_i\) is
+infinity
and \(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
+0
and \(y_i\) is greater than0
, the result is+0
.If \(x_i\) is
+0
and \(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
.
实际案例
>>> 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)