class_docstr: An abstract class for sampled subgraph. In the context of a
  heterogeneous graph, each field should be of `Dict` type. Otherwise,
  for homogeneous graphs, each field should correspond to its respective
  value type.
class_docstr_tok: ["An","abstract","class","for","sampled","subgraph",".","In","the","context","of","a","heterogeneous","graph",",","each","field","should","be","of","`","Dict","`","type",".","Otherwise",",","for","homogeneous","graphs",",","each","field","should","correspond","to","its","respective","value","type","."]
docstr: Exclude edges from the sampled subgraph.
  
  This function can be used with sampled subgraphs, regardless of whether they
  have compacted row/column nodes or not. If the original subgraph has
  compacted row or column nodes, the corresponding row or column nodes in the
  returned subgraph will also be compacted.
  
  Parameters
  ----------
  self : SampledSubgraph
      The sampled subgraph.
  edges : Union[Dict[str, Tuple[torch.Tensor, torch.Tensor]],
              Tuple[torch.Tensor, torch.Tensor]]
      Edges to exclude. If sampled subgraph is homogeneous, then `edges`
      should be a pair of tensors representing the edges to exclude. If
      sampled subgraph is heterogeneous, then `edges` should be a dictionary
      of edge types and the corresponding edges to exclude.
  assume_num_node_within_int32: bool
      If True, assumes the value of node IDs in the provided `edges` fall
      within the int32 range, which can significantly enhance computation
      speed. Default: True
  
  Returns
  -------
  SampledSubgraph
     An instance of a class that inherits from `SampledSubgraph`.
  
  Examples
  --------
  >>> import dgl.graphbolt as gb
  >>> import torch
  >>> sampled_csc = {"A:relation:B": gb.CSCFormatBase(
  ...     indptr=torch.tensor([0, 1, 2, 3]),
  ...     indices=torch.tensor([0, 1, 2]))}
  >>> original_column_node_ids = {"B": torch.tensor([10, 11, 12])}
  >>> original_row_node_ids = {"A": torch.tensor([13, 14, 15])}
  >>> original_edge_ids = {"A:relation:B": torch.tensor([19, 20, 21])}
  >>> subgraph = gb.SampledSubgraphImpl(
  ...     sampled_csc=sampled_csc,
  ...     original_column_node_ids=original_column_node_ids,
  ...     original_row_node_ids=original_row_node_ids,
  ...     original_edge_ids=original_edge_ids
  ... )
  >>> edges_to_exclude = {"A:relation:B": (torch.tensor([14, 15]),
  ...     torch.tensor([11, 12]))}
  >>> result = subgraph.exclude_edges(edges_to_exclude)
  >>> print(result.sampled_csc)
  {'A:relation:B': CSCFormatBase(indptr=tensor([0, 1, 1, 1]),
              indices=tensor([0]),
  )}
  >>> print(result.original_column_node_ids)
  {'B': tensor([10, 11, 12])}
  >>> print(result.original_row_node_ids)
  {'A': tensor([13, 14, 15])}
  >>> print(result.original_edge_ids)
  {'A:relation:B': tensor([19])}
