code: def slice_sampler_one_dim(
      target_log_prob,
      x_initial,
      step_size=0.01,
      max_doublings=30,
      seed=None,
      name=None,
  ):
      """For a given x position in each Markov chain, returns the next x.
  
      Applies the one dimensional slice sampling algorithm as defined in Neal (2003)
      to an input tensor x of shape (num_chains,) where num_chains is the number of
      simulataneous Markov chains, and returns the next tensor x of shape
      (num_chains,) when these chains are evolved by the slice sampling algorithm.
  
      Args:
        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.
        x_initial: A tensor of any shape. 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 `[]`).
        step_size: A tensor of shape and dtype compatible with `x_initial`. The min
          interval size in the doubling algorithm.
        max_doublings: Scalar tensor of dtype `tf.int32`. The maximum number of
          doublings to try to find the slice bounds.
        seed: (Optional) positive int, or Tensor seed pair. The random seed.
        name: Python `str` name prefixed to Ops created by this function.
          Default value: `None` (i.e., 'find_slice_bounds').
  
      Returns:
        retval: A tensor of the same shape and dtype as `x_initial`. The next state
          of the Markov chain.
        next_target_log_prob: The target log density evaluated at `retval`.
        bounds_satisfied: A tensor of bool dtype and shape batch dimensions.
        upper_bounds: Tensor of the same shape and dtype as `x_initial`. The upper
          bounds for the slice found.
        lower_bounds: Tensor of the same shape and dtype as `x_initial`. The lower
          bounds for the slice found.
      """
      gamma_seed, bounds_seed, sample_seed = samplers.split_seed(
          seed, n=3, salt="ssu.slice_sampler_one_dim"
      )
      with tf.name_scope(name or "slice_sampler_one_dim"):
          dtype = dtype_util.common_dtype(
              [x_initial, step_size], dtype_hint=tf.float32
          )
          x_initial = tf.convert_to_tensor(x_initial, dtype=dtype)
          step_size = tf.convert_to_tensor(step_size, dtype=dtype)
          # Obtain the input dtype of the array.
          # Select the height of the slice. Tensor of shape x_initial.shape.
          log_slice_heights = target_log_prob(
              x_initial
          ) - gamma_lib.random_gamma(
              ps.shape(x_initial),
              concentration=tf.ones([], dtype=dtype),
              seed=gamma_seed,
          )
          # Given the above x and slice heights, compute the bounds of the slice for
          # each chain.
          (
              upper_bounds,
              lower_bounds,
              bounds_satisfied,
          ) = slice_bounds_by_doubling(
              x_initial,
              target_log_prob,
              log_slice_heights,
              max_doublings,
              step_size,
              seed=bounds_seed,
          )
          retval = _sample_with_shrinkage(
              x_initial,
              target_log_prob=target_log_prob,
              log_slice_heights=log_slice_heights,
              step_size=step_size,
              lower_bounds=lower_bounds,
              upper_bounds=upper_bounds,
              seed=sample_seed,
          )
          return (
              retval,
              target_log_prob(retval),
              bounds_satisfied,
              upper_bounds,
              lower_bounds,
          )
  
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 6 for calling a global function with example usage: slice_sampler_one_dim(target_log_prob, x_initial, step_size, max_doublings, seed, name) and returns: retval,  target_log_prob,  bounds_satisfied,  upper_bounds,  lower_bounds