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


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