Skip to content

Commit

Permalink
optimize hash of operation objects using cache
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcarreras committed Mar 22, 2024
1 parent ea5603a commit cccc11b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions posym/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ def __init__(self, label):
self._determinant = 1
self._gen_rep = []
self._permutation = None
self._hash = None

def __hash__(self):
vector = np.round(np.array(self.matrix_representation).flatten(), decimals=6)
return hash(np.array(vector * 1e5, dtype=int).tobytes())
if self._hash is None:
vector = np.round(np.array(self.matrix_representation).flatten(), decimals=6)
self._hash = hash(np.array(vector * 1e5, dtype=int).tobytes())

return self._hash

def __eq__(self, other):
return hash(self) == hash(other)
Expand Down

0 comments on commit cccc11b

Please sign in to comment.