def qr(a, mode:"reduce")
    qr,tau, = Lapack.call(:geqrf, a)
    *shp,m,n = qr.shape
    r = (m >= n && %w[economic raw].include?(mode)) ?
      qr[false, 0...n, true].triu : qr.triu
    mode = mode.to_s.downcase
    case mode
    when "r"
      return r
    when "raw"
      return [qr,tau]
    when "reduce","economic"
      # skip
    else
      raise ArgumentError, "invalid mode:#{mode}"
    end
    if m < n
      q, = Lapack.call(:orgqr, qr[false, 0...m], tau)
    elsif mode == "economic"
      q, = Lapack.call(:orgqr, qr, tau)
    else
      qqr = qr.class.zeros(*(shp+[m,m]))
      qqr[false,0...n] = qr
      q, = Lapack.call(:orgqr, qqr, tau)
    end
    return [q,r]
  end
def qr(a, mode:"reduce")
    qr,tau, = Lapack.call(:geqrf, a)
    *shp,m,n = qr.shape
    r = (m >= n && %w[economic raw].include?(mode)) ?
      qr[false, 0...n, true].triu : qr.triu
    mode = mode.to_s.downcase
    case mode
    when "r"
      return r
    when "raw"
      return [qr,tau]
    when "reduce","economic"
      # skip
    else
      raise ArgumentError, "invalid mode:#{mode}"
    end
    if m < n
      q, = Lapack.call(:orgqr, qr[false, 0...m], tau)
    elsif mode == "economic"
      q, = Lapack.call(:orgqr, qr, tau)
    else
      qqr = qr.class.zeros(*(shp+[m,m]))
      qqr[false,0...n] = qr
      q, = Lapack.call(:orgqr, qqr, tau)
    end
    return [q,r]
  end
factorization
 Computes a QR factorization of a complex M-by-N matrix A: A = Q \* R.

 @param a [Numo::NArray] m-by-n matrix A (>= 2-dimensinal NArray)
 @param mode [String]
   - "reduce"   -- returns both Q and R,
   - "r"        -- returns only R,
   - "economic" -- returns both Q and R but computed in economy-size,
   - "raw"      -- returns QR and TAU used in LAPACK.
 @return [r]        if mode:"r"
 @return [[q,r]]    if mode:"reduce" or "economic"
 @return [[qr,tau]] if mode:"raw" (LAPACK geqrf result)