docs: def _internal2external_grad(xi, bounds):
      """
      Calculate the internal (unconstrained) to external (constained)
      parameter gradiants.
      """
      grad = empty_like(xi)
      for i, (v, bound) in enumerate(zip(xi, bounds)):
          lower, upper = bound
          if lower is None and upper is None:  # No constraints
              grad[i] = 1.0
          elif upper is None:     # only lower bound
              grad[i] = v / sqrt(v * v + 1.)
          elif lower is None:     # only upper bound
              grad[i] = -v / sqrt(v * v + 1.)
          else:   # lower and upper bounds
              grad[i] = (upper - lower) * cos(v) / 2.
      return grad