Skip to content

Commit 31bebf0

Browse files
committed
implement own version of 'round' that speeds up the Learner1D by 30%
1 parent 669cf07 commit 31bebf0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

adaptive/learner/learner1D.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,5 +692,7 @@ def finite_loss(ival, loss, x_scale):
692692

693693
# We round the loss to 12 digits such that losses
694694
# are equal up to numerical precision will be considered
695-
# equal.
696-
return round(loss, ndigits=12), ival
695+
# equal. This is 3.5x faster than unsing the `round` function.
696+
round_fac = 1e12
697+
loss = int(loss * round_fac + 0.5) / round_fac
698+
return loss, ival

0 commit comments

Comments
 (0)