code: def _compute_core_distances_(
      X, neighbors, min_samples, working_memory
  ):
      """Compute the k-th nearest neighbor of each sample.
  
      Equivalent to neighbors.kneighbors(X, self.min_samples)[0][:, -1]
      but with more memory efficiency.
  
      Parameters
      ----------
      X : array-like of shape (n_samples, n_features)
          The data.
      neighbors : NearestNeighbors instance
          The fitted nearest neighbors estimator.
      working_memory : int, default=None
          The sought maximum memory for temporary distance matrix chunks.
          When None (default), the value of
          ``sklearn.get_config()['working_memory']`` is used.
  
      Returns
      -------
      core_distances : ndarray of shape (n_samples,)
          Distance at which each sample becomes a core point.
          Points which will never be core have a distance of inf.
      """
      n_samples = X.shape[0]
      core_distances = np.empty(n_samples)
      core_distances.fill(np.nan)
  
      chunk_n_rows = get_chunk_n_rows(
          row_bytes=16 * min_samples,
          max_n_rows=n_samples,
          working_memory=working_memory,
      )
      slices = gen_batches(n_samples, chunk_n_rows)
      for sl in slices:
          core_distances[sl] = neighbors.kneighbors(X[sl], min_samples)[
              0
          ][:, -1]
      return core_distances
  
imports: import warnings
  from numbers import Integral, Real
  import numpy
  from scipy.sparse import SparseEfficiencyWarning, issparse
  from ..base import BaseEstimator, ClusterMixin, _fit_context
  from ..exceptions import DataConversionWarning
  from ..metrics import pairwise_distances
  from ..metrics.pairwise import _VALID_METRICS, PAIRWISE_BOOLEAN_FUNCTIONS
  from ..neighbors import NearestNeighbors
  from ..utils import gen_batches, get_chunk_n_rows
  from ..utils._param_validation import HasMethods, Interval, RealNotInt, StrOptions, validate_params
  from ..utils.validation import check_memory
label_desc: Use image node_id 2 for calling a global function with example usage: _compute_core_distances_(X, neighbors, min_samples, working_memory) and returns: core_distances