numpy/power-half
| Rule | power-half |
|---|---|
| Pack | NumPy |
| Severity | warning |
| Fix | unsafe, with xpd check --fix --unsafe-fixes |
| Library versions | every version |
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).
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
np.power with 0.5 runs the general power function, which ran 2 times slower on 1,000,000 values. Write $NP.sqrt($X).Browse the other rules of the NumPy pack.