Skip to content

Commit 0e1aa7c

Browse files
committed
Merge branch 'stable-0.7' which is tagged as v0.7.4
2 parents 5f9a146 + a9bb7f6 commit 0e1aa7c

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

adaptive/learner/learner1D.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def curvature_loss_function(area_factor=1, euclid_factor=0.02, horizontal_factor
129129
@uses_nth_neighbors(1)
130130
def curvature_loss(xs, ys):
131131
xs_middle = xs[1:3]
132-
ys_middle = xs[1:3]
132+
ys_middle = ys[1:3]
133133

134134
triangle_loss_ = triangle_loss(xs, ys)
135135
default_loss_ = default_loss(xs_middle, ys_middle)
@@ -654,7 +654,8 @@ def _get_data(self):
654654
return self.data
655655

656656
def _set_data(self, data):
657-
self.tell_many(*zip(*data.items()))
657+
if data:
658+
self.tell_many(*zip(*data.items()))
658659

659660

660661
def loss_manager(x_scale):
@@ -670,7 +671,7 @@ def finite_loss(ival, loss, x_scale):
670671
sort intervals that have infinite loss."""
671672
# If the loss is infinite we return the
672673
# distance between the two points.
673-
if math.isinf(loss):
674+
if math.isinf(loss) or math.isnan(loss):
674675
loss = (ival[1] - ival[0]) / x_scale
675676
if len(ival) == 3:
676677
# Used when constructing quals. Last item is

adaptive/learner/learnerND.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ def _get_data(self):
757757
return self.data
758758

759759
def _set_data(self, data):
760-
self.tell_many(*zip(*data.items()))
760+
if data:
761+
self.tell_many(*zip(*data.items()))
761762

762763
def _get_iso(self, level=0.0, which='surface'):
763764
if which == 'surface':

adaptive/tests/test_learner1d.py

+12
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,15 @@ def f(x):
363363
learner = Learner1D(f, (-1, 1), loss_per_interval=loss)
364364
simple(learner, goal=lambda l: l.npoints > 100)
365365
assert learner.npoints > 100
366+
367+
368+
def test_NaN_loss():
369+
# see https://github.com/python-adaptive/adaptive/issues/145
370+
def f(x):
371+
a = 0.01
372+
if random.random() < 0.2:
373+
return np.NaN
374+
return x + a**2 / (a**2 + x**2)
375+
376+
learner = Learner1D(f, bounds=(-1, 1))
377+
simple(learner, lambda l: l.npoints > 100)

0 commit comments

Comments
 (0)