code: def test_swap_along_dim_(self):
      with torch.random.fork_rng():
          torch.random.manual_seed(0)
          values = torch.rand(3, 2, 5)
  
      start = utils.build_positional_indices(shape=values.shape, dim=-2)
      min_values, i = values.min(dim=-1)
      max_values, j = values.max(dim=-1)
      out = utils.swap_along_dim_(values.clone(), i=i, j=j, dim=-1)
  
      # Verify that positions of minimum and maximum values were swapped
      for vec, min_val, min_idx, max_val, max_idx in zip(
          out.view(-1, values.shape[-1]),
          min_values.ravel(),
          i.ravel(),
          max_values.ravel(),
          j.ravel(),
      ):
          self.assertEqual(vec[min_idx], max_val)
          self.assertEqual(vec[max_idx], min_val)
  
      start = utils.build_positional_indices(shape=values.shape, dim=-2)
      i_lidx = (start + i).ravel()
      j_lidx = (start + j).ravel()
  
      # Test passing in a pre-allocated copy buffer
      temp = values.view(-1).clone()[i_lidx]
      buff = torch.empty_like(temp)
      out2 = utils.swap_along_dim_(
          values.clone(), i=i, j=j, dim=-1, buffer=buff
      )
      self.assertTrue(out.equal(out2))
      self.assertTrue(temp.equal(buff))
  
      # Test homogeneous swaps
      temp = utils.swap_along_dim_(values.clone(), i=0, j=2, dim=-1)
      self.assertTrue(values[..., 0].equal(temp[..., 2]))
      self.assertTrue(values[..., 2].equal(temp[..., 0]))
  
      # Test exception handling
      with self.assertRaisesRegex(ValueError, "Batch shapes of `i`"):
          utils.swap_along_dim_(values, i=i.unsqueeze(-1), j=j, dim=-1)
  
      with self.assertRaisesRegex(ValueError, "Batch shapes of `j`"):
          utils.swap_along_dim_(values, i=i, j=j.unsqueeze(-1), dim=-1)
  
      with self.assertRaisesRegex(ValueError, "at most 1-dimensional"):
          utils.swap_along_dim_(values.view(-1), i=i, j=j_lidx, dim=0)
  
      with self.assertRaisesRegex(ValueError, "at most 1-dimensional"):
          utils.swap_along_dim_(values.view(-1), i=i_lidx, j=j, dim=0)
  
file_path: botorch/test/utils/probability/test_utils.py
imports: from __future__ import annotations
  import torch
  from botorch.utils.probability import ndtr, utils
  from botorch.utils.probability.utils import log_erfc, log_erfcx, log_ndtr, log_phi, log_prob_normal_in, phi, standard_normal_log_hazard
  from botorch.utils.testing import BotorchTestCase
  from numpy.polynomial.legendre import leggauss
label_desc: Use image node_id 4 for calling the TestProbabilityUtils obj's underlying member method code with example usage: obj.test_swap_along_dim_() without return types