import torch


def make_complex(x, y=None):
    """A function that combines the real (x) and imaginary (y) parts of a
    vector or a matrix.

    .. note:: x and y must have the same shape. Also, this will not work for
              rank zero tensors.

    :param x: The real part
    :type x: torch.Tensor
    :param y: The imaginary part. Can be None, in which case, the resulting
              complex tensor will have imaginary part equal to zero.
    :type y: torch.Tensor

    :returns: The tensor [x,y] = x + yi.
    :rtype: torch.Tensor
    """
    if y is None:
        y = torch.zeros_like(x)
    return torch.cat((x.unsqueeze(0), y.unsqueeze(0)), dim=0)