diff --git a/nifty/operators/composed_operator.py b/nifty/operators/composed_operator.py index aacc9172db30e27f6374bdfb317c54452af9c1de..8acff7a8913074f7cc57b7a20b93e92f93c74481 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 c830da847a0e8a0331f685ad4c171f4269cffb12..f45870cac36b603b737e146e160ebd694ff8d262 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 0967e6f70ccdb8b608f7c869e07e875069b61a88..bdd11367be9ac1c9c6c4ee3b0ec8c16000dfc693 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 dafb5add7e7de35dd925d2d5f103b8457a1f118c..9e3c8fc292f61d875ea6d9b8d77887f4a368c52a 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 f4c82338fc61b84047c84d9ce61a8551c1c82b23..b069cca91d380850b169b18530b2e197477491e9 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 9945989faaaafb525c00fb162b3281353f23b86c..63765094fb43743864ad8ee61ce6a1672a6b20f0 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 632abce75927d7a15963d755da5607ac559265e7..c2b533ed4d379ff89e6fc7bf585f110ab4d61620 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 ac5cc90067dfc9c5e87697c3bba5e9b8f27932f2..53d2742f4358d2f5810a243c45ac89469cf8459b 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 822ff62c6ef7276334a78cc8694af9a53ece070d..fdf65f11ff885b02587dd45a1756521fafab387e 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 afc9d328f824dedd7655a78109a2df75e35489bc..9e12e8cae2a0e08f3d2c2ae51698c7cb1d9e7a49 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