Commit c9a6a709 authored by Martin Reinecke's avatar Martin Reinecke

long overdue cleanup

parent 9b06ed3a
......@@ -62,14 +62,6 @@ class PolynomialResponse(ift.LinearOperator):
out = self._mat.conj().T.dot(val)
return ift.from_global_data(self._tgt(mode), out)
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def capability(self):
return self.TIMES | self.ADJOINT_TIMES
......
......@@ -133,14 +133,6 @@ class AmplitudeModel(Operator):
self._smooth_op = sym(qht(ceps))
self._keys = tuple(keys)
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
def apply(self, x):
smooth_spec = self._smooth_op(x[self._keys[0]])
phi = x[self._keys[1]] + self._norm_phi_mean
......
......@@ -50,14 +50,6 @@ class CorrelatedField(Operator):
(self._amplitude_model.domain,
MultiDomain.make({"xi": self._h_space})))
@property
def domain(self):
return self._domain
@property
def target(self):
return self._ht.target
def apply(self, x):
A = self._power_distributor(self._amplitude_model(x))
correlated_field_h = A * x["xi"]
......
......@@ -30,18 +30,10 @@ from ..sugar import makeOp
class InverseGammaModel(Operator):
def __init__(self, domain, alpha, q):
self._domain = domain
self._domain = self._target = domain
self._alpha = alpha
self._q = q
@property
def domain(self):
return self._domain
@property
def target(self):
return self._domain
def apply(self, x):
lin = isinstance(x, Linearization)
val = x.val.local_data if lin else x.local_data
......
......@@ -221,14 +221,6 @@ class LOSResponse(LinearOperator):
self._target = DomainTuple.make(UnstructuredDomain(nlos))
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def capability(self):
return self.TIMES | self.ADJOINT_TIMES
......
......@@ -109,6 +109,7 @@ class MultiDomain(object):
@staticmethod
def union(inp):
res = {}
# FIXME speed up!
for dom in inp:
for key, subdom in zip(dom._keys, dom._domains):
if key in res:
......
......@@ -45,10 +45,6 @@ class BlockDiagonalOperator(EndomorphicOperator):
if op is not None:
self._cap &= op.capability
@property
def domain(self):
return self._domain
@property
def capability(self):
return self._cap
......
......@@ -53,14 +53,6 @@ class CentralZeroPadder(LinearOperator):
self.slicer[i] = tuple(tmp)
self.slicer = tuple(self.slicer)
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def capability(self):
return self.TIMES | self.ADJOINT_TIMES
......
......@@ -36,6 +36,8 @@ class ChainOperator(LinearOperator):
self._capability = self._all_ops
for op in ops:
self._capability &= op.capability
self._domain = self._ops[-1].domain
self._target = self._ops[0].target
@staticmethod
def simplify(ops):
......@@ -117,14 +119,6 @@ class ChainOperator(LinearOperator):
return ops[0]
return ChainOperator(ops, _callingfrommake=True)
@property
def domain(self):
return self._ops[-1].domain
@property
def target(self):
return self._ops[0].target
def _flip_modes(self, trafo):
ADJ = self.ADJOINT_BIT
INV = self.INVERSE_BIT
......
......@@ -150,10 +150,6 @@ class DiagonalOperator(EndomorphicOperator):
return Field.from_local_data(x.domain, x.local_data*xdiag)
return Field.from_local_data(x.domain, x.local_data/xdiag)
@property
def domain(self):
return self._domain
@property
def capability(self):
return self._all_ops
......
......@@ -143,14 +143,6 @@ class DOFDistributor(LinearOperator):
self._check_input(x, mode)
return self._times(x) if mode == self.TIMES else self._adjoint_times(x)
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def capability(self):
return self.TIMES | self.ADJOINT_TIMES
......@@ -36,14 +36,6 @@ class DomainDistributor(LinearOperator):
if i in self._spaces]
self._domain = DomainTuple.make(self._domain)
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
def apply(self, x, mode):
self._check_input(x, mode)
if mode == self.TIMES:
......
......@@ -38,7 +38,7 @@ class EndomorphicOperator(LinearOperator):
Returns `self.domain`, because this is also the target domain
for endomorphic operators."""
return self.domain
return self._domain
def draw_sample(self, from_inverse=False, dtype=np.float64):
"""Generate a zero-mean sample
......
......@@ -33,20 +33,12 @@ from .simple_linear_operators import VdotOperator
class EnergyOperator(Operator):
_target = DomainTuple.scalar_domain()
@property
def target(self):
return EnergyOperator._target
class SquaredNormOperator(EnergyOperator):
def __init__(self, domain):
super(SquaredNormOperator, self).__init__()
self._domain = domain
@property
def domain(self):
return self._domain
def apply(self, x):
if isinstance(x, Linearization):
val = Field(self._target, x.val.vdot(x.val))
......@@ -62,10 +54,7 @@ class QuadraticFormOperator(EnergyOperator):
if not isinstance(op, EndomorphicOperator):
raise TypeError("op must be an EndomorphicOperator")
self._op = op
@property
def domain(self):
return self._op.domain
self._domain = op.domain
def apply(self, x):
if isinstance(x, Linearization):
......@@ -102,10 +91,6 @@ class GaussianEnergy(EnergyOperator):
if self._domain is not newdom:
raise ValueError("domain mismatch")
@property
def domain(self):
return self._domain
def apply(self, x):
residual = x if self._mean is None else x-self._mean
res = self._op(residual)
......@@ -118,10 +103,7 @@ class GaussianEnergy(EnergyOperator):
class PoissonianEnergy(EnergyOperator):
def __init__(self, op, d):
self._op, self._d = op, d
@property
def domain(self):
return self._op.domain
self._domain = d.domain
def apply(self, x):
x = self._op(x)
......@@ -136,10 +118,7 @@ class BernoulliEnergy(EnergyOperator):
def __init__(self, p, d):
self._p = p
self._d = d
@property
def domain(self):
return self._p.domain
self._domain = d.domain
def apply(self, x):
x = self._p(x)
......@@ -157,10 +136,7 @@ class Hamiltonian(EnergyOperator):
self._lh = lh
self._prior = GaussianEnergy(domain=lh.domain)
self._ic_samp = ic_samp
@property
def domain(self):
return self._lh.domain
self._domain = lh.domain
def apply(self, x):
if self._ic_samp is None or not isinstance(x, Linearization):
......@@ -182,12 +158,9 @@ class SampledKullbachLeiblerDivergence(EnergyOperator):
"""
super(SampledKullbachLeiblerDivergence, self).__init__()
self._h = h
self._domain = h.domain
self._res_samples = tuple(res_samples)
@property
def domain(self):
return self._h.domain
def apply(self, x):
res = (utilities.my_sum(map(lambda v: self._h(x+v), self._res_samples)) *
(1./len(self._res_samples)))
......
......@@ -84,14 +84,6 @@ class ExpTransform(LinearOperator):
self._domain[self._space] = log_space
self._domain = DomainTuple.make(self._domain)
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
def apply(self, x, mode):
self._check_input(x, mode)
x = x.val
......
......@@ -31,14 +31,6 @@ class FieldZeroPadder(LinearOperator):
self._target[self._space] = tgt
self._target = DomainTuple.make(self._target)
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def capability(self):
return self.TIMES | self.ADJOINT_TIMES
......
......@@ -127,14 +127,6 @@ class FFTOperator(LinearOperator):
fct *= self._target[self._space].scalar_dvol
return Tval if fct == 1 else Tval*fct
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def capability(self):
return self._all_ops
......@@ -247,14 +239,6 @@ class HartleyOperator(LinearOperator):
fct = self._target[self._space].scalar_dvol
return Tval if fct == 1 else Tval*fct
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def capability(self):
return self._all_ops
......@@ -367,14 +351,6 @@ class SHTOperator(LinearOperator):
odat = dobj.redistribute(odat, dist=dobj.distaxis(x.val))
return Field(tdom, odat)
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def capability(self):
return self.TIMES | self.ADJOINT_TIMES
......@@ -421,19 +397,13 @@ class HarmonicTransformOperator(LinearOperator):
self._op = HartleyOperator(domain, target, space)
else:
self._op = SHTOperator(domain, target, space)
self._domain = self._op.domain
self._target = self._op.target
def apply(self, x, mode):
self._check_input(x, mode)
return self._op.apply(x, mode)
@property
def domain(self):
return self._op.domain
@property
def target(self):
return self._op.target
@property
def capability(self):
return self.TIMES | self.ADJOINT_TIMES
......
......@@ -55,10 +55,7 @@ class InversionEnabler(EndomorphicOperator):
self._op = op
self._ic = iteration_controller
self._approximation = approximation
@property
def domain(self):
return self._op.domain
self._domain = op.domain
@property
def capability(self):
......
......@@ -68,10 +68,6 @@ class LaplaceOperator(EndomorphicOperator):
self._dposc[1:] += self._dpos
self._dposc *= 0.5
@property
def domain(self):
return self._domain
@property
def capability(self):
return self.TIMES | self.ADJOINT_TIMES
......
......@@ -59,11 +59,3 @@ class MaskOperator(LinearOperator):
@property
def capability(self):
return self.TIMES | self.ADJOINT_TIMES
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
......@@ -15,14 +15,14 @@ class Operator(NiftyMetaBase()):
"""DomainTuple or MultiDomain : the operator's input domain
The domain on which the Operator's input Field lives."""
raise NotImplementedError
return self._domain
@property
def target(self):
"""DomainTuple or MultiDomain : the operator's output domain
The domain on which the Operator's output Field lives."""
raise NotImplementedError
return self._target
def scale(self, factor):
if factor == 1:
......@@ -73,17 +73,9 @@ for f in ["sqrt", "exp", "log", "tanh", "positive_tanh"]:
class _FunctionApplier(Operator):
def __init__(self, domain, funcname):
from ..sugar import makeDomain
self._domain = makeDomain(domain)
self._domain = self._target = makeDomain(domain)
self._funcname = funcname
@property
def domain(self):
return self._domain
@property
def target(self):
return self._domain
def apply(self, x):
return getattr(x, self._funcname)()
......@@ -114,14 +106,8 @@ class _CombinedOperator(Operator):
class _OpChain(_CombinedOperator):
def __init__(self, ops, _callingfrommake=False):
super(_OpChain, self).__init__(ops, _callingfrommake)
@property
def domain(self):
return self._ops[-1].domain
@property
def target(self):
return self._ops[0].target
self._domain = self._ops[-1].domain
self._target = self._ops[0].target
def apply(self, x):
for op in reversed(self._ops):
......@@ -132,14 +118,8 @@ class _OpChain(_CombinedOperator):
class _OpProd(_CombinedOperator):
def __init__(self, ops, _callingfrommake=False):
super(_OpProd, self).__init__(ops, _callingfrommake)
@property
def domain(self):
return self._ops[0].domain
@property
def target(self):
return self._ops[0].target
self._domain = self._ops[0].domain
self._target = self._ops[0].target
def apply(self, x):
return my_product(map(lambda op: op(x), self._ops))
......@@ -151,13 +131,5 @@ class _OpSum(_CombinedOperator):
self._domain = domain_union([op.domain for op in self._ops])
self._target = domain_union([op.target for op in self._ops])
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
def apply(self, x):
raise NotImplementedError
......@@ -50,14 +50,8 @@ class OperatorAdapter(LinearOperator):
self._trafo = int(op_transform)
if self._trafo < 1 or self._trafo > 3:
raise ValueError("invalid operator transformation")
@property
def domain(self):
return self._op._dom(1 << self._trafo)
@property
def target(self):
return self._op._tgt(1 << self._trafo)
self._domain = self._op._dom(1 << self._trafo)
self._target = self._op._tgt(1 << self._trafo)
@property
def capability(self):
......
......@@ -60,14 +60,6 @@ class QHTOperator(LinearOperator):
self._target[self._space].get_default_codomain()
self._domain = DomainTuple.make(self._domain)
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
def apply(self, x, mode):
self._check_input(x, mode)
dom = self._domain[self._space]
......
......@@ -46,14 +46,6 @@ class RelaxedSumOperator(LinearOperator):
# else:
# self._ops += [op]
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def adjoint(self):
return RelaxedSumOperator([op.adjoint for op in self._ops])
......
......@@ -56,6 +56,7 @@ class SamplingEnabler(EndomorphicOperator):
self._prior = prior
self._ic = iteration_controller
self._approximation = approximation
self._domain = self._op.domain
def draw_sample(self, from_inverse=False, dtype=np.float64):
try:
......@@ -76,10 +77,6 @@ class SamplingEnabler(EndomorphicOperator):
energy, convergence = inverter(energy)
return energy.position
@property
def domain(self):
return self._op.domain
@property
def capability(self):
return self._op.capability
......
......@@ -38,6 +38,7 @@ class SandwichOperator(EndomorphicOperator):
self._bun = bun
self._cheese = cheese
self._op = op
self._domain = op.domain
@staticmethod
def make(bun, cheese=None):
......@@ -65,10 +66,6 @@ class SandwichOperator(EndomorphicOperator):
return op
return SandwichOperator(bun, cheese, op, _callingfrommake=True)
@property
def domain(self):
return self._op.domain
@property
def capability(self):
return self._op.capability
......
......@@ -82,10 +82,6 @@ class ScalingOperator(EndomorphicOperator):
fct = 1./fct
return ScalingOperator(fct, self._domain)
@property
def domain(self):
return self._domain
@property
def capability(self):
return self._all_ops
......
......@@ -35,16 +35,9 @@ class VdotOperator(LinearOperator):
def __init__(self, field):
super(VdotOperator, self).__init__()
self._field = field
self._domain = field.domain
self._target = DomainTuple.scalar_domain()
@property
def domain(self):
return self._field.domain
@property
def target(self):
return self._target
@property
def capability(self):
return self.TIMES | self.ADJOINT_TIMES
......@@ -62,14 +55,6 @@ class SumReductionOperator(LinearOperator):
self._domain = domain
self._target = DomainTuple.scalar_domain()
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property