code: def test_module_add_reverse(idtype):
      transform = dgl.AddReverse()
  
      # Case1: Add reverse edges for a homogeneous graph
      g = dgl.graph(([0], [1]), idtype=idtype, device=F.ctx())
      g.ndata["h"] = F.randn((g.num_nodes(), 3))
      g.edata["w"] = F.randn((g.num_edges(), 2))
      new_g = transform(g)
      assert new_g.device == g.device
      assert new_g.idtype == g.idtype
      assert g.num_nodes() == new_g.num_nodes()
      src, dst = new_g.edges()
      eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
      assert eset == {(0, 1), (1, 0)}
      assert F.allclose(g.ndata["h"], new_g.ndata["h"])
      assert F.allclose(
          g.edata["w"], F.narrow_row(new_g.edata["w"], 0, 1)
      )
      assert F.allclose(
          F.narrow_row(new_g.edata["w"], 1, 2),
          F.zeros((1, 2), F.float32, F.ctx()),
      )
  
      # Case2: Add reverse edges for a homogeneous graph and copy edata
      transform = dgl.AddReverse(copy_edata=True)
      new_g = transform(g)
      assert new_g.device == g.device
      assert new_g.idtype == g.idtype
      assert g.num_nodes() == new_g.num_nodes()
      src, dst = new_g.edges()
      eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
      assert eset == {(0, 1), (1, 0)}
      assert F.allclose(g.ndata["h"], new_g.ndata["h"])
      assert F.allclose(
          g.edata["w"], F.narrow_row(new_g.edata["w"], 0, 1)
      )
      assert F.allclose(
          g.edata["w"], F.narrow_row(new_g.edata["w"], 1, 2)
      )
  
      # Case3: Add reverse edges for a heterogeneous graph
      g = dgl.heterograph(
          {
              ("user", "plays", "game"): ([0, 1], [1, 1]),
              ("user", "follows", "user"): ([1, 2], [2, 2]),
          },
          device=F.ctx(),
      )
      new_g = transform(g)
      assert new_g.device == g.device
      assert new_g.idtype == g.idtype
      assert g.ntypes == new_g.ntypes
      assert set(new_g.canonical_etypes) == {
          ("user", "plays", "game"),
          ("user", "follows", "user"),
          ("game", "rev_plays", "user"),
      }
      for nty in g.ntypes:
          assert g.num_nodes(nty) == new_g.num_nodes(nty)
  
      src, dst = new_g.edges(etype="plays")
      eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
      assert eset == {(0, 1), (1, 1)}
  
      src, dst = new_g.edges(etype="follows")
      eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
      assert eset == {(1, 2), (2, 2), (2, 1)}
  
      src, dst = new_g.edges(etype="rev_plays")
      eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
      assert eset == {(1, 1), (1, 0)}
  
      # Case4: Enforce reverse edge types for symmetric canonical edge types
      transform = dgl.AddReverse(sym_new_etype=True)
      new_g = transform(g)
      assert new_g.device == g.device
      assert new_g.idtype == g.idtype
      assert g.ntypes == new_g.ntypes
      assert set(new_g.canonical_etypes) == {
          ("user", "plays", "game"),
          ("user", "follows", "user"),
          ("game", "rev_plays", "user"),
          ("user", "rev_follows", "user"),
      }
      for nty in g.ntypes:
          assert g.num_nodes(nty) == new_g.num_nodes(nty)
  
      src, dst = new_g.edges(etype="plays")
      eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
      assert eset == {(0, 1), (1, 1)}
  
      src, dst = new_g.edges(etype="follows")
      eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
      assert eset == {(1, 2), (2, 2)}
  
      src, dst = new_g.edges(etype="rev_plays")
      eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
      assert eset == {(1, 1), (1, 0)}
  
      src, dst = new_g.edges(etype="rev_follows")
      eset = set(zip(list(F.asnumpy(src)), list(F.asnumpy(dst))))
      assert eset == {(2, 1), (2, 2)}
  
imports: import math
  import os
  import unittest
  import backend
  import dgl
  import dgl.function
  import dgl.partition
  import networkx
  import numpy
  import pytest
  from scipy import sparse
  from utils import parametrize_idtype
  from utils.graph_cases import get_cases
label_desc: Use image node_id 35 for calling a global function with example usage: test_module_add_reverse(idtype) without return types