code: def lstsq(a, b):
      """
      Return the least-squares solution to a linear matrix equation using
      QR decomposition.
  
      Solves the equation `a x = b` by computing a vector `x` that
      minimizes the Euclidean 2-norm `|| b - a x ||^2`.  The equation may
      be under-, well-, or over- determined (i.e., the number of
      linearly independent rows of `a` can be less than, equal to, or
      greater than its number of linearly independent columns).  If `a`
      is square and of full rank, then `x` (but for round-off error) is
      the "exact" solution of the equation.
  
      Parameters
      ----------
      a : (M, N) array_like
          "Coefficient" matrix.
      b : {(M,), (M, K)} array_like
          Ordinate or "dependent variable" values. If `b` is two-dimensional,
          the least-squares solution is calculated for each of the `K` columns
          of `b`.
  
      Returns
      -------
      x : {(N,), (N, K)} Array
          Least-squares solution. If `b` is two-dimensional,
          the solutions are in the `K` columns of `x`.
      residuals : {(1,), (K,)} Array
          Sums of residuals; squared Euclidean 2-norm for each column in
          ``b - a*x``.
          If `b` is 1-dimensional, this is a (1,) shape array.
          Otherwise the shape is (K,).
      rank : Array
          Rank of matrix `a`.
      s : (min(M, N),) Array
          Singular values of `a`.
      """
      q, r = qr(a)
      x = solve_triangular(r, q.T.conj().dot(b))
      residuals = b - a.dot(x)
      residuals = abs(residuals**2).sum(axis=0, keepdims=b.ndim == 1)
  
      token = tokenize(a, b)
  
      # r must be a triangular with single block
  
      # rank
      rname = "lstsq-rank-" + token
      rdsk = {(rname,): (np.linalg.matrix_rank, (r.name, 0, 0))}
      graph = HighLevelGraph.from_collections(
          rname, rdsk, dependencies=[r]
      )
      # rank must be an integer
      rank = Array(graph, rname, shape=(), chunks=(), dtype=int)
  
      # singular
      sname = "lstsq-singular-" + token
      rt = r.T.conj()
      sdsk = {
          (sname, 0): (
              _reverse,
              (
                  np.sqrt,
                  (
                      np.linalg.eigvalsh,
                      (np.dot, (rt.name, 0, 0), (r.name, 0, 0)),
                  ),
              ),
          )
      }
      graph = HighLevelGraph.from_collections(
          sname, sdsk, dependencies=[rt, r]
      )
      meta = meta_from_array(residuals, 1)
      s = Array(
          graph,
          sname,
          shape=(r.shape[0],),
          chunks=r.shape[0],
          meta=meta,
      )
  
      return x, residuals, rank, s
  
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 21 for calling a global function with example usage: lstsq(a, b) and returns: x,  residuals,  rank,  s