code: def calculate_gains_sparse(func, dtypes, parallel, fastmath, cache):
      @njit(dtypes, parallel=parallel, fastmath=fastmath, cache=cache)
      def calculate_gains_sparse_(
          X_data,
          X_indices,
          X_indptr,
          gains,
          current_values,
          current_concave_values,
          idxs,
      ):
          for i in prange(idxs.shape[0]):
              idx = idxs[i]
              start = X_indptr[idx]
              end = X_indptr[idx + 1]
  
              for j in range(start, end):
                  k = X_indices[j]
                  gains[i] += (
                      func(X_data[j] + current_values[k])
                      - current_concave_values[k]
                  )
  
      return calculate_gains_sparse_
  
imports: import math
  import numpy
  from .base import BaseSelection
  from ..optimizers import LazyGreedy
  from ..optimizers import ApproximateLazyGreedy
  from tqdm import tqdm
  from numba import njit
  from numba import prange
  import torch
label_desc: Use image node_id 3 for calling a global function with example usage: calculate_gains_sparse(func, dtypes, parallel, fastmath, cache) and returns: calculate_gains_sparse_