code: def apply_permutation(
      tensor: Tensor, dim: int, permutation: Optional[Tensor]
  ):
      """
      Permute elements of a tensor along a dimension `dim`. If permutation is None do nothing.
      """
      if permutation is None:
          return tensor
      return tensor.index_select(dim, permutation)
  
imports: import math
  import numbers
  import warnings
  from typing import List, Optional, Tuple, Type, Union
  import torch
  import torch.nn
  from torch import Tensor
  from torch.nn.utils.rnn import PackedSequence
  from ..utils.packed_sequences import compute_seq_lengths
  from .param_rename import RenameParamsMixin
label_desc: Use image node_id 1 for calling a global function with example usage: apply_permutation(tensor, dim, permutation) and returns: tensor, tensor