From 5cb12c78842609d1ed3dfc8a08d42bf6a11df723 Mon Sep 17 00:00:00 2001 From: peekxc Date: Thu, 24 Aug 2023 11:43:53 -0400 Subject: [PATCH] feat(reindex): Added reindexing function --- simplextree/SimplexTree.py | 7 +++++++ tests/test_simplextree.py | 2 ++ 2 files changed, 9 insertions(+) diff --git a/simplextree/SimplexTree.py b/simplextree/SimplexTree.py index b28f6f8..1d3758d 100644 --- a/simplextree/SimplexTree.py +++ b/simplextree/SimplexTree.py @@ -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 >" diff --git a/tests/test_simplextree.py b/tests/test_simplextree.py index a913373..84a9319 100644 --- a/tests/test_simplextree.py +++ b/tests/test_simplextree.py @@ -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()