import torch


def ifft2(data):
    """
    Apply centered 2-dimensional Inverse Fast Fourier Transform.

    Args:
        data (torch.Tensor): Complex valued input data containing at least 3 dimensions: dimensions
            -3 & -2 are spatial dimensions and dimension -1 has size 2. All other dimensions are
            assumed to be batch dimensions.

    Returns:
        torch.Tensor: The IFFT of the input.
    """
    assert data.size(-1) == 2
    data = torch.fft.ifftshift(data, dim=(-3, -2))
    data = torch.fft.ifft(data, 2, normalized=True)
    data = torch.fft.fftshift(data, dim=(-3, -2))
    return data