import torch


def xy_to_azimuth(xy):
    """Convert (x, y) coordinates to yaw angle."""
    assert isinstance(xy, torch.Tensor)
    # assert xy.dim() == 2
    assert xy.shape[-1] == 2  # (..., 2)
    # xy_steps = xy[1:, :] - xy[:-1, :]
    # r = xy_steps.norm(dim=1, keepdim=True)
    yaw = torch.atan2(xy[..., 1:], xy[..., :1])
    return yaw