Skip to content

Commit

Permalink
Merge pull request #1182 from adler-j/issue-1181__l1_prox_bug
Browse files Browse the repository at this point in the history
BUG: Fix bug with aliased input to l1_cconj proximal, closes #1181
  • Loading branch information
adler-j authored Oct 9, 2017
2 parents 3f5934c + 9c9002d commit baecb8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 5 additions & 1 deletion odl/solvers/nonsmooth/proximal_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,11 @@ def _call(self, x, out):
if g is not None:
diff = x - self.sigma * g
else:
diff = x
if x is out:
# Handle aliased data properly
diff = x.copy()
else:
diff = x

if isotropic:
# Calculate |x| = pointwise 2-norm of x
Expand Down
19 changes: 14 additions & 5 deletions odl/test/solvers/nonsmooth/proximal_operator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,23 @@ def test_proximal_convconj_l1_simple_space_without_data():
assert isinstance(prox, odl.Operator)

# Apply the proximal operator returning its optimal point
x_opt = space.element()
prox(x, x_opt)

# Explicit computation: x / max(lam, |x|)
denom = np.maximum(lam, np.sqrt(x_arr ** 2))
x_verify = lam * x_arr / denom
x_exact = lam * x_arr / denom

assert all_almost_equal(x_opt, x_verify, HIGH_ACC)
# Using out
x_opt = space.element()
x_result = prox(x, x_opt)
assert x_result is x_opt
assert all_almost_equal(x_opt, x_exact, HIGH_ACC)

# Without out
x_result = prox(x)
assert all_almost_equal(x_result, x_exact, HIGH_ACC)

# With aliased out
x_result = prox(x, x)
assert all_almost_equal(x_result, x_exact, HIGH_ACC)


def test_proximal_convconj_l1_simple_space_with_data():
Expand Down

0 comments on commit baecb8a

Please sign in to comment.