zggglm.c
Go to the documentation of this file.
00001 /* zggglm.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_b2 = {1.,0.};
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ int zggglm_(integer *n, integer *m, integer *p, 
00023         doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, 
00024         doublecomplex *d__, doublecomplex *x, doublecomplex *y, doublecomplex 
00025         *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 i__, nb, np, 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 *), xerbla_(char *, integer *);
00038     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00039             integer *, integer *);
00040     extern /* Subroutine */ int zggqrf_(integer *, integer *, integer *, 
00041             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00042             integer *, doublecomplex *, doublecomplex *, integer *, integer *)
00043             ;
00044     integer lwkmin, lwkopt;
00045     logical lquery;
00046     extern /* Subroutine */ int zunmqr_(char *, char *, integer *, integer *, 
00047             integer *, doublecomplex *, integer *, doublecomplex *, 
00048             doublecomplex *, integer *, doublecomplex *, integer *, integer *), zunmrq_(char *, char *, integer *, integer *, 
00049             integer *, doublecomplex *, integer *, doublecomplex *, 
00050             doublecomplex *, integer *, doublecomplex *, integer *, integer *), ztrtrs_(char *, char *, char *, integer *, 
00051             integer *, doublecomplex *, integer *, doublecomplex *, integer *, 
00052              integer *);
00053 
00054 
00055 /*  -- LAPACK driver routine (version 3.2) -- */
00056 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00057 /*     November 2006 */
00058 
00059 /*     .. Scalar Arguments .. */
00060 /*     .. */
00061 /*     .. Array Arguments .. */
00062 /*     .. */
00063 
00064 /*  Purpose */
00065 /*  ======= */
00066 
00067 /*  ZGGGLM solves a general Gauss-Markov linear model (GLM) problem: */
00068 
00069 /*          minimize || y ||_2   subject to   d = A*x + B*y */
00070 /*              x */
00071 
00072 /*  where A is an N-by-M matrix, B is an N-by-P matrix, and d is a */
00073 /*  given N-vector. It is assumed that M <= N <= M+P, and */
00074 
00075 /*             rank(A) = M    and    rank( A B ) = N. */
00076 
00077 /*  Under these assumptions, the constrained equation is always */
00078 /*  consistent, and there is a unique solution x and a minimal 2-norm */
00079 /*  solution y, which is obtained using a generalized QR factorization */
00080 /*  of the matrices (A, B) given by */
00081 
00082 /*     A = Q*(R),   B = Q*T*Z. */
00083 /*           (0) */
00084 
00085 /*  In particular, if matrix B is square nonsingular, then the problem */
00086 /*  GLM is equivalent to the following weighted linear least squares */
00087 /*  problem */
00088 
00089 /*               minimize || inv(B)*(d-A*x) ||_2 */
00090 /*                   x */
00091 
00092 /*  where inv(B) denotes the inverse of B. */
00093 
00094 /*  Arguments */
00095 /*  ========= */
00096 
00097 /*  N       (input) INTEGER */
00098 /*          The number of rows of the matrices A and B.  N >= 0. */
00099 
00100 /*  M       (input) INTEGER */
00101 /*          The number of columns of the matrix A.  0 <= M <= N. */
00102 
00103 /*  P       (input) INTEGER */
00104 /*          The number of columns of the matrix B.  P >= N-M. */
00105 
00106 /*  A       (input/output) COMPLEX*16 array, dimension (LDA,M) */
00107 /*          On entry, the N-by-M matrix A. */
00108 /*          On exit, the upper triangular part of the array A contains */
00109 /*          the M-by-M upper triangular matrix R. */
00110 
00111 /*  LDA     (input) INTEGER */
00112 /*          The leading dimension of the array A. LDA >= max(1,N). */
00113 
00114 /*  B       (input/output) COMPLEX*16 array, dimension (LDB,P) */
00115 /*          On entry, the N-by-P matrix B. */
00116 /*          On exit, if N <= P, the upper triangle of the subarray */
00117 /*          B(1:N,P-N+1:P) contains the N-by-N upper triangular matrix T; */
00118 /*          if N > P, the elements on and above the (N-P)th subdiagonal */
00119 /*          contain the N-by-P upper trapezoidal matrix T. */
00120 
00121 /*  LDB     (input) INTEGER */
00122 /*          The leading dimension of the array B. LDB >= max(1,N). */
00123 
00124 /*  D       (input/output) COMPLEX*16 array, dimension (N) */
00125 /*          On entry, D is the left hand side of the GLM equation. */
00126 /*          On exit, D is destroyed. */
00127 
00128 /*  X       (output) COMPLEX*16 array, dimension (M) */
00129 /*  Y       (output) COMPLEX*16 array, dimension (P) */
00130 /*          On exit, X and Y are the solutions of the GLM problem. */
00131 
00132 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00133 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00134 
00135 /*  LWORK   (input) INTEGER */
00136 /*          The dimension of the array WORK. LWORK >= max(1,N+M+P). */
00137 /*          For optimum performance, LWORK >= M+min(N,P)+max(N,P)*NB, */
00138 /*          where NB is an upper bound for the optimal blocksizes for */
00139 /*          ZGEQRF, ZGERQF, ZUNMQR and ZUNMRQ. */
00140 
00141 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00142 /*          only calculates the optimal size of the WORK array, returns */
00143 /*          this value as the first entry of the WORK array, and no error */
00144 /*          message related to LWORK is issued by XERBLA. */
00145 
00146 /*  INFO    (output) INTEGER */
00147 /*          = 0:  successful exit. */
00148 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00149 /*          = 1:  the upper triangular factor R associated with A in the */
00150 /*                generalized QR factorization of the pair (A, B) is */
00151 /*                singular, so that rank(A) < M; the least squares */
00152 /*                solution could not be computed. */
00153 /*          = 2:  the bottom (N-M) by (N-M) part of the upper trapezoidal */
00154 /*                factor T associated with B in the generalized QR */
00155 /*                factorization of the pair (A, B) is singular, so that */
00156 /*                rank( A B ) < N; the least squares solution could not */
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     --d__;
00183     --x;
00184     --y;
00185     --work;
00186 
00187     /* Function Body */
00188     *info = 0;
00189     np = min(*n,*p);
00190     lquery = *lwork == -1;
00191     if (*n < 0) {
00192         *info = -1;
00193     } else if (*m < 0 || *m > *n) {
00194         *info = -2;
00195     } else if (*p < 0 || *p < *n - *m) {
00196         *info = -3;
00197     } else if (*lda < max(1,*n)) {
00198         *info = -5;
00199     } else if (*ldb < max(1,*n)) {
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", " ", n, m, &c_n1, &c_n1);
00211             nb2 = ilaenv_(&c__1, "ZGERQF", " ", n, m, &c_n1, &c_n1);
00212             nb3 = ilaenv_(&c__1, "ZUNMQR", " ", n, m, p, &c_n1);
00213             nb4 = ilaenv_(&c__1, "ZUNMRQ", " ", n, m, 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 = *m + np + max(*n,*p) * 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_("ZGGGLM", &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 GQR factorization of matrices A and B: */
00242 
00243 /*            Q'*A = ( R11 ) M,    Q'*B*Z' = ( T11   T12 ) M */
00244 /*                   (  0  ) N-M             (  0    T22 ) N-M */
00245 /*                      M                     M+P-N  N-M */
00246 
00247 /*     where R11 and T22 are upper triangular, and Q and Z are */
00248 /*     unitary. */
00249 
00250     i__1 = *lwork - *m - np;
00251     zggqrf_(n, m, p, &a[a_offset], lda, &work[1], &b[b_offset], ldb, &work[*m 
00252             + 1], &work[*m + np + 1], &i__1, info);
00253     i__1 = *m + np + 1;
00254     lopt = (integer) work[i__1].r;
00255 
00256 /*     Update left-hand-side vector d = Q'*d = ( d1 ) M */
00257 /*                                             ( d2 ) N-M */
00258 
00259     i__1 = max(1,*n);
00260     i__2 = *lwork - *m - np;
00261     zunmqr_("Left", "Conjugate transpose", n, &c__1, m, &a[a_offset], lda, &
00262             work[1], &d__[1], &i__1, &work[*m + np + 1], &i__2, info);
00263 /* Computing MAX */
00264     i__3 = *m + np + 1;
00265     i__1 = lopt, i__2 = (integer) work[i__3].r;
00266     lopt = max(i__1,i__2);
00267 
00268 /*     Solve T22*y2 = d2 for y2 */
00269 
00270     if (*n > *m) {
00271         i__1 = *n - *m;
00272         i__2 = *n - *m;
00273         ztrtrs_("Upper", "No transpose", "Non unit", &i__1, &c__1, &b[*m + 1 
00274                 + (*m + *p - *n + 1) * b_dim1], ldb, &d__[*m + 1], &i__2, 
00275                 info);
00276 
00277         if (*info > 0) {
00278             *info = 1;
00279             return 0;
00280         }
00281 
00282         i__1 = *n - *m;
00283         zcopy_(&i__1, &d__[*m + 1], &c__1, &y[*m + *p - *n + 1], &c__1);
00284     }
00285 
00286 /*     Set y1 = 0 */
00287 
00288     i__1 = *m + *p - *n;
00289     for (i__ = 1; i__ <= i__1; ++i__) {
00290         i__2 = i__;
00291         y[i__2].r = 0., y[i__2].i = 0.;
00292 /* L10: */
00293     }
00294 
00295 /*     Update d1 = d1 - T12*y2 */
00296 
00297     i__1 = *n - *m;
00298     z__1.r = -1., z__1.i = -0.;
00299     zgemv_("No transpose", m, &i__1, &z__1, &b[(*m + *p - *n + 1) * b_dim1 + 
00300             1], ldb, &y[*m + *p - *n + 1], &c__1, &c_b2, &d__[1], &c__1);
00301 
00302 /*     Solve triangular system: R11*x = d1 */
00303 
00304     if (*m > 0) {
00305         ztrtrs_("Upper", "No Transpose", "Non unit", m, &c__1, &a[a_offset], 
00306                 lda, &d__[1], m, info);
00307 
00308         if (*info > 0) {
00309             *info = 2;
00310             return 0;
00311         }
00312 
00313 /*        Copy D to X */
00314 
00315         zcopy_(m, &d__[1], &c__1, &x[1], &c__1);
00316     }
00317 
00318 /*     Backward transformation y = Z'*y */
00319 
00320 /* Computing MAX */
00321     i__1 = 1, i__2 = *n - *p + 1;
00322     i__3 = max(1,*p);
00323     i__4 = *lwork - *m - np;
00324     zunmrq_("Left", "Conjugate transpose", p, &c__1, &np, &b[max(i__1, i__2)+ 
00325             b_dim1], ldb, &work[*m + 1], &y[1], &i__3, &work[*m + np + 1], &
00326             i__4, info);
00327 /* Computing MAX */
00328     i__4 = *m + np + 1;
00329     i__2 = lopt, i__3 = (integer) work[i__4].r;
00330     i__1 = *m + np + max(i__2,i__3);
00331     work[1].r = (doublereal) i__1, work[1].i = 0.;
00332 
00333     return 0;
00334 
00335 /*     End of ZGGGLM */
00336 
00337 } /* zggglm_ */


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