code: def permute(input_dim, permutation=None, dim=-1):
      """
      A helper function to create a :class:`~pyro.distributions.transforms.Permute`
      object for consistency with other helpers.
  
      :param input_dim: Dimension(s) of input variable to permute. Note that when
          `dim < -1` this must be a tuple corresponding to the event shape.
      :type input_dim: int
      :param permutation: Torch tensor of integer indices representing permutation.
          Defaults to a random permutation.
      :type permutation: torch.LongTensor
      :param dim: the tensor dimension to permute. This value must be negative and
          defines the event dim as `abs(dim)`.
      :type dim: int
  
      """
      if dim < -1 or not isinstance(input_dim, int):
          if len(input_dim) != -dim:
              raise ValueError(
                  "event shape {} must have same length as event_dim {}".format(
                      input_dim, -dim
                  )
              )
          input_dim = input_dim[dim]
  
      if permutation is None:
          permutation = torch.randperm(input_dim)
      return Permute(permutation, dim=dim)
  
file_path: pyro/pyro/distributions/transforms/permute.py
imports: import torch
  from torch.distributions.transforms import Transform
  from torch.distributions.utils import lazy_property
  from pyro.distributions import constraints
  from ..util import copy_docs_from
label_desc: Use image node_id 1 for calling a global function with example usage: permute(input_dim, permutation, dim) and returns: Permute