code: def qr(a):
      m, n = a.shape[0], a.shape[1]
      k = min(m, n)
  
      # we will store our scratch work in a_work
      a_work = core.DistArray(a.shape, np.copy(a.object_refs))
  
      result_dtype = np.linalg.qr(ray.get(a.object_refs[0, 0]))[
          0
      ].dtype.name
      # TODO(rkn): It would be preferable not to get this right after creating
      # it.
      r_res = ray.get(core.zeros.remote([k, n], result_dtype))
      # TODO(rkn): It would be preferable not to get this right after creating
      # it.
      y_res = ray.get(core.zeros.remote([m, k], result_dtype))
      Ts = []
  
      # The for loop differs from the paper, which says
      # "for i in range(a.num_blocks[1])", but that doesn't seem to make any
      # sense when a.num_blocks[1] > a.num_blocks[0].
      for i in range(min(a.num_blocks[0], a.num_blocks[1])):
          sub_dist_array = core.subblocks.remote(
              a_work, list(range(i, a_work.num_blocks[0])), [i]
          )
          y, t, _, R = tsqr_hr.remote(sub_dist_array)
          y_val = ray.get(y)
  
          for j in range(i, a.num_blocks[0]):
              y_res.object_refs[j, i] = y_val.object_refs[j - i, 0]
          if a.shape[0] > a.shape[1]:
              # in this case, R needs to be square
              R_shape = ray.get(ra.shape.remote(R))
              eye_temp = ra.eye.remote(
                  R_shape[1], R_shape[0], dtype_name=result_dtype
              )
              r_res.object_refs[i, i] = ra.dot.remote(eye_temp, R)
          else:
              r_res.object_refs[i, i] = R
          Ts.append(core.numpy_to_dist.remote(t))
  
          for c in range(i + 1, a.num_blocks[1]):
              W_rcs = []
              for r in range(i, a.num_blocks[0]):
                  y_ri = y_val.object_refs[r - i, 0]
                  W_rcs.append(
                      qr_helper2.remote(y_ri, a_work.object_refs[r, c])
                  )
              W_c = ra.sum_list.remote(*W_rcs)
              for r in range(i, a.num_blocks[0]):
                  y_ri = y_val.object_refs[r - i, 0]
                  A_rc = qr_helper1.remote(
                      a_work.object_refs[r, c], y_ri, t, W_c
                  )
                  a_work.object_refs[r, c] = A_rc
              r_res.object_refs[i, c] = a_work.object_refs[i, c]
  
      # construct q_res from Ys and Ts
      q = core.eye.remote(m, k, dtype_name=result_dtype)
      for i in range(len(Ts))[::-1]:
          y_col_block = core.subblocks.remote(y_res, [], [i])
          q = core.subtract.remote(
              q,
              core.dot.remote(
                  y_col_block,
                  core.dot.remote(
                      Ts[i],
                      core.dot.remote(
                          core.transpose.remote(y_col_block), q
                      ),
                  ),
              ),
          )
  
      return ray.get(q), r_res
  
file_path: ray/python/ray/experimental/array/distributed/linalg.py
imports: import numpy
  import ray
  import ray.experimental.array.remote
  from .None import core
label_desc: Use image node_id 8 for calling a global function with example usage: qr(a) and returns: ray,  r_res