support unequal sample sizes when dividing ensemble values

This commit is contained in:
Valentin Boettcher 2022-12-09 15:56:45 -05:00
parent 1ed2d65605
commit 3890771074
No known key found for this signature in database
GPG key ID: E034E12B7AF56ACE

View file

@ -306,14 +306,18 @@ class EnsembleValue:
if len(self) != len(other): if len(self) != len(other):
raise RuntimeError("Can only multiply values of equal length.") raise RuntimeError("Can only multiply values of equal length.")
left = self._value left = copy.deepcopy(self._value)
right = other._value right = copy.deepcopy(other._value)
out = [] out = []
for left_i, right_i in zip(left, right): for left_i, right_i in zip(left, right):
if left_i[0] != right_i[0]: if left_i[0] < right_i[0]:
raise RuntimeError("Can only divide equal sample counts.") right_i[2] *= np.sqrt(right_i[0] / left_i[0])
right_i[0] = left_i[0]
if left_i[0] > right_i[0]:
left_i[2] *= np.sqrt(left_i[0] / right_i[0])
left_i[0] = right_i[0]
out.append( out.append(
( (