__eq__ method for Corr class (#206)

* feat: implemented __eq__ method for Corr class.

* feat: __eq__ method now respects None entries in correlators.

* feat: Obs can now be compared to None, __ne__ method removed as it is
not required.

* feat: Corr.__eq__ rewritten to give a per element comparison.

* tests: additional test case for correlator comparison added.

* feat: comparison now also works for padding.
This commit is contained in:
Fabian Joswig 2023-07-19 15:06:19 +01:00 committed by GitHub
parent 1e438356fd
commit af28f77ec5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 3 deletions

View file

@ -1056,6 +1056,13 @@ class Corr:
__array_priority__ = 10000
def __eq__(self, y):
if isinstance(y, Corr):
comp = np.asarray(y.content, dtype=object)
else:
comp = np.asarray(y)
return np.asarray(self.content, dtype=object) == comp
def __add__(self, y):
if isinstance(y, Corr):
if ((self.N != y.N) or (self.T != y.T)):

View file

@ -773,11 +773,10 @@ class Obs:
return self.value >= other
def __eq__(self, other):
if other is None:
return False
return (self - other).is_zero()
def __ne__(self, other):
return not (self - other).is_zero()
# Overload math operations
def __add__(self, y):
if isinstance(y, Obs):