numpy/power-half
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| NumPy | warning | unsafe, with xpd check --fix --unsafe-fixes |
All versions |
np.power(x, 0.5) runs the general power function, which was 2 times slower. Call np.sqrt.
root = np.power(area, 0.5)root = np.sqrt(area)What the rule reports
Section titled “What the rule reports”The rule reports np.power(x, 0.5).
How to fix it
Section titled “How to fix it”xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.
The unsafe fix writes np.sqrt(x).
np.sqrt can return float16 or float32 on small integer dtypes where np.power(x, 0.5) returns float64.
Diagnostic message
Section titled “Diagnostic message”np.power with 0.5 runs the general power function, which ran 2 times slower on 1,000,000 values. Write $NP.sqrt($X).See all rules in the NumPy pack.