import torch


def cat(tensors, dim=0, out=None):
    """As torch.cat, but returns the original tensor if len(tensors) == 1, so that an unneeded copy is not made."""
    if len(tensors) == 1:
        return tensors[0]
    else:
        return torch.cat(tensors, dim=dim, out=out)