import torch


def eul_to_quat(roll, pitch, yaw):
    """
    Convert euler angles to quaternion.
    By convention, put scalar first.
    """
    sr = torch.sin(roll) # 0
    cr = torch.cos(roll) # 1
    sp = torch.sin(pitch) # 0
    cp = torch.cos(pitch) # 1
    sy = torch.sin(yaw)
    cy = torch.cos(yaw)

    qw = cr*cp*cy + sr*sp*sy
    qx = sr*cp*cy - cr*sp*sy
    qy = cr*sp*cy + sr*cp*sy
    qz = cr*cp*sy - sr*sp*cy

    return torch.stack([qw, qx, qy, qz], dim=-1)