mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
Merge pull request #114 from fjosw/feat/obs_hash
hash method for Obs objects
This commit is contained in:
commit
7737ed4ea0
2 changed files with 23 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
import warnings
|
||||
import hashlib
|
||||
import pickle
|
||||
from math import gcd
|
||||
from functools import reduce
|
||||
|
@ -684,6 +685,15 @@ class Obs:
|
|||
else:
|
||||
return '{:.0f}({:2.0f})'.format(self.value, self._dvalue)
|
||||
|
||||
def __hash__(self):
|
||||
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) & 0xFFFFFFFF
|
||||
|
||||
# Overload comparisons
|
||||
def __lt__(self, other):
|
||||
return self.value < other
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue