Commit 8ceddca
authored
⚡️ Speed up function
Here is an optimized version of your function. The original code computes `np.exp(x)` twice for the `x < 0` case. To optimize, we can precompute the exponent, reducing redundant computation.
This computes `np.exp(-np.abs(x))` once and reuses it for both cases, improving speed and efficiency for large arrays.sigmoid_stable by 232%1 parent 8947ec9 commit 8ceddca
1 file changed
+2
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
0 commit comments