From cb5ac9c6ff2f021e99abd89b8ca584c3a08b5d71 Mon Sep 17 00:00:00 2001 From: Martin Reinecke <martin@mpa-garching.mpg.de> Date: Thu, 12 Oct 2017 13:35:53 +0200 Subject: [PATCH] comment cleanup --- nifty/operators/composed_operator.py | 22 +---------- nifty/operators/diagonal_operator.py | 13 ++----- nifty/operators/direct_smoothing_operator.py | 1 - nifty/operators/endomorphic_operator.py | 17 +------- nifty/operators/fft_operator.py | 4 -- nifty/operators/fft_smoothing_operator.py | 3 -- nifty/operators/invertible_operator_mixin.py | 13 +++---- nifty/operators/laplace_operator.py | 8 ++-- nifty/operators/linear_operator.py | 41 ++++++-------------- nifty/operators/smoothness_operator.py | 6 --- 10 files changed, 27 insertions(+), 101 deletions(-) diff --git a/nifty/operators/composed_operator.py b/nifty/operators/composed_operator.py index aacc9172d..8acff7a89 100644 --- a/nifty/operators/composed_operator.py +++ b/nifty/operators/composed_operator.py @@ -20,6 +20,7 @@ from builtins import range from .linear_operator import LinearOperator from .. import DomainTuple + class ComposedOperator(LinearOperator): """ NIFTY class for composed operators. @@ -46,27 +47,6 @@ class ComposedOperator(LinearOperator): Raised if * an element of the operator list is not an instance of the LinearOperator base class. - - Notes - ----- - Very useful in case one has to transform a Field living over a product - space (see example below). - - Examples - -------- - Minimal example of transforming a Field living on two domains into its - harmonic space. - - >>> x1 = RGSpace(5) - >>> x2 = RGSpace(10) - >>> k1 = RGRGTransformation.get_codomain(x1) - >>> k2 = RGRGTransformation.get_codomain(x2) - >>> FFT1 = FFTOperator(domain=(x1,x2), target=(k1,x2), space=0) - >>> FFT2 = FFTOperator(domain=(k1,x2), target=(k1,k2), space=1) - >>> FFT = ComposedOperator((FFT1, FFT2) - >>> f = Field.from_random('normal', domain=(x1,x2)) - >>> FFT.times(f) - """ # ---Overwritten properties and methods--- diff --git a/nifty/operators/diagonal_operator.py b/nifty/operators/diagonal_operator.py index c830da847..f45870cac 100644 --- a/nifty/operators/diagonal_operator.py +++ b/nifty/operators/diagonal_operator.py @@ -31,7 +31,6 @@ class DiagonalOperator(EndomorphicOperator): EndomorphicOperator. It multiplies an input field pixel-wise with its diagonal. - Parameters ---------- diagonal : Field @@ -55,14 +54,15 @@ class DiagonalOperator(EndomorphicOperator): self_adjoint : boolean Indicates whether the operator is self_adjoint or not. + NOTE: the fields given to __init__ and returned from .diagonal() are + considered to be bare, i.e. during operator application, the colume factors + are applied explicitly. + See Also -------- EndomorphicOperator - """ - # ---Overwritten properties and methods--- - def __init__(self, diagonal, domain=None, spaces=None): super(DiagonalOperator, self).__init__() @@ -113,12 +113,9 @@ class DiagonalOperator(EndomorphicOperator): ------- out : Field The diagonal of the Operator. - """ return self._diagonal.weight(-1) - # ---Mandatory properties and methods--- - @property def domain(self): return self._domain @@ -138,8 +135,6 @@ class DiagonalOperator(EndomorphicOperator): self._unitary = (abs(self._diagonal.val) == 1.).all() return self._unitary - # ---Added properties and methods--- - def _times_helper(self, x, operation): if self._spaces is None: return operation(self._diagonal)(x) diff --git a/nifty/operators/direct_smoothing_operator.py b/nifty/operators/direct_smoothing_operator.py index 0967e6f70..bdd11367b 100644 --- a/nifty/operators/direct_smoothing_operator.py +++ b/nifty/operators/direct_smoothing_operator.py @@ -71,7 +71,6 @@ class DirectSmoothingOperator(EndomorphicOperator): wgt[i] is an array with nval[i] entries containing the normalized smoothing weights. """ - dxmax = self._effective_smoothing_width*self._sigma x = np.asarray(x) diff --git a/nifty/operators/endomorphic_operator.py b/nifty/operators/endomorphic_operator.py index dafb5add7..9e3c8fc29 100644 --- a/nifty/operators/endomorphic_operator.py +++ b/nifty/operators/endomorphic_operator.py @@ -38,17 +38,8 @@ class EndomorphicOperator(LinearOperator): Indicates whether the Operator is unitary or not. self_adjoint : boolean Indicates whether the operator is self_adjoint or not. - - Raises - ------ - NotImplementedError - Raised if - * self_adjoint is not defined - """ - # ---Overwritten properties and methods--- - def inverse_times(self, x): if self.self_adjoint and self.unitary: return self.times(x) @@ -73,17 +64,11 @@ class EndomorphicOperator(LinearOperator): else: return super(EndomorphicOperator, self).inverse_adjoint_times(x) - # ---Mandatory properties and methods--- - @property def target(self): return self.domain - # ---Added properties and methods--- - @abc.abstractproperty def self_adjoint(self): - """ States whether the Operator is self_adjoint or not. - """ - + """ States whether the Operator is self_adjoint or not.""" raise NotImplementedError diff --git a/nifty/operators/fft_operator.py b/nifty/operators/fft_operator.py index f4c82338f..b069cca91 100644 --- a/nifty/operators/fft_operator.py +++ b/nifty/operators/fft_operator.py @@ -91,8 +91,6 @@ class FFTOperator(LinearOperator): (LMSpace, GLSpace): LMGLTransformation } - # ---Overwritten properties and methods--- - def __init__(self, domain, target=None, space=None): super(FFTOperator, self).__init__() @@ -141,8 +139,6 @@ class FFTOperator(LinearOperator): def _adjoint_times(self, x): return self._times_helper(x, self.domain, self._backward_transformation) - # ---Mandatory properties and methods--- - @property def domain(self): return self._domain diff --git a/nifty/operators/fft_smoothing_operator.py b/nifty/operators/fft_smoothing_operator.py index 9945989fa..63765094f 100644 --- a/nifty/operators/fft_smoothing_operator.py +++ b/nifty/operators/fft_smoothing_operator.py @@ -32,7 +32,6 @@ class FFTSmoothingOperator(EndomorphicOperator): return self._smooth(x) - # ---Mandatory properties and methods--- @property def domain(self): return self._transformator.domain @@ -45,8 +44,6 @@ class FFTSmoothingOperator(EndomorphicOperator): def unitary(self): return False - # ---Added properties and methods--- - def _smooth(self, x): # transform to the (global-)default codomain and perform all remaining # steps therein diff --git a/nifty/operators/invertible_operator_mixin.py b/nifty/operators/invertible_operator_mixin.py index 632abce75..c2b533ed4 100644 --- a/nifty/operators/invertible_operator_mixin.py +++ b/nifty/operators/invertible_operator_mixin.py @@ -24,18 +24,17 @@ from ..field import Field class InvertibleOperatorMixin(object): """ Mixin class to invert implicit defined operators. - To invert the application of a given implicitly defined operator on a - field, this class gives the necessary functionality. Inheriting - functionality from this class provides the derived class with the inverse - to the given implicitly definied application of the operator on a field. - (e.g. .inverse_times vs. .times and - .adjoint_times vs. .adjoint_inverse_times) + This class provides the functionality necessary to invert the application + of a given implicitly defined operator on a field. Inheriting + functionality from this class provides the derived class with the + operations inverse to the defined operator applications + (e.g. .inverse_times if .times is defined and + .adjoint_times if .adjoint_inverse_times is defined) Parameters ---------- inverter : Inverter An instance of an Inverter class. - """ def __init__(self, inverter, preconditioner=None, diff --git a/nifty/operators/laplace_operator.py b/nifty/operators/laplace_operator.py index ac5cc9006..53d2742f4 100644 --- a/nifty/operators/laplace_operator.py +++ b/nifty/operators/laplace_operator.py @@ -28,7 +28,7 @@ class LaplaceOperator(EndomorphicOperator): """An irregular LaplaceOperator with free boundary and excluding monopole. This LaplaceOperator implements the second derivative of a Field in - PowerSpace on logarithmic or linear scale with vanishing curvature at the + PowerSpace on logarithmic or linear scale with vanishing curvature at the boundary, starting at the second entry of the Field. The second derivative of the Field on the irregular grid is calculated using finite differences. @@ -37,6 +37,8 @@ class LaplaceOperator(EndomorphicOperator): logarithmic : boolean, Whether smoothness is calculated on a logarithmic scale or linear scale default : True + space : int + The index of the domain on which the operator acts """ def __init__(self, domain, space=None, logarithmic=True): @@ -70,10 +72,6 @@ class LaplaceOperator(EndomorphicOperator): self._dposc[1:] += self._dpos self._dposc *= 0.5 - @property - def target(self): - return self._domain - @property def domain(self): return self._domain diff --git a/nifty/operators/linear_operator.py b/nifty/operators/linear_operator.py index 822ff62c6..fdf65f11f 100644 --- a/nifty/operators/linear_operator.py +++ b/nifty/operators/linear_operator.py @@ -40,14 +40,6 @@ class LinearOperator(with_metaclass( The domain in which the Operators result lives. unitary : boolean Indicates whether the Operator is unitary or not. - - Raises - ------ - NotImplementedError - Raised if - * domain is not defined - * target is not defined - * unitary is not set to (True/False) """ def __init__(self): @@ -56,7 +48,7 @@ class LinearOperator(with_metaclass( @abc.abstractproperty def domain(self): """ - domain : tuple of DomainObjects, i.e. Spaces and FieldTypes + domain : DomainTuple The domain on which the Operator's input Field lives. Every Operator which inherits from the abstract LinearOperator base class must have this attribute. @@ -66,7 +58,7 @@ class LinearOperator(with_metaclass( @abc.abstractproperty def target(self): """ - target : tuple of DomainObjects, i.e. Spaces and FieldTypes + target : DomainTuple The domain on which the Operator's output Field lives. Every Operator which inherits from the abstract LinearOperator base class must have this attribute. @@ -89,35 +81,31 @@ class LinearOperator(with_metaclass( def times(self, x): """ Applies the Operator to a given Field. - Operator and Field have to live over the same domain. - Parameters ---------- x : Field - The input Field. + The input Field, living on the Operator's domain. Returns ------- out : Field - The processed Field living on the target-domain. + The processed Field living on the Operator's target domain. """ self._check_input_compatibility(x) return self._times(x) def inverse_times(self, x): - """ Applies the inverse-Operator to a given Field. - - Operator and Field have to live over the same domain. + """Applies the inverse Operator to a given Field. Parameters ---------- x : Field - The input Field. + The input Field, living on the Operator's target domain Returns ------- out : Field - The processed Field living on the target-domain. + The processed Field living on the Operator's domain. """ self._check_input_compatibility(x, inverse=True) try: @@ -130,21 +118,18 @@ class LinearOperator(with_metaclass( return y def adjoint_times(self, x): - """ Applies the adjoint-Operator to a given Field. - - Operator and Field have to live over the same domain. + """Applies the adjoint-Operator to a given Field. Parameters ---------- x : Field - applies the Operator to the given Field + The input Field, living on the Operator's target domain Returns ------- out : Field - The processed Field living on the target-domain. + The processed Field living on the Operator's domain. """ - if self.unitary: return self.inverse_times(x) @@ -161,17 +146,15 @@ class LinearOperator(with_metaclass( def adjoint_inverse_times(self, x): """ Applies the adjoint-inverse Operator to a given Field. - Operator and Field have to live over the same domain. - Parameters ---------- x : Field - applies the Operator to the given Field + The input Field, living on the Operator's domain. Returns ------- out : Field - The processed Field living on the target-domain. + The processed Field living on the Operator's target domain. Notes ----- diff --git a/nifty/operators/smoothness_operator.py b/nifty/operators/smoothness_operator.py index afc9d328f..9e12e8cae 100644 --- a/nifty/operators/smoothness_operator.py +++ b/nifty/operators/smoothness_operator.py @@ -27,8 +27,6 @@ class SmoothnessOperator(EndomorphicOperator): default : True """ - # ---Overwritten properties and methods--- - def __init__(self, domain, strength=1., logarithmic=True, space=None): super(SmoothnessOperator, self).__init__() self._laplace = LaplaceOperator(domain, @@ -38,8 +36,6 @@ class SmoothnessOperator(EndomorphicOperator): raise ValueError("ERROR: invalid sigma.") self._strength = strength - # ---Mandatory properties and methods--- - @property def domain(self): return self._laplace._domain @@ -64,8 +60,6 @@ class SmoothnessOperator(EndomorphicOperator): result = Field.zeros_like(x) return result - # ---Added properties and methods--- - @property def logarithmic(self): return self._laplace.logarithmic -- GitLab