code: def test_sort_by(dtype, device, is_undirected):
      kwargs = dict(
          dtype=dtype, device=device, is_undirected=is_undirected
      )
      adj = EdgeIndex(
          [[0, 1, 1, 2], [1, 0, 2, 1]], sort_order="row", **kwargs
      )
      out = adj.sort_by("row")
      assert isinstance(out, SortReturnType)
      assert isinstance(out.values, EdgeIndex)
      assert not isinstance(out.indices, EdgeIndex)
      assert out.values.equal(adj)
      assert out.indices == slice(None, None, None)
  
      adj = EdgeIndex([[0, 1, 2, 1], [1, 0, 1, 2]], **kwargs)
      out = adj.sort_by("row")
      assert isinstance(out, SortReturnType)
      assert isinstance(out.values, EdgeIndex)
      assert not isinstance(out.indices, EdgeIndex)
      assert out.values[0].equal(tensor([0, 1, 1, 2], device=device))
      assert out.values[1].equal(
          tensor([1, 0, 2, 1], device=device)
      ) or out.values[1].equal(tensor([1, 2, 0, 1], device=device))
      assert out.indices.equal(
          tensor([0, 1, 3, 2], device=device)
      ) or out.indices.equal(tensor([0, 3, 1, 2], device=device))
  
      adj = EdgeIndex(
          [[0, 1, 1, 2], [1, 0, 2, 1]], sort_order="row", **kwargs
      )
  
      out, perm = adj.sort_by("col")
      assert adj._T_perm is not None  # Check caches.
      assert adj._T_index[0] is not None and adj._T_index[1] is not None
      assert out[0].equal(tensor([1, 0, 2, 1], device=device)) or out[
          0
      ].equal(tensor([1, 2, 0, 1], device=device))
      assert out[1].equal(tensor([0, 1, 1, 2], device=device))
      assert perm.equal(
          tensor([1, 0, 3, 2], device=device)
      ) or perm.equal(tensor([1, 3, 0, 2], device=device))
      assert out._T_perm is None
      assert out._T_index[0] is None and out._T_index[1] is None
  
      out, perm = out.sort_by("row")
      assert out[0].equal(tensor([0, 1, 1, 2], device=device))
      assert out[1].equal(tensor([1, 0, 2, 1], device=device)) or out[
          1
      ].equal(tensor([1, 2, 0, 1], device=device))
      assert perm.equal(
          tensor([1, 0, 3, 2], device=device)
      ) or perm.equal(tensor([2, 3, 0, 1], device=device))
      assert out._T_perm is None
      assert out._T_index[0] is None and out._T_index[1] is None
  
imports: import os.path
  import warnings
  from typing import List, Optional
  import pytest
  import torch
  from torch import Tensor, tensor
  import torch_geometric
  from torch_geometric import EdgeIndex
  from torch_geometric.edge_index import SUPPORTED_DTYPES, ReduceType, SortReturnType, _scatter_spmm, _torch_sparse_spmm, _TorchSPMM, set_tuple_item
  from torch_geometric.profile import benchmark
  from torch_geometric.testing import onlyCUDA, onlyLinux, withCUDA, withoutExtensions, withPackage
  from torch_geometric.typing import SparseTensor
  from torch_geometric.utils import scatter
label_desc: Use image node_id 13 for calling a global function with example usage: test_sort_by(dtype, device, is_undirected) without return types