import torch


def samespace(aff, inshape, outshape):
    """Check if two spaces are the same

    Parameters
    ----------
    aff : (dim+1, dim+1)
    inshape : tuple of `dim` int
    outshape : tuple of `dim` int

    Returns
    -------
    bool

    """
    eye = torch.eye(4, dtype=aff.dtype, device=aff.device)
    return inshape == outshape and aff.allclose(eye)