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


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