code: def test_lstsq(nrow, ncol, chunk, iscomplex):
      rng = cupy.random.default_rng(1)
      A = rng.integers(1, 20, (nrow, ncol))
      b = rng.integers(1, 20, nrow)
      if iscomplex:
          A = A + 1.0j * rng.integers(1, 20, A.shape)
          b = b + 1.0j * rng.integers(1, 20, b.shape)
  
      dA = da.from_array(A, (chunk, ncol))
      db = da.from_array(b, chunk)
  
      x, r, rank, s = cupy.linalg.lstsq(A, b, rcond=-1)
      dx, dr, drank, ds = da.linalg.lstsq(dA, db)
  
      assert_eq(dx, x)
      assert_eq(dr, r)
      assert drank.compute() == rank
      assert_eq(ds, s)
  
      # reduce rank causes multicollinearity, only compare rank
      A[:, 1] = A[:, 2]
      dA = da.from_array(A, (chunk, ncol))
      db = da.from_array(b, chunk)
      x, r, rank, s = cupy.linalg.lstsq(
          A, b, rcond=cupy.finfo(cupy.double).eps * max(nrow, ncol)
      )
      assert rank == ncol - 1
      dx, dr, drank, ds = da.linalg.lstsq(dA, db)
      assert drank.compute() == rank
  
      # 2D case
      A = rng.integers(1, 20, (nrow, ncol))
      b2D = rng.integers(1, 20, (nrow, ncol // 2))
      if iscomplex:
          A = A + 1.0j * rng.integers(1, 20, A.shape)
          b2D = b2D + 1.0j * rng.integers(1, 20, b2D.shape)
      dA = da.from_array(A, (chunk, ncol))
      db2D = da.from_array(b2D, (chunk, ncol // 2))
      x, r, rank, s = cupy.linalg.lstsq(A, b2D, rcond=-1)
      dx, dr, drank, ds = da.linalg.lstsq(dA, db2D)
  
      assert_eq(dx, x)
      assert_eq(dr, r)
      assert drank.compute() == rank
      assert_eq(ds, s)
  
file_path: dask/dask/array/tests/test_cupy_linalg.py
imports: from __future__ import annotations
  import numpy
  import pytest
  from packaging.version import parse
  import dask.array
  from dask.array.utils import assert_eq
label_desc: Use image node_id 4 for calling a global function with example usage: test_lstsq(nrow, ncol, chunk, iscomplex) without return types