Documentation for v0.1 version (#199)
* Adding Equations, solving typos * improve _code.rst * the team rst and restuctore index.rst * fixing errors --------- Co-authored-by: Dario Coscia <dariocoscia@dhcp-015.eduroam.sissa.it>
This commit is contained in:
committed by
Nicola Demo
parent
3f9305d475
commit
8b7b61b3bd
@@ -1,12 +1,7 @@
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
from pina import LabelTensor, Condition, CartesianDomain, PINN
|
||||
from pina.problem import SpatialProblem
|
||||
from pina.model import FeedForward
|
||||
from pina.operators import laplacian
|
||||
|
||||
|
||||
from pina import LabelTensor
|
||||
from pina.geometry import CartesianDomain
|
||||
|
||||
def test_constructor():
|
||||
CartesianDomain({'x': [0, 1], 'y': [0, 1]})
|
||||
@@ -20,6 +15,7 @@ def test_is_inside_check_border():
|
||||
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'])
|
||||
@@ -28,6 +24,7 @@ def test_is_inside_not_check_border():
|
||||
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'])
|
||||
|
||||
@@ -5,25 +5,63 @@ from pina.geometry import Difference, EllipsoidDomain, CartesianDomain
|
||||
|
||||
|
||||
def test_constructor_two_CartesianDomains():
|
||||
Difference([CartesianDomain({'x': [0, 2], 'y': [0, 2]}),
|
||||
CartesianDomain({'x': [1, 3], 'y': [1, 3]})])
|
||||
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]})])
|
||||
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]})])
|
||||
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]})])
|
||||
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
|
||||
|
||||
@@ -31,16 +69,34 @@ def test_is_inside_two_CartesianDomains():
|
||||
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]})])
|
||||
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]})])
|
||||
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
|
||||
|
||||
@@ -5,14 +5,13 @@ from pina import LabelTensor
|
||||
from pina.geometry import EllipsoidDomain
|
||||
|
||||
|
||||
|
||||
def test_constructor():
|
||||
EllipsoidDomain({'x': [0, 1], 'y': [0, 1]})
|
||||
EllipsoidDomain({'x': [0, 1], 'y':[0, 1]}, sample_surface=True)
|
||||
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)
|
||||
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'])
|
||||
@@ -21,10 +20,11 @@ def test_is_inside_sample_surface_false():
|
||||
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)
|
||||
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
|
||||
assert domain.is_inside(pt) == exp_result
|
||||
|
||||
@@ -5,25 +5,63 @@ from pina.geometry import Exclusion, EllipsoidDomain, CartesianDomain
|
||||
|
||||
|
||||
def test_constructor_two_CartesianDomains():
|
||||
Exclusion([CartesianDomain({'x': [0, 2], 'y': [0, 2]}),
|
||||
CartesianDomain({'x': [1, 3], 'y': [1, 3]})])
|
||||
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]})])
|
||||
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]})])
|
||||
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]})])
|
||||
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
|
||||
|
||||
@@ -31,16 +69,34 @@ def test_is_inside_two_CartesianDomains():
|
||||
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]})])
|
||||
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]})])
|
||||
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
|
||||
|
||||
@@ -5,18 +5,48 @@ from pina.geometry import Intersection, EllipsoidDomain, CartesianDomain
|
||||
|
||||
|
||||
def test_constructor_two_CartesianDomains():
|
||||
Intersection([CartesianDomain({'x': [0, 2], 'y': [0, 2]}),
|
||||
CartesianDomain({'x': [1, 3], 'y': [1, 3]})])
|
||||
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]})])
|
||||
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]})])
|
||||
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():
|
||||
@@ -24,8 +54,16 @@ def test_is_inside_two_CartesianDomains():
|
||||
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]})])
|
||||
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
|
||||
@@ -35,8 +73,18 @@ 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]})])
|
||||
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
|
||||
@@ -44,8 +92,16 @@ def test_is_inside_two_3DCartesianDomain():
|
||||
|
||||
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]})])
|
||||
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
|
||||
|
||||
@@ -6,13 +6,11 @@ from pina.geometry 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"]),
|
||||
])
|
||||
SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
@@ -23,40 +21,33 @@ def test_constructor():
|
||||
)
|
||||
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"]),
|
||||
]
|
||||
)
|
||||
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"]),
|
||||
]
|
||||
)
|
||||
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., -2.]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[-.5, -.5]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[-2., 0.]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[-.5, .5]]), labels=["x", "y"]),
|
||||
]
|
||||
)
|
||||
SimplexDomain([
|
||||
LabelTensor(torch.tensor([[0., -2.]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[-.5, -.5]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[-2., 0.]]), labels=["x", "y"]),
|
||||
LabelTensor(torch.tensor([[-.5, .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"]),
|
||||
]
|
||||
)
|
||||
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])
|
||||
@@ -127,7 +118,8 @@ def test_is_inside_2D_check_border_false():
|
||||
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]):
|
||||
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
|
||||
|
||||
|
||||
@@ -152,8 +144,7 @@ def test_is_inside_3D_check_border_true():
|
||||
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]
|
||||
):
|
||||
pts, [True, True, True, True, True, False, True, True, False]):
|
||||
assert domain.is_inside(point=pt, check_border=True) == exp_result
|
||||
|
||||
|
||||
@@ -175,5 +166,6 @@ def test_is_inside_3D_check_border_false():
|
||||
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]):
|
||||
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
|
||||
|
||||
@@ -5,25 +5,59 @@ from pina.geometry 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]})])
|
||||
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]})])
|
||||
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]})])
|
||||
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]})])
|
||||
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
|
||||
|
||||
@@ -31,8 +65,18 @@ def test_is_inside_two_CartesianDomains():
|
||||
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]})])
|
||||
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
|
||||
|
||||
@@ -40,16 +84,32 @@ def test_is_inside_two_EllipsoidDomains():
|
||||
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]})])
|
||||
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]})])
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user