Commit 912892f2 authored by Martin Reinecke's avatar Martin Reinecke

add quick Field ane MultiField comparison methods; add a FIXME in SamplingEnabler

parent e2bbed1e
Pipeline #31460 failed with stages
in 4 minutes and 5 seconds
......@@ -720,7 +720,9 @@ class Field(object):
self._domain.__str__() + \
"\n- val = " + repr(self.val)
def equivalent(self, other):
def isEquivalentTo(self, other):
"""Determines (as quickly as possible) whether `self`'s content is
identical to `other`'s content."""
if self is other:
return True
if not isinstance(other, Field):
......@@ -729,6 +731,11 @@ class Field(object):
return False
return (self._val == other._val).all()
def isSubsetOf(self, other):
"""Identical to `Field.isEquivalentTo()`. This method is provided for
easier interoperability with `MultiField`."""
return self.isEquivalentTo(other)
for op in ["__add__", "__radd__", "__iadd__",
"__sub__", "__rsub__", "__isub__",
......
......@@ -158,7 +158,9 @@ class MultiField(object):
return MultiField({key: sub_field.conjugate()
for key, sub_field in self.items()})
def equivalent(self, other):
def isEquivalentTo(self, other):
"""Determines (as quickly as possible) whether `self`'s content is
identical to `other`'s content."""
if self is other:
return True
if not isinstance(other, MultiField):
......@@ -166,10 +168,24 @@ class MultiField(object):
if self._domain != other._domain:
return False
for key, val in self._val.items():
if not val.equivalent(other[key]):
if not val.isEquivalentTo(other[key]):
return False
return True
def isSubsetOf(self, other):
"""Determines (as quickly as possible) whether `self`'s content is
a subset of `other`'s content."""
if self is other:
return True
if not isinstance(other, MultiField):
return False
for key, val in self._domain.items():
if not key in other._domain or other._domain[key] != val:
return False
for key, val in self._val.items():
if not val.isSubsetOf(other[key]):
return False
return True
for op in ["__add__", "__radd__", "__iadd__",
"__sub__", "__rsub__", "__isub__",
......
......@@ -57,6 +57,9 @@ class SamplingEnabler(EndomorphicOperator):
try:
return self._op.draw_sample(from_inverse, dtype)
except NotImplementedError:
# MR FIXME: I think there is a silent assumption that
# from_inverse==True when we arrive here.
# Can we make this explicit?
s = self._prior.draw_sample(from_inverse=True)
sp = self._prior(s)
nj = self._likelihood.draw_sample()
......
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