code: def test_weighted_reduce_readout(g, idtype, reducer):
      g = g.astype(idtype).to(F.ctx())
      g.ndata["h"] = F.randn((g.num_nodes(), 3))
      g.ndata["w"] = F.randn((g.num_nodes(), 1))
      g.edata["h"] = F.randn((g.num_edges(), 2))
      g.edata["w"] = F.randn((g.num_edges(), 1))
  
      # Test.1: node readout
      x = dgl.readout_nodes(g, "h", "w", op=reducer)
      # check correctness
      subg = dgl.unbatch(g)
      subx = []
      for sg in subg:
          sx = dgl.readout_nodes(sg, "h", "w", op=reducer)
          subx.append(sx)
      assert F.allclose(x, F.cat(subx, dim=0))
  
      x = getattr(dgl, "{}_nodes".format(reducer))(g, "h", "w")
      # check correctness
      subg = dgl.unbatch(g)
      subx = []
      for sg in subg:
          sx = getattr(dgl, "{}_nodes".format(reducer))(sg, "h", "w")
          subx.append(sx)
      assert F.allclose(x, F.cat(subx, dim=0))
  
      # Test.2: edge readout
      x = dgl.readout_edges(g, "h", "w", op=reducer)
      # check correctness
      subg = dgl.unbatch(g)
      subx = []
      for sg in subg:
          sx = dgl.readout_edges(sg, "h", "w", op=reducer)
          subx.append(sx)
      assert F.allclose(x, F.cat(subx, dim=0))
  
      x = getattr(dgl, "{}_edges".format(reducer))(g, "h", "w")
      # check correctness
      subg = dgl.unbatch(g)
      subx = []
      for sg in subg:
          sx = getattr(dgl, "{}_edges".format(reducer))(sg, "h", "w")
          subx.append(sx)
      assert F.allclose(x, F.cat(subx, dim=0))
  
file_path: dgl/tests/python/common/test_readout.py
imports: import unittest
  import backend
  import dgl
  import networkx
  import numpy
  import pytest
  from utils import parametrize_idtype
  from utils.graph_cases import get_cases
label_desc: Use image node_id 3 for calling a global function with example usage: test_weighted_reduce_readout(g, idtype, reducer) without return types