code: def lstsq(a, b, rcond="warn"):
      """Return the least-squares solution to a linear matrix equation.
  
      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.
  
      Args:
          a (cupy.ndarray): "Coefficient" matrix with dimension ``(M, N)``
          b (cupy.ndarray): "Dependent variable" values with dimension ``(M,)``
              or ``(M, K)``
          rcond (float): Cutoff parameter for small singular values.
              For stability it computes the largest singular value denoted by
              ``s``, and sets all singular values smaller than ``s`` to zero.
  
      Returns:
          tuple:
              A tuple of ``(x, residuals, rank, s)``. Note ``x`` is the
              least-squares solution with shape ``(N,)`` or ``(N, K)`` depending
              if ``b`` was two-dimensional. The sums of ``residuals`` is the
              squared Euclidean 2-norm for each column in b - a*x. The
              ``residuals`` is an empty array if the rank of a is < N or M <= N,
              but  iff b is 1-dimensional, this is a (1,) shape array, Otherwise
              the shape is (K,). The ``rank`` of matrix ``a`` is an integer. The
              singular values of ``a`` are ``s``.
  
      .. warning::
          This function calls one or more cuSOLVER routine(s) which may yield
          invalid results if input conditions are not met.
          To detect these invalid results, you can set the `linalg`
          configuration to a value that is not `ignore` in
          :func:`cupyx.errstate` or :func:`cupyx.seterr`.
  
      .. seealso:: :func:`numpy.linalg.lstsq`
      """
      if rcond == "warn":
          warnings.warn(
              "`rcond` parameter will change to the default of "
              "machine precision times ``max(M, N)`` where M and N "
              "are the input matrix dimensions.\n"
              "To use the future default and silence this warning "
              "we advise to pass `rcond=None`, to keep using the old, "
              "explicitly pass `rcond=-1`.",
              FutureWarning,
          )
          rcond = -1
  
      _util._assert_cupy_array(a, b)
      _util._assert_2d(a)
      # TODO(kataoka): Fix 0-dim
      if b.ndim > 2:
          raise linalg.LinAlgError(
              "{}-dimensional array given. Array must be at"
              " most two-dimensional".format(b.ndim)
          )
      m, n = a.shape[-2:]
      m2 = b.shape[0]
      if m != m2:
          raise linalg.LinAlgError("Incompatible dimensions")
  
      u, s, vh = cupy.linalg.svd(a, full_matrices=False)
  
      if rcond is None:
          rcond = numpy.finfo(s.dtype).eps * max(m, n)
      elif rcond <= 0 or rcond >= 1:
          # some doc of gelss/gelsd says "rcond < 0", but it's not true!
          rcond = numpy.finfo(s.dtype).eps
  
      # number of singular values and matrix rank
      s1 = 1 / s
      rank = cupy.array(s.size, numpy.int32)
      if s.size > 0:
          cutoff = rcond * s.max()
          sing_vals = s <= cutoff
          s1[sing_vals] = 0
          rank -= sing_vals.sum(dtype=numpy.int32)
  
      # Solve the least-squares solution
      # x = vh.T.conj() @ diag(s1) @ u.T.conj() @ b
      z = (cupy.dot(b.T, u.conj()) * s1).T
      x = cupy.dot(vh.T.conj(), z)
      # Calculate squared Euclidean 2-norm for each column in b - a*x
      if m <= n or rank != n:
          resids = cupy.empty((0,), dtype=s.dtype)
      else:
          e = b - a.dot(x)
          resids = cupy.atleast_1d(_nrm2_last_axis(e.T))
      return x, resids, rank, s
  
file_path: cupy/cupy/linalg/_solve.py
imports: import warnings
  import numpy
  from numpy import linalg
  import cupy
  from cupy._core import internal
  from cupy.cuda import device
  from cupy.linalg import _decomposition
  from cupy.linalg import _util
  import cupyx
label_desc: Use image node_id 4 for calling a global function with example usage: lstsq(a, b, rcond) and returns: x,  resids,  rank,  s