From 3e991a417686069909bda69e38ca71d97ccae08a Mon Sep 17 00:00:00 2001 From: Martin Reinecke <martin@mpa-garching.mpg.de> Date: Fri, 18 Aug 2017 09:56:55 +0200 Subject: [PATCH] remove inverse smoothing code, since it was broken and unused --- .../direct_smoothing_operator.py | 9 ++------- .../fft_smoothing_operator.py | 10 ++-------- .../smoothing_operator/smoothing_operator.py | 17 ++--------------- test/test_operators/test_smoothing_operator.py | 9 --------- 4 files changed, 6 insertions(+), 39 deletions(-) diff --git a/nifty/operators/smoothing_operator/direct_smoothing_operator.py b/nifty/operators/smoothing_operator/direct_smoothing_operator.py index fe4ad0d96..cca3a0a02 100644 --- a/nifty/operators/smoothing_operator/direct_smoothing_operator.py +++ b/nifty/operators/smoothing_operator/direct_smoothing_operator.py @@ -132,7 +132,7 @@ class DirectSmoothingOperator(SmoothingOperator): return outarr - def _smooth(self, x, spaces, inverse): + def _smooth(self, x, spaces): # infer affected axes # we rely on the knowledge, that `spaces` is a tuple with length 1. affected_axes = x.domain_axes[spaces[0]] @@ -203,18 +203,13 @@ class DirectSmoothingOperator(SmoothingOperator): # currently only one axis is supported data_axis = affected_axes[0] - if inverse: - true_sigma = 1. / self.sigma - else: - true_sigma = self.sigma - local_result = self._apply_along_axis( data_axis, augmented_data, startindex=true_start, endindex=true_end, distances=augmented_distance_array, - smooth_length=true_sigma, + smooth_length=self.sigma, smoothing_width=self.effective_smoothing_width) result = x.copy_empty() diff --git a/nifty/operators/smoothing_operator/fft_smoothing_operator.py b/nifty/operators/smoothing_operator/fft_smoothing_operator.py index 3b4c15baf..ebe721101 100644 --- a/nifty/operators/smoothing_operator/fft_smoothing_operator.py +++ b/nifty/operators/smoothing_operator/fft_smoothing_operator.py @@ -17,7 +17,7 @@ class FFTSmoothingOperator(SmoothingOperator): default_spaces=default_spaces) self._transformator_cache = {} - def _smooth(self, x, spaces, inverse): + def _smooth(self, x, spaces): # transform to the (global-)default codomain and perform all remaining # steps therein transformator = self._get_transformator(x.dtype) @@ -46,13 +46,7 @@ class FFTSmoothingOperator(SmoothingOperator): for i in xrange(len(transformed_x.shape))] local_kernel = np.reshape(local_kernel, reshaper) - # apply the kernel - if inverse: - # avoid zeroes in the kernel to work around divisions by zero - local_kernel = np.maximum(1e-12,local_kernel) - local_transformed_x /= local_kernel - else: - local_transformed_x *= local_kernel + local_transformed_x *= local_kernel transformed_x.val.set_local_data(local_transformed_x, copy=False) diff --git a/nifty/operators/smoothing_operator/smoothing_operator.py b/nifty/operators/smoothing_operator/smoothing_operator.py index 63843630e..dab542cfb 100644 --- a/nifty/operators/smoothing_operator/smoothing_operator.py +++ b/nifty/operators/smoothing_operator/smoothing_operator.py @@ -138,19 +138,6 @@ class SmoothingOperator(EndomorphicOperator): self._sigma = sigma self._log_distances = log_distances - def _inverse_times(self, x, spaces): - if self.sigma == 0: - return x.copy() - - # the domain of the smoothing operator contains exactly one space. - # Hence, if spaces is None, but we passed LinearOperator's - # _check_input_compatibility, we know that x is also solely defined - # on that space - if spaces is None: - spaces = (0,) - - return self._smooth(x, spaces, inverse=True) - def _times(self, x, spaces): if self.sigma == 0: return x.copy() @@ -162,7 +149,7 @@ class SmoothingOperator(EndomorphicOperator): if spaces is None: spaces = (0,) - return self._smooth(x, spaces, inverse=False) + return self._smooth(x, spaces) # ---Mandatory properties and methods--- @property @@ -188,5 +175,5 @@ class SmoothingOperator(EndomorphicOperator): return self._log_distances @abc.abstractmethod - def _smooth(self, x, spaces, inverse): + def _smooth(self, x, spaces): raise NotImplementedError diff --git a/test/test_operators/test_smoothing_operator.py b/test/test_operators/test_smoothing_operator.py index 3f830e5a9..99e86a795 100644 --- a/test/test_operators/test_smoothing_operator.py +++ b/test/test_operators/test_smoothing_operator.py @@ -69,15 +69,6 @@ class SmoothingOperator_Tests(unittest.TestCase): tt1 = op.times(rand1) assert_allclose(1, tt1.sum()) - @expand(product(spaces, [0., .5, 5.])) - def test_inverse_adjoint_times(self, space, sigma): - op = SmoothingOperator(space, sigma=sigma) - rand1 = Field.from_random('normal', domain=space) - rand2 = Field.from_random('normal', domain=space) - tt1 = rand1.vdot(op.inverse_times(rand2)) - tt2 = rand2.vdot(op.inverse_adjoint_times(rand1)) - assert_allclose(tt1, tt2) - @expand(product([128, 256], [1, 0.4], [0., 1., 3.7], [np.float64, np.complex128])) def test_smooth_regular1(self, sz, d, sigma, tp): -- GitLab