Skip to content

Commit 66b40e0

Browse files
authored
fix: small pytorch boxcox inefficiency (#683)
1 parent 06e5533 commit 66b40e0

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

models/src/anemoi/models/preprocessing/mappings.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@ def log1p_converter(x):
4242

4343
def boxcox_converter(x, lambd=0.5):
4444
"""Convert positive var in to boxcox(var)."""
45-
pos_lam = (torch.pow(x, lambd) - 1) / lambd
46-
null_lam = torch.log(x)
4745
if lambd == 0:
48-
return null_lam
49-
else:
50-
return pos_lam
46+
return torch.log(x)
47+
return (torch.pow(x, lambd) - 1) / lambd
5148

5249

5350
def sqrt_converter(x):
@@ -67,9 +64,6 @@ def square_converter(x):
6764

6865
def inverse_boxcox_converter(x, lambd=0.5):
6966
"""Convert back boxcox(var) to var."""
70-
pos_lam = torch.pow(x * lambd + 1, 1 / lambd)
71-
null_lam = torch.exp(x)
7267
if lambd == 0:
73-
return null_lam
74-
else:
75-
return pos_lam
68+
return torch.exp(x)
69+
return torch.pow(x * lambd + 1, 1 / lambd)

0 commit comments

Comments
 (0)