docstr_tok: ["Exclude","edges","from","the","sampled","subgraph",".","This","function","can","be","used","with","sampled","subgraphs",",","regardless","of","whether","they","have","compacted","row\/column","nodes","or","not",".","If","the","original","subgraph","has","compacted","row","or","column","nodes",",","the","corresponding","row","or","column","nodes","in","the","returned","subgraph","will","also","be","compacted",".","Parameters","--","--","--","--","--","self",":","SampledSubgraph","The","sampled","subgraph",".","edges",":","Union","[","Dict","[","str",",","Tuple","[","torch.Tensor",",","torch.Tensor","]","]",",","Tuple","[","torch.Tensor",",","torch.Tensor","]","]","Edges","to","exclude",".","If","sampled","subgraph","is","homogeneous",",","then","`","edges","`","should","be","a","pair","of","tensors","representing","the","edges","to","exclude",".","If","sampled","subgraph","is","heterogeneous",",","then","`","edges","`","should","be","a","dictionary","of","edge","types","and","the","corresponding","edges","to","exclude",".","assume_num_node_within_int32",":","bool","If","True",",","assumes","the","value","of","node","IDs","in","the","provided","`","edges","`","fall","within","the","int32","range",",","which","can","significantly","enhance","computation","speed",".","Default",":","True","Returns","--","--","--","-","SampledSubgraph","An","instance","of","a","class","that","inherits","from","`","SampledSubgraph","`",".","Examples","--","--","--","--",">",">",">","import","dgl.graphbolt","as","gb",">",">",">","import","torch",">",">",">","sampled_csc","=","{","``","A",":","relation",":","B","''",":","gb.CSCFormatBase","(","...","indptr=torch.tensor","(","[","0",",","1",",","2",",","3","]",")",",","...","indices=torch.tensor","(","[","0",",","1",",","2","]",")",")","}",">",">",">","original_column_node_ids","=","{","``","B","''",":","torch.tensor","(","[","10",",","11",",","12","]",")","}",">",">",">","original_row_node_ids","=","{","``","A","''",":","torch.tensor","(","[","13",",","14",",","15","]",")","}",">",">",">","original_edge_ids","=","{","``","A",":","relation",":","B","''",":","torch.tensor","(","[","19",",","20",",","21","]",")","}",">",">",">","subgraph","=","gb.SampledSubgraphImpl","(","...","sampled_csc=sampled_csc",",","...","original_column_node_ids=original_column_node_ids",",","...","original_row_node_ids=original_row_node_ids",",","...","original_edge_ids=original_edge_ids","...",")",">",">",">","edges_to_exclude","=","{","``","A",":","relation",":","B","''",":","(","torch.tensor","(","[","14",",","15","]",")",",","...","torch.tensor","(","[","11",",","12","]",")",")","}",">",">",">","result","=","subgraph.exclude_edges","(","edges_to_exclude",")",">",">",">","print","(","result.sampled_csc",")","{","'","A",":","relation",":","B","'",":","CSCFormatBase","(","indptr=tensor","(","[","0",",","1",",","1",",","1","]",")",",","indices=tensor","(","[","0","]",")",",",")","}",">",">",">","print","(","result.original_column_node_ids",")","{","'","B","'",":","tensor","(","[","10",",","11",",","12","]",")","}",">",">",">","print","(","result.original_row_node_ids",")","{","'","A","'",":","tensor","(","[","13",",","14",",","15","]",")","}",">",">",">","print","(","result.original_edge_ids",")","{","'","A",":","relation",":","B","'",":","tensor","(","[","19","]",")","}"]
code: def exclude_edges(
      self,
      edges: Union[
          Dict[str, Tuple[torch.Tensor, torch.Tensor]],
          Tuple[torch.Tensor, torch.Tensor],
      ],
      assume_num_node_within_int32: bool = True,
  ):
      r"""Exclude edges from the sampled subgraph.
  
      This function can be used with sampled subgraphs, regardless of whether they
      have compacted row/column nodes or not. If the original subgraph has
      compacted row or column nodes, the corresponding row or column nodes in the
      returned subgraph will also be compacted.
  
      Parameters
      ----------
      self : SampledSubgraph
          The sampled subgraph.
      edges : Union[Dict[str, Tuple[torch.Tensor, torch.Tensor]],
                  Tuple[torch.Tensor, torch.Tensor]]
          Edges to exclude. If sampled subgraph is homogeneous, then `edges`
          should be a pair of tensors representing the edges to exclude. If
          sampled subgraph is heterogeneous, then `edges` should be a dictionary
          of edge types and the corresponding edges to exclude.
      assume_num_node_within_int32: bool
          If True, assumes the value of node IDs in the provided `edges` fall
          within the int32 range, which can significantly enhance computation
          speed. Default: True
  
      Returns
      -------
      SampledSubgraph
         An instance of a class that inherits from `SampledSubgraph`.
  
      Examples
      --------
      >>> import dgl.graphbolt as gb
      >>> import torch
      >>> sampled_csc = {"A:relation:B": gb.CSCFormatBase(
      ...     indptr=torch.tensor([0, 1, 2, 3]),
      ...     indices=torch.tensor([0, 1, 2]))}
      >>> original_column_node_ids = {"B": torch.tensor([10, 11, 12])}
      >>> original_row_node_ids = {"A": torch.tensor([13, 14, 15])}
      >>> original_edge_ids = {"A:relation:B": torch.tensor([19, 20, 21])}
      >>> subgraph = gb.SampledSubgraphImpl(
      ...     sampled_csc=sampled_csc,
      ...     original_column_node_ids=original_column_node_ids,
      ...     original_row_node_ids=original_row_node_ids,
      ...     original_edge_ids=original_edge_ids
      ... )
      >>> edges_to_exclude = {"A:relation:B": (torch.tensor([14, 15]),
      ...     torch.tensor([11, 12]))}
      >>> result = subgraph.exclude_edges(edges_to_exclude)
      >>> print(result.sampled_csc)
      {'A:relation:B': CSCFormatBase(indptr=tensor([0, 1, 1, 1]),
                  indices=tensor([0]),
      )}
      >>> print(result.original_column_node_ids)
      {'B': tensor([10, 11, 12])}
      >>> print(result.original_row_node_ids)
      {'A': tensor([13, 14, 15])}
      >>> print(result.original_edge_ids)
      {'A:relation:B': tensor([19])}
      """
      # TODO: Add support for value > in32, then remove this line.
      assert (
          assume_num_node_within_int32
      ), "Values > int32 are not supported yet."
      assert (
          isinstance(self.sampled_csc, (CSCFormatBase, tuple))
      ) == isinstance(edges, tuple), (
          "The sampled subgraph and the edges to exclude should be both "
          "homogeneous or both heterogeneous."
      )
      # Get type of calling class.
      calling_class = type(self)
  
      # Three steps to exclude edges:
      # 1. Convert the node pairs to the original ids if they are compacted.
      # 2. Exclude the edges and get the index of the edges to keep.
      # 3. Slice the subgraph according to the index.
      if isinstance(self.sampled_csc, CSCFormatBase):
          reverse_edges = _to_reverse_ids(
              self.sampled_csc,
              self.original_row_node_ids,
              self.original_column_node_ids,
          )
          index = _exclude_homo_edges(
              reverse_edges, edges, assume_num_node_within_int32
          )
          return calling_class(*_slice_subgraph(self, index))
      else:
          index = {}
          for etype, pair in self.sampled_csc.items():
              if etype not in edges:
                  # No edges need to be excluded.
                  index[etype] = None
                  continue
              src_type, _, dst_type = etype_str_to_tuple(etype)
              original_row_node_ids = (
                  None
                  if self.original_row_node_ids is None
                  else self.original_row_node_ids.get(src_type)
              )
              original_column_node_ids = (
                  None
                  if self.original_column_node_ids is None
                  else self.original_column_node_ids.get(dst_type)
              )
              reverse_edges = _to_reverse_ids(
                  pair,
                  original_row_node_ids,
                  original_column_node_ids,
              )
              index[etype] = _exclude_homo_edges(
                  reverse_edges,
                  edges[etype],
                  assume_num_node_within_int32,
              )
          return calling_class(*_slice_subgraph(self, index))
  
file_path: dgl/python/dgl/graphbolt/sampled_subgraph.py
imports: from typing import Dict, Tuple, Union
  import torch
  from dgl.utils import recursive_apply
  from .base import apply_to, CSCFormatBase, etype_str_to_tuple, isin
label_desc: Use image node_id 5 for calling the SampledSubgraph obj's underlying member method code with example usage: obj.exclude_edges(edges, assume_num_node_within_int32) and returns: calling_class, calling_class