code: def _test_sort_discontiguous(self, device, dtype):
      # on CUDA 2048 vs >2048 have different code path for the dim being sorted
      sizes = (5, 7, 2049)
      for shape in permutations(sizes):
          for perm in permutations((0, 1, 2)):
              for dim in range(3):
                  t = torch.randn(
                      shape, device=device, dtype=dtype
                  ).permute(perm)
                  r1 = t.sort(dim=dim)
                  r2 = t.contiguous().sort(dim=dim)
                  self.assertEqual(r1, r2)
                  n = t.size(dim)
  
                  # assert ordered
                  self.assertTrue(
                      (
                          r1.values.narrow(dim, 1, n - 1)
                          >= r1.values.narrow(dim, 0, n - 1)
                      ).all()
                  )
  
                  # assert that different segments does not mix, which can easily happen
                  # if the stride is not handled correctly
                  self.assertTrue(
                      (
                          t.unsqueeze(-1).transpose(dim, -1)
                          == r1.values.unsqueeze(-1)
                      )
                      .any(dim=dim)
                      .any(dim=-1)
                      .all()
                  )
  
                  # assert stride is preserved
                  if self.device_type == "cuda":
                      # FIXME: this behavior should be true for all cases, not
                      # just the one specified in if condition
                      self.assertEqual(r1.values.stride(), t.stride())
                      self.assertEqual(r1.indices.stride(), t.stride())
  
imports: import torch
  import numpy
  import random
  from torch import nan
  from itertools import permutations, product
  from torch.testing import make_tensor
  from torch.testing._internal.common_dtype import all_types, all_types_and, floating_types_and, integral_types
  from torch.testing._internal.common_utils import TestCase, run_tests, slowTest, skipIfTorchDynamo
  from torch.testing._internal.common_device_type import instantiate_device_type_tests, dtypes, onlyNativeDeviceTypes, onlyCUDA, dtypesIfCUDA, dtypesIfCPU, onlyCPU, largeTensorTest
label_desc: Use image node_id 8 for calling the TestSortAndSelect obj's underlying member method code with example usage: obj._test_sort_discontiguous(device, dtype) without return types