Skip to content

Commit

Permalink
Merge pull request #403 from luisfpereira/fix-typo-spharapy
Browse files Browse the repository at this point in the history
Fix `from_spharapy` naming in `SimplicialComplex`
  • Loading branch information
ffl096 authored Jan 3, 2025
2 parents f652c82 + 7a75a46 commit 6a30ac8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
24 changes: 22 additions & 2 deletions test/classes/test_simplicial_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,15 +1073,35 @@ def test_normalized_laplacian_matrix(self):
),
)

@pytest.mark.skipif(
tm is None, reason="Optional dependency 'spharapy' not installed."
)
def test_from_spharapy(self):
"""Test the from_spharapy method of SimplicialComplex (support for spharapy trimesh)."""
mesh = tm.TriMesh(
[[0, 1, 2]], [[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]]
)
SC = SimplicialComplex.from_spharapy(mesh)
simplices = SC.simplices
assert len(simplices) == 7
assert [0, 1, 2] in simplices
assert [0, 1] in simplices
assert [0, 2] in simplices
assert [1, 2] in simplices
assert [0] in simplices
assert [1] in simplices
assert [2] in simplices

@pytest.mark.skipif(
tm is None, reason="Optional dependency 'spharapy' not installed."
)
def test_from_spharpy(self):
"""Test the from_spharpy method of SimplicialComplex (support for spharpy trimesh)."""
"""Test the deprecated from_spharpy method of SimplicialComplex (support for spharapy trimesh)."""
mesh = tm.TriMesh(
[[0, 1, 2]], [[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]]
)
SC = SimplicialComplex.from_spharpy(mesh)
with pytest.deprecated_call():
SC = SimplicialComplex.from_spharpy(mesh)
simplices = SC.simplices
assert len(simplices) == 7
assert [0, 1, 2] in simplices
Expand Down
25 changes: 21 additions & 4 deletions toponetx/classes/simplicial_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ def get_all_maximal_simplices(self) -> Generator[Simplex[ElementType], None, Non
yield simplex

@classmethod
def from_spharpy(cls, mesh) -> Self:
def from_spharapy(cls, mesh) -> Self:
"""Import from sharpy.
Parameters
Expand All @@ -1372,7 +1372,7 @@ def from_spharpy(cls, mesh) -> Self:
... [[0, 1, 2]], [[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]]
... )
>>> SC = tnx.SimplicialComplex.from_spharpy(mesh)
>>> SC = tnx.SimplicialComplex.from_spharapy(mesh)
"""
vertices = np.array(mesh.vertlist)
SC = cls(mesh.trilist)
Expand All @@ -1389,6 +1389,23 @@ def from_spharpy(cls, mesh) -> Self:

return SC

@classmethod
@deprecated("`SimplicialComplex.from_spharpy` is deprecated and will be removed in the future, use `SimplicialComplex.from_spharapy` instead.")
def from_spharpy(cls, mesh) -> Self:
"""Import from sharpy.
Parameters
----------
mesh : spharapy.trimesh.TriMesh
The input spharapy object.
Returns
-------
SimplicialComplex
The resulting SimplicialComplex.
"""
return cls.from_spharapy(mesh)

def to_hasse_graph(self) -> nx.DiGraph:
"""Create the hasse graph corresponding to this simplicial complex.
Expand Down Expand Up @@ -1560,7 +1577,7 @@ def to_trimesh(self, vertex_position_name: str = "position"):
return trimesh.Trimesh(faces=faces, vertices=vertices, process=False)

def to_spharapy(self, vertex_position_name: str = "position"):
"""Convert to sharapy.
"""Convert to spharapy.
Parameters
----------
Expand All @@ -1583,7 +1600,7 @@ def to_spharapy(self, vertex_position_name: str = "position"):
>>> import spharapy.spharabasis as sb
>>> import spharapy.datasets as sd
>>> mesh = tm.TriMesh([[0, 1, 2]], [[0, 0, 0], [0, 0, 1], [0, 1, 0]])
>>> SC = tnx.SimplicialComplex.from_spharpy(mesh)
>>> SC = tnx.SimplicialComplex.from_spharapy(mesh)
>>> mesh2 = SC.to_spharapy()
>>> mesh2.vertlist == mesh.vertlist
>>> mesh2.trilist == mesh.trilist
Expand Down

0 comments on commit 6a30ac8

Please sign in to comment.