code: def new_build_candidates(
      current_graph, max_candidates, rng_state, n_threads
  ):
      """Build a heap of candidate neighbors for nearest neighbor descent. For
      each vertex the candidate neighbors are any current neighbors, and any
      vertices that have the vertex as one of their nearest neighbors.
  
      Parameters
      ----------
      current_graph: heap
          The current state of the graph for nearest neighbor descent.
  
      max_candidates: int
          The maximum number of new candidate neighbors.
  
      rng_state: array of int64, shape (3,)
          The internal state of the rng
  
      Returns
      -------
      candidate_neighbors: A heap with an array of (randomly sorted) candidate
      neighbors for each vertex in the graph.
      """
      current_indices = current_graph[0]
      current_flags = current_graph[2]
  
      n_vertices = current_indices.shape[0]
      n_neighbors = current_indices.shape[1]
  
      new_candidate_indices = np.full(
          (n_vertices, max_candidates), -1, dtype=np.int32
      )
      new_candidate_priority = np.full(
          (n_vertices, max_candidates), np.inf, dtype=np.float32
      )
  
      old_candidate_indices = np.full(
          (n_vertices, max_candidates), -1, dtype=np.int32
      )
      old_candidate_priority = np.full(
          (n_vertices, max_candidates), np.inf, dtype=np.float32
      )
  
      for n in numba.prange(n_threads):
          local_rng_state = rng_state + n
          for i in range(n_vertices):
              for j in range(n_neighbors):
                  idx = current_indices[i, j]
                  isn = current_flags[i, j]
  
                  if idx < 0:
                      continue
  
                  d = tau_rand(local_rng_state)
  
                  if isn:
                      if i % n_threads == n:
                          checked_heap_push(
                              new_candidate_priority[i],
                              new_candidate_indices[i],
                              d,
                              idx,
                          )
                      if idx % n_threads == n:
                          checked_heap_push(
                              new_candidate_priority[idx],
                              new_candidate_indices[idx],
                              d,
                              i,
                          )
                  else:
                      if i % n_threads == n:
                          checked_heap_push(
                              old_candidate_priority[i],
                              old_candidate_indices[i],
                              d,
                              idx,
                          )
                      if idx % n_threads == n:
                          checked_heap_push(
                              old_candidate_priority[idx],
                              old_candidate_indices[idx],
                              d,
                              i,
                          )
  
      indices = current_graph[0]
      flags = current_graph[2]
  
      for i in numba.prange(n_vertices):
          for j in range(n_neighbors):
              idx = indices[i, j]
  
              for k in range(max_candidates):
                  if new_candidate_indices[i, k] == idx:
                      flags[i, j] = 0
                      break
  
      return new_candidate_indices, old_candidate_indices
  
imports: import time
  import numba
  from numba.core import types
  import numba.experimental.structref
  import numpy
label_desc: Use image node_id 12 for calling a global function with example usage: new_build_candidates(current_graph, max_candidates, rng_state, n_threads) and returns: new_candidate_indices,  old_candidate_indices