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

rework _needed_for_hash

parent f516d934
......@@ -11,7 +11,7 @@
# You should have received a copy of the GNU General Public License
# 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
# and financially supported by the Studienstiftung des deutschen Volkes.
......
......@@ -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):
......
......@@ -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
......
......@@ -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:
......
......@@ -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.")
......
......@@ -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.")
......
......@@ -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):
......
......@@ -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):
......
......@@ -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:
......
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