import torch


def proj_linf_ball(x, centre, radius):
    """ Euclidean projection onto a closed l-inf-ball.

    Parameters
    ----------
    x : torch.Tensor
        The input tensor to project.
    centre : torch.Tensor
        The centre of the ball.
    radius : float
        The radius of the ball. Must be non-negative.

    Returns
    -------
    torch.Tensor
        The projection of x onto the closed ball.
    """
    tmp = torch.min(x, centre + radius)
    return torch.max(tmp, centre - radius)