Skip to content

Commit

Permalink
Some performance improvements
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
ffl096 committed Sep 20, 2023
1 parent 75161c5 commit 7357c14
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
8 changes: 1 addition & 7 deletions toponetx/classes/simplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion toponetx/classes/simplex_trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7357c14

Please sign in to comment.