Commit b2330148 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

more __repr__ work

parent d68a5a82
......@@ -157,17 +157,21 @@ class DiagonalOperator(EndomorphicOperator):
xdiag = 1./xdiag
return self._from_ldiag((), xdiag)
def draw_sample(self, from_inverse=False, dtype=np.float64):
if self._complex:
raise ValueError("operator not positive definite")
if self._diagmin < 0.:
raise ValueError("operator not positive definite")
if self._diagmin == 0. and from_inverse:
raise ValueError("operator not positive definite")
res = Field.from_random(random_type="normal", domain=self._domain,
dtype=dtype)
def process_sample(self, samp, from_inverse):
if (self._complex or (self._diagmin < 0.) or
(self._diagmin == 0. and from_inverse)):
raise ValueError("operator not positive definite")
if from_inverse:
res = res.local_data/np.sqrt(self._ldiag)
res = samp.local_data/np.sqrt(self._ldiag)
else:
res = res.local_data*np.sqrt(self._ldiag)
res = samp.local_data*np.sqrt(self._ldiag)
return Field.from_local_data(self._domain, res)
def draw_sample(self, from_inverse=False, dtype=np.float64):
res = Field.from_random(random_type="normal", domain=self._domain,
dtype=dtype)
return self.process_sample(res, from_inverse)
def __repr__(self):
subs = utilities.indent(self._domain.__repr__())
return "DiagonalOperator:\n Spaces={}\n".format(self._spaces) + subs
......@@ -66,3 +66,9 @@ class OperatorAdapter(LinearOperator):
if self._trafo & self.INVERSE_BIT:
return self._op.draw_sample(not from_inverse, dtype)
return self._op.draw_sample(from_inverse, dtype)
def __repr__(self):
from ..utilities import indent
mode = ["adjoint", "inverse", "adjoint inverse"][self._trafo]
res = "OperatorAdapter: {}\n".format(mode)
return res + indent(self._op.__repr__())
......@@ -79,3 +79,11 @@ class SamplingEnabler(EndomorphicOperator):
def apply(self, x, mode):
return self._op.apply(x, mode)
def __repr__(self):
from ..utilities import indent
return "\n".join((
"SamplingEnabler:",
indent("\n".join((
"Likelihood:", self._likelihood.__repr__(),
"Prior:", self._prior.__repr__())))))
......@@ -72,7 +72,7 @@ class SandwichOperator(EndomorphicOperator):
def draw_sample(self, from_inverse=False, dtype=np.float64):
# Inverse samples from general sandwiches are not possible
if from_inverse:
if self._bun.capabilities & self._bun.INVERSE_TIMES:
if self._bun.capability & self._bun.INVERSE_TIMES:
try:
s = self._cheese.draw_sample(from_inverse, dtype)
return self._bun.inverse_times(s)
......@@ -84,3 +84,11 @@ class SandwichOperator(EndomorphicOperator):
# Samples from general sandwiches
return self._bun.adjoint_times(
self._cheese.draw_sample(from_inverse, dtype))
def __repr__(self):
from ..utilities import indent
return "\n".join((
"SandwichOperator:",
indent("\n".join((
"Cheese:", self._cheese.__repr__(),
"Bun:", self._bun.__repr__())))))
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