claqp2.c
Go to the documentation of this file.
00001 /* claqp2.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 claqp2_(integer *m, integer *n, integer *offset, complex 
00021         *a, integer *lda, integer *jpvt, complex *tau, real *vn1, real *vn2, 
00022         complex *work)
00023 {
00024     /* System generated locals */
00025     integer a_dim1, a_offset, i__1, i__2, i__3;
00026     real r__1;
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, 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     integer offpi;
00042     extern /* Subroutine */ int cswap_(integer *, complex *, integer *, 
00043             complex *, integer *);
00044     integer itemp;
00045     extern doublereal scnrm2_(integer *, complex *, integer *);
00046     extern /* Subroutine */ int clarfp_(integer *, complex *, complex *, 
00047             integer *, complex *);
00048     extern doublereal slamch_(char *);
00049     extern integer isamax_(integer *, real *, integer *);
00050 
00051 
00052 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00053 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
00054 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
00055 /*     November 2006 */
00056 
00057 /*     .. Scalar Arguments .. */
00058 /*     .. */
00059 /*     .. Array Arguments .. */
00060 /*     .. */
00061 
00062 /*  Purpose */
00063 /*  ======= */
00064 
00065 /*  CLAQP2 computes a QR factorization with column pivoting of */
00066 /*  the block A(OFFSET+1:M,1:N). */
00067 /*  The block A(1:OFFSET,1:N) is accordingly pivoted, but not factorized. */
00068 
00069 /*  Arguments */
00070 /*  ========= */
00071 
00072 /*  M       (input) INTEGER */
00073 /*          The number of rows of the matrix A. M >= 0. */
00074 
00075 /*  N       (input) INTEGER */
00076 /*          The number of columns of the matrix A. N >= 0. */
00077 
00078 /*  OFFSET  (input) INTEGER */
00079 /*          The number of rows of the matrix A that must be pivoted */
00080 /*          but no factorized. OFFSET >= 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 block A(OFFSET+1:M,1:N) is */
00085 /*          the triangular factor obtained; the elements in block */
00086 /*          A(OFFSET+1:M,1:N) below the diagonal, together with the */
00087 /*          array TAU, represent the orthogonal matrix Q as a product of */
00088 /*          elementary reflectors. Block A(1:OFFSET,1:N) has been */
00089 /*          accordingly pivoted, but no factorized. */
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 array, dimension (min(M,N)) */
00102 /*          The scalar factors of the elementary reflectors. */
00103 
00104 /*  VN1     (input/output) REAL array, dimension (N) */
00105 /*          The vector with the partial column norms. */
00106 
00107 /*  VN2     (input/output) REAL array, dimension (N) */
00108 /*          The vector with the exact column norms. */
00109 
00110 /*  WORK    (workspace) COMPLEX array, dimension (N) */
00111 
00112 /*  Further Details */
00113 /*  =============== */
00114 
00115 /*  Based on contributions by */
00116 /*    G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain */
00117 /*    X. Sun, Computer Science Dept., Duke University, USA */
00118 
00119 /*  Partial column norm updating strategy modified by */
00120 /*    Z. Drmac and Z. Bujanovic, Dept. of Mathematics, */
00121 /*    University of Zagreb, Croatia. */
00122 /*    June 2006. */
00123 /*  For more details see LAPACK Working Note 176. */
00124 /*  ===================================================================== */
00125 
00126 /*     .. Parameters .. */
00127 /*     .. */
00128 /*     .. Local Scalars .. */
00129 /*     .. */
00130 /*     .. External Subroutines .. */
00131 /*     .. */
00132 /*     .. Intrinsic Functions .. */
00133 /*     .. */
00134 /*     .. External Functions .. */
00135 /*     .. */
00136 /*     .. Executable Statements .. */
00137 
00138     /* Parameter adjustments */
00139     a_dim1 = *lda;
00140     a_offset = 1 + a_dim1;
00141     a -= a_offset;
00142     --jpvt;
00143     --tau;
00144     --vn1;
00145     --vn2;
00146     --work;
00147 
00148     /* Function Body */
00149 /* Computing MIN */
00150     i__1 = *m - *offset;
00151     mn = min(i__1,*n);
00152     tol3z = sqrt(slamch_("Epsilon"));
00153 
00154 /*     Compute factorization. */
00155 
00156     i__1 = mn;
00157     for (i__ = 1; i__ <= i__1; ++i__) {
00158 
00159         offpi = *offset + i__;
00160 
00161 /*        Determine ith pivot column and swap if necessary. */
00162 
00163         i__2 = *n - i__ + 1;
00164         pvt = i__ - 1 + isamax_(&i__2, &vn1[i__], &c__1);
00165 
00166         if (pvt != i__) {
00167             cswap_(m, &a[pvt * a_dim1 + 1], &c__1, &a[i__ * a_dim1 + 1], &
00168                     c__1);
00169             itemp = jpvt[pvt];
00170             jpvt[pvt] = jpvt[i__];
00171             jpvt[i__] = itemp;
00172             vn1[pvt] = vn1[i__];
00173             vn2[pvt] = vn2[i__];
00174         }
00175 
00176 /*        Generate elementary reflector H(i). */
00177 
00178         if (offpi < *m) {
00179             i__2 = *m - offpi + 1;
00180             clarfp_(&i__2, &a[offpi + i__ * a_dim1], &a[offpi + 1 + i__ * 
00181                     a_dim1], &c__1, &tau[i__]);
00182         } else {
00183             clarfp_(&c__1, &a[*m + i__ * a_dim1], &a[*m + i__ * a_dim1], &
00184                     c__1, &tau[i__]);
00185         }
00186 
00187         if (i__ < *n) {
00188 
00189 /*           Apply H(i)' to A(offset+i:m,i+1:n) from the left. */
00190 
00191             i__2 = offpi + i__ * a_dim1;
00192             aii.r = a[i__2].r, aii.i = a[i__2].i;
00193             i__2 = offpi + i__ * a_dim1;
00194             a[i__2].r = 1.f, a[i__2].i = 0.f;
00195             i__2 = *m - offpi + 1;
00196             i__3 = *n - i__;
00197             r_cnjg(&q__1, &tau[i__]);
00198             clarf_("Left", &i__2, &i__3, &a[offpi + i__ * a_dim1], &c__1, &
00199                     q__1, &a[offpi + (i__ + 1) * a_dim1], lda, &work[1]);
00200             i__2 = offpi + i__ * a_dim1;
00201             a[i__2].r = aii.r, a[i__2].i = aii.i;
00202         }
00203 
00204 /*        Update partial column norms. */
00205 
00206         i__2 = *n;
00207         for (j = i__ + 1; j <= i__2; ++j) {
00208             if (vn1[j] != 0.f) {
00209 
00210 /*              NOTE: The following 4 lines follow from the analysis in */
00211 /*              Lapack Working Note 176. */
00212 
00213 /* Computing 2nd power */
00214                 r__1 = c_abs(&a[offpi + j * a_dim1]) / vn1[j];
00215                 temp = 1.f - r__1 * r__1;
00216                 temp = dmax(temp,0.f);
00217 /* Computing 2nd power */
00218                 r__1 = vn1[j] / vn2[j];
00219                 temp2 = temp * (r__1 * r__1);
00220                 if (temp2 <= tol3z) {
00221                     if (offpi < *m) {
00222                         i__3 = *m - offpi;
00223                         vn1[j] = scnrm2_(&i__3, &a[offpi + 1 + j * a_dim1], &
00224                                 c__1);
00225                         vn2[j] = vn1[j];
00226                     } else {
00227                         vn1[j] = 0.f;
00228                         vn2[j] = 0.f;
00229                     }
00230                 } else {
00231                     vn1[j] *= sqrt(temp);
00232                 }
00233             }
00234 /* L10: */
00235         }
00236 
00237 /* L20: */
00238     }
00239 
00240     return 0;
00241 
00242 /*     End of CLAQP2 */
00243 
00244 } /* claqp2_ */


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