code: def test_add_edges(idtype):
      # homogeneous graph
      g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
      u = 0
      v = 1
      g = dgl.add_edges(g, u, v)
      assert g.device == F.ctx()
      assert g.num_nodes() == 3
      assert g.num_edges() == 3
      u = [0]
      v = [1]
      g = dgl.add_edges(g, u, v)
      assert g.device == F.ctx()
      assert g.num_nodes() == 3
      assert g.num_edges() == 4
      u = F.tensor(u, dtype=idtype)
      v = F.tensor(v, dtype=idtype)
      g = dgl.add_edges(g, u, v)
      assert g.device == F.ctx()
      assert g.num_nodes() == 3
      assert g.num_edges() == 5
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0, 1, 0, 0, 0], dtype=idtype))
      assert F.array_equal(v, F.tensor([1, 2, 1, 1, 1], dtype=idtype))
      g = dgl.add_edges(g, [], [])
      g = dgl.add_edges(g, 0, [])
      g = dgl.add_edges(g, [], 0)
      assert g.device == F.ctx()
      assert g.num_nodes() == 3
      assert g.num_edges() == 5
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0, 1, 0, 0, 0], dtype=idtype))
      assert F.array_equal(v, F.tensor([1, 2, 1, 1, 1], dtype=idtype))
  
      # node id larger than current max node id
      g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
      u = F.tensor([0, 1], dtype=idtype)
      v = F.tensor([2, 3], dtype=idtype)
      g = dgl.add_edges(g, u, v)
      assert g.num_nodes() == 4
      assert g.num_edges() == 4
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0, 1, 0, 1], dtype=idtype))
      assert F.array_equal(v, F.tensor([1, 2, 2, 3], dtype=idtype))
  
      # has data
      g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
      g.ndata["h"] = F.copy_to(
          F.tensor([1, 1, 1], dtype=idtype), ctx=F.ctx()
      )
      g.edata["h"] = F.copy_to(
          F.tensor([1, 1], dtype=idtype), ctx=F.ctx()
      )
      u = F.tensor([0, 1], dtype=idtype)
      v = F.tensor([2, 3], dtype=idtype)
      e_feat = {
          "h": F.copy_to(F.tensor([2, 2], dtype=idtype), ctx=F.ctx()),
          "hh": F.copy_to(F.tensor([2, 2], dtype=idtype), ctx=F.ctx()),
      }
      g = dgl.add_edges(g, u, v, e_feat)
      assert g.num_nodes() == 4
      assert g.num_edges() == 4
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0, 1, 0, 1], dtype=idtype))
      assert F.array_equal(v, F.tensor([1, 2, 2, 3], dtype=idtype))
      assert F.array_equal(
          g.ndata["h"], F.tensor([1, 1, 1, 0], dtype=idtype)
      )
      assert F.array_equal(
          g.edata["h"], F.tensor([1, 1, 2, 2], dtype=idtype)
      )
      assert F.array_equal(
          g.edata["hh"], F.tensor([0, 0, 2, 2], dtype=idtype)
      )
  
      # zero data graph
      g = dgl.graph(
          ([], []), num_nodes=0, idtype=idtype, device=F.ctx()
      )
      u = F.tensor([0, 1], dtype=idtype)
      v = F.tensor([2, 2], dtype=idtype)
      e_feat = {
          "h": F.copy_to(F.tensor([2, 2], dtype=idtype), ctx=F.ctx()),
          "hh": F.copy_to(F.tensor([2, 2], dtype=idtype), ctx=F.ctx()),
      }
      g = dgl.add_edges(g, u, v, e_feat)
      assert g.num_nodes() == 3
      assert g.num_edges() == 2
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0, 1], dtype=idtype))
      assert F.array_equal(v, F.tensor([2, 2], dtype=idtype))
      assert F.array_equal(g.edata["h"], F.tensor([2, 2], dtype=idtype))
      assert F.array_equal(
          g.edata["hh"], F.tensor([2, 2], dtype=idtype)
      )
  
      # bipartite graph
      g = dgl.heterograph(
          {("user", "plays", "game"): ([0, 1], [1, 2])},
          idtype=idtype,
          device=F.ctx(),
      )
      u = 0
      v = 1
      g = dgl.add_edges(g, u, v)
      assert g.device == F.ctx()
      assert g.num_nodes("user") == 2
      assert g.num_nodes("game") == 3
      assert g.num_edges() == 3
      u = [0]
      v = [1]
      g = dgl.add_edges(g, u, v)
      assert g.device == F.ctx()
      assert g.num_nodes("user") == 2
      assert g.num_nodes("game") == 3
      assert g.num_edges() == 4
      u = F.tensor(u, dtype=idtype)
      v = F.tensor(v, dtype=idtype)
      g = dgl.add_edges(g, u, v)
      assert g.device == F.ctx()
      assert g.num_nodes("user") == 2
      assert g.num_nodes("game") == 3
      assert g.num_edges() == 5
      u, v = g.edges(form="uv")
      assert F.array_equal(u, F.tensor([0, 1, 0, 0, 0], dtype=idtype))
      assert F.array_equal(v, F.tensor([1, 2, 1, 1, 1], dtype=idtype))
  
      # node id larger than current max node id
      g = dgl.heterograph(
          {("user", "plays", "game"): ([0, 1], [1, 2])},
          idtype=idtype,
          device=F.ctx(),
      )
      u = F.tensor([0, 2], dtype=idtype)
      v = F.tensor([2, 3], dtype=idtype)
      g = dgl.add_edges(g, u, v)
      assert g.device == F.ctx()
      assert g.num_nodes("user") == 3
      assert g.num_nodes("game") == 4
      assert g.num_edges() == 4
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0, 1, 0, 2], dtype=idtype))
      assert F.array_equal(v, F.tensor([1, 2, 2, 3], dtype=idtype))
  
      # has data
      g = dgl.heterograph(
          {("user", "plays", "game"): ([0, 1], [1, 2])},
          idtype=idtype,
          device=F.ctx(),
      )
      g.nodes["user"].data["h"] = F.copy_to(
          F.tensor([1, 1], dtype=idtype), ctx=F.ctx()
      )
      g.nodes["game"].data["h"] = F.copy_to(
          F.tensor([2, 2, 2], dtype=idtype), ctx=F.ctx()
      )
      g.edata["h"] = F.copy_to(
          F.tensor([1, 1], dtype=idtype), ctx=F.ctx()
      )
      u = F.tensor([0, 2], dtype=idtype)
      v = F.tensor([2, 3], dtype=idtype)
      e_feat = {
          "h": F.copy_to(F.tensor([2, 2], dtype=idtype), ctx=F.ctx()),
          "hh": F.copy_to(F.tensor([2, 2], dtype=idtype), ctx=F.ctx()),
      }
      g = dgl.add_edges(g, u, v, e_feat)
      assert g.num_nodes("user") == 3
      assert g.num_nodes("game") == 4
      assert g.num_edges() == 4
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0, 1, 0, 2], dtype=idtype))
      assert F.array_equal(v, F.tensor([1, 2, 2, 3], dtype=idtype))
      assert F.array_equal(
          g.nodes["user"].data["h"], F.tensor([1, 1, 0], dtype=idtype)
      )
      assert F.array_equal(
          g.nodes["game"].data["h"],
          F.tensor([2, 2, 2, 0], dtype=idtype),
      )
      assert F.array_equal(
          g.edata["h"], F.tensor([1, 1, 2, 2], dtype=idtype)
      )
      assert F.array_equal(
          g.edata["hh"], F.tensor([0, 0, 2, 2], dtype=idtype)
      )
  
      # heterogeneous graph
      g = create_test_heterograph3(idtype)
      u = F.tensor([0, 2], dtype=idtype)
      v = F.tensor([2, 3], dtype=idtype)
      g = dgl.add_edges(g, u, v, etype="plays")
      assert g.num_nodes("user") == 3
      assert g.num_nodes("game") == 4
      assert g.num_nodes("developer") == 2
      assert g.num_edges("plays") == 6
      assert g.num_edges("develops") == 2
      u, v = g.edges(form="uv", order="eid", etype="plays")
      assert F.array_equal(
          u, F.tensor([0, 1, 1, 2, 0, 2], dtype=idtype)
      )
      assert F.array_equal(
          v, F.tensor([0, 0, 1, 1, 2, 3], dtype=idtype)
      )
      assert F.array_equal(
          g.nodes["user"].data["h"], F.tensor([1, 1, 1], dtype=idtype)
      )
      assert F.array_equal(
          g.nodes["game"].data["h"],
          F.tensor([2, 2, 0, 0], dtype=idtype),
      )
      assert F.array_equal(
          g.edges["plays"].data["h"],
          F.tensor([1, 1, 1, 1, 0, 0], dtype=idtype),
      )
  
      # add with feature
      e_feat = {
          "h": F.copy_to(F.tensor([2, 2], dtype=idtype), ctx=F.ctx())
      }
      u = F.tensor([0, 2], dtype=idtype)
      v = F.tensor([2, 3], dtype=idtype)
      g.nodes["game"].data["h"] = F.copy_to(
          F.tensor([2, 2, 1, 1], dtype=idtype), ctx=F.ctx()
      )
      g = dgl.add_edges(g, u, v, data=e_feat, etype="develops")
      assert g.num_nodes("user") == 3
      assert g.num_nodes("game") == 4
      assert g.num_nodes("developer") == 3
      assert g.num_edges("plays") == 6
      assert g.num_edges("develops") == 4
      u, v = g.edges(form="uv", order="eid", etype="develops")
      assert F.array_equal(u, F.tensor([0, 1, 0, 2], dtype=idtype))
      assert F.array_equal(v, F.tensor([0, 1, 2, 3], dtype=idtype))
      assert F.array_equal(
          g.nodes["developer"].data["h"],
          F.tensor([3, 3, 0], dtype=idtype),
      )
      assert F.array_equal(
          g.nodes["game"].data["h"],
          F.tensor([2, 2, 1, 1], dtype=idtype),
      )
      assert F.array_equal(
          g.edges["develops"].data["h"],
          F.tensor([0, 0, 2, 2], dtype=idtype),
      )
  
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 25 for calling a global function with example usage: test_add_edges(idtype) without return types