cungr2.c
Go to the documentation of this file.
00001 /* cungr2.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 /* Subroutine */ int cungr2_(integer *m, integer *n, integer *k, complex *a, 
00017         integer *lda, complex *tau, complex *work, integer *info)
00018 {
00019     /* System generated locals */
00020     integer a_dim1, a_offset, i__1, i__2, i__3;
00021     complex q__1, q__2;
00022 
00023     /* Builtin functions */
00024     void r_cnjg(complex *, complex *);
00025 
00026     /* Local variables */
00027     integer i__, j, l, ii;
00028     extern /* Subroutine */ int cscal_(integer *, complex *, complex *, 
00029             integer *), clarf_(char *, integer *, integer *, complex *, 
00030             integer *, complex *, complex *, integer *, complex *), 
00031             clacgv_(integer *, complex *, integer *), xerbla_(char *, integer 
00032             *);
00033 
00034 
00035 /*  -- LAPACK routine (version 3.2) -- */
00036 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00037 /*     November 2006 */
00038 
00039 /*     .. Scalar Arguments .. */
00040 /*     .. */
00041 /*     .. Array Arguments .. */
00042 /*     .. */
00043 
00044 /*  Purpose */
00045 /*  ======= */
00046 
00047 /*  CUNGR2 generates an m by n complex matrix Q with orthonormal rows, */
00048 /*  which is defined as the last m rows of a product of k elementary */
00049 /*  reflectors of order n */
00050 
00051 /*        Q  =  H(1)' H(2)' . . . H(k)' */
00052 
00053 /*  as returned by CGERQF. */
00054 
00055 /*  Arguments */
00056 /*  ========= */
00057 
00058 /*  M       (input) INTEGER */
00059 /*          The number of rows of the matrix Q. M >= 0. */
00060 
00061 /*  N       (input) INTEGER */
00062 /*          The number of columns of the matrix Q. N >= M. */
00063 
00064 /*  K       (input) INTEGER */
00065 /*          The number of elementary reflectors whose product defines the */
00066 /*          matrix Q. M >= K >= 0. */
00067 
00068 /*  A       (input/output) COMPLEX array, dimension (LDA,N) */
00069 /*          On entry, the (m-k+i)-th row must contain the vector which */
00070 /*          defines the elementary reflector H(i), for i = 1,2,...,k, as */
00071 /*          returned by CGERQF in the last k rows of its array argument */
00072 /*          A. */
00073 /*          On exit, the m-by-n matrix Q. */
00074 
00075 /*  LDA     (input) INTEGER */
00076 /*          The first dimension of the array A. LDA >= max(1,M). */
00077 
00078 /*  TAU     (input) COMPLEX array, dimension (K) */
00079 /*          TAU(i) must contain the scalar factor of the elementary */
00080 /*          reflector H(i), as returned by CGERQF. */
00081 
00082 /*  WORK    (workspace) COMPLEX array, dimension (M) */
00083 
00084 /*  INFO    (output) INTEGER */
00085 /*          = 0: successful exit */
00086 /*          < 0: if INFO = -i, the i-th argument has an illegal value */
00087 
00088 /*  ===================================================================== */
00089 
00090 /*     .. Parameters .. */
00091 /*     .. */
00092 /*     .. Local Scalars .. */
00093 /*     .. */
00094 /*     .. External Subroutines .. */
00095 /*     .. */
00096 /*     .. Intrinsic Functions .. */
00097 /*     .. */
00098 /*     .. Executable Statements .. */
00099 
00100 /*     Test the input arguments */
00101 
00102     /* Parameter adjustments */
00103     a_dim1 = *lda;
00104     a_offset = 1 + a_dim1;
00105     a -= a_offset;
00106     --tau;
00107     --work;
00108 
00109     /* Function Body */
00110     *info = 0;
00111     if (*m < 0) {
00112         *info = -1;
00113     } else if (*n < *m) {
00114         *info = -2;
00115     } else if (*k < 0 || *k > *m) {
00116         *info = -3;
00117     } else if (*lda < max(1,*m)) {
00118         *info = -5;
00119     }
00120     if (*info != 0) {
00121         i__1 = -(*info);
00122         xerbla_("CUNGR2", &i__1);
00123         return 0;
00124     }
00125 
00126 /*     Quick return if possible */
00127 
00128     if (*m <= 0) {
00129         return 0;
00130     }
00131 
00132     if (*k < *m) {
00133 
00134 /*        Initialise rows 1:m-k to rows of the unit matrix */
00135 
00136         i__1 = *n;
00137         for (j = 1; j <= i__1; ++j) {
00138             i__2 = *m - *k;
00139             for (l = 1; l <= i__2; ++l) {
00140                 i__3 = l + j * a_dim1;
00141                 a[i__3].r = 0.f, a[i__3].i = 0.f;
00142 /* L10: */
00143             }
00144             if (j > *n - *m && j <= *n - *k) {
00145                 i__2 = *m - *n + j + j * a_dim1;
00146                 a[i__2].r = 1.f, a[i__2].i = 0.f;
00147             }
00148 /* L20: */
00149         }
00150     }
00151 
00152     i__1 = *k;
00153     for (i__ = 1; i__ <= i__1; ++i__) {
00154         ii = *m - *k + i__;
00155 
00156 /*        Apply H(i)' to A(1:m-k+i,1:n-k+i) from the right */
00157 
00158         i__2 = *n - *m + ii - 1;
00159         clacgv_(&i__2, &a[ii + a_dim1], lda);
00160         i__2 = ii + (*n - *m + ii) * a_dim1;
00161         a[i__2].r = 1.f, a[i__2].i = 0.f;
00162         i__2 = ii - 1;
00163         i__3 = *n - *m + ii;
00164         r_cnjg(&q__1, &tau[i__]);
00165         clarf_("Right", &i__2, &i__3, &a[ii + a_dim1], lda, &q__1, &a[
00166                 a_offset], lda, &work[1]);
00167         i__2 = *n - *m + ii - 1;
00168         i__3 = i__;
00169         q__1.r = -tau[i__3].r, q__1.i = -tau[i__3].i;
00170         cscal_(&i__2, &q__1, &a[ii + a_dim1], lda);
00171         i__2 = *n - *m + ii - 1;
00172         clacgv_(&i__2, &a[ii + a_dim1], lda);
00173         i__2 = ii + (*n - *m + ii) * a_dim1;
00174         r_cnjg(&q__2, &tau[i__]);
00175         q__1.r = 1.f - q__2.r, q__1.i = 0.f - q__2.i;
00176         a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00177 
00178 /*        Set A(m-k+i,n-k+i+1:n) to zero */
00179 
00180         i__2 = *n;
00181         for (l = *n - *m + ii + 1; l <= i__2; ++l) {
00182             i__3 = ii + l * a_dim1;
00183             a[i__3].r = 0.f, a[i__3].i = 0.f;
00184 /* L30: */
00185         }
00186 /* L40: */
00187     }
00188     return 0;
00189 
00190 /*     End of CUNGR2 */
00191 
00192 } /* cungr2_ */


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