From ded21e792f3e6766c78e85733a3cbbf467c408a0 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 5 Jul 2022 10:19:49 +0100 Subject: [PATCH] feat: hashing algorithm changed to md5 --- pyerrors/obs.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pyerrors/obs.py b/pyerrors/obs.py index 80b0b090..6be18c0b 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -1,4 +1,5 @@ import warnings +import hashlib import pickle from math import gcd from functools import reduce @@ -685,10 +686,13 @@ class Obs: return '{:.0f}({:2.0f})'.format(self.value, self._dvalue) def __hash__(self): - return hash((np.array([self.value]).astype(np.float32)[0], - tuple([o.astype(np.float32).data.tobytes() for o in self.deltas.values()]), - tuple(np.array([o.errsq() for o in self.covobs.values()]).astype(np.float32).data.tobytes()), - tuple(self.names))) + hash_tuple = (np.array([self.value]).astype(np.float32).data.tobytes(),) + hash_tuple += tuple([o.astype(np.float32).data.tobytes() for o in self.deltas.values()]) + hash_tuple += tuple([np.array([o.errsq()]).astype(np.float32).data.tobytes() for o in self.covobs.values()]) + hash_tuple += tuple([o.encode() for o in self.names]) + m = hashlib.md5() + [m.update(o) for o in hash_tuple] + return int(m.hexdigest(), 16) # Overload comparisons def __lt__(self, other):