More efficient 'tell_many'
import adaptive
def f(x, offset=0):
a = 0.01
return x + a**2 / (a**2 + (x - offset)**2)
learner = adaptive.Learner1D(f, bounds=(-1, 1))
adaptive.runner.simple(learner, goal=lambda l: l.npoints > 200)
Timing new implementation
%%timeit
learner2 = adaptive.Learner1D(f, bounds=(-1, 1))
learner2.tell_many(*zip(*learner.data.items()))
1.17 ms ± 24.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
Timing old implementation
%%timeit
learner2 = adaptive.Learner1D(f, bounds=(-1, 1))
for x, y in learner.data.items():
learner2.tell(x, y)
6.82 ms ± 447 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
This makes it ~6 times faster for functions that return scalars and is >10 times faster for vectors.
Edited by Bas Nijholt