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


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