code: def _gather_tensor_at_swaption_payoff(param, indices):
      """Returns the values of the input `Tensor` at Swaption payoff times.
  
      `Tensor`s such as simulated path discount factors and spot discount curves
      have shape `[batch_shape, num_samples, curve_times, sim_times, dim]`. In
      order to compute swaption payoffs at exercise times, we need to gather their
      values at `[batch_shape, num_samples, curve_times_idx, sim_times_idx, dim]`
      where `curve_times_idx` are the relevant indices corresponding to times at
      which spot discount curves are sampled and `sim_times_idx` are the relevant
      indices corresponding to simulation times.
  
      To achieve this task we first transpose the tensor to shape
      `[batch_shape, curve_times, sim_times, dim, num_samples]` and then use
      `tf.gather_nd`.
  
      Args:
        param: The `Tensor` from which values will be extracted. The shape of the
          `Tensor` is `[batch_shape, num_samples, curve_times, sim_times, dim]`.
        indices: A N-D `Tensor` of shape `batch_shape + [num_indices, 2]`. The first
          column contains the indices along the `curve_times` axis and the second
          column contains the indices along the `sim_times` axis.
  
      Returns:
        A `Tensor` of same dtype as `param` and shape
        `[num_samples, batch_shape, num_indices, dim]`.
      """
      batch_rank = param.shape[:-4].rank
      # Transpose to shape `[batch_shape, curve_times, sim_times, dim, num_samples]`
      perm = list(range(batch_rank)) + [
          batch_rank + 1,
          batch_rank + 2,
          batch_rank + 3,
          batch_rank,
      ]
      param = tf.transpose(param, perm=perm)
      param = tf.gather_nd(param, indices, batch_dims=batch_rank)
      # Transpose to shape `[num_samples, batch_shape, num_indices, dim]`
      perm = [2 + batch_rank] + list(range(2 + batch_rank))
      param = tf.transpose(param, perm=perm)
  
      return param
  
imports: from typing import Callable, Tuple
  import tensorflow.compat.v2
  from tf_quant_finance import types
  from tf_quant_finance.models import utils
label_desc: Use image node_id 2 for calling a global function with example usage: _gather_tensor_at_swaption_payoff(param, indices) and returns: param