solving dimensions issue
This commit is contained in:
committed by
Nicola Demo
parent
7424ce15bd
commit
ead952da6f
@@ -49,6 +49,11 @@ class SimplexDomain(Location):
|
|||||||
if not all(vertex.labels == matrix_labels for vertex in simplex_matrix):
|
if not all(vertex.labels == matrix_labels for vertex in simplex_matrix):
|
||||||
raise ValueError(f"Labels don't match.")
|
raise ValueError(f"Labels don't match.")
|
||||||
|
|
||||||
|
# check consistency dimensions
|
||||||
|
dim_simplex = len(matrix_labels)
|
||||||
|
if len(simplex_matrix) != dim_simplex + 1:
|
||||||
|
raise ValueError("An n-dimensional simplex is composed by n + 1 tensors of dimension n.")
|
||||||
|
|
||||||
# creating vertices matrix
|
# creating vertices matrix
|
||||||
self._vertices_matrix = torch.cat(simplex_matrix)
|
self._vertices_matrix = torch.cat(simplex_matrix)
|
||||||
self._vertices_matrix.labels = matrix_labels
|
self._vertices_matrix.labels = matrix_labels
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ def test_constructor():
|
|||||||
sample_surface=True,
|
sample_surface=True,
|
||||||
)
|
)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
|
# different labels
|
||||||
SimplexDomain(
|
SimplexDomain(
|
||||||
[
|
[
|
||||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||||
@@ -29,6 +30,7 @@ def test_constructor():
|
|||||||
LabelTensor(torch.tensor([[0, 2]]), labels=["x", "a"]),
|
LabelTensor(torch.tensor([[0, 2]]), labels=["x", "a"]),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
# not LabelTensor
|
||||||
SimplexDomain(
|
SimplexDomain(
|
||||||
[
|
[
|
||||||
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
LabelTensor(torch.tensor([[0, 0]]), labels=["x", "y"]),
|
||||||
@@ -36,6 +38,15 @@ def test_constructor():
|
|||||||
LabelTensor(torch.tensor([[0, 2]]), labels=["x", "y"]),
|
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"]),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
def test_sample():
|
def test_sample():
|
||||||
# sampling inside
|
# sampling inside
|
||||||
|
|||||||
Reference in New Issue
Block a user