code: def trim_sparse_tensor(
      src: SparseTensor, size: Tuple[int, int], num_seed_nodes: int
  ) -> SparseTensor:
      r"""Trims a :class:`SparseTensor` along both dimensions to only contain
      the upper :obj:`num_nodes` in both dimensions.
  
      It is assumed that :class:`SparseTensor` is obtained from BFS traversing,
      starting from the nodes that have been initially selected.
  
      Args:
          src (SparseTensor): The sparse tensor.
          size (Tuple[int, int]): The number of source and destination nodes to
              keep.
          num_seed_nodes (int): The number of seed nodes to compute
              representations.
      """
      rowptr, col, value = src.csr()
  
      rowptr = torch.narrow(rowptr, 0, 0, size[0] + 1).clone()
      rowptr[num_seed_nodes + 1 :] = rowptr[num_seed_nodes]
  
      col = torch.narrow(col, 0, 0, rowptr[-1])
  
      if value is not None:
          value = torch.narrow(value, 0, 0, rowptr[-1])
  
      csr2csc = src.storage._csr2csc
      if csr2csc is not None:
          csr2csc = csr2csc[csr2csc < len(col)]
  
      storage = SparseStorage(
          row=None,
          rowptr=rowptr,
          col=col,
          value=value,
          sparse_sizes=size,
          rowcount=None,
          colptr=None,
          colcount=None,
          csr2csc=csr2csc,
          csc2csr=None,
          is_sorted=True,
          trust_data=True,
      )
      return src.from_storage(storage)
  
file_path: pytorch_geometric/torch_geometric/utils/_trim_to_layer.py
imports: import copy
  from typing import Any, Dict, List, Optional, Tuple, Union, overload
  import torch
  from torch import Tensor
  from torch_geometric.typing import Adj, EdgeType, MaybeHeteroAdjTensor, MaybeHeteroEdgeTensor, MaybeHeteroNodeTensor, NodeType, SparseStorage, SparseTensor
label_desc: Use image node_id 7 for calling a global function with example usage: trim_sparse_tensor(src, size, num_seed_nodes) and returns: src