From 7357c1457a5773e9ccca03616b4deab59418691a Mon Sep 17 00:00:00 2001 From: Florian Frantzen Date: Fri, 15 Sep 2023 17:08:18 +0200 Subject: [PATCH] Some performance improvements - Don't compute simplex tree unnecessary. - The `Hashable` test is unnecessary, non-hashable elements will cause the method to fail anyway. - Optimize boundary computation of simplices. --- toponetx/classes/simplex.py | 8 +------- toponetx/classes/simplex_trie.py | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/toponetx/classes/simplex.py b/toponetx/classes/simplex.py index 7f21ee21..6332ab3a 100644 --- a/toponetx/classes/simplex.py +++ b/toponetx/classes/simplex.py @@ -61,10 +61,6 @@ def __init__( DeprecationWarning, ) - for i in elements: - if not isinstance(i, Hashable): - raise ValueError(f"All nodes of a simplex must be hashable, got {i}") - if len(elements) != len(set(elements)): raise ValueError("A simplex cannot contain duplicate nodes.") @@ -117,9 +113,7 @@ def construct_simplex_tree( faceset = set() for r in range(len(elements), 0, -1): for face in combinations(elements, r): - faceset.add( - Simplex(elements=sorted(face), construct_tree=False) - ) # any face is always ordered + faceset.add(Simplex(elements=face, construct_tree=False)) return frozenset(faceset) @property diff --git a/toponetx/classes/simplex_trie.py b/toponetx/classes/simplex_trie.py index 2b1e710d..7e33a610 100644 --- a/toponetx/classes/simplex_trie.py +++ b/toponetx/classes/simplex_trie.py @@ -78,7 +78,7 @@ def simplex(self) -> Simplex[ElementType] | None: """Return a `Simplex` object representing this node.""" if self.label is None: return None - simplex = Simplex(self.elements) + simplex = Simplex(self.elements, construct_tree=False) simplex._properties = self.attributes return simplex