docstr: insg : the subgraph yielded by compute_prob()
  neighbor_nodes_idx : the sampled nodes from the subgraph @insg, yielded by select_neighbors()
  seed_nodes_local_idx : the indices of seed nodes in the selected neighbor nodes, also yielded
                         by select_neighbors()
  P_sg : unnormalized probability of each node being sampled, yielded by compute_prob()
  W_sg : edge weights of @insg
  return : the block.
docstr_tok: ["insg",":","the","subgraph","yielded","by","compute_prob","(",")","neighbor_nodes_idx",":","the","sampled","nodes","from","the","subgraph","@","insg",",","yielded","by","select_neighbors","(",")","seed_nodes_local_idx",":","the","indices","of","seed","nodes","in","the","selected","neighbor","nodes",",","also","yielded","by","select_neighbors","(",")","P_sg",":","unnormalized","probability","of","each","node","being","sampled",",","yielded","by","compute_prob","(",")","W_sg",":","edge","weights","of","@","insg","return",":","the","block","."]
code: def generate_block(
      self, insg, neighbor_nodes_idx, seed_nodes, P_sg, W_sg
  ):
      """
      insg : the subgraph yielded by compute_prob()
      neighbor_nodes_idx : the sampled nodes from the subgraph @insg, yielded by select_neighbors()
      seed_nodes_local_idx : the indices of seed nodes in the selected neighbor nodes, also yielded
                             by select_neighbors()
      P_sg : unnormalized probability of each node being sampled, yielded by compute_prob()
      W_sg : edge weights of @insg
      return : the block.
      """
      seed_nodes_idx = find_indices_in(seed_nodes, insg.ndata[dgl.NID])
      u_nodes = union(neighbor_nodes_idx, seed_nodes_idx)
      sg = insg.subgraph(u_nodes.type(insg.idtype))
      u, v = sg.edges()
      lu = sg.ndata[dgl.NID][u.long()]
      s = find_indices_in(lu, neighbor_nodes_idx)
      eg = dgl.edge_subgraph(
          sg, lu == neighbor_nodes_idx[s], relabel_nodes=False
      )
      eg.ndata[dgl.NID] = sg.ndata[dgl.NID][: eg.num_nodes()]
      eg.edata[dgl.EID] = sg.edata[dgl.EID][eg.edata[dgl.EID].long()]
      sg = eg
      nids = insg.ndata[dgl.NID][sg.ndata[dgl.NID].long()]
      P = P_sg[u_nodes.long()]
      W = W_sg[sg.edata[dgl.EID].long()]
      W_tilde = dgl.ops.e_div_u(sg, W, P)
      W_tilde_sum = dgl.ops.copy_e_sum(sg, W_tilde)
      d = sg.in_degrees()
      W_tilde = dgl.ops.e_mul_v(sg, W_tilde, d / W_tilde_sum)
  
      block = dgl.to_block(sg, seed_nodes_idx.type(sg.idtype))
      block.edata[self.output_weight] = W_tilde
      # correct node ID mapping
      block.srcdata[dgl.NID] = nids[block.srcdata[dgl.NID].long()]
      block.dstdata[dgl.NID] = nids[block.dstdata[dgl.NID].long()]
  
      sg_eids = insg.edata[dgl.EID][sg.edata[dgl.EID].long()]
      block.edata[dgl.EID] = sg_eids[block.edata[dgl.EID].long()]
      return block
  
file_path: dgl/examples/pytorch/labor/ladies_sampler.py
imports: import dgl
  import dgl.function
  import torch
label_desc: Use image node_id 4 for calling the LadiesSampler obj's underlying member method code with example usage: obj.generate_block(insg, neighbor_nodes_idx, seed_nodes, P_sg, W_sg) and returns: block