code: def swap_along_dim_(
      values: Tensor,
      i: Union[int, LongTensor],
      j: Union[int, LongTensor],
      dim: int,
      buffer: Optional[Tensor] = None,
  ) -> Tensor:
      r"""Swaps Tensor slices in-place along dimension `dim`.
  
      When passed as Tensors, `i` (and `j`) should be `dim`-dimensional tensors
      with the same shape as `values.shape[:dim]`. The xception to this rule occurs
      when `dim=0`, in which case `i` (and `j`) should be (at most) one-dimensional
      when passed as a Tensor.
  
      Args:
          values: Tensor whose values are to be swapped.
          i: Indices for slices along dimension `dim`.
          j: Indices for slices along dimension `dim`.
          dim: The dimension of `values` along which to swap slices.
          buffer: Optional buffer used internally to store copied values.
  
      Returns:
          The original `values` tensor.
      """
      dim = values.ndim + dim if dim < 0 else dim
      if dim and (
          (isinstance(i, Tensor) and i.ndim)
          or (isinstance(j, Tensor) and j.ndim)
      ):
          # Handle n-dimensional batches of heterogeneous swaps via linear indexing
          if isinstance(i, Tensor) and i.shape != values.shape[:dim]:
              raise ValueError(
                  "Batch shapes of `i` and `values` do not match."
              )
  
          if isinstance(j, Tensor) and j.shape != values.shape[:dim]:
              raise ValueError(
                  "Batch shapes of `j` and `values` do not match."
              )
  
          pidx = build_positional_indices(
              shape=values.shape[: dim + 1],
              dim=-2,
              device=values.device,
          )
  
          swap_along_dim_(
              values.view(-1, *values.shape[dim + 1 :]),
              i=(pidx + i).view(-1),
              j=(pidx + j).view(-1),
              dim=0,
              buffer=buffer,
          )
  
      else:
          # Base cases: homogeneous swaps and 1-dimenensional heterogeneous swaps
          if isinstance(i, Tensor) and i.ndim > 1:
              raise ValueError(
                  "Tensor `i` must be at most 1-dimensional when `dim=0`."
              )
  
          if isinstance(j, Tensor) and j.ndim > 1:
              raise ValueError(
                  "Tensor `j` must be at most 1-dimensional when `dim=0`."
              )
  
          if dim:
              ctx = tuple(slice(None) for _ in range(dim))
              i = ctx + (i,)
              j = ctx + (j,)
  
          if buffer is None:
              buffer = values[i].clone()
          else:
              buffer.copy_(values[i])
  
          values[i] = values[j]
          values[j] = buffer
  
      return values
  
imports: from __future__ import annotations
  import math
  from functools import lru_cache
  from math import pi
  from numbers import Number
  from typing import Any, Callable, Iterable, Iterator, Optional, Tuple, Union
  import torch
  from botorch.utils.safe_math import logdiffexp
  from numpy.polynomial.legendre import leggauss
  from torch import BoolTensor, LongTensor, Tensor
label_desc: Use image node_id 15 for calling a global function with example usage: swap_along_dim_(values, i, j, dim, buffer) and returns: values