code: def _fast_svd(X, n_components, random_state=None):
      """Automatically switch between randomized and lapack SVD (heuristic \
      of scikit-learn).
  
      Parameters
      ----------
      X : array, shape (n_samples, n_features)
          The data to decompose
  
      n_components : integer
          The order of the dimensionality of the truncated SVD
  
      random_state : int or RandomState, optional
          Pseudo number generator state used for random sampling.
  
      Returns
      -------
      U : array, shape (n_samples, n_components)
          The first matrix of the truncated svd
  
      S : array, shape (n_components)
          The second matrix of the truncated svd
  
      V : array, shape (n_components, n_features)
          The last matrix of the truncated svd
  
      """
      random_state = check_random_state(random_state)
      # Small problem, just call full PCA
      if max(X.shape) <= 500:
          svd_solver = "full"
      elif n_components >= 1 and n_components < 0.8 * min(X.shape):
          svd_solver = "randomized"
      # This is also the case of n_components in (0,1)
      else:
          svd_solver = "full"
  
      # Call different fits for either full or truncated SVD
      if svd_solver == "full":
          U, S, V = linalg.svd(X, full_matrices=False)
          # flip eigenvectors' sign to enforce deterministic output
          U, V = svd_flip(U, V)
          # The "copy" are there to free the reference on the non reduced
          # data, and hence clear memory early
          U = U[:, :n_components].copy()
          S = S[:n_components]
          V = V[:n_components].copy()
      else:
          n_iter = "auto"
  
          U, S, V = randomized_svd(
              X,
              n_components=n_components,
              n_iter=n_iter,
              flip_sign=True,
              random_state=random_state,
          )
      return U, S, V
  
imports: import glob
  import itertools
  from math import ceil
  import numpy
  from joblib import Memory, Parallel, delayed
  from scipy import linalg
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.linear_model import LinearRegression
  from sklearn.utils import check_random_state
  from sklearn.utils.extmath import randomized_svd, svd_flip
  import nilearn
  from nilearn._utils.masker_validation import check_embedded_masker
  from nilearn.maskers import NiftiMapsMasker
  from .._utils import fill_doc
  from .._utils.cache_mixin import CacheMixin, cache
  from .._utils.niimg import safe_get_data
  from .._utils.niimg_conversions import resolve_globbing
  from ..signal import row_sum_of_squares
label_desc: Use image node_id 1 for calling a global function with example usage: _fast_svd(X, n_components, random_state) and returns: U,  S,  V