Fix Codacy Warnings (#477)
--------- Co-authored-by: Dario Coscia <dariocos99@gmail.com>
This commit is contained in:
committed by
Nicola Demo
parent
e3790e049a
commit
4177bfbb50
@@ -5,31 +5,31 @@ from pina.domain import CartesianDomain
|
||||
|
||||
|
||||
def test_constructor():
|
||||
CartesianDomain({'x': [0, 1], 'y': [0, 1]})
|
||||
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]})
|
||||
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]})
|
||||
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]})
|
||||
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
|
||||
|
||||
@@ -5,98 +5,67 @@ 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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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
|
||||
|
||||
@@ -6,15 +6,15 @@ 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)
|
||||
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'])
|
||||
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]):
|
||||
@@ -22,9 +22,9 @@ def test_is_inside_sample_surface_false():
|
||||
|
||||
|
||||
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'])
|
||||
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
|
||||
|
||||
@@ -5,98 +5,67 @@ 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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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,86 +5,59 @@ 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]
|
||||
})
|
||||
])
|
||||
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():
|
||||
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'])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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
|
||||
@@ -92,16 +65,12 @@ 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,11 +6,13 @@ 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"]),
|
||||
]
|
||||
)
|
||||
SimplexDomain(
|
||||
[
|
||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||
@@ -21,32 +23,41 @@ 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.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"]),
|
||||
])
|
||||
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])
|
||||
@@ -117,8 +128,9 @@ 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
|
||||
|
||||
|
||||
@@ -143,7 +155,8 @@ 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
|
||||
|
||||
|
||||
@@ -165,6 +178,7 @@ 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,111 +5,88 @@ 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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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]
|
||||
})
|
||||
])
|
||||
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