Skip to content

Commit

Permalink
Use expm1 instead of exp - 1 (#2660)
Browse files Browse the repository at this point in the history
Summary:
Similarly to #2540 and #2541: use more numerically stable `expm1`.

Found with TorchFix https://github.com/pytorch-labs/torchfix/.  This should be the last instance to replace in the current codebase.

Pull Request resolved: #2660

Reviewed By: saitcakmak

Differential Revision: D67613867

Pulled By: kit1980

fbshipit-source-id: a6305f0f3ec4a3e6ec6f6f6b9c9361a61eaf06e9
  • Loading branch information
kit1980 authored and facebook-github-bot committed Dec 24, 2024
1 parent 7715ff4 commit 466da73
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion botorch/test_functions/multi_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ def penicillin_vectorized(cls, X_input: Tensor) -> Tensor:
F_loss = (
V[active]
* cls.lambd
* (torch.exp(5 * ((T[active] - cls.T_o) / (cls.T_v - cls.T_o))) - 1)
* torch.special.expm1(5 * ((T[active] - cls.T_o) / (cls.T_v - cls.T_o)))
)
dV_dt = F[active] - F_loss
mu = (
Expand Down
2 changes: 1 addition & 1 deletion test/models/transforms/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_norm_to_lognorm(self):
mu_ln_expected = torch.tensor(
[1.0, 2.0, 3.0], device=self.device, dtype=dtype
)
var_ln_expected = (torch.exp(var) - 1) * mu_ln_expected**2
var_ln_expected = torch.special.expm1(var) * mu_ln_expected**2
self.assertAllClose(mu_ln, mu_ln_expected)
self.assertAllClose(var_ln, var_ln_expected)

Expand Down

0 comments on commit 466da73

Please sign in to comment.