class_docstr: SGC layer from `Simplifying Graph
  Convolutional Networks <https://arxiv.org/pdf/1902.07153.pdf>`__
  
  .. math::
      H^{K} = (\tilde{D}^{-1/2} \tilde{A} \tilde{D}^{-1/2})^K X \Theta
  
  where :math:`\tilde{A}` is :math:`A` + :math:`I`.
  Thus the graph input is expected to have self-loop edges added.
  
  Parameters
  ----------
  in_feats : int
      Number of input features; i.e, the number of dimensions of :math:`X`.
  out_feats : int
      Number of output features; i.e, the number of dimensions of :math:`H^{K}`.
  k : int
      Number of hops :math:`K`. Defaults:``1``.
  cached : bool
      If True, the module would cache
  
      .. math::
          (\tilde{D}^{-\frac{1}{2}}\tilde{A}\tilde{D}^{-\frac{1}{2}})^K X\Theta
  
      at the first forward call. This parameter should only be set to
      ``True`` in Transductive Learning setting.
  bias : bool
      If True, adds a learnable bias to the output. Default: ``True``.
  norm : callable activation function/layer or None, optional
      If not None, applies normalization to the updated node features.  Default: ``False``.
  allow_zero_in_degree : bool, optional
      If there are 0-in-degree nodes in the graph, output for those nodes will be invalid
      since no message will be passed to those nodes. This is harmful for some applications
      causing silent performance regression. This module will raise a DGLError if it detects
      0-in-degree nodes in input graph. By setting ``True``, it will suppress the check
      and let the users handle it by themselves. Default: ``False``.
  
  Note
  ----
  Zero in-degree nodes will lead to invalid output value. This is because no message
  will be passed to those nodes, the aggregation function will be appied on empty input.
  A common practice to avoid this is to add a self-loop for each node in the graph if
  it is homogeneous, which can be achieved by:
  
  >>> g = ... # a DGLGraph
  >>> g = dgl.add_self_loop(g)
  
  Calling ``add_self_loop`` will not work for some graphs, for example, heterogeneous graph
  since the edge type can not be decided for self_loop edges. Set ``allow_zero_in_degree``
  to ``True`` for those cases to unblock the code and handle zero-in-degree nodes manually.
  A common practise to handle this is to filter out the nodes with zero-in-degree when use
  after conv.
  
  Example
  -------
  >>> import dgl
  >>> import numpy as np
  >>> import torch as th
  >>> from dgl.nn import SGConv
  >>>
  >>> g = dgl.graph(([0,1,2,3,2,5], [1,2,3,4,0,3]))
  >>> g = dgl.add_self_loop(g)
  >>> feat = th.ones(6, 10)
  >>> conv = SGConv(10, 2, k=2)
  >>> res = conv(g, feat)
  >>> res
  tensor([[-1.9441, -0.9343],
          [-1.9441, -0.9343],
          [-1.9441, -0.9343],
          [-2.7709, -1.3316],
          [-1.9297, -0.9273],
          [-1.9441, -0.9343]], grad_fn=<AddmmBackward>)
