code: def randomized_range_finder(
      A,
      *,
      size,
      n_iter,
      power_iteration_normalizer="auto",
      random_state=None,
  ):
      """Compute an orthonormal matrix whose range approximates the range of A.
  
      Parameters
      ----------
      A : 2D array
          The input data matrix.
  
      size : int
          Size of the return array.
  
      n_iter : int
          Number of power iterations used to stabilize the result.
  
      power_iteration_normalizer : {'auto', 'QR', 'LU', 'none'}, default='auto'
          Whether the power iterations are normalized with step-by-step
          QR factorization (the slowest but most accurate), 'none'
          (the fastest but numerically unstable when `n_iter` is large, e.g.
          typically 5 or larger), or 'LU' factorization (numerically stable
          but can lose slightly in accuracy). The 'auto' mode applies no
          normalization if `n_iter` <= 2 and switches to LU otherwise.
  
          .. versionadded:: 0.18
  
      random_state : int, RandomState instance or None, default=None
          The seed of the pseudo random number generator to use when shuffling
          the data, i.e. getting the random vectors to initialize the algorithm.
          Pass an int for reproducible results across multiple function calls.
          See :term:`Glossary <random_state>`.
  
      Returns
      -------
      Q : ndarray
          A (size x size) projection matrix, the range of which
          approximates well the range of the input matrix A.
  
      Notes
      -----
  
      Follows Algorithm 4.3 of
      :arxiv:`"Finding structure with randomness:
      Stochastic algorithms for constructing approximate matrix decompositions"
      <0909.4061>`
      Halko, et al. (2009)
  
      An implementation of a randomized algorithm for principal component
      analysis
      A. Szlam et al. 2014
      """
      xp, is_array_api_compliant = get_namespace(A)
      random_state = check_random_state(random_state)
  
      # Generating normal random vectors with shape: (A.shape[1], size)
      # XXX: generate random number directly from xp if it's possible
      # one day.
      Q = xp.asarray(random_state.normal(size=(A.shape[1], size)))
      if hasattr(A, "dtype") and xp.isdtype(
          A.dtype, kind="real floating"
      ):
          # Use float32 computation and components if A has a float32 dtype.
          Q = xp.astype(Q, A.dtype, copy=False)
  
      # Move Q to device if needed only after converting to float32 if needed to
      # avoid allocating unnecessary memory on the device.
  
      # Note: we cannot combine the astype and to_device operations in one go
      # using xp.asarray(..., dtype=dtype, device=device) because downcasting
      # from float64 to float32 in asarray might not always be accepted as only
      # casts following type promotion rules are guarateed to work.
      # https://github.com/data-apis/array-api/issues/647
      if is_array_api_compliant:
          Q = xp.asarray(Q, device=device(A))
  
      # Deal with "auto" mode
      if power_iteration_normalizer == "auto":
          if n_iter <= 2:
              power_iteration_normalizer = "none"
          elif is_array_api_compliant:
              # XXX: https://github.com/data-apis/array-api/issues/627
              warnings.warn(
                  "Array API does not support LU factorization, falling back to QR"
                  " instead. Set `power_iteration_normalizer='QR'` explicitly to silence"
                  " this warning."
              )
              power_iteration_normalizer = "QR"
          else:
              power_iteration_normalizer = "LU"
      elif (
          power_iteration_normalizer == "LU" and is_array_api_compliant
      ):
          raise ValueError(
              "Array API does not support LU factorization. Set "
              "`power_iteration_normalizer='QR'` instead."
          )
  
      if is_array_api_compliant:
          qr_normalizer = partial(xp.linalg.qr, mode="reduced")
      else:
          # Use scipy.linalg instead of numpy.linalg when not explicitly
          # using the Array API.
          qr_normalizer = partial(linalg.qr, mode="economic")
  
      if power_iteration_normalizer == "QR":
          normalizer = qr_normalizer
      elif power_iteration_normalizer == "LU":
          normalizer = partial(linalg.lu, permute_l=True)
      else:
          normalizer = lambda x: (x, None)
  
      # Perform power iterations with Q to further 'imprint' the top
      # singular vectors of A in Q
      for _ in range(n_iter):
          Q, _ = normalizer(A @ Q)
          Q, _ = normalizer(A.T @ Q)
  
      # Sample the range of A using by linear projection of Q
      # Extract an orthonormal basis
      Q, _ = qr_normalizer(A @ Q)
  
      return Q
  
imports: import warnings
  from functools import partial
  from numbers import Integral
  import numpy
  from scipy import linalg, sparse
  from ..utils import deprecated
  from ..utils._param_validation import Interval, StrOptions, validate_params
  from .None import check_random_state
  from ._array_api import _is_numpy_namespace, device, get_namespace
  from .sparsefuncs_fast import csr_row_norms
  from .validation import check_array
label_desc: Use image node_id 6 for calling a global function with example usage: randomized_range_finder(A) and returns: Q