Skip to content
Snippets Groups Projects
Commit 0dacb0e1 authored by Bas Nijholt's avatar Bas Nijholt
Browse files

Merge branch 'fix_97_98' into 'master'

Fix #97 and #98

Closes #97 and #98

See merge request !97
parents 555517d4 103f1490
No related branches found
No related tags found
1 merge request!97Fix #97 and #98
Pipeline #12065 passed
......@@ -152,6 +152,7 @@ class Learner1D(BaseLearner):
self.update_interpolated_loss_in_interval(x_left, x)
self.update_interpolated_loss_in_interval(x, x_right)
self.losses.pop((x_left, x_right), None)
self.losses_combined.pop((x_left, x_right), None)
else:
losses_combined = self.losses_combined
x_left, x_right = self.find_neighbors(x, self.neighbors)
......@@ -212,8 +213,11 @@ class Learner1D(BaseLearner):
self._scale[1] = self._bbox[1][1] - self._bbox[1][0]
def tell(self, x, y):
real = y is not None
if x in self.data:
# The point is already evaluated before
return
real = y is not None
if real:
# Add point to the real data dict
self.data[x] = y
......
......@@ -438,6 +438,24 @@ def test_termination_on_discontinuities():
assert smallest_interval >= 0.5E3 * np.finfo(float).eps
def test_order_adding_points():
# and https://gitlab.kwant-project.org/qt/adaptive/issues/98
l = Learner1D(lambda x: x, (0, 1))
l.tell_many([1, 0, 0.5], [0, 0, 0])
assert l.losses_combined == {(0, 0.5): 0.5, (0.5, 1): 0.5}
assert l.losses == {(0, 0.5): 0.5, (0.5, 1): 0.5}
l.ask(1)
def test_adding_existing_point_passes_silently():
# See https://gitlab.kwant-project.org/qt/adaptive/issues/97
l = Learner1D(lambda x: x, (0, 4))
l.tell(0, 0)
l.tell(1, 0)
l.tell(2, 0)
l.tell(1, None)
def test_loss_at_machine_precision_interval_is_zero():
"""The loss of an interval smaller than _dx_eps
should be set to zero."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment