Commit 72670f97 authored by Martin Reinecke's avatar Martin Reinecke

rework _needed_for_hash

parent f516d934
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
# 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 # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
......
...@@ -22,10 +22,12 @@ from .structured_domain import StructuredDomain ...@@ -22,10 +22,12 @@ from .structured_domain import StructuredDomain
class DOFSpace(StructuredDomain): class DOFSpace(StructuredDomain):
"""Generic degree-of-freedom space.""" """Generic degree-of-freedom space."""
_needed_for_hash = ["_dvol"]
def __init__(self, dof_weights): def __init__(self, dof_weights):
super(DOFSpace, self).__init__() super(DOFSpace, self).__init__()
self._dvol = tuple(dof_weights) self._dvol = tuple(dof_weights)
self._needed_for_hash += ['_dvol']
@property @property
def harmonic(self): def harmonic(self):
......
...@@ -25,16 +25,10 @@ import numpy as np ...@@ -25,16 +25,10 @@ import numpy as np
class Domain(with_metaclass( class Domain(with_metaclass(
NiftyMeta, type('NewBase', (object,), {}))): NiftyMeta, type('NewBase', (object,), {}))):
"""The abstract class repesenting a (structured or unstructured) domain. """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): def __init__(self):
self._needed_for_hash = [] pass
@abc.abstractmethod @abc.abstractmethod
def __repr__(self): def __repr__(self):
...@@ -68,7 +62,7 @@ class Domain(with_metaclass( ...@@ -68,7 +62,7 @@ class Domain(with_metaclass(
Notes Notes
----- -----
Only members that are explicitly added to 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__`, Subclasses of Domain should not re-define :meth:`__eq__`,
:meth:`__ne__`, or :meth:`__hash__`; they should instead add their :meth:`__ne__`, or :meth:`__hash__`; they should instead add their
......
...@@ -37,9 +37,10 @@ class GLSpace(StructuredDomain): ...@@ -37,9 +37,10 @@ class GLSpace(StructuredDomain):
Default value is 2*nlat + 1. Default value is 2*nlat + 1.
""" """
_needed_for_hash = ["_nlat", "_nlon"]
def __init__(self, nlat, nlon=None): def __init__(self, nlat, nlon=None):
super(GLSpace, self).__init__() super(GLSpace, self).__init__()
self._needed_for_hash += ["_nlat", "_nlon"]
self._nlat = int(nlat) self._nlat = int(nlat)
if self._nlat < 1: if self._nlat < 1:
......
...@@ -34,9 +34,10 @@ class HPSpace(StructuredDomain): ...@@ -34,9 +34,10 @@ class HPSpace(StructuredDomain):
and typically is a power of 2. and typically is a power of 2.
""" """
_needed_for_hash = ["_nside"]
def __init__(self, nside): def __init__(self, nside):
super(HPSpace, self).__init__() super(HPSpace, self).__init__()
self._needed_for_hash += ["_nside"]
self._nside = int(nside) self._nside = int(nside)
if self._nside < 1: if self._nside < 1:
raise ValueError("nside must be >=1.") raise ValueError("nside must be >=1.")
......
...@@ -43,9 +43,10 @@ class LMSpace(StructuredDomain): ...@@ -43,9 +43,10 @@ class LMSpace(StructuredDomain):
Must be :math:`\ge 0` and :math:`\le` `lmax`. Must be :math:`\ge 0` and :math:`\le` `lmax`.
""" """
_needed_for_hash = ["_lmax", "_mmax"]
def __init__(self, lmax, mmax=None): def __init__(self, lmax, mmax=None):
super(LMSpace, self).__init__() super(LMSpace, self).__init__()
self._needed_for_hash += ["_lmax", "_mmax"]
self._lmax = np.int(lmax) self._lmax = np.int(lmax)
if self._lmax < 0: if self._lmax < 0:
raise ValueError("lmax must be >=0.") raise ValueError("lmax must be >=0.")
......
...@@ -46,6 +46,7 @@ class PowerSpace(StructuredDomain): ...@@ -46,6 +46,7 @@ class PowerSpace(StructuredDomain):
""" """
_powerIndexCache = {} _powerIndexCache = {}
_needed_for_hash = ["_harmonic_partner", "_binbounds"]
@staticmethod @staticmethod
def linear_binbounds(nbin, first_bound, last_bound): def linear_binbounds(nbin, first_bound, last_bound):
...@@ -138,7 +139,6 @@ class PowerSpace(StructuredDomain): ...@@ -138,7 +139,6 @@ class PowerSpace(StructuredDomain):
def __init__(self, harmonic_partner, binbounds=None): def __init__(self, harmonic_partner, binbounds=None):
super(PowerSpace, self).__init__() super(PowerSpace, self).__init__()
self._needed_for_hash += ['_harmonic_partner', '_binbounds']
if not (isinstance(harmonic_partner, StructuredDomain) and if not (isinstance(harmonic_partner, StructuredDomain) and
harmonic_partner.harmonic): harmonic_partner.harmonic):
......
...@@ -47,10 +47,10 @@ class RGSpace(StructuredDomain): ...@@ -47,10 +47,10 @@ class RGSpace(StructuredDomain):
Whether the space represents a grid in position or harmonic space. Whether the space represents a grid in position or harmonic space.
(default: False). (default: False).
""" """
_needed_for_hash = ["_distances", "_shape", "_harmonic"]
def __init__(self, shape, distances=None, harmonic=False): def __init__(self, shape, distances=None, harmonic=False):
super(RGSpace, self).__init__() super(RGSpace, self).__init__()
self._needed_for_hash += ["_distances", "_shape", "_harmonic"]
self._harmonic = bool(harmonic) self._harmonic = bool(harmonic)
if np.isscalar(shape): if np.isscalar(shape):
......
...@@ -26,10 +26,10 @@ class UnstructuredDomain(Domain): ...@@ -26,10 +26,10 @@ class UnstructuredDomain(Domain):
Typically used for data spaces. Typically used for data spaces.
""" """
_needed_for_hash = ["_shape"]
def __init__(self, shape): def __init__(self, shape):
super(UnstructuredDomain, self).__init__() super(UnstructuredDomain, self).__init__()
self._needed_for_hash += ["_shape"]
try: try:
self._shape = tuple([int(i) for i in shape]) self._shape = tuple([int(i) for i in shape])
except TypeError: except TypeError:
......
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