code: def _threshold_and_support_graph(
      gidx: HeteroGraphIndex, scores: Tensor, end_n_ids: Tensor
  ):
      """Find the threshold for each node and its edges"""
      in_degrees = _gspmm(
          gidx, "copy_rhs", "sum", None, torch.ones_like(scores)
      )[0]
      cum_in_degrees = torch.cat(
          [in_degrees.new_zeros(1), in_degrees.cumsum(dim=0)[:-1]],
          dim=0,
      )
  
      # perform sort on edges for each node
      (
          sorted_scores,
          cumsum_scores,
          rhos,
          reverse_perm,
          dense_reverse_perm,
      ) = _neighbor_sort(scores, end_n_ids, in_degrees, cum_in_degrees)
      cumsum_scores = cumsum_scores - 1.0
      support = rhos * sorted_scores > cumsum_scores
      support = support[
          dense_reverse_perm
      ]  # from sorted order to unsorted order
      support = support[reverse_perm]  # from src-dst order to eid order
  
      support_size = _gspmm(
          gidx, "copy_rhs", "sum", None, support.float()
      )[0]
      support_size = support_size.long()
      idx = support_size + cum_in_degrees - 1
  
      # mask invalid index, for example, if batch is not start from 0 or not continuous, it may result in negative index
      mask = idx < 0
      idx[mask] = 0
      tau = cumsum_scores.gather(0, idx.long())
      tau /= support_size.to(scores.dtype)
  
      return tau, support_size
  
file_path: dgl/examples/pytorch/hgp_sl/functions.py
imports: import dgl
  import torch
  from dgl.backend import astype
  from dgl.base import ALL, is_all
  from dgl.heterograph_index import HeteroGraphIndex
  from dgl.sparse import _gsddmm, _gspmm
  from torch import Tensor
  from torch.autograd import Function
label_desc: Use image node_id 2 for calling a global function with example usage: _threshold_and_support_graph(gidx, scores, end_n_ids) and returns: tau,  support_size