cgglse.c
Go to the documentation of this file.
00001 /* cgglse.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static complex c_b1 = {1.f,0.f};
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ int cgglse_(integer *m, integer *n, integer *p, complex *a, 
00023         integer *lda, complex *b, integer *ldb, complex *c__, complex *d__, 
00024         complex *x, complex *work, integer *lwork, integer *info)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
00028     complex q__1;
00029 
00030     /* Local variables */
00031     integer nb, mn, nr, nb1, nb2, nb3, nb4, lopt;
00032     extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex *
00033 , complex *, integer *, complex *, integer *, complex *, complex *
00034 , integer *), ccopy_(integer *, complex *, integer *, 
00035             complex *, integer *), caxpy_(integer *, complex *, complex *, 
00036             integer *, complex *, integer *), ctrmv_(char *, char *, char *, 
00037             integer *, complex *, integer *, complex *, integer *), cggrqf_(integer *, integer *, integer *, complex 
00038             *, integer *, complex *, complex *, integer *, complex *, complex 
00039             *, integer *, integer *), xerbla_(char *, integer *);
00040     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00041             integer *, integer *);
00042     integer lwkmin;
00043     extern /* Subroutine */ int cunmqr_(char *, char *, integer *, integer *, 
00044             integer *, complex *, integer *, complex *, complex *, integer *, 
00045             complex *, integer *, integer *), cunmrq_(char *, 
00046             char *, integer *, integer *, integer *, complex *, integer *, 
00047             complex *, complex *, integer *, complex *, integer *, integer *);
00048     integer lwkopt;
00049     logical lquery;
00050     extern /* Subroutine */ int ctrtrs_(char *, char *, char *, integer *, 
00051             integer *, complex *, integer *, complex *, integer *, integer *);
00052 
00053 
00054 /*  -- LAPACK driver routine (version 3.2) -- */
00055 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00056 /*     November 2006 */
00057 
00058 /*     .. Scalar Arguments .. */
00059 /*     .. */
00060 /*     .. Array Arguments .. */
00061 /*     .. */
00062 
00063 /*  Purpose */
00064 /*  ======= */
00065 
00066 /*  CGGLSE solves the linear equality-constrained least squares (LSE) */
00067 /*  problem: */
00068 
00069 /*          minimize || c - A*x ||_2   subject to   B*x = d */
00070 
00071 /*  where A is an M-by-N matrix, B is a P-by-N matrix, c is a given */
00072 /*  M-vector, and d is a given P-vector. It is assumed that */
00073 /*  P <= N <= M+P, and */
00074 
00075 /*           rank(B) = P and  rank( (A) ) = N. */
00076 /*                                ( (B) ) */
00077 
00078 /*  These conditions ensure that the LSE problem has a unique solution, */
00079 /*  which is obtained using a generalized RQ factorization of the */
00080 /*  matrices (B, A) given by */
00081 
00082 /*     B = (0 R)*Q,   A = Z*T*Q. */
00083 
00084 /*  Arguments */
00085 /*  ========= */
00086 
00087 /*  M       (input) INTEGER */
00088 /*          The number of rows of the matrix A.  M >= 0. */
00089 
00090 /*  N       (input) INTEGER */
00091 /*          The number of columns of the matrices A and B. N >= 0. */
00092 
00093 /*  P       (input) INTEGER */
00094 /*          The number of rows of the matrix B. 0 <= P <= N <= M+P. */
00095 
00096 /*  A       (input/output) COMPLEX array, dimension (LDA,N) */
00097 /*          On entry, the M-by-N matrix A. */
00098 /*          On exit, the elements on and above the diagonal of the array */
00099 /*          contain the min(M,N)-by-N upper trapezoidal matrix T. */
00100 
00101 /*  LDA     (input) INTEGER */
00102 /*          The leading dimension of the array A. LDA >= max(1,M). */
00103 
00104 /*  B       (input/output) COMPLEX array, dimension (LDB,N) */
00105 /*          On entry, the P-by-N matrix B. */
00106 /*          On exit, the upper triangle of the subarray B(1:P,N-P+1:N) */
00107 /*          contains the P-by-P upper triangular matrix R. */
00108 
00109 /*  LDB     (input) INTEGER */
00110 /*          The leading dimension of the array B. LDB >= max(1,P). */
00111 
00112 /*  C       (input/output) COMPLEX array, dimension (M) */
00113 /*          On entry, C contains the right hand side vector for the */
00114 /*          least squares part of the LSE problem. */
00115 /*          On exit, the residual sum of squares for the solution */
00116 /*          is given by the sum of squares of elements N-P+1 to M of */
00117 /*          vector C. */
00118 
00119 /*  D       (input/output) COMPLEX array, dimension (P) */
00120 /*          On entry, D contains the right hand side vector for the */
00121 /*          constrained equation. */
00122 /*          On exit, D is destroyed. */
00123 
00124 /*  X       (output) COMPLEX array, dimension (N) */
00125 /*          On exit, X is the solution of the LSE problem. */
00126 
00127 /*  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) */
00128 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00129 
00130 /*  LWORK   (input) INTEGER */
00131 /*          The dimension of the array WORK. LWORK >= max(1,M+N+P). */
00132 /*          For optimum performance LWORK >= P+min(M,N)+max(M,N)*NB, */
00133 /*          where NB is an upper bound for the optimal blocksizes for */
00134 /*          CGEQRF, CGERQF, CUNMQR and CUNMRQ. */
00135 
00136 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00137 /*          only calculates the optimal size of the WORK array, returns */
00138 /*          this value as the first entry of the WORK array, and no error */
00139 /*          message related to LWORK is issued by XERBLA. */
00140 
00141 /*  INFO    (output) INTEGER */
00142 /*          = 0:  successful exit. */
00143 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00144 /*          = 1:  the upper triangular factor R associated with B in the */
00145 /*                generalized RQ factorization of the pair (B, A) is */
00146 /*                singular, so that rank(B) < P; the least squares */
00147 /*                solution could not be computed. */
00148 /*          = 2:  the (N-P) by (N-P) part of the upper trapezoidal factor */
00149 /*                T associated with A in the generalized RQ factorization */
00150 /*                of the pair (B, A) is singular, so that */
00151 /*                rank( (A) ) < N; the least squares solution could not */
00152 /*                    ( (B) ) */
00153 /*                be computed. */
00154 
00155 /*  ===================================================================== */
00156 
00157 /*     .. Parameters .. */
00158 /*     .. */
00159 /*     .. Local Scalars .. */
00160 /*     .. */
00161 /*     .. External Subroutines .. */
00162 /*     .. */
00163 /*     .. External Functions .. */
00164 /*     .. */
00165 /*     .. Intrinsic Functions .. */
00166 /*     .. */
00167 /*     .. Executable Statements .. */
00168 
00169 /*     Test the input parameters */
00170 
00171     /* Parameter adjustments */
00172     a_dim1 = *lda;
00173     a_offset = 1 + a_dim1;
00174     a -= a_offset;
00175     b_dim1 = *ldb;
00176     b_offset = 1 + b_dim1;
00177     b -= b_offset;
00178     --c__;
00179     --d__;
00180     --x;
00181     --work;
00182 
00183     /* Function Body */
00184     *info = 0;
00185     mn = min(*m,*n);
00186     lquery = *lwork == -1;
00187     if (*m < 0) {
00188         *info = -1;
00189     } else if (*n < 0) {
00190         *info = -2;
00191     } else if (*p < 0 || *p > *n || *p < *n - *m) {
00192         *info = -3;
00193     } else if (*lda < max(1,*m)) {
00194         *info = -5;
00195     } else if (*ldb < max(1,*p)) {
00196         *info = -7;
00197     }
00198 
00199 /*     Calculate workspace */
00200 
00201     if (*info == 0) {
00202         if (*n == 0) {
00203             lwkmin = 1;
00204             lwkopt = 1;
00205         } else {
00206             nb1 = ilaenv_(&c__1, "CGEQRF", " ", m, n, &c_n1, &c_n1);
00207             nb2 = ilaenv_(&c__1, "CGERQF", " ", m, n, &c_n1, &c_n1);
00208             nb3 = ilaenv_(&c__1, "CUNMQR", " ", m, n, p, &c_n1);
00209             nb4 = ilaenv_(&c__1, "CUNMRQ", " ", m, n, p, &c_n1);
00210 /* Computing MAX */
00211             i__1 = max(nb1,nb2), i__1 = max(i__1,nb3);
00212             nb = max(i__1,nb4);
00213             lwkmin = *m + *n + *p;
00214             lwkopt = *p + mn + max(*m,*n) * nb;
00215         }
00216         work[1].r = (real) lwkopt, work[1].i = 0.f;
00217 
00218         if (*lwork < lwkmin && ! lquery) {
00219             *info = -12;
00220         }
00221     }
00222 
00223     if (*info != 0) {
00224         i__1 = -(*info);
00225         xerbla_("CGGLSE", &i__1);
00226         return 0;
00227     } else if (lquery) {
00228         return 0;
00229     }
00230 
00231 /*     Quick return if possible */
00232 
00233     if (*n == 0) {
00234         return 0;
00235     }
00236 
00237 /*     Compute the GRQ factorization of matrices B and A: */
00238 
00239 /*            B*Q' = (  0  T12 ) P   Z'*A*Q' = ( R11 R12 ) N-P */
00240 /*                     N-P  P                  (  0  R22 ) M+P-N */
00241 /*                                               N-P  P */
00242 
00243 /*     where T12 and R11 are upper triangular, and Q and Z are */
00244 /*     unitary. */
00245 
00246     i__1 = *lwork - *p - mn;
00247     cggrqf_(p, m, n, &b[b_offset], ldb, &work[1], &a[a_offset], lda, &work[*p 
00248             + 1], &work[*p + mn + 1], &i__1, info);
00249     i__1 = *p + mn + 1;
00250     lopt = work[i__1].r;
00251 
00252 /*     Update c = Z'*c = ( c1 ) N-P */
00253 /*                       ( c2 ) M+P-N */
00254 
00255     i__1 = max(1,*m);
00256     i__2 = *lwork - *p - mn;
00257     cunmqr_("Left", "Conjugate Transpose", m, &c__1, &mn, &a[a_offset], lda, &
00258             work[*p + 1], &c__[1], &i__1, &work[*p + mn + 1], &i__2, info);
00259 /* Computing MAX */
00260     i__3 = *p + mn + 1;
00261     i__1 = lopt, i__2 = (integer) work[i__3].r;
00262     lopt = max(i__1,i__2);
00263 
00264 /*     Solve T12*x2 = d for x2 */
00265 
00266     if (*p > 0) {
00267         ctrtrs_("Upper", "No transpose", "Non-unit", p, &c__1, &b[(*n - *p + 
00268                 1) * b_dim1 + 1], ldb, &d__[1], p, info);
00269 
00270         if (*info > 0) {
00271             *info = 1;
00272             return 0;
00273         }
00274 
00275 /*        Put the solution in X */
00276 
00277         ccopy_(p, &d__[1], &c__1, &x[*n - *p + 1], &c__1);
00278 
00279 /*        Update c1 */
00280 
00281         i__1 = *n - *p;
00282         q__1.r = -1.f, q__1.i = -0.f;
00283         cgemv_("No transpose", &i__1, p, &q__1, &a[(*n - *p + 1) * a_dim1 + 1]
00284 , lda, &d__[1], &c__1, &c_b1, &c__[1], &c__1);
00285     }
00286 
00287 /*     Solve R11*x1 = c1 for x1 */
00288 
00289     if (*n > *p) {
00290         i__1 = *n - *p;
00291         i__2 = *n - *p;
00292         ctrtrs_("Upper", "No transpose", "Non-unit", &i__1, &c__1, &a[
00293                 a_offset], lda, &c__[1], &i__2, info);
00294 
00295         if (*info > 0) {
00296             *info = 2;
00297             return 0;
00298         }
00299 
00300 /*        Put the solutions in X */
00301 
00302         i__1 = *n - *p;
00303         ccopy_(&i__1, &c__[1], &c__1, &x[1], &c__1);
00304     }
00305 
00306 /*     Compute the residual vector: */
00307 
00308     if (*m < *n) {
00309         nr = *m + *p - *n;
00310         if (nr > 0) {
00311             i__1 = *n - *m;
00312             q__1.r = -1.f, q__1.i = -0.f;
00313             cgemv_("No transpose", &nr, &i__1, &q__1, &a[*n - *p + 1 + (*m + 
00314                     1) * a_dim1], lda, &d__[nr + 1], &c__1, &c_b1, &c__[*n - *
00315                     p + 1], &c__1);
00316         }
00317     } else {
00318         nr = *p;
00319     }
00320     if (nr > 0) {
00321         ctrmv_("Upper", "No transpose", "Non unit", &nr, &a[*n - *p + 1 + (*n 
00322                 - *p + 1) * a_dim1], lda, &d__[1], &c__1);
00323         q__1.r = -1.f, q__1.i = -0.f;
00324         caxpy_(&nr, &q__1, &d__[1], &c__1, &c__[*n - *p + 1], &c__1);
00325     }
00326 
00327 /*     Backward transformation x = Q'*x */
00328 
00329     i__1 = *lwork - *p - mn;
00330     cunmrq_("Left", "Conjugate Transpose", n, &c__1, p, &b[b_offset], ldb, &
00331             work[1], &x[1], n, &work[*p + mn + 1], &i__1, info);
00332 /* Computing MAX */
00333     i__4 = *p + mn + 1;
00334     i__2 = lopt, i__3 = (integer) work[i__4].r;
00335     i__1 = *p + mn + max(i__2,i__3);
00336     work[1].r = (real) i__1, work[1].i = 0.f;
00337 
00338     return 0;
00339 
00340 /*     End of CGGLSE */
00341 
00342 } /* cgglse_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:27