import torch


def check_stacked_complex(data: torch.Tensor) -> torch.Tensor:
    """
    Check if tensor is stacked complex (real & imag parts stacked along last dim) and convert it to a combined complex
    tensor.

    Args:
        data: A complex valued tensor, where the size of the final dimension might be 2.

    Returns:
        A complex valued tensor.
    """
    return torch.view_as_complex(data) if data.shape[-1] == 2 else data