Skip to content

Commit

Permalink
adding hashing and equality of AGraph objects
Browse files Browse the repository at this point in the history
  • Loading branch information
gbomarito committed Dec 10, 2024
1 parent ff9087a commit 263dc89
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bingo/symbolic_regression/agraph/agraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def __init__(self, use_simplification=False, equation=None):
# self._needs_opt
# self._modified
self._init_command_array_and_const(equation)
self._hash = None

# pylint: disable=attribute-defined-outside-init
def _init_command_array_and_const(self, equation):
Expand Down Expand Up @@ -507,6 +508,15 @@ def save_onnx_model(self, file_name, model_name="bingo_equation"):
with open(file_name, "wb") as onnx_file:
onnx_file.write(model.SerializeToString())

def __hash__(self):
if self._modified or self._hash is None:
self._update()
self._hash = hash(tuple(map(tuple, self._simplified_command_array)))
return self._hash

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

def __deepcopy__(self, memodict=None):
duplicate = AGraph()
self._copy_agraph_values_to_new_graph(duplicate)
Expand Down

0 comments on commit 263dc89

Please sign in to comment.