code: def _init_centroids(
      X,
      n_clusters=8,
      init="k-means++",
      random_state=None,
      x_squared_norms=None,
      init_size=None,
      oversampling_factor=2,
      init_iter=5,
  ):
      """Compute the initial centroids
  
      Parameters
      ----------
  
      X : Tensor of shape (n_samples, n_features)
          The input samples.
  
      n_clusters : int, default=8
          number of centroids.
  
      init : {'k-means++', 'k-means||', 'random', tensor, callable}, default="k-means++"
          Method for initialization.
  
      random_state : int, RandomState instance, default=None
          Determines random number generation for centroid initialization. Use
          an int to make the randomness deterministic.
          See :term:`Glossary <random_state>`.
  
      x_squared_norms : tensor of shape (n_samples,), default=None
          Squared euclidean norm of each data point. Pass it if you have it at
          hands already to avoid it being recomputed here. Default: None
  
      init_size : int, default=None
          Number of samples to randomly sample for speeding up the
          initialization (sometimes at the expense of accuracy): the
          only algorithm is initialized by running a batch KMeans on a
          random subset of the data. This needs to be larger than k.
  
      Returns
      -------
      centers : tensor of shape(k, n_features)
      """
      random_state = check_random_state(random_state).to_numpy()
      n_samples = X.shape[0]
  
      if x_squared_norms is None:
          x_squared_norms = row_norms(X, squared=True)
  
      if (
          init_size is not None and init_size < n_samples
      ):  # pragma: no cover
          if init_size < n_clusters:
              warnings.warn(
                  f"init_size={init_size} should be larger than k={n_clusters}. "
                  "Setting it to 3*k",
                  RuntimeWarning,
                  stacklevel=2,
              )
              init_size = 3 * n_clusters
          init_indices = random_state.randint(0, n_samples, init_size)
          X = X[init_indices]
          x_squared_norms = x_squared_norms[init_indices]
          n_samples = X.shape[0]
      elif n_samples < n_clusters:
          raise ValueError(
              f"n_samples={n_samples} should be larger than n_clusters={n_clusters}"
          )
  
      if isinstance(init, str) and init == "k-means++":
          centers = _k_init(
              X,
              n_clusters,
              random_state=random_state,
              x_squared_norms=x_squared_norms,
          )
      elif isinstance(init, str) and init == "k-means||":
          centers = _scalable_k_init(
              X,
              n_clusters,
              random_state=random_state,
              x_squared_norms=x_squared_norms,
              oversampling_factor=oversampling_factor,
              init_iter=init_iter,
          )
      elif isinstance(init, str) and init == "random":
          seeds = random_state.choice(
              n_samples, size=n_clusters, replace=False
          )
          centers = X[seeds].rechunk((n_clusters, X.shape[1]))
      elif hasattr(init, "__array__"):
          # ensure that the centers have the same dtype as X
          # this is a requirement of fused types of cython
          centers = mt.array(init, dtype=X.dtype)
      elif callable(init):
          centers = init(X, n_clusters, random_state=random_state)
          centers = mt.asarray(centers, dtype=X.dtype)
      else:  # pragma: no cover
          raise ValueError(
              "the init parameter for the k-means should "
              "be 'k-means++' or 'random' or a tensor, "
              f"'{init}' (type '{type(init)}') was passed."
          )
  
      if centers.issparse():
          centers = centers.todense()
  
      _validate_center_shape(X, n_clusters, centers)
      return centers
  
imports: import warnings
  import numpy
  from sklearn.base import ClusterMixin, TransformerMixin
  from sklearn.exceptions import ConvergenceWarning
  from ...None import tensor
  from ...tensor.utils import check_random_state
  from ..base import BaseEstimator
  from ..metrics.pairwise import euclidean_distances
  from ..utils.extmath import row_norms
  from ..utils.validation import _check_sample_weight, check_array, _num_samples, check_is_fitted
  from ._k_means_common import _inertia
  from ._k_means_elkan_iter import init_bounds, elkan_iter
  from ._k_means_init import _k_init, _scalable_k_init
  from ._k_means_lloyd_iter import lloyd_iter
label_desc: Use image node_id 8 for calling a global function with example usage: _init_centroids(X, n_clusters, init, random_state, x_squared_norms, init_size, oversampling_factor, init_iter) and returns: centers