code: def test_edge_coarsening(idtype, g, weight, relabel):
      num_nodes = g.num_nodes()
      g = dgl.to_bidirected(g)
      g = g.astype(idtype).to(F.ctx())
      edge_weight = None
      if weight:
          edge_weight = F.abs(F.randn((g.num_edges(),))).to(F.ctx())
      node_labels = neighbor_matching(
          g, edge_weight, relabel_idx=relabel
      )
      unique_ids, counts = th.unique(node_labels, return_counts=True)
      num_result_ids = unique_ids.size(0)
  
      # shape correct
      assert node_labels.shape == (g.num_nodes(),)
  
      # all nodes marked
      assert F.reduce_sum(node_labels < 0).item() == 0
  
      # number of unique node ids correct.
      assert (
          num_result_ids >= num_nodes // 2
          and num_result_ids <= num_nodes
      )
  
      # each unique id has <= 2 nodes
      assert F.reduce_sum(counts > 2).item() == 0
  
      # if two nodes have the same id, they must be neighbors
      idxs = F.arange(0, num_nodes, idtype)
      for l in unique_ids:
          l = l.item()
          idx = idxs[(node_labels == l)]
          if idx.size(0) == 2:
              u, v = idx[0].item(), idx[1].item()
              assert g.has_edges_between(u, v)
  
file_path: dgl/tests/python/pytorch/geometry/test_geometry.py
imports: import backend
  import dgl
  import dgl.nn
  import numpy
  import pytest
  import torch
  from dgl import DGLError
  from dgl.base import DGLWarning
  from dgl.geometry import farthest_point_sampler, neighbor_matching
  from utils import parametrize_idtype
  from utils.graph_cases import get_cases
label_desc: Use image node_id 7 for calling a global function with example usage: test_edge_coarsening(idtype, g, weight, relabel) without return types