code: def _get_endpoint_b(i, j, q1, q0, batch_shape):
      """Determine the end of the interval, `b` as either `q0[j]` or `q1[i]`."""
  
      # Get `i`-th element of `q1` and the `j`-th of `q0` (for batched data).
      i_geq_0 = tf.where(tf.greater_equal(i, 0))
      q1_i = _get_q_slice(q1, i, i_geq_0, batch_shape=batch_shape)
      j_geq_0 = tf.where(tf.greater_equal(j, 0))
      q0_j = _get_q_slice(q0, j, j_geq_0, batch_shape=batch_shape)
  
      # Find `b`. If `b==q0[j]`, decrement `j`; if `b==q1[i]`, decrement `i`.
      # Note: we could have just said "b = a;" at the end of this loop but then
      # we'd have to handle corner cases before the loop and within.  Grabbing
      # it each time is minimal more work and saves added code complexity.
  
      # if i < 0: i, j, b = i, j-1, q0[j]
      i_lt_0 = tf.less(i, 0)
      ind = tf.where(i_lt_0)
      b = _update_batch(ind, q0_j, batch_shape=batch_shape)
      j = _update_batch(ind, j - 1, b=j)
  
      # elif j < 0: i, j, b = i - 1, j, q1[i]
      j_lt_0 = tf.less(j, 0)
      cond_from_previous = ~i_lt_0
      ind = tf.where(j_lt_0 & cond_from_previous)
      b = _update_batch(ind, q1_i, b=b)
      i = _update_batch(ind, i - 1, b=i)
  
      # elif q1[i] == q0[j]: i, j, b = i - 1, j - 1, q1[i]
      q_equal = tf.equal(q1_i, q0_j)
      cond_from_previous = cond_from_previous & ~j_lt_0
      ind = tf.where(q_equal & cond_from_previous)
      b = _update_batch(ind, q1_i, b=b)
      i = _update_batch(ind, i - 1, b=i)
      j = _update_batch(ind, j - 1, b=j)
  
      # elif q1[i] > q0[j]: i, j, b = i - 1, j, q1[i]
      q1_gt_q0 = tf.greater(q1_i, q0_j)
      cond_from_previous = cond_from_previous & ~q_equal
      ind = tf.where(q1_gt_q0 & cond_from_previous)
      b = _update_batch(ind, q1_i, b=b)
      i = _update_batch(ind, i - 1, b=i)
  
      # else: i, j, b = i, j - 1, q0[j]
      ind = tf.where(cond_from_previous & ~q1_gt_q0)
      b = _update_batch(ind, q0_j, b=b)
      j = _update_batch(ind, j - 1, b=j)
  
      return b, i, j
  
file_path: probability/tensorflow_probability/python/stats/ranking.py
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
label_desc: Use image node_id 5 for calling a global function with example usage: _get_endpoint_b(i, j, q1, q0, batch_shape) and returns: b,  i,  j