dqrt12.c
Go to the documentation of this file.
00001 /* dqrt12.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__7 = 7;
00019 static integer c__1 = 1;
00020 static doublereal c_b6 = 0.;
00021 static integer c__0 = 0;
00022 static doublereal c_b33 = -1.;
00023 
00024 doublereal dqrt12_(integer *m, integer *n, doublereal *a, integer *lda, 
00025         doublereal *s, doublereal *work, integer *lwork)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, i__1, i__2;
00029     doublereal ret_val;
00030 
00031     /* Local variables */
00032     integer i__, j, mn, iscl, info;
00033     doublereal anrm;
00034     extern doublereal dnrm2_(integer *, doublereal *, integer *), dasum_(
00035             integer *, doublereal *, integer *);
00036     extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *, 
00037             integer *, doublereal *, integer *), dgebd2_(integer *, integer *, 
00038              doublereal *, integer *, doublereal *, doublereal *, doublereal *
00039 , doublereal *, doublereal *, integer *);
00040     doublereal dummy[1];
00041     extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
00042     extern doublereal dlamch_(char *), dlange_(char *, integer *, 
00043             integer *, doublereal *, integer *, doublereal *);
00044     extern /* Subroutine */ int dlascl_(char *, integer *, integer *, 
00045             doublereal *, doublereal *, integer *, integer *, doublereal *, 
00046             integer *, integer *), dlaset_(char *, integer *, integer 
00047             *, doublereal *, doublereal *, doublereal *, integer *), 
00048             xerbla_(char *, integer *), dbdsqr_(char *, integer *, 
00049             integer *, integer *, integer *, doublereal *, doublereal *, 
00050             doublereal *, integer *, doublereal *, integer *, doublereal *, 
00051             integer *, doublereal *, integer *);
00052     doublereal bignum, smlnum, nrmsvl;
00053 
00054 
00055 /*  -- LAPACK test routine (version 3.1.1) -- */
00056 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00057 /*     January 2007 */
00058 
00059 /*     .. Scalar Arguments .. */
00060 /*     .. */
00061 /*     .. Array Arguments .. */
00062 /*     .. */
00063 
00064 /*  Purpose */
00065 /*  ======= */
00066 
00067 /*  DQRT12 computes the singular values `svlues' of the upper trapezoid */
00068 /*  of A(1:M,1:N) and returns the ratio */
00069 
00070 /*       || s - svlues||/(||svlues||*eps*max(M,N)) */
00071 
00072 /*  Arguments */
00073 /*  ========= */
00074 
00075 /*  M       (input) INTEGER */
00076 /*          The number of rows of the matrix A. */
00077 
00078 /*  N       (input) INTEGER */
00079 /*          The number of columns of the matrix A. */
00080 
00081 /*  A       (input) DOUBLE PRECISION array, dimension (LDA,N) */
00082 /*          The M-by-N matrix A. Only the upper trapezoid is referenced. */
00083 
00084 /*  LDA     (input) INTEGER */
00085 /*          The leading dimension of the array A. */
00086 
00087 /*  S       (input) DOUBLE PRECISION array, dimension (min(M,N)) */
00088 /*          The singular values of the matrix A. */
00089 
00090 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (LWORK) */
00091 
00092 /*  LWORK   (input) INTEGER */
00093 /*          The length of the array WORK. LWORK >= max(M*N + 4*min(M,N) + */
00094 /*          max(M,N), M*N+2*MIN( M, N )+4*N). */
00095 
00096 /*  ===================================================================== */
00097 
00098 /*     .. Parameters .. */
00099 /*     .. */
00100 /*     .. Local Scalars .. */
00101 /*     .. */
00102 /*     .. External Functions .. */
00103 /*     .. */
00104 /*     .. External Subroutines .. */
00105 /*     .. */
00106 /*     .. Intrinsic Functions .. */
00107 /*     .. */
00108 /*     .. Local Arrays .. */
00109 /*     .. */
00110 /*     .. Executable Statements .. */
00111 
00112     /* Parameter adjustments */
00113     a_dim1 = *lda;
00114     a_offset = 1 + a_dim1;
00115     a -= a_offset;
00116     --s;
00117     --work;
00118 
00119     /* Function Body */
00120     ret_val = 0.;
00121 
00122 /*     Test that enough workspace is supplied */
00123 
00124 /* Computing MAX */
00125     i__1 = *m * *n + (min(*m,*n) << 2) + max(*m,*n), i__2 = *m * *n + (min(*m,
00126             *n) << 1) + (*n << 2);
00127     if (*lwork < max(i__1,i__2)) {
00128         xerbla_("DQRT12", &c__7);
00129         return ret_val;
00130     }
00131 
00132 /*     Quick return if possible */
00133 
00134     mn = min(*m,*n);
00135     if ((doublereal) mn <= 0.) {
00136         return ret_val;
00137     }
00138 
00139     nrmsvl = dnrm2_(&mn, &s[1], &c__1);
00140 
00141 /*     Copy upper triangle of A into work */
00142 
00143     dlaset_("Full", m, n, &c_b6, &c_b6, &work[1], m);
00144     i__1 = *n;
00145     for (j = 1; j <= i__1; ++j) {
00146         i__2 = min(j,*m);
00147         for (i__ = 1; i__ <= i__2; ++i__) {
00148             work[(j - 1) * *m + i__] = a[i__ + j * a_dim1];
00149 /* L10: */
00150         }
00151 /* L20: */
00152     }
00153 
00154 /*     Get machine parameters */
00155 
00156     smlnum = dlamch_("S") / dlamch_("P");
00157     bignum = 1. / smlnum;
00158     dlabad_(&smlnum, &bignum);
00159 
00160 /*     Scale work if max entry outside range [SMLNUM,BIGNUM] */
00161 
00162     anrm = dlange_("M", m, n, &work[1], m, dummy);
00163     iscl = 0;
00164     if (anrm > 0. && anrm < smlnum) {
00165 
00166 /*        Scale matrix norm up to SMLNUM */
00167 
00168         dlascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &work[1], m, &info);
00169         iscl = 1;
00170     } else if (anrm > bignum) {
00171 
00172 /*        Scale matrix norm down to BIGNUM */
00173 
00174         dlascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &work[1], m, &info);
00175         iscl = 1;
00176     }
00177 
00178     if (anrm != 0.) {
00179 
00180 /*        Compute SVD of work */
00181 
00182         dgebd2_(m, n, &work[1], m, &work[*m * *n + 1], &work[*m * *n + mn + 1]
00183 , &work[*m * *n + (mn << 1) + 1], &work[*m * *n + mn * 3 + 1], 
00184                  &work[*m * *n + (mn << 2) + 1], &info);
00185         dbdsqr_("Upper", &mn, &c__0, &c__0, &c__0, &work[*m * *n + 1], &work[*
00186                 m * *n + mn + 1], dummy, &mn, dummy, &c__1, dummy, &mn, &work[
00187                 *m * *n + (mn << 1) + 1], &info);
00188 
00189         if (iscl == 1) {
00190             if (anrm > bignum) {
00191                 dlascl_("G", &c__0, &c__0, &bignum, &anrm, &mn, &c__1, &work[*
00192                         m * *n + 1], &mn, &info);
00193             }
00194             if (anrm < smlnum) {
00195                 dlascl_("G", &c__0, &c__0, &smlnum, &anrm, &mn, &c__1, &work[*
00196                         m * *n + 1], &mn, &info);
00197             }
00198         }
00199 
00200     } else {
00201 
00202         i__1 = mn;
00203         for (i__ = 1; i__ <= i__1; ++i__) {
00204             work[*m * *n + i__] = 0.;
00205 /* L30: */
00206         }
00207     }
00208 
00209 /*     Compare s and singular values of work */
00210 
00211     daxpy_(&mn, &c_b33, &s[1], &c__1, &work[*m * *n + 1], &c__1);
00212     ret_val = dasum_(&mn, &work[*m * *n + 1], &c__1) / (dlamch_("Epsilon") * (doublereal) max(*m,*n));
00213     if (nrmsvl != 0.) {
00214         ret_val /= nrmsvl;
00215     }
00216 
00217     return ret_val;
00218 
00219 /*     End of DQRT12 */
00220 
00221 } /* dqrt12_ */


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