import torch


def cmul(input, other):
    """
    Returns the pointwise product of the elements of two complex tensors.
    """

    assert (torch.is_tensor(input) and torch.is_tensor(other)), "Inputs are expected " \
                                                          + "to be tensors."

    assert (input.size(-1) == 2 and other.size(-1) == 2), "Inputs must be " \
                                                          + "complex tensors (their last dimension should be equal to two)."

    real = input[..., 0].mul(other[..., 0]) - input[..., 1].mul(other[..., 1])
    imag = input[..., 0].mul(other[..., 1]) + input[..., 1].mul(other[..., 0])

    return torch.cat((real.unsqueeze(-1), imag.unsqueeze(-1)), dim=-1)