def qr(a, overwrite_a=False, lwork=None, mode='full', pivoting=False, check_finite=True):
 if (mode not in ['full', 'qr', 'r', 'economic', 'raw']):
  raise ValueError("Mode argument should be one of ['full', 'r', 'economic', 'raw']")
 if check_finite:
  a1 = numpy.asarray_chkfinite(a)
 else:
  a1 = numpy.asarray(a)
 if (len(a1.shape) != 2):
  raise ValueError('expected 2D array')
 (M, N) = a1.shape
 overwrite_a = (overwrite_a or _datacopied(a1, a))
 if pivoting:
  (geqp3,) = get_lapack_funcs(('geqp3',), (a1,))
  (qr, jpvt, tau) = safecall(geqp3, 'geqp3', a1, overwrite_a=overwrite_a)
  jpvt -= 1
 else:
  (geqrf,) = get_lapack_funcs(('geqrf',), (a1,))
  (qr, tau) = safecall(geqrf, 'geqrf', a1, lwork=lwork, overwrite_a=overwrite_a)
 if ((mode not in ['economic', 'raw']) or (M < N)):
  R = numpy.triu(qr)
 else:
  R = numpy.triu(qr[:N, :])
 if pivoting:
  Rj = (R, jpvt)
 else:
  Rj = (R,)
 if (mode == 'r'):
  return Rj
 elif (mode == 'raw'):
  return (((qr, tau),) + Rj)
 (gor_un_gqr,) = get_lapack_funcs(('orgqr',), (qr,))
 if (M < N):
  (Q,) = safecall(gor_un_gqr, 'gorgqr/gungqr', qr[:, :M], tau, lwork=lwork, overwrite_a=1)
 elif (mode == 'economic'):
  (Q,) = safecall(gor_un_gqr, 'gorgqr/gungqr', qr, tau, lwork=lwork, overwrite_a=1)
 else:
  t = qr.dtype.char
  qqr = numpy.empty((M, M), dtype=t)
  qqr[:, :N] = qr
  (Q,) = safecall(gor_un_gqr, 'gorgqr/gungqr', qqr, tau, lwork=lwork, overwrite_a=1)
 return ((Q,) + Rj)

def qr ( a , overwrite_a = False , lwork = None , mode = 'full' , pivoting = False , check_finite = True ) : if ( mode not in [ 'full' , 'qr' , 'r' , 'economic' , 'raw' ] ) : raise ValueError ( "Mode argument should be one of ['full', 'r', 'economic', 'raw']" ) if check_finite : a1 = numpy . asarray_chkfinite ( a ) else : a1 = numpy . asarray ( a ) if ( len ( a1 . shape ) != 2 ) : raise ValueError ( 'expected 2D array' ) ( M , N ) = a1 . shape overwrite_a = ( overwrite_a or _datacopied ( a1 , a ) ) if pivoting : ( geqp3 , ) = get_lapack_funcs ( ( 'geqp3' , ) , ( a1 , ) ) ( qr , jpvt , tau ) = safecall ( geqp3 , 'geqp3' , a1 , overwrite_a = overwrite_a ) jpvt -= 1 else : ( geqrf , ) = get_lapack_funcs ( ( 'geqrf' , ) , ( a1 , ) ) ( qr , tau ) = safecall ( geqrf , 'geqrf' , a1 , lwork = lwork , overwrite_a = overwrite_a ) if ( ( mode not in [ 'economic' , 'raw' ] ) or ( M < N ) ) : R = numpy . triu ( qr ) else : R = numpy . triu ( qr [ : N , : ] ) if pivoting : Rj = ( R , jpvt ) else : Rj = ( R , ) if ( mode == 'r' ) : return Rj elif ( mode == 'raw' ) : return ( ( ( qr , tau ) , ) + Rj ) ( gor_un_gqr , ) = get_lapack_funcs ( ( 'orgqr' , ) , ( qr , ) ) if ( M < N ) : ( Q , ) = safecall ( gor_un_gqr , 'gorgqr/gungqr' , qr [ : , : M ] , tau , lwork = lwork , overwrite_a = 1 ) elif ( mode == 'economic' ) : ( Q , ) = safecall ( gor_un_gqr , 'gorgqr/gungqr' , qr , tau , lwork = lwork , overwrite_a = 1 ) else : t = qr . dtype . char qqr = numpy . empty ( ( M , M ) , dtype = t ) qqr [ : , : N ] = qr ( Q , ) = safecall ( gor_un_gqr , 'gorgqr/gungqr' , qqr , tau , lwork = lwork , overwrite_a = 1 ) return ( ( Q , ) + Rj )
compute the qr factorization of a matrix .