carpet/proximity_tv.py
def backward(ctx, grad_output):
        """Compute the gradient of loss + mu*reg using a prox step.

        The gradient is derived as the additive update that would be
        used in a proximal gradient descent:

            G(u) = (u - prox(u - eps * nabla(loss)(u), eps*lbda))/eps

        with a small eps (here hard coded to 1e-10).
        """
        loss, reg, u, lbda = ctx.saved_tensors

        device = u.device

        # do clever computations
        eps = 1e-10
        grad, = torch.autograd.grad(loss, u, only_inputs=True,
                                    retain_graph=True)
        x = (u - eps * grad).data
        lbda = lbda.data

        prox_x = check_tensor(
            np.array([prox_tv.tv1_1d(xx, eps * lbda) for xx in x]),
            device=device,
        )
        grad_u = (u - prox_x) / eps
        grad_lbda = reg.clone()
        return (torch.ones(0), grad_u, grad_lbda)
Compute the gradient of loss + mu*reg using a prox step.

        The gradient is derived as the additive update that would be
        used in a proximal gradient descent:

            G(u) = (u - prox(u - eps * nabla(loss)(u), eps*lbda))/eps

        with a small eps (here hard coded to 1e-10).
        
Compute the gradient of loss + mu*reg using a prox step.
The gradient is derived as the additive update that would be
used in a proximal gradient descent.



with a small eps (here hard coded to 1e-10).
Compute the gradient of loss + mu * reg using a prox step . The gradient is derived as the additive update that would be used in a proximal gradient descent . with a small eps ( here hard coded to 1e - 10 ) .
def backward(ctx, grad_output):
        loss, reg, u, lbda = ctx.saved_tensors
        device = u.device
        eps = 1e-10
        grad, = torch.autograd.grad(loss, u, only_inputs=True,
                                    retain_graph=True)
        x = (u - eps * grad).data
        lbda = lbda.data
        prox_x = check_tensor(
            np.array([prox_tv.tv1_1d(xx, eps * lbda) for xx in x]),
            device=device,
        )
        grad_u = (u - prox_x) / eps
        grad_lbda = reg.clone()
        return (torch.ones(0), grad_u, grad_lbda)
def backward ( ctx , grad_output ) : loss , reg , u , lbda = ctx . saved_tensors device = u . device eps = 1e-10 grad , = torch . autograd . grad ( loss , u , only_inputs = True , retain_graph = True ) x = ( u - eps * grad ) . data lbda = lbda . data prox_x = check_tensor ( np . array ( [ prox_tv . tv1_1d ( xx , eps * lbda ) for xx in x ] ) , device = device , ) grad_u = ( u - prox_x ) / eps grad_lbda = reg . clone ( ) return ( torch . ones ( 0 ) , grad_u , grad_lbda )
Compute the gradient of loss + mu*reg using a prox step.
Compute the gradient of loss + mu * reg using a prox step .
"""Compute the gradient of loss + mu*reg using a prox step.

        The gradient is derived as the additive update that would be
        used in a proximal gradient descent:

            G(u) = (u - prox(u - eps * nabla(loss)(u), eps*lbda))/eps

        with a small eps (here hard coded to 1e-10).
        """ # do clever computations
ctx
grad_output