zgeqpf.c
Go to the documentation of this file.
00001 /* zgeqpf.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 integer c__1 = 1;
00019 
00020 /* Subroutine */ int zgeqpf_(integer *m, integer *n, doublecomplex *a, 
00021         integer *lda, integer *jpvt, doublecomplex *tau, doublecomplex *work, 
00022         doublereal *rwork, integer *info)
00023 {
00024     /* System generated locals */
00025     integer a_dim1, a_offset, i__1, i__2, i__3;
00026     doublereal d__1, d__2;
00027     doublecomplex z__1;
00028 
00029     /* Builtin functions */
00030     double sqrt(doublereal);
00031     void d_cnjg(doublecomplex *, doublecomplex *);
00032     double z_abs(doublecomplex *);
00033 
00034     /* Local variables */
00035     integer i__, j, ma, mn;
00036     doublecomplex aii;
00037     integer pvt;
00038     doublereal temp, temp2, tol3z;
00039     integer itemp;
00040     extern /* Subroutine */ int zlarf_(char *, integer *, integer *, 
00041             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00042             integer *, doublecomplex *), zswap_(integer *, 
00043             doublecomplex *, integer *, doublecomplex *, integer *), zgeqr2_(
00044             integer *, integer *, doublecomplex *, integer *, doublecomplex *, 
00045              doublecomplex *, integer *);
00046     extern doublereal dznrm2_(integer *, doublecomplex *, integer *), dlamch_(
00047             char *);
00048     extern /* Subroutine */ int zunm2r_(char *, char *, integer *, integer *, 
00049             integer *, doublecomplex *, integer *, doublecomplex *, 
00050             doublecomplex *, integer *, doublecomplex *, integer *);
00051     extern integer idamax_(integer *, doublereal *, integer *);
00052     extern /* Subroutine */ int xerbla_(char *, integer *), zlarfp_(
00053             integer *, doublecomplex *, doublecomplex *, integer *, 
00054             doublecomplex *);
00055 
00056 
00057 /*  -- LAPACK deprecated driver routine (version 3.2) -- */
00058 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00059 /*     November 2006 */
00060 
00061 /*     .. Scalar Arguments .. */
00062 /*     .. */
00063 /*     .. Array Arguments .. */
00064 /*     .. */
00065 
00066 /*  Purpose */
00067 /*  ======= */
00068 
00069 /*  This routine is deprecated and has been replaced by routine ZGEQP3. */
00070 
00071 /*  ZGEQPF computes a QR factorization with column pivoting of a */
00072 /*  complex M-by-N matrix A: A*P = Q*R. */
00073 
00074 /*  Arguments */
00075 /*  ========= */
00076 
00077 /*  M       (input) INTEGER */
00078 /*          The number of rows of the matrix A. M >= 0. */
00079 
00080 /*  N       (input) INTEGER */
00081 /*          The number of columns of the matrix A. N >= 0 */
00082 
00083 /*  A       (input/output) COMPLEX*16 array, dimension (LDA,N) */
00084 /*          On entry, the M-by-N matrix A. */
00085 /*          On exit, the upper triangle of the array contains the */
00086 /*          min(M,N)-by-N upper triangular matrix R; the elements */
00087 /*          below the diagonal, together with the array TAU, */
00088 /*          represent the unitary matrix Q as a product of */
00089 /*          min(m,n) elementary reflectors. */
00090 
00091 /*  LDA     (input) INTEGER */
00092 /*          The leading dimension of the array A. LDA >= max(1,M). */
00093 
00094 /*  JPVT    (input/output) INTEGER array, dimension (N) */
00095 /*          On entry, if JPVT(i) .ne. 0, the i-th column of A is permuted */
00096 /*          to the front of A*P (a leading column); if JPVT(i) = 0, */
00097 /*          the i-th column of A is a free column. */
00098 /*          On exit, if JPVT(i) = k, then the i-th column of A*P */
00099 /*          was the k-th column of A. */
00100 
00101 /*  TAU     (output) COMPLEX*16 array, dimension (min(M,N)) */
00102 /*          The scalar factors of the elementary reflectors. */
00103 
00104 /*  WORK    (workspace) COMPLEX*16 array, dimension (N) */
00105 
00106 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (2*N) */
00107 
00108 /*  INFO    (output) INTEGER */
00109 /*          = 0:  successful exit */
00110 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00111 
00112 /*  Further Details */
00113 /*  =============== */
00114 
00115 /*  The matrix Q is represented as a product of elementary reflectors */
00116 
00117 /*     Q = H(1) H(2) . . . H(n) */
00118 
00119 /*  Each H(i) has the form */
00120 
00121 /*     H = I - tau * v * v' */
00122 
00123 /*  where tau is a complex scalar, and v is a complex vector with */
00124 /*  v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i). */
00125 
00126 /*  The matrix P is represented in jpvt as follows: If */
00127 /*     jpvt(j) = i */
00128 /*  then the jth column of P is the ith canonical unit vector. */
00129 
00130 /*  Partial column norm updating strategy modified by */
00131 /*    Z. Drmac and Z. Bujanovic, Dept. of Mathematics, */
00132 /*    University of Zagreb, Croatia. */
00133 /*    June 2006. */
00134 /*  For more details see LAPACK Working Note 176. */
00135 
00136 /*  ===================================================================== */
00137 
00138 /*     .. Parameters .. */
00139 /*     .. */
00140 /*     .. Local Scalars .. */
00141 /*     .. */
00142 /*     .. External Subroutines .. */
00143 /*     .. */
00144 /*     .. Intrinsic Functions .. */
00145 /*     .. */
00146 /*     .. External Functions .. */
00147 /*     .. */
00148 /*     .. Executable Statements .. */
00149 
00150 /*     Test the input arguments */
00151 
00152     /* Parameter adjustments */
00153     a_dim1 = *lda;
00154     a_offset = 1 + a_dim1;
00155     a -= a_offset;
00156     --jpvt;
00157     --tau;
00158     --work;
00159     --rwork;
00160 
00161     /* Function Body */
00162     *info = 0;
00163     if (*m < 0) {
00164         *info = -1;
00165     } else if (*n < 0) {
00166         *info = -2;
00167     } else if (*lda < max(1,*m)) {
00168         *info = -4;
00169     }
00170     if (*info != 0) {
00171         i__1 = -(*info);
00172         xerbla_("ZGEQPF", &i__1);
00173         return 0;
00174     }
00175 
00176     mn = min(*m,*n);
00177     tol3z = sqrt(dlamch_("Epsilon"));
00178 
00179 /*     Move initial columns up front */
00180 
00181     itemp = 1;
00182     i__1 = *n;
00183     for (i__ = 1; i__ <= i__1; ++i__) {
00184         if (jpvt[i__] != 0) {
00185             if (i__ != itemp) {
00186                 zswap_(m, &a[i__ * a_dim1 + 1], &c__1, &a[itemp * a_dim1 + 1], 
00187                          &c__1);
00188                 jpvt[i__] = jpvt[itemp];
00189                 jpvt[itemp] = i__;
00190             } else {
00191                 jpvt[i__] = i__;
00192             }
00193             ++itemp;
00194         } else {
00195             jpvt[i__] = i__;
00196         }
00197 /* L10: */
00198     }
00199     --itemp;
00200 
00201 /*     Compute the QR factorization and update remaining columns */
00202 
00203     if (itemp > 0) {
00204         ma = min(itemp,*m);
00205         zgeqr2_(m, &ma, &a[a_offset], lda, &tau[1], &work[1], info);
00206         if (ma < *n) {
00207             i__1 = *n - ma;
00208             zunm2r_("Left", "Conjugate transpose", m, &i__1, &ma, &a[a_offset]
00209 , lda, &tau[1], &a[(ma + 1) * a_dim1 + 1], lda, &work[1], 
00210                     info);
00211         }
00212     }
00213 
00214     if (itemp < mn) {
00215 
00216 /*        Initialize partial column norms. The first n elements of */
00217 /*        work store the exact column norms. */
00218 
00219         i__1 = *n;
00220         for (i__ = itemp + 1; i__ <= i__1; ++i__) {
00221             i__2 = *m - itemp;
00222             rwork[i__] = dznrm2_(&i__2, &a[itemp + 1 + i__ * a_dim1], &c__1);
00223             rwork[*n + i__] = rwork[i__];
00224 /* L20: */
00225         }
00226 
00227 /*        Compute factorization */
00228 
00229         i__1 = mn;
00230         for (i__ = itemp + 1; i__ <= i__1; ++i__) {
00231 
00232 /*           Determine ith pivot column and swap if necessary */
00233 
00234             i__2 = *n - i__ + 1;
00235             pvt = i__ - 1 + idamax_(&i__2, &rwork[i__], &c__1);
00236 
00237             if (pvt != i__) {
00238                 zswap_(m, &a[pvt * a_dim1 + 1], &c__1, &a[i__ * a_dim1 + 1], &
00239                         c__1);
00240                 itemp = jpvt[pvt];
00241                 jpvt[pvt] = jpvt[i__];
00242                 jpvt[i__] = itemp;
00243                 rwork[pvt] = rwork[i__];
00244                 rwork[*n + pvt] = rwork[*n + i__];
00245             }
00246 
00247 /*           Generate elementary reflector H(i) */
00248 
00249             i__2 = i__ + i__ * a_dim1;
00250             aii.r = a[i__2].r, aii.i = a[i__2].i;
00251             i__2 = *m - i__ + 1;
00252 /* Computing MIN */
00253             i__3 = i__ + 1;
00254             zlarfp_(&i__2, &aii, &a[min(i__3, *m)+ i__ * a_dim1], &c__1, &tau[
00255                     i__]);
00256             i__2 = i__ + i__ * a_dim1;
00257             a[i__2].r = aii.r, a[i__2].i = aii.i;
00258 
00259             if (i__ < *n) {
00260 
00261 /*              Apply H(i) to A(i:m,i+1:n) from the left */
00262 
00263                 i__2 = i__ + i__ * a_dim1;
00264                 aii.r = a[i__2].r, aii.i = a[i__2].i;
00265                 i__2 = i__ + i__ * a_dim1;
00266                 a[i__2].r = 1., a[i__2].i = 0.;
00267                 i__2 = *m - i__ + 1;
00268                 i__3 = *n - i__;
00269                 d_cnjg(&z__1, &tau[i__]);
00270                 zlarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &
00271                         z__1, &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]);
00272                 i__2 = i__ + i__ * a_dim1;
00273                 a[i__2].r = aii.r, a[i__2].i = aii.i;
00274             }
00275 
00276 /*           Update partial column norms */
00277 
00278             i__2 = *n;
00279             for (j = i__ + 1; j <= i__2; ++j) {
00280                 if (rwork[j] != 0.) {
00281 
00282 /*                 NOTE: The following 4 lines follow from the analysis in */
00283 /*                 Lapack Working Note 176. */
00284 
00285                     temp = z_abs(&a[i__ + j * a_dim1]) / rwork[j];
00286 /* Computing MAX */
00287                     d__1 = 0., d__2 = (temp + 1.) * (1. - temp);
00288                     temp = max(d__1,d__2);
00289 /* Computing 2nd power */
00290                     d__1 = rwork[j] / rwork[*n + j];
00291                     temp2 = temp * (d__1 * d__1);
00292                     if (temp2 <= tol3z) {
00293                         if (*m - i__ > 0) {
00294                             i__3 = *m - i__;
00295                             rwork[j] = dznrm2_(&i__3, &a[i__ + 1 + j * a_dim1]
00296 , &c__1);
00297                             rwork[*n + j] = rwork[j];
00298                         } else {
00299                             rwork[j] = 0.;
00300                             rwork[*n + j] = 0.;
00301                         }
00302                     } else {
00303                         rwork[j] *= sqrt(temp);
00304                     }
00305                 }
00306 /* L30: */
00307             }
00308 
00309 /* L40: */
00310         }
00311     }
00312     return 0;
00313 
00314 /*     End of ZGEQPF */
00315 
00316 } /* zgeqpf_ */


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