code: def test_add_reverse_edges():
      # homogeneous graph
      g = dgl.graph((F.tensor([0, 1, 3, 1]), F.tensor([1, 2, 0, 2])))
      g.ndata["h"] = F.tensor([[0.0], [1.0], [2.0], [1.0]])
      g.edata["h"] = F.tensor([[3.0], [4.0], [5.0], [6.0]])
      bg = dgl.add_reverse_edges(g, copy_ndata=True, copy_edata=True)
      u, v = g.edges()
      ub, vb = bg.edges()
      assert F.array_equal(F.cat([u, v], dim=0), ub)
      assert F.array_equal(F.cat([v, u], dim=0), vb)
      assert F.array_equal(g.ndata["h"], bg.ndata["h"])
      assert F.array_equal(
          F.cat([g.edata["h"], g.edata["h"]], dim=0), bg.edata["h"]
      )
      bg.ndata["hh"] = F.tensor([[0.0], [1.0], [2.0], [1.0]])
      assert ("hh" in g.ndata) is False
      bg.edata["hh"] = F.tensor(
          [[0.0], [1.0], [2.0], [1.0], [0.0], [1.0], [2.0], [1.0]]
      )
      assert ("hh" in g.edata) is False
  
      # donot share ndata and edata
      bg = dgl.add_reverse_edges(g, copy_ndata=False, copy_edata=False)
      ub, vb = bg.edges()
      assert F.array_equal(F.cat([u, v], dim=0), ub)
      assert F.array_equal(F.cat([v, u], dim=0), vb)
      assert ("h" in bg.ndata) is False
      assert ("h" in bg.edata) is False
  
      # zero edge graph
      g = dgl.graph(([], []))
      bg = dgl.add_reverse_edges(
          g, copy_ndata=True, copy_edata=True, exclude_self=False
      )
  
      # heterogeneous graph
      g = dgl.heterograph(
          {
              ("user", "wins", "user"): (
                  F.tensor([0, 2, 0, 2, 2]),
                  F.tensor([1, 1, 2, 1, 0]),
              ),
              ("user", "plays", "game"): (
                  F.tensor([1, 2, 1]),
                  F.tensor([2, 1, 1]),
              ),
              ("user", "follows", "user"): (
                  F.tensor([1, 2, 1]),
                  F.tensor([0, 0, 0]),
              ),
          }
      )
      g.nodes["game"].data["hv"] = F.ones((3, 1))
      g.nodes["user"].data["hv"] = F.ones((3, 1))
      g.edges["wins"].data["h"] = F.tensor([0, 1, 2, 3, 4])
      bg = dgl.add_reverse_edges(
          g, copy_ndata=True, copy_edata=True, ignore_bipartite=True
      )
      assert F.array_equal(
          g.nodes["game"].data["hv"], bg.nodes["game"].data["hv"]
      )
      assert F.array_equal(
          g.nodes["user"].data["hv"], bg.nodes["user"].data["hv"]
      )
      u, v = g.all_edges(order="eid", etype=("user", "wins", "user"))
      ub, vb = bg.all_edges(order="eid", etype=("user", "wins", "user"))
      assert F.array_equal(F.cat([u, v], dim=0), ub)
      assert F.array_equal(F.cat([v, u], dim=0), vb)
      assert F.array_equal(
          F.cat(
              [g.edges["wins"].data["h"], g.edges["wins"].data["h"]],
              dim=0,
          ),
          bg.edges["wins"].data["h"],
      )
      u, v = g.all_edges(order="eid", etype=("user", "follows", "user"))
      ub, vb = bg.all_edges(
          order="eid", etype=("user", "follows", "user")
      )
      assert F.array_equal(F.cat([u, v], dim=0), ub)
      assert F.array_equal(F.cat([v, u], dim=0), vb)
      u, v = g.all_edges(order="eid", etype=("user", "plays", "game"))
      ub, vb = bg.all_edges(
          order="eid", etype=("user", "plays", "game")
      )
      assert F.array_equal(u, ub)
      assert F.array_equal(v, vb)
      assert set(bg.edges["plays"].data.keys()) == {dgl.EID}
      assert set(bg.edges["follows"].data.keys()) == {dgl.EID}
  
      # donot share ndata and edata
      bg = dgl.add_reverse_edges(
          g, copy_ndata=False, copy_edata=False, ignore_bipartite=True
      )
      assert len(bg.edges["wins"].data) == 0
      assert len(bg.edges["plays"].data) == 0
      assert len(bg.edges["follows"].data) == 0
      assert len(bg.nodes["game"].data) == 0
      assert len(bg.nodes["user"].data) == 0
      u, v = g.all_edges(order="eid", etype=("user", "wins", "user"))
      ub, vb = bg.all_edges(order="eid", etype=("user", "wins", "user"))
      assert F.array_equal(F.cat([u, v], dim=0), ub)
      assert F.array_equal(F.cat([v, u], dim=0), vb)
      u, v = g.all_edges(order="eid", etype=("user", "follows", "user"))
      ub, vb = bg.all_edges(
          order="eid", etype=("user", "follows", "user")
      )
      assert F.array_equal(F.cat([u, v], dim=0), ub)
      assert F.array_equal(F.cat([v, u], dim=0), vb)
      u, v = g.all_edges(order="eid", etype=("user", "plays", "game"))
      ub, vb = bg.all_edges(
          order="eid", etype=("user", "plays", "game")
      )
      assert F.array_equal(u, ub)
      assert F.array_equal(v, vb)
  
      # test the case when some nodes have zero degree
      # homogeneous graph
      g = dgl.graph(
          (F.tensor([0, 1, 3, 1]), F.tensor([1, 2, 0, 2])), num_nodes=6
      )
      g.ndata["h"] = F.tensor(
          [[0.0], [1.0], [2.0], [1.0], [1.0], [1.0]]
      )
      g.edata["h"] = F.tensor([[3.0], [4.0], [5.0], [6.0]])
      bg = dgl.add_reverse_edges(g, copy_ndata=True, copy_edata=True)
      assert g.num_nodes() == bg.num_nodes()
      assert F.array_equal(g.ndata["h"], bg.ndata["h"])
      assert F.array_equal(
          F.cat([g.edata["h"], g.edata["h"]], dim=0), bg.edata["h"]
      )
  
      # heterogeneous graph
      g = dgl.heterograph(
          {
              ("user", "wins", "user"): (
                  F.tensor([0, 2, 0, 2, 2]),
                  F.tensor([1, 1, 2, 1, 0]),
              ),
              ("user", "plays", "game"): (
                  F.tensor([1, 2, 1]),
                  F.tensor([2, 1, 1]),
              ),
              ("user", "follows", "user"): (
                  F.tensor([1, 2, 1]),
                  F.tensor([0, 0, 0]),
              ),
          },
          num_nodes_dict={"user": 5, "game": 3},
      )
      g.nodes["game"].data["hv"] = F.ones((3, 1))
      g.nodes["user"].data["hv"] = F.ones((5, 1))
      g.edges["wins"].data["h"] = F.tensor([0, 1, 2, 3, 4])
      bg = dgl.add_reverse_edges(
          g, copy_ndata=True, copy_edata=True, ignore_bipartite=True
      )
      assert g.num_nodes("user") == bg.num_nodes("user")
      assert g.num_nodes("game") == bg.num_nodes("game")
      assert F.array_equal(
          g.nodes["game"].data["hv"], bg.nodes["game"].data["hv"]
      )
      assert F.array_equal(
          g.nodes["user"].data["hv"], bg.nodes["user"].data["hv"]
      )
      assert F.array_equal(
          F.cat(
              [g.edges["wins"].data["h"], g.edges["wins"].data["h"]],
              dim=0,
          ),
          bg.edges["wins"].data["h"],
      )
  
      # test exclude_self
      g = dgl.heterograph(
          {
              ("A", "r1", "A"): (
                  F.tensor([0, 0, 1, 1]),
                  F.tensor([0, 1, 1, 2]),
              ),
              ("A", "r2", "A"): (F.tensor([0, 1]), F.tensor([1, 2])),
          }
      )
      g.edges["r1"].data["h"] = F.tensor([0, 1, 2, 3])
      rg = dgl.add_reverse_edges(g, copy_edata=True, exclude_self=True)
      assert rg.num_edges("r1") == 6
      assert rg.num_edges("r2") == 4
      assert F.array_equal(
          rg.edges["r1"].data["h"], F.tensor([0, 1, 2, 3, 1, 3])
      )
  
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 10 for calling a global function with example usage: test_add_reverse_edges() without return types