code: def _get_permutation(tensor, n_dims, active_dim):
      """Returns the permutation that swaps the active and the last dimensions.
  
      Args:
        tensor: `Tensor` having a statically known rank.
        n_dims: Number of spatial dimensions.
        active_dim: The active spatial dimension.
  
      Returns:
        A list representing the permutation, or `None` if no permutation needed.
  
      For example, with 'tensor` having rank 5, `n_dims = 3` and `active_dim = 1`
      yields [0, 1, 2, 4, 3]. Explanation: we start with [0, 1, 2, 3, 4], where the
      last n_dims=3 dimensions are spatial dimensions, and the first two are batch
      dimensions. Among the spatial dimensions, we take the one at index 1, which
      is "3", and swap it with the last dimension "4".
      """
      if not tensor.shape:
          raise ValueError("Tensor's rank should be static")
      rank = len(tensor.shape)
      batch_rank = rank - n_dims
      if active_dim == n_dims - 1:
          return None
      perm = np.arange(rank)
      perm[rank - 1] = batch_rank + active_dim
      perm[batch_rank + active_dim] = rank - 1
      return perm
  
file_path: tf-quant-finance/tf_quant_finance/math/pde/steppers/douglas_adi.py
imports: import numpy
  import tensorflow.compat.v2
  from tf_quant_finance.math.pde.steppers.multidim_parabolic_equation_stepper import multidim_parabolic_equation_step
label_desc: Use image node_id 6 for calling a global function with example usage: _get_permutation(tensor, n_dims, active_dim) and returns: perm, None