Commit 044543bd authored by Martin Reinecke's avatar Martin Reinecke

test, not working

parent ad4c6cde
Pipeline #70955 failed with stages
in 17 minutes and 21 seconds
......@@ -30,6 +30,36 @@ import sys
import numpy as np
import nifty6 as ift
from nifty6 import LinearOperator
class ParanoiaOperator(LinearOperator):
"""Operator wrapping another operator. It simply calls the wrapped operator
twice and warns if the results are not bit-identical.
Parameters
----------
op : Operator
The operator to wrap
"""
def __init__(self, op):
self._op = op
self._domain = op.domain
self._target = op.target
self._capability = op._capability if isinstance(op, LinearOperator) else LinearOperator.TIMES
def apply(self, x, mode=LinearOperator.TIMES):
self._check_mode(mode)
if isinstance(self._op, LinearOperator):
res1 = self._op.apply(x, mode)
res2 = self._op.apply(x, mode)
else:
if (mode != LinearOperator.TIMES):
raise ValueError("only TIMES supported")
res1 = self._op.apply(x)
res2 = self._op.apply(x)
if (res1 != res2).s_any():
print("warning: operator result mismatch")
return res1
def random_los(n_los):
......@@ -90,7 +120,8 @@ if __name__ == '__main__':
# Set up likelihood and information Hamiltonian
likelihood = (ift.GaussianEnergy(mean=data, inverse_covariance=N.inverse) @
signal_response)
H = ift.StandardHamiltonian(likelihood, ic_sampling)
H = ParanoiaOperator(ift.StandardHamiltonian(likelihood, ic_sampling))
# H = ift.StandardHamiltonian(likelihood, ic_sampling)
initial_mean = ift.MultiField.full(H.domain, 0.)
mean = initial_mean
......
......@@ -82,8 +82,8 @@ class MetricGaussianKL(Energy):
napprox=0, _samples=None, lh_sampling_dtype=np.float64):
super(MetricGaussianKL, self).__init__(mean)
if not isinstance(hamiltonian, StandardHamiltonian):
raise TypeError
# if not isinstance(hamiltonian, StandardHamiltonian):
# raise TypeError
if hamiltonian.domain is not mean.domain:
raise ValueError
if not isinstance(n_samples, int):
......
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