Skip to content

Commit

Permalink
feat(reindex): Added reindexing function
Browse files Browse the repository at this point in the history
  • Loading branch information
peekxc committed Aug 24, 2023
1 parent 9974335 commit 5cb12c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions simplextree/SimplexTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ def expand(self, k: int, f: Callable[[Collection], bool] = None) -> None:
assert isinstance(f([]), bool), "Supplied callable must be boolean-valued"
self._expand_f(int(k), f)

def reindex(self, labels: Sequence = None) -> None:
"""Reindexes the vertex labels of the complex."""
if len(self.n_simplices) == 0: return
labels = list(range(self.n_simplices[0])) if labels is None else list(labels)
assert len(labels) == self.n_simplices[0]
self._reindex(labels)

def __repr__(self) -> str:
if len(self.n_simplices) == 0:
return "< Empty simplex tree >"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_simplextree.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def test_SimplexTree():
assert st.simplices() == [f for f in st]
assert st.card() == (5,6,2)
assert tuple(st.card(d) for d in range(st.dimension+1)) == st.card()
assert st.reindex() is None
assert st.vertices == [0,1,2,3,4]

def test_insert():
st = SimplexTree()
Expand Down

0 comments on commit 5cb12c7

Please sign in to comment.