Introduce add_points method in AbstractProblem, removed unused comments in Collector class and add the test for add_points and codacy corrections
This commit is contained in:
committed by
Nicola Demo
parent
004cbc00c0
commit
f578b2ed12
@@ -1,6 +1,8 @@
|
||||
import torch
|
||||
import pytest
|
||||
from pina.problem.zoo import Poisson2DSquareProblem as Poisson
|
||||
from pina import LabelTensor
|
||||
|
||||
|
||||
def test_discretise_domain():
|
||||
n = 10
|
||||
@@ -14,7 +16,7 @@ def test_discretise_domain():
|
||||
assert poisson_problem.discretised_domains[b].shape[0] == n
|
||||
|
||||
poisson_problem.discretise_domain(n, 'grid', domains=['D'])
|
||||
assert poisson_problem.discretised_domains['D'].shape[0] == n**2
|
||||
assert poisson_problem.discretised_domains['D'].shape[0] == n ** 2
|
||||
poisson_problem.discretise_domain(n, 'random', domains=['D'])
|
||||
assert poisson_problem.discretised_domains['D'].shape[0] == n
|
||||
|
||||
@@ -25,6 +27,8 @@ def test_discretise_domain():
|
||||
assert poisson_problem.discretised_domains['D'].shape[0] == n
|
||||
|
||||
poisson_problem.discretise_domain(n)
|
||||
|
||||
|
||||
'''
|
||||
def test_sampling_few_variables():
|
||||
n = 10
|
||||
@@ -36,8 +40,8 @@ def test_sampling_few_variables():
|
||||
assert poisson_problem.discretised_domains['D'].shape[1] == 1
|
||||
'''
|
||||
|
||||
def test_variables_correct_order_sampling():
|
||||
|
||||
def test_variables_correct_order_sampling():
|
||||
n = 10
|
||||
poisson_problem = Poisson()
|
||||
poisson_problem.discretise_domain(n,
|
||||
@@ -50,15 +54,15 @@ def test_variables_correct_order_sampling():
|
||||
assert poisson_problem.discretised_domains['D'].labels == sorted(
|
||||
poisson_problem.input_variables)
|
||||
|
||||
# def test_add_points():
|
||||
# poisson_problem = Poisson()
|
||||
# poisson_problem.discretise_domain(0,
|
||||
# 'random',
|
||||
# domains=['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.discretised_domain['D'].extract('x'),
|
||||
# new_pts.extract('x'))
|
||||
# assert torch.isclose(poisson_problem.discretised_domain['D'].extract('y'),
|
||||
# new_pts.extract('y'))
|
||||
|
||||
def test_add_points():
|
||||
poisson_problem = Poisson()
|
||||
poisson_problem.discretise_domain(0,
|
||||
'random',
|
||||
domains=['D'])
|
||||
new_pts = LabelTensor(torch.tensor([[0.5, -0.5]]), labels=['x', 'y'])
|
||||
poisson_problem.add_points({'D': new_pts})
|
||||
assert torch.isclose(poisson_problem.discretised_domains['D'].extract('x'),
|
||||
new_pts.extract('x'))
|
||||
assert torch.isclose(poisson_problem.discretised_domains['D'].extract('y'),
|
||||
new_pts.extract('y'))
|
||||
|
||||
Reference in New Issue
Block a user