code: def _get_indices_and_values(
      x, jump_locations, values, side, batch_rank
  ):
      """Computes values and jump locations of the piecewise constant function.
  
      Given `jump_locations` and the `values` on the corresponding segments of the
      piecewise constant function, the function identifies the nearest jump to `x`
      from the right or left (which is determined by the `side` argument) and the
      corresponding value of the piecewise constant function at `x`
  
      Args:
        x: A real `Tensor` of shape `batch_shape + [num_points]`. Points at which
          the function has to be evaluated.
        jump_locations: A `Tensor` of the same `dtype` as `x` and shape
          `batch_shape + [num_jump_points]`. The locations where the function
          changes its values. Note that the values are expected to be ordered
          along the last dimension.
        values: A `Tensor` of the same `dtype` as `x` and shape
          `batch_shape + [num_jump_points + 1]`. Defines `values[..., i]` on
          `jump_locations[..., i - 1], jump_locations[..., i]`.
        side: A Python string. Whether the function is left- or right- continuous.
          The corresponding values for side should be `left` and `right`.
        batch_rank: A Python scalar stating the batch rank of `x`.
  
      Returns:
        A tuple of three `Tensor` of the same `dtype` as `x` and shapes
        `batch_shape + [num_points] + event_shape`, `batch_shape + [num_points]`,
        and `batch_shape + [num_points] + [2 * len(batch_shape)]`. The `Tensor`s
        correspond to the values, jump locations at `x`, and the corresponding
        indices used to obtain jump locations via `tf.gather_nd`.
      """
      indices = tf.searchsorted(jump_locations, x, side=side)
      num_data_points = tf.shape(values)[batch_rank] - 2
      if side == "right":
          indices_jump = indices - 1
          indices_jump = tf.maximum(indices_jump, 0)
      else:
          indices_jump = tf.minimum(indices, num_data_points)
      value = tf.gather(
          values, indices, axis=batch_rank, batch_dims=batch_rank
      )
      jump_location = tf.gather(
          jump_locations,
          indices_jump,
          axis=batch_rank,
          batch_dims=batch_rank,
      )
      return value, jump_location, indices_jump
  
file_path: tf-quant-finance/tf_quant_finance/math/piecewise.py
imports: import tensorflow.compat.v2
label_desc: Use image node_id 4 for calling a global function with example usage: _get_indices_and_values(x, jump_locations, values, side, batch_rank) and returns: value,  jump_location,  indices_jump