code: def compression_matrix(
      data,
      q,
      iterator="power",
      n_power_iter=0,
      n_oversamples=10,
      seed=None,
      compute=False,
  ):
      """Randomly sample matrix to find most active subspace
  
      This compression matrix returned by this algorithm can be used to
      compute both the QR decomposition and the Singular Value
      Decomposition.
  
      Parameters
      ----------
      data: Array
      q: int
          Size of the desired subspace (the actual size will be bigger,
          because of oversampling, see ``da.linalg.compression_level``)
      iterator: {'power', 'QR'}, default='power'
          Define the technique used for iterations to cope with flat
          singular spectra or when the input matrix is very large.
      n_power_iter: int
          Number of power iterations, useful when the singular values
          decay slowly. Error decreases exponentially as `n_power_iter`
          increases. In practice, set `n_power_iter` <= 4.
      n_oversamples: int, default=10
          Number of oversamples used for generating the sampling matrix.
          This value increases the size of the subspace computed, which is more
          accurate at the cost of efficiency.  Results are rarely sensitive to this choice
          though and in practice a value of 10 is very commonly high enough.
      compute : bool
          Whether or not to compute data at each use.
          Recomputing the input while performing several passes reduces memory
          pressure, but means that we have to compute the input multiple times.
          This is a good choice if the data is larger than memory and cheap to
          recreate.
  
      References
      ----------
      N. Halko, P. G. Martinsson, and J. A. Tropp.
      Finding structure with randomness: Probabilistic algorithms for
      constructing approximate matrix decompositions.
      SIAM Rev., Survey and Review section, Vol. 53, num. 2,
      pp. 217-288, June 2011
      https://arxiv.org/abs/0909.4061
      """
      if iterator not in ["power", "QR"]:
          raise ValueError(
              f"Iterator '{iterator}' not valid, must one one of ['power', 'QR']"
          )
      m, n = data.shape
      comp_level = compression_level(
          min(m, n), q, n_oversamples=n_oversamples
      )
      if isinstance(seed, RandomState):
          state = seed
      else:
          state = default_rng(seed)
      datatype = np.float64
      if (data.dtype).type in {np.float32, np.complex64}:
          datatype = np.float32
      omega = state.standard_normal(
          size=(n, comp_level), chunks=(data.chunks[1], (comp_level,))
      ).astype(datatype, copy=False)
      mat_h = data.dot(omega)
      if iterator == "power":
          for _ in range(n_power_iter):
              if compute:
                  mat_h = mat_h.persist()
                  wait(mat_h)
              tmp = data.T.dot(mat_h)
              if compute:
                  tmp = tmp.persist()
                  wait(tmp)
              mat_h = data.dot(tmp)
          q, _ = tsqr(mat_h)
      else:
          q, _ = tsqr(mat_h)
          for _ in range(n_power_iter):
              if compute:
                  q = q.persist()
                  wait(q)
              q, _ = tsqr(data.T.dot(q))
              if compute:
                  q = q.persist()
                  wait(q)
              q, _ = tsqr(data.dot(q))
      return q.T
  
imports: from __future__ import annotations
  import operator
  import warnings
  from functools import partial
  from numbers import Number
  import numpy
  import tlz
  from dask.array.core import Array, concatenate, dotmany, from_delayed
  from dask.array.creation import eye
  from dask.array.random import RandomState, default_rng
  from dask.array.utils import array_safe, meta_from_array, solve_triangular_safe, svd_flip
  from dask.base import tokenize, wait
  from dask.blockwise import blockwise
  from dask.delayed import delayed
  from dask.highlevelgraph import HighLevelGraph
  from dask.utils import apply, derived_from
label_desc: Use image node_id 8 for calling a global function with example usage: compression_matrix(data, q, iterator, n_power_iter, n_oversamples, seed, compute) and returns: q