(source: np.ndarray,
                      target: np.ndarray)
return 0.5 * np.arccos(dist)[..., np.newaxis]
Computes a quaternion distance limiting the difference to a max of pi/2.

  This function supports an arbitrary number of batch dimensions, B.

  Args:
    source: a quaternion, shape (B, 4).
    target: another quaternion, shape (B, 4).

  Returns:
    Quaternion distance, shape (B, 1).
Computes a quaternion distance limiting the difference to a max of pi/2.
Computes a quaternion distance limiting the difference to a max of pi / 2 .
def bounded_quat_dist(source: np.ndarray,
                      target: np.ndarray) -> np.ndarray:
  """Computes a quaternion distance limiting the difference to a max of pi/2.

  This function supports an arbitrary number of batch dimensions, B.

  Args:
    source: a quaternion, shape (B, 4).
    target: another quaternion, shape (B, 4).

  Returns:
    Quaternion distance, shape (B, 1).
  """
  source /= np.linalg.norm(source, axis=-1, keepdims=True)
  target /= np.linalg.norm(target, axis=-1, keepdims=True)
  # "Distance" in interval [-1, 1].
  dist = 2 * np.einsum('...i,...i', source, target) ** 2 - 1
  # Clip at 1 to avoid occasional machine epsilon leak beyond 1.
  dist = np.minimum(1., dist)
  # Divide by 2 and add an axis to ensure consistency with expected return
  # shape and magnitude.
  return 0.5 * np.arccos(dist)[..., np.newaxis]
def bounded_quat_dist ( source : np . ndarray , target : np . ndarray ) -> np . ndarray : source /= np . linalg . norm ( source , axis = - 1 , keepdims = True ) target /= np . linalg . norm ( target , axis = - 1 , keepdims = True ) # "Distance" in interval [-1, 1]. dist = 2 * np . einsum ( '...i,...i' , source , target ) ** 2 - 1 # Clip at 1 to avoid occasional machine epsilon leak beyond 1. dist = np . minimum ( 1. , dist ) # Divide by 2 and add an axis to ensure consistency with expected return # shape and magnitude. return 0.5 * np . arccos ( dist ) [ ... , np . newaxis ]