code: def _find_best_interval_idx(x, name=None):
      """Finds the index of the optimal set of bounds for each chain.
  
      For each chain, finds the smallest set of bounds for which both edges lie
      outside the slice. This is equivalent to the point at which a for loop
      implementation (P715 of Neal (2003)) of the algorithm would terminate.
  
      Performs the following calculation, where i is the number of doublings that
      have been performed and k is the max number of doublings:
  
      (2 * k - i) * flag + i
  
      The argmax of the above returns the earliest index where the bounds were
      outside the slice and if there is no such point, the widest bounds.
  
      Args:
        x: A tensor of shape (max_doublings+1, batch_shape). Type int32, with value
          0 or 1. Indicates if this set of bounds is outside the slice.
        name: Python `str` name prefixed to Ops created by this function.
          Default value: `None` (i.e., 'find_slice_bounds').
  
      Returns:
        indices: A tensor of shape batch_shape. Type int32, with the index of the
          first set of bounds outside the slice and if there are none, the index of
          the widest set.
      """
      with tf.name_scope(name or "find_best_interval_idx"):
          # Returns max_doublings + 1. Positive int32.
          k = ps.shape(x)[0]
          dtype = dtype_util.base_dtype(x.dtype)
          # Factors by which to multiply the flag. Corresponds to (2 * k - i) above.
          mults = ps.range(2 * k, k, -1, dtype=dtype)[:, tf.newaxis]
          # Factors by which to shift the flag. Corresponds to i above. Ensures the
          # widest bounds are selected if there are no bounds outside the slice.
          shifts = ps.range(k, dtype=dtype)[:, tf.newaxis]
          indices = tf.argmax(
              mults * x + shifts, axis=0, output_type=dtype
          )
          return indices
  
file_path: probability/tensorflow_probability/python/mcmc/internal/slice_sampler_utils.py
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import bernoulli
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import samplers
label_desc: Use image node_id 2 for calling a global function with example usage: _find_best_interval_idx(x, name) and returns: indices