def quaternion_to_angle_axis(quaternion: torch.Tensor) -> torch.Tensor:
    'Convert quaternion vector to angle axis of rotation.\n    The quaternion should be in (x, y, z, w) format.\n\n    Adapted from ceres C++ library: ceres-solver/include/ceres/rotation.h\n\n    Args:\n        quaternion (torch.Tensor): tensor with quaternions.\n\n    Return:\n        torch.Tensor: tensor with angle axis of rotation.\n\n    Shape:\n        - Input: :math:`(*, 4)` where `*` means, any number of dimensions\n        - Output: :math:`(*, 3)`\n\n    Example:\n        >>> quaternion = torch.rand(2, 4)  # Nx4\n        >>> angle_axis = quaternion_to_angle_axis(quaternion)  # Nx3\n    '
    if (not torch.is_tensor(quaternion)):
        raise TypeError('Input type is not a torch.Tensor. Got {}'.format(type(quaternion)))
    if (not (quaternion.shape[(- 1)] == 4)):
        raise ValueError('Input must be a tensor of shape Nx4 or 4. Got {}'.format(quaternion.shape))
    q1: torch.Tensor = quaternion[(..., 1)]
    q2: torch.Tensor = quaternion[(..., 2)]
    q3: torch.Tensor = quaternion[(..., 3)]
    sin_squared_theta: torch.Tensor = (((q1 * q1) + (q2 * q2)) + (q3 * q3))
    sin_theta: torch.Tensor = torch.sqrt(sin_squared_theta)
    cos_theta: torch.Tensor = quaternion[(..., 0)]
    two_theta: torch.Tensor = (2.0 * torch.where((cos_theta < 0.0), torch.atan2((- sin_theta), (- cos_theta)), torch.atan2(sin_theta, cos_theta)))
    k_pos: torch.Tensor = (two_theta / sin_theta)
    k_neg: torch.Tensor = (2.0 * torch.ones_like(sin_theta))
    k: torch.Tensor = torch.where((sin_squared_theta > 0.0), k_pos, k_neg)
    angle_axis: torch.Tensor = torch.zeros_like(quaternion)[..., :3]
    angle_axis[(..., 0)] += (q1 * k)
    angle_axis[(..., 1)] += (q2 * k)
    angle_axis[(..., 2)] += (q3 * k)
    return angle_axis
Convert quaternion vector to angle axis of rotation.
The quaternion should be in (x, y, z, w) format.

Adapted from ceres C++ library: ceres-solver/include/ceres/rotation.h

Args:
    quaternion (torch.Tensor): tensor with quaternions.

Return:
    torch.Tensor: tensor with angle axis of rotation.

Shape:
    - Input: :math:`(*, 4)` where `*` means, any number of dimensions
    - Output: :math:`(*, 3)`

Example:
    >>> quaternion = torch.rand(2, 4)  # Nx4
    >>> angle_axis = quaternion_to_angle_axis(quaternion)  # Nx3
def quaternion_to_angle_axis(quaternion: torch.Tensor) -> torch.Tensor:
    'Convert quaternion vector to angle axis of rotation.\n    The quaternion should be in (x, y, z, w) format.\n\n    Adapted from ceres C++ library: ceres-solver/include/ceres/rotation.h\n\n    Args:\n        quaternion (torch.Tensor): tensor with quaternions.\n\n    Return:\n        torch.Tensor: tensor with angle axis of rotation.\n\n    Shape:\n        - Input: :math:`(*, 4)` where `*` means, any number of dimensions\n        - Output: :math:`(*, 3)`\n\n    Example:\n        >>> quaternion = torch.rand(2, 4)  # Nx4\n        >>> angle_axis = quaternion_to_angle_axis(quaternion)  # Nx3\n    '
    if (not torch.is_tensor(quaternion)):
        raise TypeError('Input type is not a torch.Tensor. Got {}'.format(type(quaternion)))
    if (not (quaternion.shape[(- 1)] == 4)):
        raise ValueError('Input must be a tensor of shape Nx4 or 4. Got {}'.format(quaternion.shape))
    q1: torch.Tensor = quaternion[(..., 1)]
    q2: torch.Tensor = quaternion[(..., 2)]
    q3: torch.Tensor = quaternion[(..., 3)]
    sin_squared_theta: torch.Tensor = (((q1 * q1) + (q2 * q2)) + (q3 * q3))
    sin_theta: torch.Tensor = torch.sqrt(sin_squared_theta)
    cos_theta: torch.Tensor = quaternion[(..., 0)]
    two_theta: torch.Tensor = (2.0 * torch.where((cos_theta < 0.0), torch.atan2((- sin_theta), (- cos_theta)), torch.atan2(sin_theta, cos_theta)))
    k_pos: torch.Tensor = (two_theta / sin_theta)
    k_neg: torch.Tensor = (2.0 * torch.ones_like(sin_theta))
    k: torch.Tensor = torch.where((sin_squared_theta > 0.0), k_pos, k_neg)
    angle_axis: torch.Tensor = torch.zeros_like(quaternion)[..., :3]
    angle_axis[(..., 0)] += (q1 * k)
    angle_axis[(..., 1)] += (q2 * k)
    angle_axis[(..., 2)] += (q3 * k)
    return angle_axis