def _complex_matrix_multiplication(x, y, mult_func):
    """
    Perform a matrix multiplication, helper function for complex_bmm and complex_mm.

    Parameters
    ----------
    x : torch.Tensor
    y : torch.Tensor
    mult_func : Callable
        Multiplication function e.g. torch.bmm or torch.mm

    Returns
    -------
    torch.Tensor
    """
    if not x.is_complex() or not y.is_complex():
        raise ValueError("Both x and y have to be complex-valued torch tensors.")

    output = (
        mult_func(x.real, y.real)
        - mult_func(x.imag, y.imag)
        + 1j * mult_func(x.real, y.imag)
        + 1j * mult_func(x.imag, y.real)
    )
    return output