code: def test_simple_pool():
      g = dgl.from_networkx(nx.path_graph(15)).to(F.ctx())
  
      sum_pool = nn.SumPooling()
      avg_pool = nn.AvgPooling()
      max_pool = nn.MaxPooling()
      sort_pool = nn.SortPooling(10)  # k = 10
      print(sum_pool, avg_pool, max_pool, sort_pool)
  
      # test#1: basic
      h0 = F.randn((g.num_nodes(), 5))
      h1 = sum_pool(g, h0)
      check_close(F.squeeze(h1, 0), F.sum(h0, 0))
      h1 = avg_pool(g, h0)
      check_close(F.squeeze(h1, 0), F.mean(h0, 0))
      h1 = max_pool(g, h0)
      check_close(F.squeeze(h1, 0), F.max(h0, 0))
      h1 = sort_pool(g, h0)
      assert h1.shape[0] == 1 and h1.shape[1] == 10 * 5 and h1.ndim == 2
  
      # test#2: batched graph
      g_ = dgl.from_networkx(nx.path_graph(5)).to(F.ctx())
      bg = dgl.batch([g, g_, g, g_, g])
      h0 = F.randn((bg.num_nodes(), 5))
      h1 = sum_pool(bg, h0)
      truth = mx.nd.stack(
          F.sum(h0[:15], 0),
          F.sum(h0[15:20], 0),
          F.sum(h0[20:35], 0),
          F.sum(h0[35:40], 0),
          F.sum(h0[40:55], 0),
          axis=0,
      )
      check_close(h1, truth)
  
      h1 = avg_pool(bg, h0)
      truth = mx.nd.stack(
          F.mean(h0[:15], 0),
          F.mean(h0[15:20], 0),
          F.mean(h0[20:35], 0),
          F.mean(h0[35:40], 0),
          F.mean(h0[40:55], 0),
          axis=0,
      )
      check_close(h1, truth)
  
      h1 = max_pool(bg, h0)
      truth = mx.nd.stack(
          F.max(h0[:15], 0),
          F.max(h0[15:20], 0),
          F.max(h0[20:35], 0),
          F.max(h0[35:40], 0),
          F.max(h0[40:55], 0),
          axis=0,
      )
      check_close(h1, truth)
  
      h1 = sort_pool(bg, h0)
      assert h1.shape[0] == 5 and h1.shape[1] == 10 * 5 and h1.ndim == 2
  
imports: import backend
  import dgl
  import dgl.function
  import dgl.nn.mxnet
  import mxnet
  import networkx
  import numpy
  import pytest
  import scipy
  from mxnet import autograd, gluon, nd
  from utils import parametrize_idtype
  from utils.graph_cases import get_cases, random_bipartite, random_dglgraph, random_graph
label_desc: Use image node_id 32 for calling a global function with example usage: test_simple_pool() without return types