import torch


def hat(v: torch.Tensor):
    """Maps a vector to a 3x3 skew symmetric matrix."""
    h = torch.zeros((*v.shape, 3), dtype=v.dtype, device=v.device)
    h[..., 0, 1] = -v[..., 2]
    h[..., 0, 2] = v[..., 1]
    h[..., 1, 2] = -v[..., 0]
    h = h - h.transpose(-1, -2)
    return h