Commit 7baeb7d
authored
⚡️ Speed up function
Here is a faster and more memory-efficient version of the function. The bottleneck in the original implementation is calling `np.exp(x)` twice for `x < 0` branches. We can compute `exp_x = np.exp(x)` once, then reuse it for both cases.
This version calls `np.exp` only once and chooses the correct formulation based on `x`, which results in a significant speedup and less redundant computation.sigmoid_stable by 236%1 parent 8947ec9 commit 7baeb7d
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