code: def _predict(self, X, sample_weight=None):
      """Predict the closest cluster each sample in X belongs to.
  
      In the vector quantization literature, `cluster_centers_` is called
      the code book and each value returned by `predict` is the index of
      the closest code in the code book.
  
      Parameters
      ----------
      X : {array-like, sparse matrix}, shape = [n_samples, n_features]
         New data to predict.
  
      sample_weight : array-like, shape (n_samples,), optional
          The weights for each observation in X. If None, all observations
          are assigned equal weight (default: None)
  
      Returns
      -------
      labels : array, shape [n_samples,]
          Index of the cluster each sample belongs to.
      """
      check_is_fitted(self)
  
      X = _daal4py_check_test_data(self, X)
  
      _patching_status = PatchingConditionsChain(
          "sklearn.cluster.KMeans.predict"
      )
      _patching_status.and_conditions(
          [
              (
                  sample_weight is None,
                  "Sample weights are not supported.",
              ),
              (
                  hasattr(X, "__array__"),
                  "X does not have '__array__' attribute.",
              ),
          ]
      )
  
      # CSR array is introduced in scipy 1.11, this requires an initial attribute check
      if hasattr(sp, "csr_array"):
          _dal_ready = _patching_status.or_conditions(
              [
                  (
                      sp.isspmatrix_csr(X)
                      or isinstance(X, sp.csr_array),
                      "X is not csr sparse.",
                  )
              ]
          )
      else:
          _dal_ready = _patching_status.or_conditions(
              [(sp.isspmatrix_csr(X), "X is not csr sparse.")]
          )
  
      _patching_status.write_log()
      if _dal_ready:
          return _daal4py_k_means_predict(
              X, self.n_clusters, self.cluster_centers_
          )[0]
      if sklearn_check_version("1.2"):
          if sklearn_check_version("1.3") and sample_weight is not None:
              warnings.warn(
                  "'sample_weight' was deprecated in version 1.3 and "
                  "will be removed in 1.5.",
                  FutureWarning,
              )
          return _labels_inertia(
              X, sample_weight, self.cluster_centers_
          )[0]
      else:
          x_squared_norms = row_norms(X, squared=True)
          return _labels_inertia(
              X, sample_weight, x_squared_norms, self.cluster_centers_
          )[0]
  
imports: import numbers
  import warnings
  import numpy
  from scipy import sparse
  from sklearn.cluster import KMeans
  from sklearn.cluster._kmeans import _labels_inertia
  from sklearn.exceptions import ConvergenceWarning
  from sklearn.utils import check_array, check_random_state
  from sklearn.utils._openmp_helpers import _openmp_effective_n_threads
  from sklearn.utils.extmath import row_norms
  from sklearn.utils.sparsefuncs import mean_variance_axis
  from sklearn.utils.validation import _deprecate_positional_args, _num_samples, check_is_fitted
  import daal4py
  from .._device_offload import support_usm_ndarray
  from .._utils import PatchingConditionsChain, control_n_jobs, getFPType, run_with_n_jobs, sklearn_check_version
label_desc: Use image node_id 9 for calling a global function with example usage: _predict(X, sample_weight) and returns: _daal4py_k_means_predict, _labels_inertia, _labels_inertia