import torch


def fliplr(img):
    """
    Flip image horizontally in a differentiable manner.

    Parameters
    ----------
    img: Torch.Tensor
        Image batch (BCHW) to be horizontally flipped along the last dimension.

    Returns
    -------
    torch.Tensor:
        Horizontally flipped image (BCHW).
    """
    assert img.dim() == 4
    return torch.flip(img, [3])