--- 
:name: sgelsy
:md5sum: ef95fb1aa71e1dc5559fe35dd26c6aac
:category: :subroutine
:arguments: 
- m: 
    :type: integer
    :intent: input
- n: 
    :type: integer
    :intent: input
- nrhs: 
    :type: integer
    :intent: input
- a: 
    :type: real
    :intent: input/output
    :dims: 
    - lda
    - n
- lda: 
    :type: integer
    :intent: input
- b: 
    :type: real
    :intent: input/output
    :dims: 
    - m
    - nrhs
    :outdims:
    - n
    - nrhs
- ldb: 
    :type: integer
    :intent: input
- jpvt: 
    :type: integer
    :intent: input/output
    :dims: 
    - n
- rcond: 
    :type: real
    :intent: input
- rank: 
    :type: integer
    :intent: output
- work: 
    :type: real
    :intent: output
    :dims: 
    - MAX(1,lwork)
- lwork: 
    :type: integer
    :intent: input
    :option: true
    :default: MAX(MIN(m,n)+3*n+1, 2*MIN(m,n)+nrhs)
- info: 
    :type: integer
    :intent: output
:substitutions: 
  m: lda
  ldb: MAX(m,n)
:fortran_help: "      SUBROUTINE SGELSY( M, N, NRHS, A, LDA, B, LDB, JPVT, RCOND, RANK, WORK, LWORK, INFO )\n\n\
  *  Purpose\n\
  *  =======\n\
  *\n\
  *  SGELSY computes the minimum-norm solution to a real linear least\n\
  *  squares problem:\n\
  *      minimize || A * X - B ||\n\
  *  using a complete orthogonal factorization of A.  A is an M-by-N\n\
  *  matrix which may be rank-deficient.\n\
  *\n\
  *  Several right hand side vectors b and solution vectors x can be\n\
  *  handled in a single call; they are stored as the columns of the\n\
  *  M-by-NRHS right hand side matrix B and the N-by-NRHS solution\n\
  *  matrix X.\n\
  *\n\
  *  The routine first computes a QR factorization with column pivoting:\n\
  *      A * P = Q * [ R11 R12 ]\n\
  *                  [  0  R22 ]\n\
  *  with R11 defined as the largest leading submatrix whose estimated\n\
  *  condition number is less than 1/RCOND.  The order of R11, RANK,\n\
  *  is the effective rank of A.\n\
  *\n\
  *  Then, R22 is considered to be negligible, and R12 is annihilated\n\
  *  by orthogonal transformations from the right, arriving at the\n\
  *  complete orthogonal factorization:\n\
  *     A * P = Q * [ T11 0 ] * Z\n\
  *                 [  0  0 ]\n\
  *  The minimum-norm solution is then\n\
  *     X = P * Z' [ inv(T11)*Q1'*B ]\n\
  *                [        0       ]\n\
  *  where Q1 consists of the first RANK columns of Q.\n\
  *\n\
  *  This routine is basically identical to the original xGELSX except\n\
  *  three differences:\n\
  *    o The call to the subroutine xGEQPF has been substituted by the\n\
  *      the call to the subroutine xGEQP3. This subroutine is a Blas-3\n\
  *      version of the QR factorization with column pivoting.\n\
  *    o Matrix B (the right hand side) is updated with Blas-3.\n\
  *    o The permutation of matrix B (the right hand side) is faster and\n\
  *      more simple.\n\
  *\n\n\
  *  Arguments\n\
  *  =========\n\
  *\n\
  *  M       (input) INTEGER\n\
  *          The number of rows of the matrix A.  M >= 0.\n\
  *\n\
  *  N       (input) INTEGER\n\
  *          The number of columns of the matrix A.  N >= 0.\n\
  *\n\
  *  NRHS    (input) INTEGER\n\
  *          The number of right hand sides, i.e., the number of\n\
  *          columns of matrices B and X. NRHS >= 0.\n\
  *\n\
  *  A       (input/output) REAL array, dimension (LDA,N)\n\
  *          On entry, the M-by-N matrix A.\n\
  *          On exit, A has been overwritten by details of its\n\
  *          complete orthogonal factorization.\n\
  *\n\
  *  LDA     (input) INTEGER\n\
  *          The leading dimension of the array A.  LDA >= max(1,M).\n\
  *\n\
  *  B       (input/output) REAL array, dimension (LDB,NRHS)\n\
  *          On entry, the M-by-NRHS right hand side matrix B.\n\
  *          On exit, the N-by-NRHS solution matrix X.\n\
  *\n\
  *  LDB     (input) INTEGER\n\
  *          The leading dimension of the array B. LDB >= max(1,M,N).\n\
  *\n\
  *  JPVT    (input/output) INTEGER array, dimension (N)\n\
  *          On entry, if JPVT(i) .ne. 0, the i-th column of A is permuted\n\
  *          to the front of AP, otherwise column i is a free column.\n\
  *          On exit, if JPVT(i) = k, then the i-th column of AP\n\
  *          was the k-th column of A.\n\
  *\n\
  *  RCOND   (input) REAL\n\
  *          RCOND is used to determine the effective rank of A, which\n\
  *          is defined as the order of the largest leading triangular\n\
  *          submatrix R11 in the QR factorization with pivoting of A,\n\
  *          whose estimated condition number < 1/RCOND.\n\
  *\n\
  *  RANK    (output) INTEGER\n\
  *          The effective rank of A, i.e., the order of the submatrix\n\
  *          R11.  This is the same as the order of the submatrix T11\n\
  *          in the complete orthogonal factorization of A.\n\
  *\n\
  *  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK))\n\
  *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.\n\
  *\n\
  *  LWORK   (input) INTEGER\n\
  *          The dimension of the array WORK.\n\
  *          The unblocked strategy requires that:\n\
  *             LWORK >= MAX( MN+3*N+1, 2*MN+NRHS ),\n\
  *          where MN = min( M, N ).\n\
  *          The block algorithm requires that:\n\
  *             LWORK >= MAX( MN+2*N+NB*(N+1), 2*MN+NB*NRHS ),\n\
  *          where NB is an upper bound on the blocksize returned\n\
  *          by ILAENV for the routines SGEQP3, STZRZF, STZRQF, SORMQR,\n\
  *          and SORMRZ.\n\
  *\n\
  *          If LWORK = -1, then a workspace query is assumed; the routine\n\
  *          only calculates the optimal size of the WORK array, returns\n\
  *          this value as the first entry of the WORK array, and no error\n\
  *          message related to LWORK is issued by XERBLA.\n\
  *\n\
  *  INFO    (output) INTEGER\n\
  *          = 0: successful exit\n\
  *          < 0: If INFO = -i, the i-th argument had an illegal value.\n\
  *\n\n\
  *  Further Details\n\
  *  ===============\n\
  *\n\
  *  Based on contributions by\n\
  *    A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA\n\
  *    E. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain\n\
  *    G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain\n\
  *\n\
  *  =====================================================================\n\
  *\n"
