import torch


def skew_matrix_from_array(x, device=torch.device("cpu"), dtype=torch.float32):
    """
Receives a 3-element array and return its respective skew matrix.

    :param x: 3-element array.
    :return: Respective skew-matrix (3x3).
    :param device: Device to allocate new tensors. Default: torch.device("cpu").
    :param dtype: Data type for new tensors. Default: torch.float32.
    """

    # zeros with the same batch size
    zeros = torch.zeros((x.shape[0], 1), device=device, dtype=dtype)

    return torch.stack((
        torch.hstack((zeros, -x[:, 2:], x[:, 1:2])),
        torch.hstack((x[:, 2:], zeros, -x[:, 0:1])),
        torch.hstack((-x[:, 1:2], x[:, 0:1], zeros)),
    ), dim=1)