Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow TV proximal to be calculated in place #1941

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Wrappers/Python/cil/optimisation/functions/TotalVariation.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ def __call__(self, x):
def proximal(self, x, tau, out=None):
r""" Returns the proximal operator of the TotalVariation function at :code:`x` ."""

if id(x)==id(out):
raise InPlaceError(message="TotalVariation.proximal cannot be used in place")


if self.strong_convexity_constant > 0:

strongly_convex_factor = (1 + tau * self.strong_convexity_constant)
Expand All @@ -266,7 +262,8 @@ def proximal(self, x, tau, out=None):
solution = self._fista_on_dual_rof(x, tau, out=out)

if self.strong_convexity_constant > 0:
x *= strongly_convex_factor
if id(x) != id(solution):
x *= strongly_convex_factor
tau *= strongly_convex_factor

return solution
Expand Down Expand Up @@ -306,12 +303,16 @@ def _fista_on_dual_rof(self, x, tau, out=None):

if out is None:
out = self.gradient_operator.domain_geometry().allocate(0)
if id(x) == id(out):
x_eval= x.copy()
else:
x_eval = x

for k in range(self.iterations):

t0 = t
self.gradient_operator.adjoint(tmp_q, out=out)
out.sapyb(tau_reg_neg, x, 1.0, out=out)
out.sapyb(tau_reg_neg, x_eval, 1.0, out=out)
self.projection_C(out, tau=None, out=out)

self.gradient_operator.direct(out, out=p1)
Expand Down
3 changes: 2 additions & 1 deletion Wrappers/Python/cil/optimisation/operators/Operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def domain(self):
@property
def range(self):
return self.range_geometry()



def __rmul__(self, scalar):
'''Defines the multiplication by a scalar on the left

Expand Down
1 change: 1 addition & 0 deletions Wrappers/Python/test/test_out_in_place.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def setUp(self):
(WeightedL2NormSquared(weight=b_ig), ig),
(TotalVariation(backend='c', warm_start=False, max_iteration=100), ig),
(TotalVariation(backend='numpy', warm_start=False, max_iteration=100), ig),
(TotalVariation(backend='numpy', warm_start=False, max_iteration=100, strong_convexity_constant=0.5), ig),
(OperatorCompositionFunction(L2NormSquared(), A), ig),
(MixedL21Norm(), bg),
(SmoothMixedL21Norm(epsilon=0.3), bg),
Expand Down
Loading