import torch


def add_alpha(img):
    """
    Adds a totally opaque alpha channel to a tensor, whose last axis corresponds to RGB color.

    Parameters
    ----------
    img : torch.Tensor
        The RGB image.

    Returns
    -------
    torch.Tensor
        The resulting RGBA image.

    """
    alpha_shape = list(img.shape)
    alpha_shape[-1] = 1
    return torch.cat([img, torch.ones(alpha_shape, dtype=img.dtype)], dim=-1)