code: def generate_graph_updates(
      new_candidate_block,
      old_candidate_block,
      dist_thresholds,
      inds,
      indptr,
      data,
      dist,
  ):
      block_size = new_candidate_block.shape[0]
      updates = [[(-1, -1, np.inf)] for i in range(block_size)]
      max_candidates = new_candidate_block.shape[1]
  
      for i in numba.prange(block_size):
          for j in range(max_candidates):
              p = int(new_candidate_block[i, j])
              if p < 0:
                  continue
              for k in range(j, max_candidates):
                  q = int(new_candidate_block[i, k])
                  if q < 0:
                      continue
  
                  from_inds = inds[indptr[p] : indptr[p + 1]]
                  from_data = data[indptr[p] : indptr[p + 1]]
  
                  to_inds = inds[indptr[q] : indptr[q + 1]]
                  to_data = data[indptr[q] : indptr[q + 1]]
                  d = dist(from_inds, from_data, to_inds, to_data)
  
                  if d <= dist_thresholds[p] or d <= dist_thresholds[q]:
                      updates[i].append((p, q, d))
  
              for k in range(max_candidates):
                  q = int(old_candidate_block[i, k])
                  if q < 0:
                      continue
  
                  from_inds = inds[indptr[p] : indptr[p + 1]]
                  from_data = data[indptr[p] : indptr[p + 1]]
  
                  to_inds = inds[indptr[q] : indptr[q + 1]]
                  to_data = data[indptr[q] : indptr[q + 1]]
                  d = dist(from_inds, from_data, to_inds, to_data)
  
                  if d <= dist_thresholds[p] or d <= dist_thresholds[q]:
                      updates[i].append((p, q, d))
  
      return updates
  
file_path: pynndescent/pynndescent/sparse_nndescent.py
imports: from __future__ import print_function
  import locale
  import numpy
  import numba
  from pynndescent.utils import tau_rand_int, make_heap, new_build_candidates, deheap_sort, checked_flagged_heap_push, apply_graph_updates_high_memory, apply_graph_updates_low_memory
  from pynndescent.sparse import sparse_euclidean
label_desc: Use image node_id 4 for calling a global function with example usage: generate_graph_updates(new_candidate_block, old_candidate_block, dist_thresholds, inds, indptr, data, dist) and returns: updates