code: def test_remove_nodes(idtype):
      # homogeneous Graphs
      g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
      n = 0
      g = dgl.remove_nodes(g, n)
      assert g.num_nodes() == 2
      assert g.num_edges() == 1
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0], dtype=idtype))
      assert F.array_equal(v, F.tensor([1], dtype=idtype))
      g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
      n = [1]
      g = dgl.remove_nodes(g, n)
      assert g.num_nodes() == 2
      assert g.num_edges() == 0
      g = dgl.graph(([0, 1], [1, 2]), idtype=idtype, device=F.ctx())
      n = F.tensor([2], dtype=idtype)
      g = dgl.remove_nodes(g, n)
      assert g.num_nodes() == 2
      assert g.num_edges() == 1
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0], dtype=idtype))
      assert F.array_equal(v, F.tensor([1], dtype=idtype))
  
      # invalid nid
      assert_fail = False
      try:
          g.remove_nodes(3)
      except:
          assert_fail = True
      assert assert_fail
  
      # has node and edge data
      g = dgl.graph(
          ([0, 0, 2], [0, 1, 2]), idtype=idtype, device=F.ctx()
      )
      g.ndata["hv"] = F.copy_to(
          F.tensor([1, 2, 3], dtype=idtype), ctx=F.ctx()
      )
      g.edata["he"] = F.copy_to(
          F.tensor([1, 2, 3], dtype=idtype), ctx=F.ctx()
      )
      g = dgl.remove_nodes(g, F.tensor([0], dtype=idtype))
      assert g.num_nodes() == 2
      assert g.num_edges() == 1
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([1], dtype=idtype))
      assert F.array_equal(v, F.tensor([1], dtype=idtype))
      assert F.array_equal(
          g.ndata["hv"], F.tensor([2, 3], dtype=idtype)
      )
      assert F.array_equal(g.edata["he"], F.tensor([3], 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(),
      )
      n = 0
      g = dgl.remove_nodes(g, n, ntype="user")
      assert g.num_nodes("user") == 1
      assert g.num_nodes("game") == 3
      assert g.num_edges() == 1
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0], dtype=idtype))
      assert F.array_equal(v, F.tensor([2], dtype=idtype))
      g = dgl.heterograph(
          {("user", "plays", "game"): ([0, 1], [1, 2])},
          idtype=idtype,
          device=F.ctx(),
      )
      n = [1]
      g = dgl.remove_nodes(g, n, ntype="user")
      assert g.num_nodes("user") == 1
      assert g.num_nodes("game") == 3
      assert g.num_edges() == 1
      u, v = g.edges(form="uv", order="eid")
      assert F.array_equal(u, F.tensor([0], dtype=idtype))
      assert F.array_equal(v, F.tensor([1], dtype=idtype))
      g = dgl.heterograph(
          {("user", "plays", "game"): ([0, 1], [1, 2])},
          idtype=idtype,
          device=F.ctx(),
      )
      n = F.tensor([0], dtype=idtype)
      g = dgl.remove_nodes(g, n, ntype="game")
      assert g.num_nodes("user") == 2
      assert g.num_nodes("game") == 2
      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([0, 1], dtype=idtype))
  
      # heterogeneous graph
      g = create_test_heterograph3(idtype)
      g.edges["plays"].data["h"] = F.copy_to(
          F.tensor([1, 2, 3, 4], dtype=idtype), ctx=F.ctx()
      )
      g = dgl.remove_nodes(g, 0, ntype="game")
      assert g.num_nodes("user") == 3
      assert g.num_nodes("game") == 1
      assert g.num_nodes("developer") == 2
      assert g.num_edges("plays") == 2
      assert g.num_edges("develops") == 1
      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], dtype=idtype)
      )
      assert F.array_equal(
          g.nodes["developer"].data["h"], F.tensor([3, 3], dtype=idtype)
      )
      u, v = g.edges(form="uv", order="eid", etype="plays")
      assert F.array_equal(u, F.tensor([1, 2], dtype=idtype))
      assert F.array_equal(v, F.tensor([0, 0], dtype=idtype))
      assert F.array_equal(
          g.edges["plays"].data["h"], F.tensor([3, 4], dtype=idtype)
      )
      u, v = g.edges(form="uv", order="eid", etype="develops")
      assert F.array_equal(u, F.tensor([1], dtype=idtype))
      assert F.array_equal(v, F.tensor([0], dtype=idtype))
  
      # batched graph
      ctx = F.ctx()
      g1 = dgl.graph(
          ([0, 1], [1, 2]), num_nodes=5, idtype=idtype, device=ctx
      )
      g2 = dgl.graph(([], []), idtype=idtype, device=ctx)
      g3 = dgl.graph(([2, 3, 4], [3, 2, 1]), idtype=idtype, device=ctx)
      bg = dgl.batch([g1, g2, g3])
      bg_r = dgl.remove_nodes(bg, 1)
      assert bg_r.batch_size == bg.batch_size
      assert F.array_equal(
          bg_r.batch_num_nodes(), F.tensor([4, 0, 5], dtype=idtype)
      )
      assert F.array_equal(
          bg_r.batch_num_edges(), F.tensor([0, 0, 3], dtype=idtype)
      )
  
      bg_r = dgl.remove_nodes(bg, [1, 7])
      assert bg_r.batch_size == bg.batch_size
      assert F.array_equal(
          bg_r.batch_num_nodes(), F.tensor([4, 0, 4], dtype=idtype)
      )
      assert F.array_equal(
          bg_r.batch_num_edges(), F.tensor([0, 0, 1], dtype=idtype)
      )
  
      bg_r = dgl.remove_nodes(bg, F.tensor([1, 7], dtype=idtype))
      assert bg_r.batch_size == bg.batch_size
      assert F.array_equal(
          bg_r.batch_num_nodes(), F.tensor([4, 0, 4], dtype=idtype)
      )
      assert F.array_equal(
          bg_r.batch_num_edges(), F.tensor([0, 0, 1], dtype=idtype)
      )
  
      # batched heterogeneous graph
      g1 = dgl.heterograph(
          {
              ("user", "follows", "user"): ([0, 1], [1, 2]),
              ("user", "plays", "game"): ([1, 3], [0, 1]),
          },
          num_nodes_dict={"user": 4, "game": 3},
          idtype=idtype,
          device=ctx,
      )
      g2 = dgl.heterograph(
          {
              ("user", "follows", "user"): ([0, 2], [3, 4]),
              ("user", "plays", "game"): ([], []),
          },
          num_nodes_dict={"user": 6, "game": 2},
          idtype=idtype,
          device=ctx,
      )
      g3 = dgl.heterograph(
          {
              ("user", "follows", "user"): ([], []),
              ("user", "plays", "game"): ([1, 2], [1, 2]),
          },
          idtype=idtype,
          device=ctx,
      )
      bg = dgl.batch([g1, g2, g3])
      bg_r = dgl.remove_nodes(bg, 1, ntype="user")
      assert bg_r.batch_size == bg.batch_size
      assert F.array_equal(
          bg_r.batch_num_nodes("user"),
          F.tensor([3, 6, 3], dtype=idtype),
      )
      assert F.array_equal(
          bg.batch_num_nodes("game"), bg_r.batch_num_nodes("game")
      )
      assert F.array_equal(
          bg_r.batch_num_edges("follows"),
          F.tensor([0, 2, 0], dtype=idtype),
      )
      assert F.array_equal(
          bg_r.batch_num_edges("plays"),
          F.tensor([1, 0, 2], dtype=idtype),
      )
  
      bg_r = dgl.remove_nodes(bg, 6, ntype="game")
      assert bg_r.batch_size == bg.batch_size
      assert F.array_equal(
          bg.batch_num_nodes("user"), bg_r.batch_num_nodes("user")
      )
      assert F.array_equal(
          bg_r.batch_num_nodes("game"),
          F.tensor([3, 2, 2], dtype=idtype),
      )
      assert F.array_equal(
          bg.batch_num_edges("follows"), bg_r.batch_num_edges("follows")
      )
      assert F.array_equal(
          bg_r.batch_num_edges("plays"),
          F.tensor([2, 0, 1], dtype=idtype),
      )
  
      bg_r = dgl.remove_nodes(bg, [1, 5, 6, 11], ntype="user")
      assert bg_r.batch_size == bg.batch_size
      assert F.array_equal(
          bg_r.batch_num_nodes("user"),
          F.tensor([3, 4, 2], dtype=idtype),
      )
      assert F.array_equal(
          bg.batch_num_nodes("game"), bg_r.batch_num_nodes("game")
      )
      assert F.array_equal(
          bg_r.batch_num_edges("follows"),
          F.tensor([0, 1, 0], dtype=idtype),
      )
      assert F.array_equal(
          bg_r.batch_num_edges("plays"),
          F.tensor([1, 0, 1], dtype=idtype),
      )
  
      bg_r = dgl.remove_nodes(bg, [0, 3, 4, 7], ntype="game")
      assert bg_r.batch_size == bg.batch_size
      assert F.array_equal(
          bg.batch_num_nodes("user"), bg_r.batch_num_nodes("user")
      )
      assert F.array_equal(
          bg_r.batch_num_nodes("game"),
          F.tensor([2, 0, 2], dtype=idtype),
      )
      assert F.array_equal(
          bg.batch_num_edges("follows"), bg_r.batch_num_edges("follows")
      )
      assert F.array_equal(
          bg_r.batch_num_edges("plays"),
          F.tensor([1, 0, 1], dtype=idtype),
      )
  
      bg_r = dgl.remove_nodes(
          bg, F.tensor([1, 5, 6, 11], dtype=idtype), ntype="user"
      )
      assert bg_r.batch_size == bg.batch_size
      assert F.array_equal(
          bg_r.batch_num_nodes("user"),
          F.tensor([3, 4, 2], dtype=idtype),
      )
      assert F.array_equal(
          bg.batch_num_nodes("game"), bg_r.batch_num_nodes("game")
      )
      assert F.array_equal(
          bg_r.batch_num_edges("follows"),
          F.tensor([0, 1, 0], dtype=idtype),
      )
      assert F.array_equal(
          bg_r.batch_num_edges("plays"),
          F.tensor([1, 0, 1], dtype=idtype),
      )
  
      bg_r = dgl.remove_nodes(
          bg, F.tensor([0, 3, 4, 7], dtype=idtype), ntype="game"
      )
      assert bg_r.batch_size == bg.batch_size
      assert F.array_equal(
          bg.batch_num_nodes("user"), bg_r.batch_num_nodes("user")
      )
      assert F.array_equal(
          bg_r.batch_num_nodes("game"),
          F.tensor([2, 0, 2], dtype=idtype),
      )
      assert F.array_equal(
          bg.batch_num_edges("follows"), bg_r.batch_num_edges("follows")
      )
      assert F.array_equal(
          bg_r.batch_num_edges("plays"),
          F.tensor([1, 0, 1], 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 28 for calling a global function with example usage: test_remove_nodes(idtype) without return types