code: def __segment_topk_rank(
      scores, segment_ids, num_nodes, max_num_nodes
  ):
      """
      Used by segment_topk.
      This function offer the rank results according to scores.
      """
      batch_size = int(num_nodes.shape[0])
      nodes_cumsum = num_nodes.cumsum(0)
      cum_num_nodes = paddle.zeros([1])
      if nodes_cumsum.shape[0] > 1:
          cum_num_nodes = paddle.concat(
              [cum_num_nodes, nodes_cumsum[:-1]], 0
          )
      index = paddle.arange(segment_ids.shape[0], dtype=paddle.int32)
      index = (index - cum_num_nodes[segment_ids]) + (
          segment_ids * max_num_nodes
      )
      dense_x = paddle.full([batch_size * max_num_nodes], -1e20).astype(
          paddle.float32
      )
      dense_x = paddle.scatter(dense_x, index, scores.reshape([-1]))
      dense_x = dense_x.reshape([batch_size, max_num_nodes])
      perm = dense_x.argsort(-1, descending=True)
      perm = perm + cum_num_nodes.reshape([-1, 1])
      perm = perm.reshape([-1])
      return perm
  
file_path: PGL/pgl/math.py
imports: import paddle
  from pgl.utils.op import get_index_from_counts
label_desc: Use image node_id 8 for calling a global function with example usage: __segment_topk_rank(scores, segment_ids, num_nodes, max_num_nodes) and returns: perm