code: def slice_along_dim(
      a: torch.Tensor, dim: int, slice_: slice
  ) -> torch.Tensor:
      """
      Slice a tensor along a given dimension.
  
      Parameters
      ----------
      a
          Original tensor to slice.
      dim
          Dimension to slice over.
      slice_
          Slice to take.
  
      Returns
      -------
      torch.Tensor
          A tensor with the same size as the input one, except dimension
          ``dim`` which has length equal to the slice length.
      """
      idx = [slice(None)] * len(a.shape)
      idx[dim] = slice_
      return a[idx]
  
file_path: gluonts/src/gluonts/torch/util.py
imports: from typing import List, Optional, Type, Union
  import inspect
  import torch
label_desc: Use image node_id 7 for calling a global function with example usage: slice_along_dim(a, dim, slice_) and returns: a