class_docstr: Find closest anchors using :mod:`torch_sparse` on a GPU.
class_docstr_tok: ["Find","closest","anchors","using",":","mod",":","`","torch_sparse","`","on","a","GPU","."]
docstr: Create a sparse adjacency matrix (in the form of the edge list) from a given edge index.
  
  :param edge_index: shape: (2, m)
      the edge index
  :param num_entities:
      The number of entities. If not given, inferred from the edge index
  
  :return: shape: (2, 2m + n)
      edge list with inverse edges and self-loops
docstr_tok: ["Create","a","sparse","adjacency","matrix","(","in","the","form","of","the","edge","list",")","from","a","given","edge","index",".",":","param","edge_index",":","shape",":","(","2",",","m",")","the","edge","index",":","param","num_entities",":","The","number","of","entities",".","If","not","given",",","inferred","from","the","edge","index",":","return",":","shape",":","(","2",",","2m","+","n",")","edge","list","with","inverse","edges","and","self-loops"]
code: def create_adjacency(
      edge_index: numpy.ndarray,
      num_entities: Optional[int] = None,
  ) -> torch.tensor:
      """
      Create a sparse adjacency matrix (in the form of the edge list) from a given edge index.
  
      :param edge_index: shape: (2, m)
          the edge index
      :param num_entities:
          The number of entities. If not given, inferred from the edge index
  
      :return: shape: (2, 2m + n)
          edge list with inverse edges and self-loops
      """
      num_entities = ensure_num_entities(
          edge_index, num_entities=num_entities
      )
      edge_index = torch.as_tensor(edge_index, dtype=torch.long)
  
      # symmetric + self-loops
      edge_list = torch.cat(
          [
              edge_index,
              edge_index.flip(0),
              torch.arange(num_entities).unsqueeze(0).repeat(2, 1),
          ],
          dim=-1,
      ).unique(
          dim=1
      )  # unique for deduplicating repeated edges
  
      return edge_list
  
imports: import logging
  from abc import ABC, abstractmethod
  from typing import Iterable, Optional
  import numpy
  import scipy.sparse
  import torch
  from class_resolver import ClassResolver, OptionalKwargs
  from torch_ppr import page_rank
  from torch_ppr.utils import edge_index_to_sparse_matrix, prepare_page_rank_adjacency, prepare_x0
  from tqdm.auto import tqdm
  from .utils import ensure_num_entities
  from ...typing import DeviceHint
  from ...utils import ExtraReprMixin, format_relative_comparison, resolve_device
label_desc: Use image node_id 3 for calling the SparseBFSSearcher obj's underlying member method code with example usage: obj.create_adjacency(edge_index, num_entities) and returns: edge_list