diff --git a/nifty/library/critical_filter/critical_power_curvature.py b/nifty/library/critical_filter/critical_power_curvature.py index 17089189f0305a27140a1b3896b7467a05ed9e71..8bfc858a61022f68f3fcac20faad98db8fea8b7f 100644 --- a/nifty/library/critical_filter/critical_power_curvature.py +++ b/nifty/library/critical_filter/critical_power_curvature.py @@ -33,23 +33,6 @@ class CriticalPowerCurvature(InvertibleOperatorMixin, EndomorphicOperator): preconditioner=preconditioner, **kwargs) - def _add_attributes_to_copy(self, copy, **kwargs): - copy._domain = self._domain - if 'theta' in kwargs: - theta = kwargs['theta'] - copy.theta = DiagonalOperator(theta.domain, diagonal=theta) - else: - copy.theta = self.theta.copy() - - if 'T' in kwargs: - copy.T = kwargs['T'] - else: - copy.T = self.T - - copy = super(CriticalPowerCurvature, - self)._add_attributes_to_copy(copy, **kwargs) - return copy - def _times(self, x, spaces): return self.T(x) + self.theta(x) diff --git a/nifty/library/critical_filter/critical_power_energy.py b/nifty/library/critical_filter/critical_power_energy.py index 0ca0ce7393744c5267ce770222255d71c1a9eec3..8ddf9d777e2b0f65c108a077ce2d6ca0ab8805c5 100644 --- a/nifty/library/critical_filter/critical_power_energy.py +++ b/nifty/library/critical_filter/critical_power_energy.py @@ -54,8 +54,7 @@ class CriticalPowerEnergy(Energy): # ---Overwritten properties and methods--- def __init__(self, position, m, D=None, alpha=1.0, q=0., - smoothness_prior=0., logarithmic=True, samples=3, w=None, - old_curvature=None): + smoothness_prior=0., logarithmic=True, samples=3, w=None): super(CriticalPowerEnergy, self).__init__(position=position) self.m = m self.D = D @@ -67,8 +66,6 @@ class CriticalPowerEnergy(Energy): logarithmic=logarithmic) self.rho = self.position.domain[0].rho self._w = w if w is not None else None - self._old_curvature = old_curvature - self._curvature = None # ---Mandatory properties and methods--- @@ -76,11 +73,9 @@ class CriticalPowerEnergy(Energy): return self.__class__(position, self.m, D=self.D, alpha=self.alpha, q=self.q, smoothness_prior=self.smoothness_prior, logarithmic=self.logarithmic, - w=self.w, samples=self.samples, - old_curvature=self._curvature) + w=self.w, samples=self.samples) @property - @memo def value(self): energy = self._theta.sum() energy += self.position.vdot(self._rho_prime, bare=True) @@ -88,7 +83,6 @@ class CriticalPowerEnergy(Energy): return energy.real @property - @memo def gradient(self): gradient = -self._theta.weight(-1) gradient += (self._rho_prime).weight(-1) @@ -98,14 +92,9 @@ class CriticalPowerEnergy(Energy): @property def curvature(self): - if self._curvature is None: - if self._old_curvature is None: - self._curvature = CriticalPowerCurvature( - theta=self._theta.weight(-1), T=self.T) - else: - self._curvature = self._old_curvature.copy( - theta=self._theta.weight(-1), T=self.T) - return self._curvature + curvature = CriticalPowerCurvature(theta=self._theta.weight(-1), + T=self.T) + return curvature # ---Added properties and methods--- diff --git a/nifty/library/log_normal_wiener_filter/log_normal_wiener_filter_curvature.py b/nifty/library/log_normal_wiener_filter/log_normal_wiener_filter_curvature.py index ddb81c51e697085113e2d9f4e433f665762ae71b..182dae37f01c644122dc4a72f3c5c60cbb242b46 100644 --- a/nifty/library/log_normal_wiener_filter/log_normal_wiener_filter_curvature.py +++ b/nifty/library/log_normal_wiener_filter/log_normal_wiener_filter_curvature.py @@ -48,23 +48,6 @@ class LogNormalWienerFilterCurvature(InvertibleOperatorMixin, preconditioner=preconditioner, **kwargs) - def _add_attributes_to_copy(self, copy, **kwargs): - copy._cache = {} - copy._domain = self._domain - copy.R = self.R.copy() - copy.N = self.N.copy() - copy.S = self.S.copy() - copy.d = self.d.copy() - if 'position' in kwargs: - copy.position = kwargs['position'] - else: - copy.position = self.position.copy() - copy._fft = self._fft - - copy = super(LogNormalWienerFilterCurvature, - self)._add_attributes_to_copy(copy, **kwargs) - return copy - @property def domain(self): return self._domain diff --git a/nifty/library/log_normal_wiener_filter/log_normal_wiener_filter_energy.py b/nifty/library/log_normal_wiener_filter/log_normal_wiener_filter_energy.py index d878f3fc5d2038f3b8323cfa853631668d6dea0f..ad221fc2f2c6b9a0d5d6d6df6d4ecfcee5b473d6 100644 --- a/nifty/library/log_normal_wiener_filter/log_normal_wiener_filter_energy.py +++ b/nifty/library/log_normal_wiener_filter/log_normal_wiener_filter_energy.py @@ -24,7 +24,7 @@ class LogNormalWienerFilterEnergy(Energy): The prior signal covariance in harmonic space. """ - def __init__(self, position, d, R, N, S, fft4exp=None, old_curvature=None): + def __init__(self, position, d, R, N, S, fft4exp=None): super(LogNormalWienerFilterEnergy, self).__init__(position=position) self.d = d self.R = R @@ -37,13 +37,9 @@ class LogNormalWienerFilterEnergy(Energy): else: self._fft = fft4exp - self._old_curvature = old_curvature - self._curvature = None - def at(self, position): return self.__class__(position=position, d=self.d, R=self.R, N=self.N, - S=self.S, fft4exp=self._fft, - old_curvature=self._curvature) + S=self.S, fft4exp=self._fft) @property @memo @@ -57,20 +53,11 @@ class LogNormalWienerFilterEnergy(Energy): return self._Sp + self._exppRNRexppd @property + @memo def curvature(self): - if self._curvature is None: - if self._old_curvature is None: - self._curvature = LogNormalWienerFilterCurvature( - R=self.R, - N=self.N, - S=self.S, - d=self.d, - position=self.position, - fft4exp=self._fft) - else: - self._curvature = \ - self._old_curvature.copy(position=self.position) - return self._curvature + return LogNormalWienerFilterCurvature(R=self.R, N=self.N, S=self.S, + d=self.d, position=self.position, + fft4exp=self._fft) @property def _expp(self): diff --git a/nifty/library/wiener_filter/wiener_filter_curvature.py b/nifty/library/wiener_filter/wiener_filter_curvature.py index d8e361377b63217990d63c1c7211f33441ac2920..5fb7b403ddb63ab23d0e123a1bf928328bfeb1af 100644 --- a/nifty/library/wiener_filter/wiener_filter_curvature.py +++ b/nifty/library/wiener_filter/wiener_filter_curvature.py @@ -35,15 +35,6 @@ class WienerFilterCurvature(InvertibleOperatorMixin, EndomorphicOperator): preconditioner=preconditioner, **kwargs) - def _add_attributes_to_copy(self, copy, **kwargs): - copy._domain = self._domain - copy.R = self.R.copy() - copy.N = self.N.copy() - copy.S = self.S.copy() - copy = super(WienerFilterCurvature, self)._add_attributes_to_copy( - copy, **kwargs) - return copy - @property def domain(self): return self._domain diff --git a/nifty/library/wiener_filter/wiener_filter_energy.py b/nifty/library/wiener_filter/wiener_filter_energy.py index 3d74d3ad8c54c7a7e40e390a5600c41038dc3213..63dd0cfad29acbe4a5482fe4d584f9e51fe21508 100644 --- a/nifty/library/wiener_filter/wiener_filter_energy.py +++ b/nifty/library/wiener_filter/wiener_filter_energy.py @@ -23,17 +23,16 @@ class WienerFilterEnergy(Energy): The prior signal covariance in harmonic space. """ - def __init__(self, position, d, R, N, S, old_curvature=None): + def __init__(self, position, d, R, N, S): super(WienerFilterEnergy, self).__init__(position=position) self.d = d self.R = R self.N = N self.S = S - self._curvature = old_curvature def at(self, position): return self.__class__(position=position, d=self.d, R=self.R, N=self.N, - S=self.S, old_curvature=self.curvature) + S=self.S) @property @memo @@ -46,12 +45,9 @@ class WienerFilterEnergy(Energy): return self._Dx - self._j @property + @memo def curvature(self): - if self._curvature is None: - self._curvature = WienerFilterCurvature(R=self.R, - N=self.N, - S=self.S) - return self._curvature + return WienerFilterCurvature(R=self.R, N=self.N, S=self.S) @property @memo diff --git a/nifty/operators/composed_operator/composed_operator.py b/nifty/operators/composed_operator/composed_operator.py index cbfe2fe0e69fda2d633f1cac0cab8a1ce98222b4..01319365bae3c8b6a5c6a0490243a07aff2cb2a5 100644 --- a/nifty/operators/composed_operator/composed_operator.py +++ b/nifty/operators/composed_operator/composed_operator.py @@ -85,14 +85,6 @@ class ComposedOperator(LinearOperator): "instances of the LinearOperator-baseclass") self._operator_store += (op,) - def _add_attributes_to_copy(self, copy, **kwargs): - copy._operator_store = () - for op in self._operator_store: - copy._operator_store += (op.copy(),) - copy = super(ComposedOperator, self)._add_attributes_to_copy( - copy, **kwargs) - return copy - def _check_input_compatibility(self, x, spaces, inverse=False): """ The input check must be disabled for the ComposedOperator, since it diff --git a/nifty/operators/diagonal_operator/diagonal_operator.py b/nifty/operators/diagonal_operator/diagonal_operator.py index b452632a9f6e55ed83ae97d020cb365cf0a4bac4..55353d4fccb3fb9ba7b69320df8db2b37439297d 100644 --- a/nifty/operators/diagonal_operator/diagonal_operator.py +++ b/nifty/operators/diagonal_operator/diagonal_operator.py @@ -90,15 +90,6 @@ class DiagonalOperator(EndomorphicOperator): self._unitary = None self.set_diagonal(diagonal=diagonal, bare=bare, copy=copy) - def _add_attributes_to_copy(self, copy, **kwargs): - copy._domain = self._domain - copy.set_diagonal(diagonal=self.diagonal(bare=True), bare=True) - copy._self_adjoint = self._self_adjoint - copy._unitary = self._unitary - copy = super(DiagonalOperator, self)._add_attributes_to_copy(copy, - **kwargs) - return copy - def _times(self, x, spaces): return self._times_helper(x, spaces, operation=lambda z: z.__mul__) @@ -107,8 +98,7 @@ class DiagonalOperator(EndomorphicOperator): operation=lambda z: z.adjoint().__mul__) def _inverse_times(self, x, spaces): - return self._times_helper( - x, spaces, operation=lambda z: z.__rtruediv__) + return self._times_helper(x, spaces, operation=lambda z: z.__rtruediv__) def _adjoint_inverse_times(self, x, spaces): return self._times_helper(x, spaces, diff --git a/nifty/operators/fft_operator/fft_operator.py b/nifty/operators/fft_operator/fft_operator.py index 9b91204cd5cf42b1a2e0831a9a3c771e1aa4e9fe..3c2c07251f4458808cf50b2feae1c767ee16a143 100644 --- a/nifty/operators/fft_operator/fft_operator.py +++ b/nifty/operators/fft_operator/fft_operator.py @@ -125,15 +125,6 @@ class FFTOperator(LinearOperator): self._backward_transformation = backward_class( self.target[0], self.domain[0]) - def _add_attributes_to_copy(self, copy, **kwargs): - copy._domain = self._domain - copy._target = self._target - copy._forward_transformation = self._forward_transformation - copy._backward_transformation = self._backward_transformation - copy = super(FFTOperator, self)._add_attributes_to_copy(copy, - **kwargs) - return copy - def _times(self, x, spaces): spaces = utilities.cast_axis_to_tuple(spaces, len(x.domain)) if spaces is None: diff --git a/nifty/operators/invertible_operator_mixin/invertible_operator_mixin.py b/nifty/operators/invertible_operator_mixin/invertible_operator_mixin.py index b84900f3d2d03ffb7a87957cfc5dfdb99d73a556..9c2135c298d563788c54bc0a4393c344471452ec 100644 --- a/nifty/operators/invertible_operator_mixin/invertible_operator_mixin.py +++ b/nifty/operators/invertible_operator_mixin/invertible_operator_mixin.py @@ -57,23 +57,6 @@ class InvertibleOperatorMixin(object): self.__backward_x0 = backward_x0 super(InvertibleOperatorMixin, self).__init__(*args, **kwargs) - def _add_attributes_to_copy(self, copy, **kwargs): - copy.__preconditioner = self.__preconditioner - copy.__inverter = self.__inverter - try: - copy.__forward_x0 = self.__forward_x0.copy() - except AttributeError: - copy.__forward_x0 = self.__forward_x0 - - try: - copy.__backward_x0 = self.__backward_x0.copy() - except AttributeError: - copy.__backward_x0 = self.__backward_x0 - - copy = super(InvertibleOperatorMixin, self)._add_attributes_to_copy( - copy, **kwargs) - return copy - def _times(self, x, spaces): if self.__forward_x0 is not None: x0 = self.__forward_x0 diff --git a/nifty/operators/laplace_operator/laplace_operator.py b/nifty/operators/laplace_operator/laplace_operator.py index 3be1fd6a4f516cfc97474685ccbc9745124bd968..8f0dd0f9d09031439d0b04b49b6db07436becaa1 100644 --- a/nifty/operators/laplace_operator/laplace_operator.py +++ b/nifty/operators/laplace_operator/laplace_operator.py @@ -64,15 +64,6 @@ class LaplaceOperator(EndomorphicOperator): self._dposc[1:] += self._dpos self._dposc *= 0.5 - def _add_attributes_to_copy(self, copy, **kwargs): - copy._domain = self._domain - copy._logarithmic = self._logarithmic - copy._dpos = self._dpos - copy._dposc = self._dposc - copy = super(LaplaceOperator, self)._add_attributes_to_copy(copy, - **kwargs) - return copy - @property def target(self): return self._domain diff --git a/nifty/operators/linear_operator/linear_operator.py b/nifty/operators/linear_operator/linear_operator.py index 345e24984a829a75e7f096db5ae0a9894f2fe9a4..93a277228a299db28a1e2b5061b2dab7bc58452c 100644 --- a/nifty/operators/linear_operator/linear_operator.py +++ b/nifty/operators/linear_operator/linear_operator.py @@ -70,20 +70,6 @@ class LinearOperator(with_metaclass( def __init__(self, default_spaces=None): self._default_spaces = default_spaces - def copy(self, **kwargs): - class EmptyCopy(self.__class__): - def __init__(self): - pass - - result = EmptyCopy() - result.__class__ = self.__class__ - result = self._add_attributes_to_copy(result, **kwargs) - return result - - def _add_attributes_to_copy(self, copy, **kwargs): - copy._default_spaces = self.default_spaces - return copy - @staticmethod def _parse_domain(domain): return utilities.parse_domain(domain) diff --git a/nifty/operators/projection_operator/projection_operator.py b/nifty/operators/projection_operator/projection_operator.py index 1c5316fb5232d174f56c9ce626926925ef00d95e..9a5086be32c6df19e9dc3c506ef213bc3991b022 100644 --- a/nifty/operators/projection_operator/projection_operator.py +++ b/nifty/operators/projection_operator/projection_operator.py @@ -87,13 +87,6 @@ class ProjectionOperator(EndomorphicOperator): self._projection_field = projection_field self._unitary = None - def _add_attributes_to_copy(self, copy, **kwargs): - copy._projection_field = self._projection_field - copy._unitary = self._unitary - copy = super(ProjectionOperator, self)._add_attributes_to_copy( - copy, **kwargs) - return copy - def _times(self, x, spaces): # if the domain matches directly # -> multiply the fields directly diff --git a/nifty/operators/response_operator/response_operator.py b/nifty/operators/response_operator/response_operator.py index ba884bb6d4a5be3571a3f3b02c6587b377cb12c6..510da740f6de9e634fe75bcc72df85c69a30078e 100644 --- a/nifty/operators/response_operator/response_operator.py +++ b/nifty/operators/response_operator/response_operator.py @@ -61,7 +61,7 @@ class ResponseOperator(LinearOperator): for ii in range(len(kernel_smoothing)): kernel_smoothing[ii] = FFTSmoothingOperator(self._domain[ii], - sigma=sigma[ii]) + sigma=sigma[ii]) kernel_exposure[ii] = DiagonalOperator(self._domain[ii], diagonal=exposure[ii]) @@ -74,15 +74,6 @@ class ResponseOperator(LinearOperator): self._target = self._parse_domain(target_list) - def _add_attributes_to_copy(self, copy, **kwargs): - copy._domain = self._domain - copy._target = self._target - copy._composed_kernel = self._composed_kernel.copy() - copy._composed_exposure = self._composed_exposure.copy() - copy = super(DiagonalOperator, self)._add_attributes_to_copy(copy, - **kwargs) - return copy - @property def domain(self): return self._domain diff --git a/nifty/operators/smoothing_operator/direct_smoothing_operator.py b/nifty/operators/smoothing_operator/direct_smoothing_operator.py index 5a356cb4f10aaf2f7659b82cf495ef3ea581c20a..51ff77646a38ec08461267b78c954c38ca2655db 100644 --- a/nifty/operators/smoothing_operator/direct_smoothing_operator.py +++ b/nifty/operators/smoothing_operator/direct_smoothing_operator.py @@ -57,13 +57,6 @@ class DirectSmoothingOperator(EndomorphicOperator): def log_distances(self): return self._log_distances - def _add_attributes_to_copy(self, copy, **kwargs): - copy.effective_smoothing_width = self.effective_smoothing_width - - copy = super(DirectSmoothingOperator, self)._add_attributes_to_copy( - copy, **kwargs) - return copy - def _precompute(self, x, sigma, dxmax=None): """ Does precomputations for Gaussian smoothing on a 1D irregular grid. diff --git a/nifty/operators/smoothing_operator/fft_smoothing_operator.py b/nifty/operators/smoothing_operator/fft_smoothing_operator.py index 54ec531de1e1d8062cca6244b77622a2ad7833a7..e08c68139640a50f361d51add5a6bb574a504901 100644 --- a/nifty/operators/smoothing_operator/fft_smoothing_operator.py +++ b/nifty/operators/smoothing_operator/fft_smoothing_operator.py @@ -53,13 +53,6 @@ class FFTSmoothingOperator(EndomorphicOperator): def sigma(self): return self._sigma - def _add_attributes_to_copy(self, copy, **kwargs): - copy._transformator_cache = self._transformator_cache - - copy = super(FFTSmoothingOperator, self)._add_attributes_to_copy( - copy, **kwargs) - return copy - def _smooth(self, x, spaces): # transform to the (global-)default codomain and perform all remaining # steps therein diff --git a/nifty/operators/smoothness_operator/smoothness_operator.py b/nifty/operators/smoothness_operator/smoothness_operator.py index 11b5673b6d92fe786ea3f299aff6af1e5f64f250..e937cf9dcd9ae7cf7b35ec5f36b17059f6009f4a 100644 --- a/nifty/operators/smoothness_operator/smoothness_operator.py +++ b/nifty/operators/smoothness_operator/smoothness_operator.py @@ -48,15 +48,6 @@ class SmoothnessOperator(EndomorphicOperator): self._laplace = LaplaceOperator(domain=self.domain, logarithmic=logarithmic) - def _add_attributes_to_copy(self, copy, **kwargs): - copy._domain = self._domain - copy._strength = self._strength - copy._laplace = self._laplace.copy() - - copy = super(SmoothnessOperator, self)._add_attributes_to_copy( - copy, **kwargs) - return copy - # ---Mandatory properties and methods--- @property