cqrt14.c
Go to the documentation of this file.
00001 /* cqrt14.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__10 = 10;
00019 static integer c__1 = 1;
00020 static integer c__0 = 0;
00021 static real c_b15 = 1.f;
00022 
00023 doublereal cqrt14_(char *trans, integer *m, integer *n, integer *nrhs, 
00024         complex *a, integer *lda, complex *x, integer *ldx, complex *work, 
00025         integer *lwork)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, x_dim1, x_offset, i__1, i__2, i__3;
00029     real ret_val, r__1, r__2;
00030     complex q__1;
00031 
00032     /* Builtin functions */
00033     double c_abs(complex *);
00034     void r_cnjg(complex *, complex *);
00035 
00036     /* Local variables */
00037     integer i__, j;
00038     real err;
00039     integer info;
00040     real anrm;
00041     logical tpsd;
00042     real xnrm;
00043     extern logical lsame_(char *, char *);
00044     real rwork[1];
00045     extern /* Subroutine */ int cgelq2_(integer *, integer *, complex *, 
00046             integer *, complex *, complex *, integer *), cgeqr2_(integer *, 
00047             integer *, complex *, integer *, complex *, complex *, integer *);
00048     extern doublereal clange_(char *, integer *, integer *, complex *, 
00049             integer *, real *);
00050     extern /* Subroutine */ int clascl_(char *, integer *, integer *, real *, 
00051             real *, integer *, integer *, complex *, integer *, integer *);
00052     extern doublereal slamch_(char *);
00053     extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex 
00054             *, integer *, complex *, integer *), xerbla_(char *, 
00055             integer *);
00056     integer ldwork;
00057 
00058 
00059 /*  -- LAPACK test routine (version 3.1) -- */
00060 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00061 /*     November 2006 */
00062 
00063 /*     .. Scalar Arguments .. */
00064 /*     .. */
00065 /*     .. Array Arguments .. */
00066 /*     .. */
00067 
00068 /*  Purpose */
00069 /*  ======= */
00070 
00071 /*  CQRT14 checks whether X is in the row space of A or A'.  It does so */
00072 /*  by scaling both X and A such that their norms are in the range */
00073 /*  [sqrt(eps), 1/sqrt(eps)], then computing a QR factorization of [A,X] */
00074 /*  (if TRANS = 'C') or an LQ factorization of [A',X]' (if TRANS = 'N'), */
00075 /*  and returning the norm of the trailing triangle, scaled by */
00076 /*  MAX(M,N,NRHS)*eps. */
00077 
00078 /*  Arguments */
00079 /*  ========= */
00080 
00081 /*  TRANS   (input) CHARACTER*1 */
00082 /*          = 'N':  No transpose, check for X in the row space of A */
00083 /*          = 'C':  Conjugate transpose, check for X in row space of A'. */
00084 
00085 /*  M       (input) INTEGER */
00086 /*          The number of rows of the matrix A. */
00087 
00088 /*  N       (input) INTEGER */
00089 /*          The number of columns of the matrix A. */
00090 
00091 /*  NRHS    (input) INTEGER */
00092 /*          The number of right hand sides, i.e., the number of columns */
00093 /*          of X. */
00094 
00095 /*  A       (input) COMPLEX array, dimension (LDA,N) */
00096 /*          The M-by-N matrix A. */
00097 
00098 /*  LDA     (input) INTEGER */
00099 /*          The leading dimension of the array A. */
00100 
00101 /*  X       (input) COMPLEX array, dimension (LDX,NRHS) */
00102 /*          If TRANS = 'N', the N-by-NRHS matrix X. */
00103 /*          IF TRANS = 'C', the M-by-NRHS matrix X. */
00104 
00105 /*  LDX     (input) INTEGER */
00106 /*          The leading dimension of the array X. */
00107 
00108 /*  WORK    (workspace) COMPLEX array dimension (LWORK) */
00109 
00110 /*  LWORK   (input) INTEGER */
00111 /*          length of workspace array required */
00112 /*          If TRANS = 'N', LWORK >= (M+NRHS)*(N+2); */
00113 /*          if TRANS = 'C', LWORK >= (N+NRHS)*(M+2). */
00114 
00115 /*  ===================================================================== */
00116 
00117 /*     .. Parameters .. */
00118 /*     .. */
00119 /*     .. Local Scalars .. */
00120 /*     .. */
00121 /*     .. Local Arrays .. */
00122 /*     .. */
00123 /*     .. External Functions .. */
00124 /*     .. */
00125 /*     .. External Subroutines .. */
00126 /*     .. */
00127 /*     .. Intrinsic Functions .. */
00128 /*     .. */
00129 /*     .. Executable Statements .. */
00130 
00131     /* Parameter adjustments */
00132     a_dim1 = *lda;
00133     a_offset = 1 + a_dim1;
00134     a -= a_offset;
00135     x_dim1 = *ldx;
00136     x_offset = 1 + x_dim1;
00137     x -= x_offset;
00138     --work;
00139 
00140     /* Function Body */
00141     ret_val = 0.f;
00142     if (lsame_(trans, "N")) {
00143         ldwork = *m + *nrhs;
00144         tpsd = FALSE_;
00145         if (*lwork < (*m + *nrhs) * (*n + 2)) {
00146             xerbla_("CQRT14", &c__10);
00147             return ret_val;
00148         } else if (*n <= 0 || *nrhs <= 0) {
00149             return ret_val;
00150         }
00151     } else if (lsame_(trans, "C")) {
00152         ldwork = *m;
00153         tpsd = TRUE_;
00154         if (*lwork < (*n + *nrhs) * (*m + 2)) {
00155             xerbla_("CQRT14", &c__10);
00156             return ret_val;
00157         } else if (*m <= 0 || *nrhs <= 0) {
00158             return ret_val;
00159         }
00160     } else {
00161         xerbla_("CQRT14", &c__1);
00162         return ret_val;
00163     }
00164 
00165 /*     Copy and scale A */
00166 
00167     clacpy_("All", m, n, &a[a_offset], lda, &work[1], &ldwork);
00168     anrm = clange_("M", m, n, &work[1], &ldwork, rwork);
00169     if (anrm != 0.f) {
00170         clascl_("G", &c__0, &c__0, &anrm, &c_b15, m, n, &work[1], &ldwork, &
00171                 info);
00172     }
00173 
00174 /*     Copy X or X' into the right place and scale it */
00175 
00176     if (tpsd) {
00177 
00178 /*        Copy X into columns n+1:n+nrhs of work */
00179 
00180         clacpy_("All", m, nrhs, &x[x_offset], ldx, &work[*n * ldwork + 1], &
00181                 ldwork);
00182         xnrm = clange_("M", m, nrhs, &work[*n * ldwork + 1], &ldwork, rwork);
00183         if (xnrm != 0.f) {
00184             clascl_("G", &c__0, &c__0, &xnrm, &c_b15, m, nrhs, &work[*n * 
00185                     ldwork + 1], &ldwork, &info);
00186         }
00187         i__1 = *n + *nrhs;
00188         anrm = clange_("One-norm", m, &i__1, &work[1], &ldwork, rwork);
00189 
00190 /*        Compute QR factorization of X */
00191 
00192         i__1 = *n + *nrhs;
00193 /* Computing MIN */
00194         i__2 = *m, i__3 = *n + *nrhs;
00195         cgeqr2_(m, &i__1, &work[1], &ldwork, &work[ldwork * (*n + *nrhs) + 1], 
00196                  &work[ldwork * (*n + *nrhs) + min(i__2, i__3)+ 1], &info);
00197 
00198 /*        Compute largest entry in upper triangle of */
00199 /*        work(n+1:m,n+1:n+nrhs) */
00200 
00201         err = 0.f;
00202         i__1 = *n + *nrhs;
00203         for (j = *n + 1; j <= i__1; ++j) {
00204             i__2 = min(*m,j);
00205             for (i__ = *n + 1; i__ <= i__2; ++i__) {
00206 /* Computing MAX */
00207                 r__1 = err, r__2 = c_abs(&work[i__ + (j - 1) * *m]);
00208                 err = dmax(r__1,r__2);
00209 /* L10: */
00210             }
00211 /* L20: */
00212         }
00213 
00214     } else {
00215 
00216 /*        Copy X' into rows m+1:m+nrhs of work */
00217 
00218         i__1 = *n;
00219         for (i__ = 1; i__ <= i__1; ++i__) {
00220             i__2 = *nrhs;
00221             for (j = 1; j <= i__2; ++j) {
00222                 i__3 = *m + j + (i__ - 1) * ldwork;
00223                 r_cnjg(&q__1, &x[i__ + j * x_dim1]);
00224                 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00225 /* L30: */
00226             }
00227 /* L40: */
00228         }
00229 
00230         xnrm = clange_("M", nrhs, n, &work[*m + 1], &ldwork, rwork)
00231                 ;
00232         if (xnrm != 0.f) {
00233             clascl_("G", &c__0, &c__0, &xnrm, &c_b15, nrhs, n, &work[*m + 1], 
00234                     &ldwork, &info);
00235         }
00236 
00237 /*        Compute LQ factorization of work */
00238 
00239         cgelq2_(&ldwork, n, &work[1], &ldwork, &work[ldwork * *n + 1], &work[
00240                 ldwork * (*n + 1) + 1], &info);
00241 
00242 /*        Compute largest entry in lower triangle in */
00243 /*        work(m+1:m+nrhs,m+1:n) */
00244 
00245         err = 0.f;
00246         i__1 = *n;
00247         for (j = *m + 1; j <= i__1; ++j) {
00248             i__2 = ldwork;
00249             for (i__ = j; i__ <= i__2; ++i__) {
00250 /* Computing MAX */
00251                 r__1 = err, r__2 = c_abs(&work[i__ + (j - 1) * ldwork]);
00252                 err = dmax(r__1,r__2);
00253 /* L50: */
00254             }
00255 /* L60: */
00256         }
00257 
00258     }
00259 
00260 /* Computing MAX */
00261     i__1 = max(*m,*n);
00262     ret_val = err / ((real) max(i__1,*nrhs) * slamch_("Epsilon"));
00263 
00264     return ret_val;
00265 
00266 /*     End of CQRT14 */
00267 
00268 } /* cqrt14_ */


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