code: def test_topological_nodes(idtype, n=100):
      a = sp.random(n, n, 3 / n, data_rvs=lambda n: np.ones(n))
      b = sp.tril(a, -1).tocoo()
      g = dgl.from_scipy(b).astype(idtype)
  
      layers_dgl = dgl.topological_nodes_generator(g)
  
      adjmat = g.adj_external(transpose=True)
  
      def tensor_topo_traverse():
          n = g.num_nodes()
          mask = F.copy_to(F.ones((n, 1)), F.cpu())
          degree = F.spmm(adjmat, mask)
          while F.reduce_sum(mask) != 0.0:
              v = F.astype((degree == 0.0), F.float32)
              v = v * mask
              mask = mask - v
              frontier = F.copy_to(
                  F.nonzero_1d(F.squeeze(v, 1)), F.cpu()
              )
              yield frontier
              degree -= F.spmm(adjmat, v)
  
      layers_spmv = list(tensor_topo_traverse())
  
      assert len(layers_dgl) == len(layers_spmv)
      assert all(
          toset(x) == toset(y) for x, y in zip(layers_dgl, layers_spmv)
      )
  
file_path: dgl/tests/python/common/test_traversal.py
imports: import itertools
  import random
  import sys
  import time
  import unittest
  import backend
  import dgl
  import networkx
  import numpy
  import scipy.sparse
  from utils import parametrize_idtype
label_desc: Use image node_id 3 for calling a global function with example usage: test_topological_nodes(idtype, n) without return types