Commit 4c2a4012 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

tweak DomainObject comparisons

parent fd036abf
......@@ -43,8 +43,7 @@ class DomainObject(with_metaclass(
"""
def __init__(self):
# _global_id is used in the Versioning module from keepers
self._ignore_for_hash = ['_global_id']
self._needed_for_hash = []
@abc.abstractmethod
def __repr__(self):
......@@ -53,11 +52,8 @@ class DomainObject(with_metaclass(
def __hash__(self):
# Extract the identifying parts from the vars(self) dict.
result_hash = 0
for key in sorted(vars(self).keys()):
item = vars(self)[key]
if key in self._ignore_for_hash or key == '_ignore_for_hash':
continue
result_hash ^= item.__hash__() ^ int(hash(key)//117)
for key in self._needed_for_hash:
result_hash ^= hash(vars(self)[key])
return result_hash
def __eq__(self, x):
......@@ -74,18 +70,14 @@ class DomainObject(with_metaclass(
True if `self` and x describe the same manifold.
"""
if isinstance(x, type(self)):
for key in list(vars(self).keys()):
item1 = vars(self)[key]
if key in self._ignore_for_hash or key == '_ignore_for_hash':
continue
item2 = vars(x)[key]
if item1 != item2:
return False
if self is x: # shortcut for simple case
return True
else:
if not isinstance(x, type(self)):
return False
for key in self._needed_for_hash:
if vars(self)[key] != vars(x)[key]:
return False
return True
def __ne__(self, x):
return not self.__eq__(x)
......
......@@ -94,6 +94,7 @@ class GLSpace(Space):
"The module pyHealpix is needed but not available.")
super(GLSpace, self).__init__()
self._needed_for_hash += ["_nlat", "_nlon"]
self._nlat = self._parse_nlat(nlat)
self._nlon = self._parse_nlon(nlon)
......
......@@ -80,7 +80,7 @@ class HPSpace(Space):
def __init__(self, nside):
super(HPSpace, self).__init__()
self._needed_for_hash += ["_nside"]
self._nside = self._parse_nside(nside)
# ---Mandatory properties and methods---
......@@ -94,7 +94,7 @@ class HPSpace(Space):
@property
def shape(self):
return (np.int(12 * self.nside * self.nside),)
return (self.dim,)
@property
def dim(self):
......
......@@ -87,6 +87,7 @@ class LMSpace(Space):
def __init__(self, lmax):
super(LMSpace, self).__init__()
self._needed_for_hash += ["_lmax"]
self._lmax = self._parse_lmax(lmax)
# ---Mandatory properties and methods---
......
......@@ -87,8 +87,8 @@ class PowerSpace(Space):
def __init__(self, harmonic_partner, distribution_strategy=None,
volume_type='rho', binbounds=None):
super(PowerSpace, self).__init__()
self._ignore_for_hash += ['_pindex', '_kindex', '_rho',
'_volume_weight']
self._needed_for_hash += ['_harmonic_partner', '_binbounds',
'volume_type']
if distribution_strategy is None:
distribution_strategy = gc['default_distribution_strategy']
......
......@@ -75,10 +75,10 @@ class RGSpace(Space):
# ---Overwritten properties and methods---
def __init__(self, shape, distances=None, harmonic=False):
self._harmonic = bool(harmonic)
super(RGSpace, self).__init__()
self._needed_for_hash += ["_distances", "_shape", "_harmonic"]
self._harmonic = bool(harmonic)
self._shape = self._parse_shape(shape)
self._distances = self._parse_distances(distances)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment