docs: def _sample_weight(kappa, dim):
      """Rejection sampling scheme for sampling distance from center on
      surface of the sphere.
      """
      dim = dim - 1  # since S^{n-1}
      b = dim / (np.sqrt(4. * kappa ** 2 + dim ** 2) + 2 * kappa)
      x = (1. - b) / (1. + b)
      c = kappa * x + dim * np.log(1 - x ** 2)
  
      while True:
          z = np.random.beta(dim / 2., dim / 2.)
          w = (1. - (1. + b) * z) / (1. - (1. - b) * z)
          u = np.random.uniform(low=0, high=1)
          if kappa * w + dim * np.log(1. - x * w) - c >= np.log(u):
              return w