class_docstr: An abstract base class for implementing explainer algorithms.
docstr: Returns hard node and edge masks that only include the nodes and
  edges visited during message passing.
docstr_tok: ["Returns","hard","node","and","edge","masks","that","only","include","the","nodes","and","edges","visited","during","message","passing","."]
code: def _get_hard_masks(
      model: torch.nn.Module,
      node_index: Optional[Union[int, Tensor]],
      edge_index: Tensor,
      num_nodes: int,
  ) -> Tuple[Optional[Tensor], Optional[Tensor]]:
      r"""Returns hard node and edge masks that only include the nodes and
      edges visited during message passing.
      """
      if node_index is None:
          return None, None  # Consider all nodes and edges.
  
      index, _, _, edge_mask = k_hop_subgraph(
          node_index,
          num_hops=ExplainerAlgorithm._num_hops(model),
          edge_index=edge_index,
          num_nodes=num_nodes,
          flow=ExplainerAlgorithm._flow(model),
      )
  
      node_mask = edge_index.new_zeros(num_nodes, dtype=torch.bool)
      node_mask[index] = True
  
      return node_mask, edge_mask
  
imports: from abc import abstractmethod
  from typing import Dict, Optional, Tuple, Union
  import torch
  import torch.nn.functional
  from torch import Tensor
  from torch_geometric.explain import Explanation, HeteroExplanation
  from torch_geometric.explain.config import ExplainerConfig, ModelConfig, ModelReturnType
  from torch_geometric.nn import MessagePassing
  from torch_geometric.typing import EdgeType, NodeType
  from torch_geometric.utils import k_hop_subgraph
label_desc: Use image node_id 7 for calling the ExplainerAlgorithm obj's underlying member method code with example usage: obj._get_hard_masks(model, node_index, edge_index, num_nodes) and returns: node_mask,  edge_mask, None,  None