Skip to content

Commit e17a27d

Browse files
committed
ensure that points are never outside of the domain, closes #132
1 parent 2353438 commit e17a27d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

adaptive/learner/learner2D.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ def _fill_stack(self, stack_till=1):
435435
triangle = ip.tri.points[ip.tri.vertices[jsimplex]]
436436
point_new = choose_point_in_triangle(triangle, max_badness=5)
437437
point_new = tuple(self._unscale(point_new))
438+
439+
# np.clip results in numerical precision problems
440+
# https://gitlab.kwant-project.org/qt/adaptive/issues/132
441+
clip = lambda x, l, u: max(l, min(u, x))
442+
point_new = (clip(point_new[0], *self.bounds[0]),
443+
clip(point_new[1], *self.bounds[1]))
444+
438445
loss_new = losses[jsimplex]
439446

440447
points_new.append(point_new)

0 commit comments

Comments
 (0)