Commit c385b8bc authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'issue77_2' into 'master'

try to address hashing/equality problems and fix caches

See merge request !72
parents 42951308 bd1e0f27
Pipeline #11891 passed with stages
in 16 minutes and 4 seconds
...@@ -40,7 +40,14 @@ class DomainObject(Versionable, Loggable, object): ...@@ -40,7 +40,14 @@ class DomainObject(Versionable, Loggable, object):
def __eq__(self, x): def __eq__(self, x):
if isinstance(x, type(self)): if isinstance(x, type(self)):
return hash(self) == hash(x) for key in 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
return True
else: else:
return False return False
......
...@@ -223,11 +223,7 @@ class FFTW(Transform): ...@@ -223,11 +223,7 @@ class FFTW(Transform):
local_offset_Q, is_local, transform_shape=None, local_offset_Q, is_local, transform_shape=None,
**kwargs): **kwargs):
# generate a id-tuple which identifies the domain-codomain setting # generate a id-tuple which identifies the domain-codomain setting
temp_id = (domain.__hash__() ^ temp_id = (domain, codomain, transform_shape, is_local)
(101 * codomain.__hash__()) ^
(211 * transform_shape.__hash__()) ^
(131 * is_local.__hash__())
)
# generate the plan_and_info object if not already there # generate the plan_and_info object if not already there
if temp_id not in self.info_dict: if temp_id not in self.info_dict:
......
...@@ -22,8 +22,7 @@ class _TransformationCache(object): ...@@ -22,8 +22,7 @@ class _TransformationCache(object):
self.cache = {} self.cache = {}
def create(self, transformation_class, domain, codomain, module): def create(self, transformation_class, domain, codomain, module):
key = domain.__hash__() ^ ((codomain.__hash__()/111) ^ key = (domain, codomain, module)
(module.__hash__())/179)
if key not in self.cache: if key not in self.cache:
self.cache[key] = transformation_class(domain, codomain, module) self.cache[key] = transformation_class(domain, codomain, module)
......
...@@ -25,13 +25,13 @@ class _PowerIndexFactory(object): ...@@ -25,13 +25,13 @@ class _PowerIndexFactory(object):
def get_power_index(self, domain, distribution_strategy, def get_power_index(self, domain, distribution_strategy,
log=False, nbin=None, binbounds=None): log=False, nbin=None, binbounds=None):
current_hash = domain.__hash__() ^ (111*hash(distribution_strategy)) key = (domain, distribution_strategy)
if current_hash not in self.power_indices_storage: if key not in self.power_indices_storage:
self.power_indices_storage[current_hash] = \ self.power_indices_storage[key] = \
PowerIndices(domain, distribution_strategy, PowerIndices(domain, distribution_strategy,
log=log, nbin=nbin, binbounds=binbounds) log=log, nbin=nbin, binbounds=binbounds)
power_indices = self.power_indices_storage[current_hash] power_indices = self.power_indices_storage[key]
power_index = power_indices.get_index_dict(log=log, power_index = power_indices.get_index_dict(log=log,
nbin=nbin, nbin=nbin,
binbounds=binbounds) binbounds=binbounds)
......
...@@ -157,7 +157,6 @@ class Space(DomainObject): ...@@ -157,7 +157,6 @@ class Space(DomainObject):
""" """
super(Space, self).__init__() super(Space, self).__init__()
self._ignore_for_hash += ['_global_id']
@abc.abstractproperty @abc.abstractproperty
def harmonic(self): def harmonic(self):
......
Markdown is supported
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