code: def test_module_sign(g):
      import torch
  
      atol = 1e-06
  
      ctx = F.ctx()
      g = g.to(ctx)
      adj = g.adj_external(transpose=True, scipy_fmt="coo").todense()
      adj = torch.tensor(adj).float().to(ctx)
  
      weight_adj = (
          g.adj_external(transpose=True, scipy_fmt="coo")
          .astype(float)
          .todense()
      )
      weight_adj = torch.tensor(weight_adj).float().to(ctx)
      src, dst = g.edges()
      src, dst = src.long(), dst.long()
      weight_adj[dst, src] = g.edata["scalar_w"]
  
      # raw
      transform = dgl.SIGNDiffusion(
          k=1, in_feat_name="h", diffuse_op="raw"
      )
      g = transform(g)
      target = torch.matmul(adj, g.ndata["h"])
      assert torch.allclose(g.ndata["out_feat_1"], target, atol=atol)
  
      transform = dgl.SIGNDiffusion(
          k=1,
          in_feat_name="h",
          eweight_name="scalar_w",
          diffuse_op="raw",
      )
      g = transform(g)
      target = torch.matmul(weight_adj, g.ndata["h"])
      assert torch.allclose(g.ndata["out_feat_1"], target, atol=atol)
  
      # rw
      adj_rw = torch.matmul(torch.diag(1 / adj.sum(dim=1)), adj)
      transform = dgl.SIGNDiffusion(
          k=1, in_feat_name="h", diffuse_op="rw"
      )
      g = transform(g)
      target = torch.matmul(adj_rw, g.ndata["h"])
      assert torch.allclose(g.ndata["out_feat_1"], target, atol=atol)
  
      weight_adj_rw = torch.matmul(
          torch.diag(1 / weight_adj.sum(dim=1)), weight_adj
      )
      transform = dgl.SIGNDiffusion(
          k=1,
          in_feat_name="h",
          eweight_name="scalar_w",
          diffuse_op="rw",
      )
      g = transform(g)
      target = torch.matmul(weight_adj_rw, g.ndata["h"])
      assert torch.allclose(g.ndata["out_feat_1"], target, atol=atol)
  
      # gcn
      raw_eweight = g.edata["scalar_w"]
      gcn_norm = dgl.GCNNorm()
      g = gcn_norm(g)
      adj_gcn = adj.clone()
      adj_gcn[dst, src] = g.edata.pop("w")
      transform = dgl.SIGNDiffusion(
          k=1, in_feat_name="h", diffuse_op="gcn"
      )
      g = transform(g)
      target = torch.matmul(adj_gcn, g.ndata["h"])
      assert torch.allclose(g.ndata["out_feat_1"], target, atol=atol)
  
      gcn_norm = dgl.GCNNorm("scalar_w")
      g = gcn_norm(g)
      weight_adj_gcn = weight_adj.clone()
      weight_adj_gcn[dst, src] = g.edata["scalar_w"]
      g.edata["scalar_w"] = raw_eweight
      transform = dgl.SIGNDiffusion(
          k=1,
          in_feat_name="h",
          eweight_name="scalar_w",
          diffuse_op="gcn",
      )
      g = transform(g)
      target = torch.matmul(weight_adj_gcn, g.ndata["h"])
      assert torch.allclose(g.ndata["out_feat_1"], target, atol=atol)
  
      # ppr
      alpha = 0.2
      transform = dgl.SIGNDiffusion(
          k=1, in_feat_name="h", diffuse_op="ppr", alpha=alpha
      )
      g = transform(g)
      target = (1 - alpha) * torch.matmul(
          adj_gcn, g.ndata["h"]
      ) + alpha * g.ndata["h"]
      assert torch.allclose(g.ndata["out_feat_1"], target, atol=atol)
  
      transform = dgl.SIGNDiffusion(
          k=1,
          in_feat_name="h",
          eweight_name="scalar_w",
          diffuse_op="ppr",
          alpha=alpha,
      )
      g = transform(g)
      target = (1 - alpha) * torch.matmul(
          weight_adj_gcn, g.ndata["h"]
      ) + alpha * g.ndata["h"]
      assert torch.allclose(g.ndata["out_feat_1"], target, atol=atol)
  
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 51 for calling a global function with example usage: test_module_sign(g) without return types