import torch


def hat(v: torch.Tensor):
    """
    Compute the Hat operator [1] of a batch of 3D vectors.

    Args:
        v: batch of vectors of shape `(minibatch , 3)`

    Returns:
        batch of skew-symmetric matrices of shape `(minibatch, 3, 3)`

    Raises:
        ValueError if `v` is of incorrect shape

    [1] https://en.wikipedia.org/wiki/Hat_operator
    """

    N, dim = v.shape
    if dim != 3:
        raise ValueError('Input vectors have to be 3-dimensional.')

    h = v.new_zeros(N, 3, 3)

    x, y, z = v[:, 0], v[:, 1], v[:, 2]

    h[:, 0, 1] = -z
    h[:, 0, 2] = y
    h[:, 1, 0] = z
    h[:, 1, 2] = -x
    h[:, 2, 0] = -y
    h[:, 2, 1] = x

    return h