remove back compatibility files for version 0.2
This commit is contained in:
committed by
Giovanni Canali
parent
ef3542486c
commit
684d691b78
35
tests/test_domain/test_cartesian.py
Normal file
35
tests/test_domain/test_cartesian.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import torch
|
||||
|
||||
from pina import LabelTensor
|
||||
from pina.domain import CartesianDomain
|
||||
|
||||
|
||||
def test_constructor():
|
||||
CartesianDomain({"x": [0, 1], "y": [0, 1]})
|
||||
|
||||
|
||||
def test_is_inside_check_border():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5]]), ["x", "y"])
|
||||
pt_2 = LabelTensor(torch.tensor([[1.0, 0.5]]), ["x", "y"])
|
||||
pt_3 = LabelTensor(torch.tensor([[1.5, 0.5]]), ["x", "y"])
|
||||
domain = CartesianDomain({"x": [0, 1], "y": [0, 1]})
|
||||
for pt, exp_result in zip([pt_1, pt_2, pt_3], [True, True, False]):
|
||||
assert domain.is_inside(pt, check_border=True) == exp_result
|
||||
|
||||
|
||||
def test_is_inside_not_check_border():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5]]), ["x", "y"])
|
||||
pt_2 = LabelTensor(torch.tensor([[1.0, 0.5]]), ["x", "y"])
|
||||
pt_3 = LabelTensor(torch.tensor([[1.5, 0.5]]), ["x", "y"])
|
||||
domain = CartesianDomain({"x": [0, 1], "y": [0, 1]})
|
||||
for pt, exp_result in zip([pt_1, pt_2, pt_3], [True, False, False]):
|
||||
assert domain.is_inside(pt, check_border=False) == exp_result
|
||||
|
||||
|
||||
def test_is_inside_fixed_variables():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5]]), ["x", "y"])
|
||||
pt_2 = LabelTensor(torch.tensor([[1.0, 0.5]]), ["x", "y"])
|
||||
pt_3 = LabelTensor(torch.tensor([[1.0, 1.5]]), ["x", "y"])
|
||||
domain = CartesianDomain({"x": 1, "y": [0, 1]})
|
||||
for pt, exp_result in zip([pt_1, pt_2, pt_3], [False, True, False]):
|
||||
assert domain.is_inside(pt, check_border=False) == exp_result
|
||||
76
tests/test_domain/test_difference.py
Normal file
76
tests/test_domain/test_difference.py
Normal file
@@ -0,0 +1,76 @@
|
||||
import torch
|
||||
|
||||
from pina import LabelTensor
|
||||
from pina.domain import Difference, EllipsoidDomain, CartesianDomain
|
||||
|
||||
|
||||
def test_constructor_two_CartesianDomains():
|
||||
Difference(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_constructor_two_3DCartesianDomain():
|
||||
Difference(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2], "z": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3], "z": [1, 3]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_constructor_three_CartesianDomains():
|
||||
Difference(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3]}),
|
||||
CartesianDomain({"x": [2, 4], "y": [2, 4]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_is_inside_two_CartesianDomains():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5]]), ["x", "y"])
|
||||
pt_2 = LabelTensor(torch.tensor([[-1, -0.5]]), ["x", "y"])
|
||||
domain = Difference(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3]}),
|
||||
]
|
||||
)
|
||||
assert domain.is_inside(pt_1) == True
|
||||
assert domain.is_inside(pt_2) == False
|
||||
|
||||
|
||||
def test_is_inside_two_3DCartesianDomain():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5, 0.5]]), ["x", "y", "z"])
|
||||
pt_2 = LabelTensor(torch.tensor([[-1, -0.5, -0.5]]), ["x", "y", "z"])
|
||||
domain = Difference(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2], "z": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3], "z": [1, 3]}),
|
||||
]
|
||||
)
|
||||
assert domain.is_inside(pt_1) == True
|
||||
assert domain.is_inside(pt_2) == False
|
||||
|
||||
|
||||
def test_sample():
|
||||
n = 100
|
||||
domain = Difference(
|
||||
[
|
||||
EllipsoidDomain({"x": [-1, 1], "y": [-1, 1]}),
|
||||
CartesianDomain({"x": [-0.5, 0.5], "y": [-0.5, 0.5]}),
|
||||
]
|
||||
)
|
||||
pts = domain.sample(n)
|
||||
assert isinstance(pts, LabelTensor)
|
||||
assert pts.shape[0] == n
|
||||
|
||||
n = 105
|
||||
pts = domain.sample(n)
|
||||
assert isinstance(pts, LabelTensor)
|
||||
assert pts.shape[0] == n
|
||||
30
tests/test_domain/test_ellipsoid.py
Normal file
30
tests/test_domain/test_ellipsoid.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
from pina import LabelTensor
|
||||
from pina.domain import EllipsoidDomain
|
||||
|
||||
|
||||
def test_constructor():
|
||||
EllipsoidDomain({"x": [0, 1], "y": [0, 1]})
|
||||
EllipsoidDomain({"x": [0, 1], "y": [0, 1]}, sample_surface=True)
|
||||
|
||||
|
||||
def test_is_inside_sample_surface_false():
|
||||
domain = EllipsoidDomain({"x": [0, 1], "y": [0, 1]}, sample_surface=False)
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5]]), ["x", "y"])
|
||||
pt_2 = LabelTensor(torch.tensor([[1.0, 0.5]]), ["x", "y"])
|
||||
pt_3 = LabelTensor(torch.tensor([[1.5, 0.5]]), ["x", "y"])
|
||||
for pt, exp_result in zip([pt_1, pt_2, pt_3], [True, False, False]):
|
||||
assert domain.is_inside(pt) == exp_result
|
||||
for pt, exp_result in zip([pt_1, pt_2, pt_3], [True, True, False]):
|
||||
assert domain.is_inside(pt, check_border=True) == exp_result
|
||||
|
||||
|
||||
def test_is_inside_sample_surface_true():
|
||||
domain = EllipsoidDomain({"x": [0, 1], "y": [0, 1]}, sample_surface=True)
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5]]), ["x", "y"])
|
||||
pt_2 = LabelTensor(torch.tensor([[1.0, 0.5]]), ["x", "y"])
|
||||
pt_3 = LabelTensor(torch.tensor([[1.5, 0.5]]), ["x", "y"])
|
||||
for pt, exp_result in zip([pt_1, pt_2, pt_3], [False, True, False]):
|
||||
assert domain.is_inside(pt) == exp_result
|
||||
76
tests/test_domain/test_exclusion.py
Normal file
76
tests/test_domain/test_exclusion.py
Normal file
@@ -0,0 +1,76 @@
|
||||
import torch
|
||||
|
||||
from pina import LabelTensor
|
||||
from pina.domain import Exclusion, EllipsoidDomain, CartesianDomain
|
||||
|
||||
|
||||
def test_constructor_two_CartesianDomains():
|
||||
Exclusion(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_constructor_two_3DCartesianDomain():
|
||||
Exclusion(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2], "z": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3], "z": [1, 3]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_constructor_three_CartesianDomains():
|
||||
Exclusion(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3]}),
|
||||
CartesianDomain({"x": [2, 4], "y": [2, 4]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_is_inside_two_CartesianDomains():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5]]), ["x", "y"])
|
||||
pt_2 = LabelTensor(torch.tensor([[-1, -0.5]]), ["x", "y"])
|
||||
domain = Exclusion(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3]}),
|
||||
]
|
||||
)
|
||||
assert domain.is_inside(pt_1) == True
|
||||
assert domain.is_inside(pt_2) == False
|
||||
|
||||
|
||||
def test_is_inside_two_3DCartesianDomain():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5, 0.5]]), ["x", "y", "z"])
|
||||
pt_2 = LabelTensor(torch.tensor([[-1, -0.5, -0.5]]), ["x", "y", "z"])
|
||||
domain = Exclusion(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2], "z": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3], "z": [1, 3]}),
|
||||
]
|
||||
)
|
||||
assert domain.is_inside(pt_1) == True
|
||||
assert domain.is_inside(pt_2) == False
|
||||
|
||||
|
||||
def test_sample():
|
||||
n = 100
|
||||
domain = Exclusion(
|
||||
[
|
||||
EllipsoidDomain({"x": [-1, 1], "y": [-1, 1]}),
|
||||
CartesianDomain({"x": [0.3, 1.5], "y": [0.3, 1.5]}),
|
||||
]
|
||||
)
|
||||
pts = domain.sample(n)
|
||||
assert isinstance(pts, LabelTensor)
|
||||
assert pts.shape[0] == n
|
||||
|
||||
n = 105
|
||||
pts = domain.sample(n)
|
||||
assert isinstance(pts, LabelTensor)
|
||||
assert pts.shape[0] == n
|
||||
81
tests/test_domain/test_intersection.py
Normal file
81
tests/test_domain/test_intersection.py
Normal file
@@ -0,0 +1,81 @@
|
||||
import torch
|
||||
|
||||
from pina import LabelTensor
|
||||
from pina.domain import Intersection, EllipsoidDomain, CartesianDomain
|
||||
|
||||
|
||||
def test_constructor_two_CartesianDomains():
|
||||
Intersection(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_constructor_two_3DCartesianDomain():
|
||||
Intersection(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2], "z": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3], "z": [1, 3]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_constructor_three_CartesianDomains():
|
||||
Intersection(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3]}),
|
||||
CartesianDomain({"x": [2, 4], "y": [2, 4]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_is_inside_two_CartesianDomains():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5]]), ["x", "y"])
|
||||
pt_2 = LabelTensor(torch.tensor([[-1, -0.5]]), ["x", "y"])
|
||||
pt_3 = LabelTensor(torch.tensor([[1.5, 1.5]]), ["x", "y"])
|
||||
|
||||
domain = Intersection(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3]}),
|
||||
]
|
||||
)
|
||||
assert domain.is_inside(pt_1) == False
|
||||
assert domain.is_inside(pt_2) == False
|
||||
assert domain.is_inside(pt_3) == True
|
||||
|
||||
|
||||
def test_is_inside_two_3DCartesianDomain():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5, 0.5]]), ["x", "y", "z"])
|
||||
pt_2 = LabelTensor(torch.tensor([[-1, -0.5, -0.5]]), ["x", "y", "z"])
|
||||
pt_3 = LabelTensor(torch.tensor([[1.5, 1.5, 1.5]]), ["x", "y", "z"])
|
||||
domain = Intersection(
|
||||
[
|
||||
CartesianDomain({"x": [0, 2], "y": [0, 2], "z": [0, 2]}),
|
||||
CartesianDomain({"x": [1, 3], "y": [1, 3], "z": [1, 3]}),
|
||||
]
|
||||
)
|
||||
assert domain.is_inside(pt_1) == False
|
||||
assert domain.is_inside(pt_2) == False
|
||||
assert domain.is_inside(pt_3) == True
|
||||
|
||||
|
||||
def test_sample():
|
||||
n = 100
|
||||
domain = Intersection(
|
||||
[
|
||||
EllipsoidDomain({"x": [-1, 1], "y": [-1, 1]}),
|
||||
CartesianDomain({"x": [-0.5, 0.5], "y": [-0.5, 0.5]}),
|
||||
]
|
||||
)
|
||||
pts = domain.sample(n)
|
||||
assert isinstance(pts, LabelTensor)
|
||||
assert pts.shape[0] == n
|
||||
|
||||
n = 105
|
||||
pts = domain.sample(n)
|
||||
assert isinstance(pts, LabelTensor)
|
||||
assert pts.shape[0] == n
|
||||
184
tests/test_domain/test_simplex.py
Normal file
184
tests/test_domain/test_simplex.py
Normal file
@@ -0,0 +1,184 @@
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
from pina import LabelTensor
|
||||
from pina.domain import SimplexDomain
|
||||
|
||||
|
||||
def test_constructor():
|
||||
SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[1, 1]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[0, 2]]), labels=["x", "y"]),
|
||||
]
|
||||
)
|
||||
SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[1, 1]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[0, 2]]), labels=["x", "y"]),
|
||||
],
|
||||
sample_surface=True,
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
# different labels
|
||||
SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[1, 1]]), labels=["x", "z"]),
|
||||
LabelTensor(torch.tensor([[0, 2]]), labels=["x", "a"]),
|
||||
]
|
||||
)
|
||||
# not LabelTensor
|
||||
SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
[1, 1],
|
||||
LabelTensor(torch.tensor([[0, 2]]), labels=["x", "y"]),
|
||||
]
|
||||
)
|
||||
# different number of vertices
|
||||
SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0.0, -2.0]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[-0.5, -0.5]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[-2.0, 0.0]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[-0.5, 0.5]]), labels=["x", "y"]),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_sample():
|
||||
# sampling inside
|
||||
simplex = SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[1, 1]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[0, 2]]), labels=["x", "y"]),
|
||||
]
|
||||
)
|
||||
pts = simplex.sample(10)
|
||||
assert isinstance(pts, LabelTensor)
|
||||
assert pts.size() == torch.Size([10, 2])
|
||||
|
||||
# sampling border
|
||||
SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[1, 1]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[0, 2]]), labels=["x", "y"]),
|
||||
],
|
||||
sample_surface=True,
|
||||
)
|
||||
|
||||
pts = simplex.sample(10)
|
||||
assert isinstance(pts, LabelTensor)
|
||||
assert pts.size() == torch.Size([10, 2])
|
||||
|
||||
|
||||
def test_is_inside_faulty_point():
|
||||
domain = SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[2, 2]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[4, 0]]), labels=["x", "y"]),
|
||||
],
|
||||
sample_surface=True,
|
||||
)
|
||||
pt = LabelTensor(torch.tensor([[2, 1]]), ["x", "z"])
|
||||
with pytest.raises(ValueError):
|
||||
assert domain.is_inside(point=pt, check_border=False) == True
|
||||
|
||||
|
||||
def test_is_inside_2D_check_border_true():
|
||||
domain = SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[2, 2]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[4, 0]]), labels=["x", "y"]),
|
||||
],
|
||||
sample_surface=True,
|
||||
)
|
||||
pt1 = LabelTensor(torch.tensor([[0, 0]]), ["x", "y"])
|
||||
pt2 = LabelTensor(torch.tensor([[2, 2]]), ["x", "y"])
|
||||
pt3 = LabelTensor(torch.tensor([[4, 0]]), ["x", "y"])
|
||||
pt4 = LabelTensor(torch.tensor([[3, 1]]), ["x", "y"])
|
||||
pt5 = LabelTensor(torch.tensor([[2, 1]]), ["x", "y"])
|
||||
pt6 = LabelTensor(torch.tensor([[100, 100]]), ["x", "y"])
|
||||
pts = [pt1, pt2, pt3, pt4, pt5, pt6]
|
||||
for pt, exp_result in zip(pts, [True, True, True, True, False, False]):
|
||||
assert domain.is_inside(point=pt, check_border=True) == exp_result
|
||||
|
||||
|
||||
def test_is_inside_2D_check_border_false():
|
||||
domain = SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[2, 2]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[4, 0]]), labels=["x", "y"]),
|
||||
],
|
||||
sample_surface=False,
|
||||
)
|
||||
pt1 = LabelTensor(torch.tensor([[0, 0]]), ["x", "y"])
|
||||
pt2 = LabelTensor(torch.tensor([[2, 2]]), ["x", "y"])
|
||||
pt3 = LabelTensor(torch.tensor([[4, 0]]), ["x", "y"])
|
||||
pt4 = LabelTensor(torch.tensor([[3, 1]]), ["x", "y"])
|
||||
pt5 = LabelTensor(torch.tensor([[2, 1]]), ["x", "y"])
|
||||
pt6 = LabelTensor(torch.tensor([[2.5, 1]]), ["x", "y"])
|
||||
pt7 = LabelTensor(torch.tensor([[100, 100]]), ["x", "y"])
|
||||
pts = [pt1, pt2, pt3, pt4, pt5, pt6, pt7]
|
||||
for pt, exp_result in zip(
|
||||
pts, [False, False, False, False, True, True, False]
|
||||
):
|
||||
assert domain.is_inside(point=pt, check_border=False) == exp_result
|
||||
|
||||
|
||||
def test_is_inside_3D_check_border_true():
|
||||
domain = SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0, 0]]), labels=["x", "y", "z"]),
|
||||
LabelTensor(torch.tensor([[2, 2, 0]]), labels=["x", "y", "z"]),
|
||||
LabelTensor(torch.tensor([[4, 0, 0]]), labels=["x", "y", "z"]),
|
||||
LabelTensor(torch.tensor([[0, 0, 20]]), labels=["x", "y", "z"]),
|
||||
],
|
||||
sample_surface=True,
|
||||
)
|
||||
pt1 = LabelTensor(torch.tensor([[0, 0, 0]]), ["x", "y", "z"])
|
||||
pt2 = LabelTensor(torch.tensor([[2, 2, 0]]), ["x", "y", "z"])
|
||||
pt3 = LabelTensor(torch.tensor([[4, 0, 0]]), ["x", "y", "z"])
|
||||
pt4 = LabelTensor(torch.tensor([[3, 1, 0]]), ["x", "y", "z"])
|
||||
pt5 = LabelTensor(torch.tensor([[2, 1, 0]]), ["x", "y", "z"])
|
||||
pt6 = LabelTensor(torch.tensor([[100, 100, 0]]), ["x", "y", "z"])
|
||||
pt7 = LabelTensor(torch.tensor([[0, 0, 19]]), ["x", "y", "z"])
|
||||
pt8 = LabelTensor(torch.tensor([[0, 0, 20]]), ["x", "y", "z"])
|
||||
pt9 = LabelTensor(torch.tensor([[2, 1, 1]]), ["x", "y", "z"])
|
||||
pts = [pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8, pt9]
|
||||
for pt, exp_result in zip(
|
||||
pts, [True, True, True, True, True, False, True, True, False]
|
||||
):
|
||||
assert domain.is_inside(point=pt, check_border=True) == exp_result
|
||||
|
||||
|
||||
def test_is_inside_3D_check_border_false():
|
||||
domain = SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0, 0]]), labels=["x", "y", "z"]),
|
||||
LabelTensor(torch.tensor([[2, 2, 0]]), labels=["x", "y", "z"]),
|
||||
LabelTensor(torch.tensor([[4, 0, 0]]), labels=["x", "y", "z"]),
|
||||
LabelTensor(torch.tensor([[0, 0, 20]]), labels=["x", "y", "z"]),
|
||||
],
|
||||
sample_surface=False,
|
||||
)
|
||||
pt1 = LabelTensor(torch.tensor([[0, 0, 0]]), ["x", "y", "z"])
|
||||
pt2 = LabelTensor(torch.tensor([[3, 1, 0]]), ["x", "y", "z"])
|
||||
pt3 = LabelTensor(torch.tensor([[2, 1, 0]]), ["x", "y", "z"])
|
||||
pt4 = LabelTensor(torch.tensor([[100, 100, 0]]), ["x", "y", "z"])
|
||||
pt5 = LabelTensor(torch.tensor([[0, 0, 19]]), ["x", "y", "z"])
|
||||
pt6 = LabelTensor(torch.tensor([[0, 0, 20]]), ["x", "y", "z"])
|
||||
pt7 = LabelTensor(torch.tensor([[2, 1, 1]]), ["x", "y", "z"])
|
||||
pts = [pt1, pt2, pt3, pt4, pt5, pt6, pt7]
|
||||
for pt, exp_result in zip(
|
||||
pts, [False, False, False, False, False, False, True]
|
||||
):
|
||||
assert domain.is_inside(point=pt, check_border=False) == exp_result
|
||||
97
tests/test_domain/test_union.py
Normal file
97
tests/test_domain/test_union.py
Normal file
@@ -0,0 +1,97 @@
|
||||
import torch
|
||||
|
||||
from pina import LabelTensor
|
||||
from pina.domain import Union, EllipsoidDomain, CartesianDomain
|
||||
|
||||
|
||||
def test_constructor_two_CartesianDomains():
|
||||
Union(
|
||||
[
|
||||
CartesianDomain({"x": [0, 1], "y": [0, 1]}),
|
||||
CartesianDomain({"x": [0.5, 2], "y": [-1, 0.1]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_constructor_two_EllipsoidDomains():
|
||||
Union(
|
||||
[
|
||||
EllipsoidDomain({"x": [-1, 1], "y": [-1, 1], "z": [-1, 1]}),
|
||||
EllipsoidDomain(
|
||||
{"x": [-0.5, 0.5], "y": [-0.5, 0.5], "z": [-0.5, 0.5]}
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_constructor_EllipsoidDomain_CartesianDomain():
|
||||
Union(
|
||||
[
|
||||
EllipsoidDomain({"x": [-1, 1], "y": [-1, 1]}),
|
||||
CartesianDomain({"x": [-0.5, 0.5], "y": [-0.5, 0.5]}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_is_inside_two_CartesianDomains():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5]]), ["x", "y"])
|
||||
pt_2 = LabelTensor(torch.tensor([[-1, -1]]), ["x", "y"])
|
||||
domain = Union(
|
||||
[
|
||||
CartesianDomain({"x": [0, 1], "y": [0, 1]}),
|
||||
CartesianDomain({"x": [0.5, 2], "y": [-1, 0.1]}),
|
||||
]
|
||||
)
|
||||
assert domain.is_inside(pt_1) == True
|
||||
assert domain.is_inside(pt_2) == False
|
||||
|
||||
|
||||
def test_is_inside_two_EllipsoidDomains():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5, 0.5]]), ["x", "y", "z"])
|
||||
pt_2 = LabelTensor(torch.tensor([[-1, -1, -1]]), ["x", "y", "z"])
|
||||
domain = Union(
|
||||
[
|
||||
EllipsoidDomain({"x": [-1, 1], "y": [-1, 1], "z": [-1, 1]}),
|
||||
EllipsoidDomain(
|
||||
{"x": [-0.5, 0.5], "y": [-0.5, 0.5], "z": [-0.5, 0.5]}
|
||||
),
|
||||
]
|
||||
)
|
||||
assert domain.is_inside(pt_1) == True
|
||||
assert domain.is_inside(pt_2) == False
|
||||
|
||||
|
||||
def test_is_inside_EllipsoidDomain_CartesianDomain():
|
||||
pt_1 = LabelTensor(torch.tensor([[0.5, 0.5]]), ["x", "y"])
|
||||
pt_2 = LabelTensor(torch.tensor([[-1, -1]]), ["x", "y"])
|
||||
domain = Union(
|
||||
[
|
||||
EllipsoidDomain(
|
||||
{
|
||||
"x": [-1, 1],
|
||||
"y": [-1, 1],
|
||||
}
|
||||
),
|
||||
CartesianDomain({"x": [0.6, 1.5], "y": [-2, 0]}),
|
||||
]
|
||||
)
|
||||
assert domain.is_inside(pt_1) == True
|
||||
assert domain.is_inside(pt_2) == False
|
||||
|
||||
|
||||
def test_sample():
|
||||
n = 100
|
||||
domain = Union(
|
||||
[
|
||||
EllipsoidDomain({"x": [-1, 1], "y": [-1, 1]}),
|
||||
CartesianDomain({"x": [-0.5, 0.5], "y": [-0.5, 0.5]}),
|
||||
]
|
||||
)
|
||||
pts = domain.sample(n)
|
||||
assert isinstance(pts, LabelTensor)
|
||||
assert pts.shape[0] == n
|
||||
|
||||
n = 105
|
||||
pts = domain.sample(n)
|
||||
assert isinstance(pts, LabelTensor)
|
||||
assert pts.shape[0] == n
|
||||
Reference in New Issue
Block a user