code: def _infer_dimension(spectrum, n_samples):
      """Infers the dimension of a dataset with a given spectrum.
  
      The returned value will be in [1, n_features - 1].
      """
      xp = get_array_module(spectrum, nosparse=True)
  
      ll = xp.empty_like(spectrum)
      ll[0] = -np.inf  # we don't want to return n_components = 0
      for rank in range(1, spectrum.shape[0]):
          ll[rank] = _assess_dimension(spectrum, rank, n_samples)
      return ll.argmax()
  
imports: from math import log, sqrt
  import numbers
  import numpy
  from scipy.special import gammaln
  from sklearn.utils.validation import check_is_fitted
  from sklearn.utils.extmath import fast_logdet
  from ...None import tensor
  from ...None import remote
  from ...tensor.array_utils import get_array_module
  from ...tensor.core import TENSOR_TYPE
  from ...tensor.utils import check_random_state
  from ...tensor.linalg import randomized_svd
  from ...tensor.linalg.randomized_svd import svd_flip
  from ...lib.sparse import issparse
  from ...core import ExecutableTuple
  from ..utils import check_array
  from ._base import _BasePCA
label_desc: Use image node_id 2 for calling a global function with example usage: _infer_dimension(spectrum, n_samples) and returns: ll