import torch


def from_mag_and_phase(mag, phase, dim=-2):
    """ Return a complex-like torch tensor from magnitude and phase components.

    Args:
        mag (torch.tensor): magnitude of the tensor.
        phase (torch.tensor): angle of the tensor
        dim(int, optional): the frequency (or equivalent) dimension along which
            real and imaginary values are concatenated.

    Returns:
        :class:`torch.Tensor`:
            The corresponding complex-like torch tensor.
    """
    return torch.cat([mag*torch.cos(phase), mag*torch.sin(phase)], dim=dim)