code: def _slice_along_axis(x, start=0, stop=None, step=1, axis=0):
      """Slices a Tensor along the given axis."""
      axis_ = tf.get_static_value(axis)
      if axis_ is None:  # Non-static axis: use `gather`.
          axis_len = ps.shape(x)[axis]
          start = (
              0
              if start is None
              else start
              if start >= 0
              else start + axis_len
          )
          stop = (
              axis_len
              if stop is None
              else stop
              if stop >= 0
              else stop + axis_len
          )
          return tf.gather(
              x, tf.range(start, stop, delta=step), axis=axis
          )
  
      # Static axis: construct explicit slice sequence.
      axis = int(axis_)
      if axis >= 0:
          slices = [slice(None)] * axis + [slice(start, stop, step)]
      else:
          slices = [Ellipsis, slice(start, stop, step)] + [
              slice(None)
          ] * (-1 - axis)
      return x[tuple(slices)]
  
imports: import functools
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import prefer_static
label_desc: Use image node_id 1 for calling a global function with example usage: _slice_along_axis(x, start, stop, step, axis) and returns: x, tf