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


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