def prox_of_constraint_conjugate(proj):
    """ Proximal operator of the conjugate of a convex constraint.

    Let C be a convex set and F(z) = Chi_C(z) be the characteristic function of
    C. Then the convex conjugate  of F is

        F*(x) = sup_{z in C} Re(<z, x>)

    and by the Moreau decompisition we know

        prox_F* = Id - prox_F = Id - proj_C

    thus the proximal of F* can be easily obtained from the projection onto C.

    This function wraps Id-proj_C for a given projection operator. The
    projection is assumed to take arguments proj(x, *args, **kwargs), where
    x is the input to project and further arguments can be used to specify C.

    Parameters
    ----------
    proj : callable
        The projection function to wrap.

    Returns
    -------
    callable
        A function providing the proximal of F*. It will take arguments
        x : torch.Tensor
            The input tensor.
        *args
            Additional variable length arguments passed on to the projection,
            e.g. to specify C.
        **kwargs
            Additional keyword arguments passed on to the projection, e.g. to
            specify C.

    """

    def _prox(x, *args, **kwargs):
        return x - proj(x, *args, **kwargs)

    return _prox