From c7973a97da4a546521d78d8d6b63ea1fafb91bde Mon Sep 17 00:00:00 2001 From: Gabriele Codega <114943643+Gabriele-Codega@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:57:46 +0200 Subject: [PATCH] Fix bug in `add_points` method * solving `add_points` --------- Co-authored-by: Gabriele Codega --- pina/problem/abstract_problem.py | 2 +- tests/test_problem.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pina/problem/abstract_problem.py b/pina/problem/abstract_problem.py index 90a33d9..e43ac24 100644 --- a/pina/problem/abstract_problem.py +++ b/pina/problem/abstract_problem.py @@ -273,7 +273,7 @@ class AbstractProblem(metaclass=ABCMeta): new_pts.labels = old_pts.labels # merging - merged_pts = torch.vstack([old_pts, new_points[location]]) + merged_pts = torch.vstack([old_pts, new_pts]) merged_pts.labels = old_pts.labels self.input_pts[location] = merged_pts diff --git a/tests/test_problem.py b/tests/test_problem.py index f75fd58..09133d4 100644 --- a/tests/test_problem.py +++ b/tests/test_problem.py @@ -130,4 +130,15 @@ def test_variables_correct_order_sampling(): locations=['D'], variables=['x']) assert poisson_problem.input_pts['D'].labels == sorted( - poisson_problem.input_variables) \ No newline at end of file + poisson_problem.input_variables) + +def test_add_points(): + poisson_problem = Poisson() + poisson_problem.discretise_domain(0, + 'random', + locations=['D'], + variables=['x','y']) + new_pts = LabelTensor(torch.tensor([[0.5,-0.5]]),labels=['x','y']) + poisson_problem.add_points({'D': new_pts}) + assert torch.isclose(poisson_problem.input_pts['D'].extract('x'),new_pts.extract('x')) + assert torch.isclose(poisson_problem.input_pts['D'].extract('y'),new_pts.extract('y'))