Commit f94e696d by Martin Reinecke

### try to improve ditance handling

parent c7bbcba3
 ... ... @@ -47,9 +47,9 @@ class RGSpace(StructuredDomain): Topologically, a n-dimensional RGSpace is a n-Torus, i.e. it has periodic boundary conditions. """ _needed_for_hash = ["_distances", "_shape", "_harmonic"] _needed_for_hash = ["_rdistances", "_shape", "_harmonic"] def __init__(self, shape, distances=None, harmonic=False): def __init__(self, shape, distances=None, harmonic=False, _realdistances=None): self._harmonic = bool(harmonic) if np.isscalar(shape): shape = (shape,) ... ... @@ -57,21 +57,30 @@ class RGSpace(StructuredDomain): if min(self._shape) < 0: raise ValueError('Negative number of pixels encountered') if _realdistances is not None: self._rdistances = _realdistances else: if distances is None: if self.harmonic: self._distances = (1.,) * len(self._shape) if self._harmonic: self._rdistances = tuple(1. / (np.array(self._shape))) else: self._distances = tuple(1./s for s in self._shape) self._rdistances = tuple(1./s for s in self._shape) elif np.isscalar(distances): self._distances = (float(distances),) * len(self._shape) if self.harmonic: self._rdistances = tuple( 1. / (np.array(self._shape) * float(distances))) else: self._rdistances = (float(distances),) * len(self._shape) else: temp = np.empty(len(self.shape), dtype=np.float64) temp[:] = distances self._distances = tuple(temp) if min(self._distances) <= 0: if self._harmonic: temp = 1. / (np.array(self._shape) * temp) self._rdistances = tuple(temp) if min(self._rdistances) <= 0: raise ValueError('Non-positive distances encountered') self._dvol = float(reduce(lambda x, y: x*y, self._distances)) self._dvol = float(reduce(lambda x, y: x*y, self.distances)) self._size = int(reduce(lambda x, y: x*y, self._shape)) def __repr__(self): ... ... @@ -181,8 +190,7 @@ class RGSpace(StructuredDomain): RGSpace The partner domain """ distances = 1. / (np.array(self.shape)*np.array(self.distances)) return RGSpace(self.shape, distances, not self.harmonic) return RGSpace(self.shape, None, not self.harmonic, self._rdistances) def check_codomain(self, codomain): """Raises `TypeError` if `codomain` is not a matching partner domain ... ... @@ -212,4 +220,7 @@ class RGSpace(StructuredDomain): The n-th entry of the tuple is the distance between neighboring grid points along the n-th dimension. """ return self._distances if self._harmonic: return tuple(1. / (np.array(self.shape)*np.array(self._rdistances))) else: return self._rdistances
 ... ... @@ -98,3 +98,9 @@ def test_k_length_array(shape, distances, expected): def test_dvol(shape, distances, harmonic, power): r = ift.RGSpace(shape=shape, distances=distances, harmonic=harmonic) assert_allclose(r.dvol, np.prod(r.distances)**power) def test_codomain(): for i in range(1, 1000): r = ift.RGSpace(shape=(i,), distances=(1.,), harmonic=False) assert_equal(r.get_default_codomain().get_default_codomain(), r)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!