From 72670f97c184fe56bb1e68f99b9f0d7c86027ac9 Mon Sep 17 00:00:00 2001 From: Martin Reinecke Date: Sat, 17 Feb 2018 13:58:12 +0100 Subject: [PATCH] rework _needed_for_hash --- nifty4/domain_tuple.py | 2 +- nifty4/domains/dof_space.py | 4 +++- nifty4/domains/domain.py | 10 ++-------- nifty4/domains/gl_space.py | 3 ++- nifty4/domains/hp_space.py | 3 ++- nifty4/domains/lm_space.py | 3 ++- nifty4/domains/power_space.py | 2 +- nifty4/domains/rg_space.py | 2 +- nifty4/domains/unstructured_domain.py | 2 +- 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/nifty4/domain_tuple.py b/nifty4/domain_tuple.py index 901624c0..3eb51ad7 100644 --- a/nifty4/domain_tuple.py +++ b/nifty4/domain_tuple.py @@ -11,7 +11,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Copyright(C) 2013-2017 Max-Planck-Society +# Copyright(C) 2013-2018 Max-Planck-Society # # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # and financially supported by the Studienstiftung des deutschen Volkes. diff --git a/nifty4/domains/dof_space.py b/nifty4/domains/dof_space.py index a1ce6002..967aeb5d 100644 --- a/nifty4/domains/dof_space.py +++ b/nifty4/domains/dof_space.py @@ -22,10 +22,12 @@ from .structured_domain import StructuredDomain class DOFSpace(StructuredDomain): """Generic degree-of-freedom space.""" + + _needed_for_hash = ["_dvol"] + def __init__(self, dof_weights): super(DOFSpace, self).__init__() self._dvol = tuple(dof_weights) - self._needed_for_hash += ['_dvol'] @property def harmonic(self): diff --git a/nifty4/domains/domain.py b/nifty4/domains/domain.py index 09b40dc6..1f783efe 100644 --- a/nifty4/domains/domain.py +++ b/nifty4/domains/domain.py @@ -25,16 +25,10 @@ import numpy as np class Domain(with_metaclass( NiftyMeta, type('NewBase', (object,), {}))): """The abstract class repesenting a (structured or unstructured) domain. - - Attributes: - ----------- - _needed_for_hash : list of str - the names of all members that are relevant for comparison against - other Domain objects. """ def __init__(self): - self._needed_for_hash = [] + pass @abc.abstractmethod def __repr__(self): @@ -68,7 +62,7 @@ class Domain(with_metaclass( Notes ----- Only members that are explicitly added to - :attr:`._needed_for_hash` will be used for comparisom. + :attr:`._needed_for_hash` will be used for comparison. Subclasses of Domain should not re-define :meth:`__eq__`, :meth:`__ne__`, or :meth:`__hash__`; they should instead add their diff --git a/nifty4/domains/gl_space.py b/nifty4/domains/gl_space.py index 02bce2d5..6afc7850 100644 --- a/nifty4/domains/gl_space.py +++ b/nifty4/domains/gl_space.py @@ -37,9 +37,10 @@ class GLSpace(StructuredDomain): Default value is 2*nlat + 1. """ + _needed_for_hash = ["_nlat", "_nlon"] + def __init__(self, nlat, nlon=None): super(GLSpace, self).__init__() - self._needed_for_hash += ["_nlat", "_nlon"] self._nlat = int(nlat) if self._nlat < 1: diff --git a/nifty4/domains/hp_space.py b/nifty4/domains/hp_space.py index 653021d9..4971dbdb 100644 --- a/nifty4/domains/hp_space.py +++ b/nifty4/domains/hp_space.py @@ -34,9 +34,10 @@ class HPSpace(StructuredDomain): and typically is a power of 2. """ + _needed_for_hash = ["_nside"] + def __init__(self, nside): super(HPSpace, self).__init__() - self._needed_for_hash += ["_nside"] self._nside = int(nside) if self._nside < 1: raise ValueError("nside must be >=1.") diff --git a/nifty4/domains/lm_space.py b/nifty4/domains/lm_space.py index 37e78bfb..ab49b365 100644 --- a/nifty4/domains/lm_space.py +++ b/nifty4/domains/lm_space.py @@ -43,9 +43,10 @@ class LMSpace(StructuredDomain): Must be :math:`\ge 0` and :math:`\le` `lmax`. """ + _needed_for_hash = ["_lmax", "_mmax"] + def __init__(self, lmax, mmax=None): super(LMSpace, self).__init__() - self._needed_for_hash += ["_lmax", "_mmax"] self._lmax = np.int(lmax) if self._lmax < 0: raise ValueError("lmax must be >=0.") diff --git a/nifty4/domains/power_space.py b/nifty4/domains/power_space.py index 8f5f4b9e..023ae4bc 100644 --- a/nifty4/domains/power_space.py +++ b/nifty4/domains/power_space.py @@ -46,6 +46,7 @@ class PowerSpace(StructuredDomain): """ _powerIndexCache = {} + _needed_for_hash = ["_harmonic_partner", "_binbounds"] @staticmethod def linear_binbounds(nbin, first_bound, last_bound): @@ -138,7 +139,6 @@ class PowerSpace(StructuredDomain): def __init__(self, harmonic_partner, binbounds=None): super(PowerSpace, self).__init__() - self._needed_for_hash += ['_harmonic_partner', '_binbounds'] if not (isinstance(harmonic_partner, StructuredDomain) and harmonic_partner.harmonic): diff --git a/nifty4/domains/rg_space.py b/nifty4/domains/rg_space.py index 7be46ab6..32bc0fbf 100644 --- a/nifty4/domains/rg_space.py +++ b/nifty4/domains/rg_space.py @@ -47,10 +47,10 @@ class RGSpace(StructuredDomain): Whether the space represents a grid in position or harmonic space. (default: False). """ + _needed_for_hash = ["_distances", "_shape", "_harmonic"] def __init__(self, shape, distances=None, harmonic=False): super(RGSpace, self).__init__() - self._needed_for_hash += ["_distances", "_shape", "_harmonic"] self._harmonic = bool(harmonic) if np.isscalar(shape): diff --git a/nifty4/domains/unstructured_domain.py b/nifty4/domains/unstructured_domain.py index 80b55533..bfd72ce7 100644 --- a/nifty4/domains/unstructured_domain.py +++ b/nifty4/domains/unstructured_domain.py @@ -26,10 +26,10 @@ class UnstructuredDomain(Domain): Typically used for data spaces. """ + _needed_for_hash = ["_shape"] def __init__(self, shape): super(UnstructuredDomain, self).__init__() - self._needed_for_hash += ["_shape"] try: self._shape = tuple([int(i) for i in shape]) except TypeError: -- GitLab