import torch


def _q_bar_matrix(q):
    """Matrix representation of quaternion for multiplication purposes.
    """
    return torch.cat((
        torch.stack((q[0], -q[1], -q[2], -q[3]), 1),
        torch.stack((q[1],  q[0],  q[3], -q[2]), 1),
        torch.stack((q[2], -q[3],  q[0],  q[1]), 1),
        torch.stack((q[3],  q[2], -q[1],  q[0]), 1)), dim=0)