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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:36