code: def calculate_gains_sieve(dtypes, parallel, fastmath, cache):
      @njit(dtypes, parallel=parallel, fastmath=fastmath, cache=cache)
      def calculate_gains_sieve_(
          X,
          k,
          current_values,
          selections,
          gains,
          total_gains,
          max_values,
          n_selected,
          row_sums,
          idxs,
      ):
          n, d = X.shape
          t = max_values.shape[0]
  
          for j in prange(t):
              for i in range(n):
                  if n_selected[j] == k:
                      break
  
                  idx = idxs[i]
                  threshold = (max_values[j] / 2.0 - total_gains[j]) / (
                      k - n_selected[j]
                  )
                  gain = row_sums[i] - current_values[j, i]
  
                  if gain > threshold:
                      total_gains[j] += gain
  
                      selections[j, n_selected[j]] = idx
                      gains[j, n_selected[j]] = gain
                      n_selected[j] += 1
  
      return calculate_gains_sieve_
  
file_path: apricot/apricot/functions/graphCut.py
imports: import numpy
  from .base import BaseGraphSelection
  from ..utils import _calculate_pairwise_distances
  from tqdm import tqdm
  from numba import njit
  from numba import prange
  from scipy.sparse import csr_matrix
label_desc: Use image node_id 1 for calling a global function with example usage: calculate_gains_sieve(dtypes, parallel, fastmath, cache) and returns: calculate_gains_sieve_