class_docstr_tok: ["SGC","layer","from","`","Simplifying","Graph","Convolutional","Networks","<","https",":","\/\/arxiv.org\/pdf\/1902.07153.pdf",">","`","__","..","math",":",":","H^","{","K","}","=","(","\\tilde","{","D","}","^","{","-1\/2","}","\\tilde","{","A","}","\\tilde","{","D","}","^","{","-1\/2","}",")","^K","X","\\Theta","where",":","math",":","`","\\tilde","{","A","}","`","is",":","math",":","`","A","`","+",":","math",":","`","I","`",".","Thus","the","graph","input","is","expected","to","have","self-loop","edges","added",".","Parameters","--","--","--","--","--","in_feats",":","int","Number","of","input","features",";","i.e",",","the","number","of","dimensions","of",":","math",":","`","X","`",".","out_feats",":","int","Number","of","output","features",";","i.e",",","the","number","of","dimensions","of",":","math",":","`","H^","{","K","}","`",".","k",":","int","Number","of","hops",":","math",":","`","K","`",".","Defaults",":","``","1","``",".","cached",":","bool","If","True",",","the","module","would","cache","..","math",":",":","(","\\tilde","{","D","}","^","{","-\\frac","{","1","}","{","2","}","}","\\tilde","{","A","}","\\tilde","{","D","}","^","{","-\\frac","{","1","}","{","2","}","}",")","^K","X\\Theta","at","the","first","forward","call",".","This","parameter","should","only","be","set","to","``","True","``","in","Transductive","Learning","setting",".","bias",":","bool","If","True",",","adds","a","learnable","bias","to","the","output",".","Default",":","``","True","``",".","norm",":","callable","activation","function\/layer","or","None",",","optional","If","not","None",",","applies","normalization","to","the","updated","node","features",".","Default",":","``","False","``",".","allow_zero_in_degree",":","bool",",","optional","If","there","are","0-in-degree","nodes","in","the","graph",",","output","for","those","nodes","will","be","invalid","since","no","message","will","be","passed","to","those","nodes",".","This","is","harmful","for","some","applications","causing","silent","performance","regression",".","This","module","will","raise","a","DGLError","if","it","detects","0-in-degree","nodes","in","input","graph",".","By","setting","``","True","``",",","it","will","suppress","the","check","and","let","the","users","handle","it","by","themselves",".","Default",":","``","False","``",".","Note","--","--","Zero","in-degree","nodes","will","lead","to","invalid","output","value",".","This","is","because","no","message","will","be","passed","to","those","nodes",",","the","aggregation","function","will","be","appied","on","empty","input",".","A","common","practice","to","avoid","this","is","to","add","a","self-loop","for","each","node","in","the","graph","if","it","is","homogeneous",",","which","can","be","achieved","by",":",">",">",">","g","=","...","#","a","DGLGraph",">",">",">","g","=","dgl.add_self_loop","(","g",")","Calling","``","add_self_loop","``","will","not","work","for","some","graphs",",","for","example",",","heterogeneous","graph","since","the","edge","type","can","not","be","decided","for","self_loop","edges",".","Set","``","allow_zero_in_degree","``","to","``","True","``","for","those","cases","to","unblock","the","code","and","handle","zero-in-degree","nodes","manually",".","A","common","practise","to","handle","this","is","to","filter","out","the","nodes","with","zero-in-degree","when","use","after","conv",".","Example","--","--","--","-",">",">",">","import","dgl",">",">",">","import","numpy","as","np",">",">",">","import","torch","as","th",">",">",">","from","dgl.nn","import","SGConv",">",">",">",">",">",">","g","=","dgl.graph","(","(","[","0,1,2,3,2,5","]",",","[","1,2,3,4,0,3","]",")",")",">",">",">","g","=","dgl.add_self_loop","(","g",")",">",">",">","feat","=","th.ones","(","6",",","10",")",">",">",">","conv","=","SGConv","(","10",",","2",",","k=2",")",">",">",">","res","=","conv","(","g",",","feat",")",">",">",">","res","tensor","(","[","[","-1.9441",",","-0.9343","]",",","[","-1.9441",",","-0.9343","]",",","[","-1.9441",",","-0.9343","]",",","[","-2.7709",",","-1.3316","]",",","[","-1.9297",",","-0.9273","]",",","[","-1.9441",",","-0.9343","]","]",",","grad_fn=","<","AddmmBackward",">",")"]
docstr: Description
  -----------
  Compute Simplifying Graph Convolution layer.
  
  Parameters
  ----------
  graph : DGLGraph
      The graph.
  feat : torch.Tensor
      The input feature of shape :math:`(N, D_{in})` where :math:`D_{in}`
      is size of input feature, :math:`N` is the number of nodes.
  edge_weight: torch.Tensor, optional
      edge_weight to use in the message passing process. This is equivalent to
      using weighted adjacency matrix in the equation above, and
      :math:`\tilde{D}^{-1/2}\tilde{A} \tilde{D}^{-1/2}`
      is based on :class:`dgl.nn.pytorch.conv.graphconv.EdgeWeightNorm`.
  
  Returns
  -------
  torch.Tensor
      The output feature of shape :math:`(N, D_{out})` where :math:`D_{out}`
      is size of output feature.
  
  Raises
  ------
  DGLError
      If there are 0-in-degree nodes in the input graph, it will raise DGLError
      since no message will be passed to those nodes. This will cause invalid output.
      The error can be ignored by setting ``allow_zero_in_degree`` parameter to ``True``.
  
  Note
  ----
  If ``cache`` is set to True, ``feat`` and ``graph`` should not change during
  training, or you will get wrong results.
