Commit feb207b2 authored by Philipp Arras's avatar Philipp Arras
Browse files

Add adjointness and inverse test

parent 9a5abf11
Pipeline #24356 passed with stage
in 6 minutes and 13 seconds
......@@ -163,3 +163,25 @@ class LinearOperator(with_metaclass(
if x.domain != self._dom(mode):
raise ValueError("The operator's and and field's domains "
"don't match.")
def test_adjointness(self, domain_dtype=np.float64, target_dtype=np.float64):
f1 = Field.from_random("normal", domain=self.domain,
dtype=domain_dtype)
f2 = Field.from_random("normal", domain=self.target,
dtype=target_dtype)
res1 = f1.vdot(self.adjoint_times(f2))
res2 = self.times(f1).vdot(f2)
return (res1 - res2) / (res1 + res2) * 2
def test_inverse(self, dtype_domain=np.float64, dtype_target=np.float64):
foo = Field.from_random(
domain=self.target, random_type='normal', dtype=dtype_target)
bar = self.times(self.inverse_times(foo)).val
np.testing.assert_allclose(bar, Field.ones(self.target).val)
foo = Field.from_random(
domain=self.domain, random_type='normal', dtype=dtype_domain)
bar = self.inverse_times(self.times(foo)).val
np.testing.assert_allclose(bar, Field.ones(self.domain).val)
return True
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