Commit 75145bf8 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

further small tweaks

parent 76145cba
Pipeline #18337 passed with stage
in 6 minutes and 3 seconds
......@@ -41,7 +41,7 @@ class DomainObject(with_metaclass(
"""
def __init__(self):
self._ignore_for_hash = []
self._ignore_for_hash = ['_ignore_for_hash']
@abc.abstractmethod
def __repr__(self):
......@@ -51,10 +51,8 @@ class DomainObject(with_metaclass(
# 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)
if key not in self._ignore_for_hash:
result_hash ^= vars(self)[key].__hash__() ^ int(hash(key)//117)
return result_hash
def __eq__(self, x):
......@@ -73,18 +71,13 @@ class DomainObject(with_metaclass(
"""
if self is x: # shortcut for simple case
return True
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
return True
else:
if not isinstance(x, type(self)):
return False
for key in list(vars(self).keys()):
if key not in self._ignore_for_hash:
if vars(self)[key] != vars(x)[key]:
return False
return True
def __ne__(self, x):
return not self.__eq__(x)
......
......@@ -82,9 +82,11 @@ class GLSpace(Space):
def __init__(self, nlat, nlon=None):
super(GLSpace, self).__init__()
self._ignore_for_hash += ["_wgt"]
self._nlat = self._parse_nlat(nlat)
self._nlon = self._parse_nlon(nlon)
self._wgt = None
# ---Mandatory properties and methods---
......@@ -113,10 +115,13 @@ class GLSpace(Space):
def scalar_weight(self):
return None
# MR FIXME: this is potentially wasteful, since the return array is
# blown up by a factor of self.nlon
def weight(self):
from pyHealpix import GL_weights
vol = GL_weights(self.nlat, self.nlon)
return np.outer(vol, np.ones(self.nlon,dtype=np.float64)).ravel()
if self._wgt is None:
self._wgt = GL_weights(self.nlat, self.nlon)
return np.repeat(self._wgt, self.nlon)
# ---Added properties and methods---
......
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