docstr_tok: ["Description","--","--","--","--","--","-","Compute","Simplifying","Graph","Convolution","layer",".","Parameters","--","--","--","--","--","graph",":","DGLGraph","The","graph",".","feat",":","torch.Tensor","The","input","feature","of","shape",":","math",":","`","(","N",",","D_","{","in","}",")","`","where",":","math",":","`","D_","{","in","}","`","is","size","of","input","feature",",",":","math",":","`","N","`","is","the","number","of","nodes",".","edge_weight",":","torch.Tensor",",","optional","edge_weight","to","use","in","the","message","passing","process",".","This","is","equivalent","to","using","weighted","adjacency","matrix","in","the","equation","above",",","and",":","math",":","`","\\tilde","{","D","}","^","{","-1\/2","}","\\tilde","{","A","}","\\tilde","{","D","}","^","{","-1\/2","}","`","is","based","on",":","class",":","`","dgl.nn.pytorch.conv.graphconv.EdgeWeightNorm","`",".","Returns","--","--","--","-","torch.Tensor","The","output","feature","of","shape",":","math",":","`","(","N",",","D_","{","out","}",")","`","where",":","math",":","`","D_","{","out","}","`","is","size","of","output","feature",".","Raises","--","--","--","DGLError","If","there","are","0-in-degree","nodes","in","the","input","graph",",","it","will","raise","DGLError","since","no","message","will","be","passed","to","those","nodes",".","This","will","cause","invalid","output",".","The","error","can","be","ignored","by","setting","``","allow_zero_in_degree","``","parameter","to","``","True","``",".","Note","--","--","If","``","cache","``","is","set","to","True",",","``","feat","``","and","``","graph","``","should","not","change","during","training",",","or","you","will","get","wrong","results","."]
code: def forward(self, graph, feat, edge_weight=None):
      r"""
  
      Description
      -----------
      Compute Simplifying Graph Convolution layer.
  
      Parameters
      ----------
      graph : DGLGraph
          The graph.
      feat : torch.Tensor
          The input feature of shape :math:`(N, D_{in})` where :math:`D_{in}`
          is size of input feature, :math:`N` is the number of nodes.
      edge_weight: torch.Tensor, optional
          edge_weight to use in the message passing process. This is equivalent to
          using weighted adjacency matrix in the equation above, and
          :math:`\tilde{D}^{-1/2}\tilde{A} \tilde{D}^{-1/2}`
          is based on :class:`dgl.nn.pytorch.conv.graphconv.EdgeWeightNorm`.
  
      Returns
      -------
      torch.Tensor
          The output feature of shape :math:`(N, D_{out})` where :math:`D_{out}`
          is size of output feature.
  
      Raises
      ------
      DGLError
          If there are 0-in-degree nodes in the input graph, it will raise DGLError
          since no message will be passed to those nodes. This will cause invalid output.
          The error can be ignored by setting ``allow_zero_in_degree`` parameter to ``True``.
  
      Note
      ----
      If ``cache`` is set to True, ``feat`` and ``graph`` should not change during
      training, or you will get wrong results.
      """
      with graph.local_scope():
          if not self._allow_zero_in_degree:
              if (graph.in_degrees() == 0).any():
                  raise DGLError(
                      "There are 0-in-degree nodes in the graph, "
                      "output for those nodes will be invalid. "
                      "This is harmful for some applications, "
                      "causing silent performance regression. "
                      "Adding self-loop on the input graph by "
                      "calling `g = dgl.add_self_loop(g)` will resolve "
                      "the issue. Setting ``allow_zero_in_degree`` "
                      "to be `True` when constructing this module will "
                      "suppress the check and let the code run."
                  )
  
          msg_func = fn.copy_u("h", "m")
          if edge_weight is not None:
              graph.edata["_edge_weight"] = EdgeWeightNorm("both")(
                  graph, edge_weight
              )
              msg_func = fn.u_mul_e("h", "_edge_weight", "m")
  
          if self._cached_h is not None:
              feat = self._cached_h
          else:
              if edge_weight is None:
                  # compute normalization
                  degs = graph.in_degrees().to(feat).clamp(min=1)
                  norm = th.pow(degs, -0.5)
                  norm = norm.to(feat.device).unsqueeze(1)
              # compute (D^-1 A^k D)^k X
              for _ in range(self._k):
                  if edge_weight is None:
                      feat = feat * norm
                  graph.ndata["h"] = feat
                  graph.update_all(msg_func, fn.sum("m", "h"))
                  feat = graph.ndata.pop("h")
                  if edge_weight is None:
                      feat = feat * norm
  
              if self.norm is not None:
                  feat = self.norm(feat)
  
              # cache feature
              if self._cached:
                  self._cached_h = feat
          return self.fc(feat)
  
file_path: dgl/python/dgl/nn/pytorch/conv/sgconv.py
imports: import torch
  from torch import nn
  from ....None import function
  from ....base import DGLError
  from .graphconv import EdgeWeightNorm
label_desc: Use image node_id 4 for calling the SGConv obj's underlying member method code with example usage: obj.forward(graph, feat, edge_weight) and returns: self