Commit cf93d61d authored by Philipp Arras's avatar Philipp Arras

No whitespace after """ and further cosmetics

parent 2627a1e3
......@@ -25,7 +25,7 @@ from .domain_tuple import DomainTuple
class Field(object):
_scalar_dom = DomainTuple.scalar_domain()
""" The discrete representation of a continuous field over multiple spaces.
"""The discrete representation of a continuous field over multiple spaces.
In NIFTy, Fields are used to store data arrays and carry all the needed
metainformation (i.e. the domain) for operators to be able to work on them.
......@@ -165,7 +165,7 @@ class Field(object):
@staticmethod
def from_random(random_type, domain, dtype=np.float64, **kwargs):
""" Draws a random field with the given parameters.
"""Draws a random field with the given parameters.
Parameters
----------
......@@ -284,7 +284,7 @@ class Field(object):
return res
def weight(self, power=1, spaces=None):
""" Weights the pixels of `self` with their invidual pixel-volume.
"""Weights the pixels of `self` with their invidual pixel-volume.
Parameters
----------
......@@ -325,7 +325,7 @@ class Field(object):
return Field.from_local_data(self._domain, aout)
def outer(self, x):
""" Computes the outer product of 'self' with x.
"""Computes the outer product of 'self' with x.
Parameters
----------
......@@ -342,7 +342,7 @@ class Field(object):
return OuterProduct(self, x.domain)(x)
def vdot(self, x=None, spaces=None):
""" Computes the dot product of 'self' with x.
"""Computes the dot product of 'self' with x.
Parameters
----------
......@@ -375,7 +375,7 @@ class Field(object):
return (self.conjugate()*x).sum(spaces=spaces)
def norm(self, ord=2):
""" Computes the L2-norm of the field values.
"""Computes the L2-norm of the field values.
Parameters
----------
......@@ -390,7 +390,7 @@ class Field(object):
return dobj.norm(self._val, ord)
def conjugate(self):
""" Returns the complex conjugate of the field.
"""Returns the complex conjugate of the field.
Returns
-------
......
......@@ -30,7 +30,7 @@ def make_adjust_variances(a,
samples=[],
scaling=None,
ic_samp=None):
""" Creates a Hamiltonian for constant likelihood optimizations.
"""Creates a Hamiltonian for constant likelihood optimizations.
Constructs a Hamiltonian to solve constant likelihood optimizations of the
form phi = a * xi under the constraint that phi remains constant.
......
......@@ -20,7 +20,7 @@ from .minimizer import Minimizer
class ConjugateGradient(Minimizer):
""" Implementation of the Conjugate Gradient scheme.
"""Implementation of the Conjugate Gradient scheme.
It is an iterative method for solving a linear system of equations:
Ax = b
......@@ -44,7 +44,7 @@ class ConjugateGradient(Minimizer):
self._nreset = nreset
def __call__(self, energy, preconditioner=None):
""" Runs the conjugate gradient minimization.
"""Runs the conjugate gradient minimization.
Parameters
----------
......
......@@ -23,7 +23,7 @@ from .minimizer import Minimizer
class DescentMinimizer(Minimizer):
""" A base class used by gradient methods to find a local minimum.
"""A base class used by gradient methods to find a local minimum.
Descent minimization methods are used to find a local minimum of a scalar
function by following a descent direction. This class implements the
......@@ -44,7 +44,7 @@ class DescentMinimizer(Minimizer):
self.line_searcher = line_searcher
def __call__(self, energy):
""" Performs the minimization of the provided Energy functional.
"""Performs the minimization of the provided Energy functional.
Parameters
----------
......@@ -104,7 +104,7 @@ class DescentMinimizer(Minimizer):
pass
def get_descent_direction(self, energy):
""" Calculates the next descent direction.
"""Calculates the next descent direction.
Parameters
----------
......@@ -121,7 +121,7 @@ class DescentMinimizer(Minimizer):
class SteepestDescent(DescentMinimizer):
""" Implementation of the steepest descent minimization scheme.
"""Implementation of the steepest descent minimization scheme.
Also known as 'gradient descent'. This algorithm simply follows the
functional's gradient for minimization.
......@@ -132,7 +132,7 @@ class SteepestDescent(DescentMinimizer):
class RelaxedNewton(DescentMinimizer):
""" Calculates the descent direction according to a Newton scheme.
"""Calculates the descent direction according to a Newton scheme.
The descent direction is determined by weighting the gradient at the
current parameter position with the inverse local metric.
......@@ -149,7 +149,7 @@ class RelaxedNewton(DescentMinimizer):
class NewtonCG(DescentMinimizer):
""" Calculates the descent direction according to a Newton-CG scheme.
"""Calculates the descent direction according to a Newton-CG scheme.
Algorithm derived from SciPy sources.
"""
......
......@@ -19,7 +19,7 @@ from ..utilities import NiftyMetaBase
class Energy(NiftyMetaBase()):
""" Provides the functional used by minimization schemes.
"""Provides the functional used by minimization schemes.
The Energy object is an implementation of a scalar function including its
gradient and metric at some position.
......@@ -47,7 +47,7 @@ class Energy(NiftyMetaBase()):
self._gradnorm = None
def at(self, position):
""" Returns a new Energy object, initialized at `position`.
"""Returns a new Energy object, initialized at `position`.
Parameters
----------
......
......@@ -21,7 +21,7 @@ import numpy as np
class LineEnergy(object):
""" Evaluates an underlying Energy along a certain line direction.
"""Evaluates an underlying Energy along a certain line direction.
Given an Energy class and a line direction, its position is parametrized by
a scalar step size along the descent direction relative to a zero point.
......@@ -60,7 +60,7 @@ class LineEnergy(object):
self._energy = energy.at(position=pos)
def at(self, line_position):
""" Returns LineEnergy at new position, memorizing the zero point.
"""Returns LineEnergy at new position, memorizing the zero point.
Parameters
----------
......
......@@ -19,11 +19,11 @@ from ..utilities import NiftyMetaBase
class Minimizer(NiftyMetaBase()):
""" A base class used by all minimizers."""
"""A base class used by all minimizers."""
# MR FIXME: the docstring is partially ignored by Sphinx. Why?
def __call__(self, energy, preconditioner=None):
""" Performs the minimization of the provided Energy functional.
"""Performs the minimization of the provided Energy functional.
Parameters
----------
......
......@@ -20,7 +20,7 @@ from .minimizer import Minimizer
class NonlinearCG(Minimizer):
""" Nonlinear Conjugate Gradient scheme according to Polak-Ribiere.
"""Nonlinear Conjugate Gradient scheme according to Polak-Ribiere.
Algorithm 5.4 from Nocedal & Wright.
......
......@@ -42,7 +42,7 @@ class QuadraticEnergy(Energy):
return QuadraticEnergy(position, self._A, self._b)
def at_with_grad(self, position, grad):
""" Specialized version of `at`, taking also a gradient.
"""Specialized version of `at`, taking also a gradient.
This custom method is meant for use within :class:ConjugateGradient`
minimizers, which already have the gradient available. It saves time
......
......@@ -142,7 +142,7 @@ class MultiField(object):
for key in domain.keys()))
def norm(self, ord=2):
""" Computes the norm of the field values.
"""Computes the norm of the field values.
Parameters
----------
......@@ -161,7 +161,7 @@ class MultiField(object):
# return np.sqrt(np.abs(self.vdot(x=self)))
def sum(self):
""" Computes the sum all field values.
"""Computes the sum all field values.
Returns
-------
......@@ -172,7 +172,7 @@ class MultiField(object):
@property
def size(self):
""" Computes the overall degrees of freedom.
"""Computes the overall degrees of freedom.
Returns
-------
......@@ -222,7 +222,7 @@ class MultiField(object):
@staticmethod
def union(fields, domain=None):
""" Returns the union of its input fields.
"""Returns the union of its input fields.
Parameters
----------
......
......@@ -21,14 +21,14 @@ from .endomorphic_operator import EndomorphicOperator
class BlockDiagonalOperator(EndomorphicOperator):
"""
Parameters
----------
operators : dict
Dictionary with operators domain names as keys and LinearOperators as
items.
"""
def __init__(self, domain, operators):
"""
Parameters
----------
operators : dict
dictionary with operators domain names as keys and
LinearOperators as items
"""
if not isinstance(domain, MultiDomain):
raise TypeError("MultiDomain expected")
if not isinstance(operators, tuple):
......
......@@ -35,7 +35,7 @@ class ContractionOperator(LinearOperator):
spaces : int or tuple of int
The elements of "domain" which are contracted.
weight : int, default=0
if nonzero, the fields defined on self.domain are weighted with the
If nonzero, the fields defined on self.domain are weighted with the
specified power.
"""
......
......@@ -24,7 +24,7 @@ from .endomorphic_operator import EndomorphicOperator
class DiagonalOperator(EndomorphicOperator):
""" NIFTy class for diagonal operators.
"""NIFTy class for diagonal operators.
The NIFTy DiagonalOperator class is a subclass derived from the
EndomorphicOperator. It multiplies an input field pixel-wise with its
......
......@@ -21,7 +21,7 @@ from .linear_operator import LinearOperator
class EndomorphicOperator(LinearOperator):
""" NIFTy class for endomorphic operators.
"""NIFTy class for endomorphic operators.
The NIFTy EndomorphicOperator class is a class derived from the
LinearOperator. By definition, domain and target are the same in
......
......@@ -27,8 +27,7 @@ from .linear_operator import LinearOperator
class ExpTransform(LinearOperator):
"""
Transforms log-space to target.
"""Transforms log-space to target
This operator creates a log-space subject to the degrees of freedom and
and its target-domain.
......
......@@ -385,9 +385,8 @@ class HarmonicTransformOperator(LinearOperator):
def HarmonicSmoothingOperator(domain, sigma, space=None):
""" This function returns an operator that carries out a smoothing with
a Gaussian kernel of width `sigma` on the part of `domain` given by
`space`.
"""Returns an operator that carries out a smoothing with a Gaussian kernel
of width `sigma` on the part of `domain` given by `space`
Parameters
----------
......@@ -403,8 +402,8 @@ def HarmonicSmoothingOperator(domain, sigma, space=None):
Notes
-----
The sub-domain on which the smoothing is carried out *must* be a
non-harmonic `RGSpace`.
The sub-domain on which the smoothing is carried out *must* be a
non-harmonic `RGSpace`.
"""
sigma = float(sigma)
......
......@@ -30,8 +30,7 @@ from .linear_operator import LinearOperator
class LinearInterpolator(LinearOperator):
"""
Multilinear interpolation for points in an RGSpace
"""Multilinear interpolation for points in an RGSpace
Parameters
----------
......
......@@ -143,7 +143,7 @@ class LinearOperator(Operator):
return self.apply(x.extract(self.domain), self.TIMES)
def apply(self, x, mode):
""" Applies the Operator to a given `x`, in a specified `mode`.
"""Applies the Operator to a given `x`, in a specified `mode`.
Parameters
----------
......@@ -178,7 +178,7 @@ class LinearOperator(Operator):
return self.__matmul__(x)
def times(self, x):
""" Applies the Operator to a given Field.
"""Applies the Operator to a given Field.
Parameters
----------
......@@ -223,7 +223,7 @@ class LinearOperator(Operator):
return self.apply(x, self.ADJOINT_TIMES)
def adjoint_inverse_times(self, x):
""" Applies the adjoint-inverse Operator to a given Field.
"""Applies the adjoint-inverse Operator to a given Field.
Parameters
----------
......
......@@ -27,16 +27,16 @@ from .linear_operator import LinearOperator
# Possible approach: keep everything defined on `domain` distributed and only
# collect the unstructured Fields.
class MaskOperator(LinearOperator):
def __init__(self, mask):
"""Implementation of a mask response
"""Implementation of a mask response
This operator takes a field, applies a mask and returns the values of
the field in a UnstructuredDomain. It can be used as response operator.
Takes a field, applies a mask and returns the values of the field in a
UnstructuredDomain. It can be used as response operator.
Parameters
----------
mask : Field
"""
Parameters
----------
mask : Field
"""
def __init__(self, mask):
if not isinstance(mask, Field):
raise TypeError
......
......@@ -15,17 +15,11 @@
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import itertools
import numpy as np
from .. import dobj, utilities
from ..domain_tuple import DomainTuple
from ..domains.rg_space import RGSpace
from ..multi_field import MultiField, MultiDomain
from ..field import Field
from .linear_operator import LinearOperator
import operator
class OuterProduct(LinearOperator):
......@@ -37,14 +31,11 @@ class OuterProduct(LinearOperator):
domain: DomainTuple, the domain of the input field
---------
"""
def __init__(self, field, domain):
self._domain = domain
self._field = field
self._target = DomainTuple.make(
tuple(sub_d for sub_d in field.domain._dom + domain._dom))
self._capability = self.TIMES | self.ADJOINT_TIMES
def apply(self, x, mode):
......
......@@ -24,8 +24,7 @@ from .linear_operator import LinearOperator
class QHTOperator(LinearOperator):
"""
Does a Hartley transform on LogRGSpace
"""Does a Hartley transform on LogRGSpace
This operator takes a field on a LogRGSpace and transforms it
according to the Hartley transform. The zero modes are not transformed
......
......@@ -25,12 +25,11 @@ from .linear_operator import LinearOperator
class SlopeOperator(LinearOperator):
"""
Creates a slope on target.
"""Creates a slope on target.
This operator creates a field on a LogRGSpace, which is created
according to a slope of given entries, (mean, y-intercept).
The slope mean is the power law of the field in normal-space.
This operator creates a field on a LogRGSpace, which is created according
to a slope of given entries, (mean, y-intercept). The slope mean is the
power law of the field in normal-space.
Parameters
----------
......
......@@ -99,7 +99,7 @@ def _single_power_analyze(field, idx, binbounds):
# subdomain at once, because it allows only one set of binbounds.
def power_analyze(field, spaces=None, binbounds=None,
keep_phase_information=False):
""" Computes the power spectrum for a subspace of `field`.
"""Computes the power spectrum for a subspace of `field`.
Creates a PowerSpace for the space addressed by `spaces` with the given
binning and computes the power spectrum as a Field over this
......@@ -184,7 +184,7 @@ def _create_power_field(domain, power_spectrum):
def create_power_operator(domain, power_spectrum, space=None):
""" Creates a diagonal operator with the given power spectrum.
"""Creates a diagonal operator with the given power spectrum.
Constructs a diagonal operator that is defined on the specified domain.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment