class_docstr: A composite data class for data structure in the graphbolt.
  
  It is designed to facilitate the exchange of data among different components
  involved in processing data. The purpose of this class is to unify the
  representation of input and output data across different stages, ensuring
  consistency and ease of use throughout the loading process.
class_docstr_tok: ["A","composite","data","class","for","data","structure","in","the","graphbolt",".","It","is","designed","to","facilitate","the","exchange","of","data","among","different","components","involved","in","processing","data",".","The","purpose","of","this","class","is","to","unify","the","representation","of","input","and","output","data","across","different","stages",",","ensuring","consistency","and","ease","of","use","throughout","the","loading","process","."]
docstr: Extracts DGL blocks from `MiniBatch` to construct a graphical
  structure and ID mappings.
docstr_tok: ["Extracts","DGL","blocks","from","`","MiniBatch","`","to","construct","a","graphical","structure","and","ID","mappings","."]
code: def blocks(self):
      """Extracts DGL blocks from `MiniBatch` to construct a graphical
      structure and ID mappings.
      """
      if not self.sampled_subgraphs:
          return None
  
      is_heterogeneous = isinstance(
          self.sampled_subgraphs[0].sampled_csc, Dict
      )
  
      blocks = []
      for subgraph in self.sampled_subgraphs:
          original_row_node_ids = subgraph.original_row_node_ids
          assert (
              original_row_node_ids is not None
          ), "Missing `original_row_node_ids` in sampled subgraph."
          original_column_node_ids = subgraph.original_column_node_ids
          assert (
              original_column_node_ids is not None
          ), "Missing `original_column_node_ids` in sampled subgraph."
          if is_heterogeneous:
              sampled_csc = {
                  etype_str_to_tuple(etype): (
                      "csc",
                      (
                          v.indptr,
                          v.indices,
                          torch.arange(
                              0,
                              len(v.indices),
                              device=v.indptr.device,
                              dtype=v.indptr.dtype,
                          ),
                      ),
                  )
                  for etype, v in subgraph.sampled_csc.items()
              }
              num_src_nodes = {
                  ntype: nodes.size(0)
                  for ntype, nodes in original_row_node_ids.items()
              }
              num_dst_nodes = {
                  ntype: nodes.size(0)
                  for ntype, nodes in original_column_node_ids.items()
              }
          else:
              sampled_csc = subgraph.sampled_csc
              sampled_csc = (
                  "csc",
                  (
                      sampled_csc.indptr,
                      sampled_csc.indices,
                      torch.arange(
                          0,
                          len(sampled_csc.indices),
                          device=sampled_csc.indptr.device,
                          dtype=sampled_csc.indptr.dtype,
                      ),
                  ),
              )
              num_src_nodes = original_row_node_ids.size(0)
              num_dst_nodes = original_column_node_ids.size(0)
          blocks.append(
              dgl.create_block(
                  sampled_csc,
                  num_src_nodes=num_src_nodes,
                  num_dst_nodes=num_dst_nodes,
              )
          )
  
      if is_heterogeneous:
          # Assign reverse node ids to the outermost layer's source nodes.
          for node_type, reverse_ids in self.sampled_subgraphs[
              0
          ].original_row_node_ids.items():
              blocks[0].srcnodes[node_type].data[dgl.NID] = reverse_ids
          # Assign reverse edges ids.
          for block, subgraph in zip(blocks, self.sampled_subgraphs):
              if subgraph.original_edge_ids:
                  for (
                      edge_type,
                      reverse_ids,
                  ) in subgraph.original_edge_ids.items():
                      block.edges[etype_str_to_tuple(edge_type)].data[
                          dgl.EID
                      ] = reverse_ids
      else:
          blocks[0].srcdata[dgl.NID] = self.sampled_subgraphs[
              0
          ].original_row_node_ids
          # Assign reverse edges ids.
          for block, subgraph in zip(blocks, self.sampled_subgraphs):
              if subgraph.original_edge_ids is not None:
                  block.edata[dgl.EID] = subgraph.original_edge_ids
      return blocks
  
imports: from dataclasses import dataclass
  from typing import Dict, List, Tuple, Union
  import torch
  import dgl
  from dgl.utils import recursive_apply
  from .base import etype_str_to_tuple
  from .internal import get_attributes
  from .sampled_subgraph import SampledSubgraph
label_desc: Use image node_id 7 for calling the MiniBatch obj's underlying member method code with example usage: obj.blocks() and returns: blocks, None