code: def calculate_gains_sieve_sparse(dtypes, parallel, fastmath, cache):
      @njit(dtypes, parallel=parallel, fastmath=fastmath, cache=cache)
      def calculate_gains_sieve_sparse_(
          X_data,
          X_indices,
          X_indptr,
          k,
          current_values,
          selections,
          gains,
          total_gains,
          max_values,
          n_selected,
          thresh,
          idxs,
      ):
          d = max_values.shape[0]
  
          for j in prange(d):
              for i in range(idxs.shape[0]):
                  if n_selected[j] == k:
                      break
  
                  idx = idxs[i]
                  start = X_indptr[i]
                  end = X_indptr[i + 1]
                  threshold = (max_values[j] / 2.0 - total_gains[j]) / (
                      k - n_selected[j]
                  )
  
                  gain = 0.0
                  for l in range(start, end):
                      m = X_indices[l]
                      gain += (
                          min(current_values[j, m] + X_data[l], thresh)
                          - current_values[j, m]
                      )
  
                  if gain > threshold:
                      for l in range(start, end):
                          m = X_indices[l]
                          current_values[j, m] = min(
                              current_values[j, m] + X_data[l], thresh
                          )
  
                      total_gains[j] += gain
                      selections[j, n_selected[j]] = idx
                      gains[j, n_selected[j]] = gain
                      n_selected[j] += 1
  
      return calculate_gains_sieve_sparse_
  
file_path: apricot/apricot/functions/maxCoverage.py
imports: import numpy
  from .base import BaseSelection
  from ..optimizers import LazyGreedy
  from ..optimizers import ApproximateLazyGreedy
  from ..optimizers import SieveGreedy
  from numba import njit
  from numba import prange
label_desc: Use image node_id 4 for calling a global function with example usage: calculate_gains_sieve_sparse(dtypes, parallel, fastmath, cache) and returns: calculate_gains_sieve_sparse_