code: def _test_acceptance(
      x_initial,
      target_log_prob,
      decided,
      log_slice_heights,
      x_proposed,
      step_size,
      lower_bounds,
      upper_bounds,
      name=None,
  ):
      """Ensures the chosen point does not violate reversibility.
  
        Implements Fig 6 of Neal 2003 page 717, which checks that the path from the
        existing point to the new point would also have been possible in reverse.
        This is done by checking that the algorithm would not have been terminated
        before reaching the old point.
  
      Args:
        x_initial: A tensor of any shape and real dtype. The initial positions of
          the chains. This function assumes that all the dimensions of `x_initial`
          are batch dimensions (i.e. the event shape is `[]`).
        target_log_prob: Callable accepting a tensor like `x_initial` and returning
          a tensor containing the log density at that point of the same shape.
        decided: A `tf.bool` tensor of the same shape as `x_initial`. Indicates
          whether the acceptance has already been decided. A point is tested only
          if `decided` for that point is False.
        log_slice_heights: Tensor of the same shape and dtype as the return value
          of `target_log_prob` when applied to `x_initial`. The log of the height of
          the chosen slice.
        x_proposed: A tensor of the same shape and dtype as `x_initial`. The
          proposed points.
        step_size: A tensor of shape and dtype compatible with `x_initial`. The min
          interval size in the doubling algorithm.
        lower_bounds: Tensor of same shape and dtype as `x_initial`. Slice lower
          bounds for each chain.
        upper_bounds: Tensor of same shape and dtype as `x_initial`. Slice upper
          bounds for each chain.
        name: Python `str` name prefixed to Ops created by this function.
          Default value: `None` (i.e., 'find_slice_bounds').
  
      Returns:
        acceptable: A boolean tensor of same shape as `x_initial` indicating whether
          the proposed points are acceptable for reversibility or not.
      """
      with tf.name_scope(name or "test_acceptance"):
          d = tf.zeros_like(x_initial, dtype=tf.bool)
  
          # Keeps track of points for which the loop has "effectively terminated".
          # Termination is when either their interval width has shrunk to the minimum
          # value (step_size) or if the point has already been rejected.
          def cond(
              _, decided, *ignored_args
          ):  # pylint: disable=unused-argument
              # Continue until all the points have been decided.
              return ~tf.reduce_all(decided)
  
          acceptable = tf.ones_like(x_initial, dtype=tf.bool)
  
          def body(acceptable, decided, left, right, d):
              """Checks reversibility as described on P717 of Neal 2003."""
              midpoint = (left + right) / 2
              divided = (
                  (x_initial < midpoint) & (x_proposed >= midpoint)
              ) | ((x_proposed < midpoint) & (x_initial >= midpoint))
              next_d = d | divided
              next_right = tf.where(
                  x_proposed < midpoint, midpoint, right
              )
              next_left = tf.where(
                  x_proposed >= midpoint, midpoint, left
              )
              left_test = log_slice_heights >= target_log_prob(
                  next_left
              )
              right_test = log_slice_heights >= target_log_prob(
                  next_right
              )
              unacceptable = next_d & left_test & right_test
              # Logic here: For points which have not already been decided,
              # and are unacceptable, set acceptable to False. For others, let them
              # be as they were.
              now_decided = ~decided & unacceptable
              next_acceptable = tf.where(
                  now_decided, ~unacceptable, acceptable
              )
              # Decided if (a) was already decided, or
              # (b) the new width is less than 1.1 step_size, or
              # (c) was marked unacceptable.
              next_decided = (
                  decided
                  | (next_right - next_left <= 1.1 * step_size)
                  | now_decided
              )
              return (
                  next_acceptable,
                  next_decided,
                  next_left,
                  next_right,
                  next_d,
              )
  
          return tf.while_loop(
              cond=cond,
              body=body,
              loop_vars=(
                  acceptable,
                  decided,
                  lower_bounds,
                  upper_bounds,
                  d,
              ),
          )[0]
  
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 4 for calling a global function with example usage: _test_acceptance(x_initial, target_log_prob, decided, log_slice_heights, x_proposed, step_size, lower_bounds, upper_bounds, name) and returns: tf, unknown, next_acceptable,  next_decided,  next_left,  next_right,  next_d