From 14d2ab57424362a32827d572d55f24a083493932 Mon Sep 17 00:00:00 2001 From: Holger Kohr Date: Sat, 21 Oct 2017 23:13:12 +0200 Subject: [PATCH] BUG: fix in-out aliasing bug in OperatorSum and OperatorPointwiseProduct Closes #1181 --- odl/operator/operator.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/odl/operator/operator.py b/odl/operator/operator.py index 3c0e01fa00d..f6bc6a3edbb 100644 --- a/odl/operator/operator.py +++ b/odl/operator/operator.py @@ -1154,8 +1154,10 @@ def _call(self, x, out=None): else: tmp = (self.__tmp_ran if self.__tmp_ran is not None else self.range.element()) - self.left(x, out=out) - self.right(x, out=tmp) + # Write to `tmp` first, otherwise aliased `x` and `out` lead + # to wrong result + self.left(x, out=tmp) + self.right(x, out=out) out += tmp def derivative(self, x): @@ -1492,8 +1494,10 @@ def _call(self, x, out=None): return self.left(x) * self.right(x) else: tmp = self.right.range.element() - self.left(x, out=out) - self.right(x, out=tmp) + # Write to `tmp` first, otherwise aliased `x` and `out` lead + # to wrong result + self.left(x, out=tmp) + self.right(x, out=out) out *= tmp def derivative(self, x):