cspt03.c
Go to the documentation of this file.
00001 /* cspt03.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__1 = 1;
00019 
00020 /* Subroutine */ int cspt03_(char *uplo, integer *n, complex *a, complex *
00021         ainv, complex *work, integer *ldw, real *rwork, real *rcond, real *
00022         resid)
00023 {
00024     /* System generated locals */
00025     integer work_dim1, work_offset, i__1, i__2, i__3, i__4, i__5;
00026     complex q__1, q__2;
00027 
00028     /* Local variables */
00029     integer i__, j, k;
00030     complex t;
00031     real eps;
00032     integer icol, jcol, kcol, nall;
00033     extern logical lsame_(char *, char *);
00034     real anorm;
00035     extern /* Complex */ VOID cdotu_(complex *, integer *, complex *, integer 
00036             *, complex *, integer *);
00037     extern doublereal clange_(char *, integer *, integer *, complex *, 
00038             integer *, real *), slamch_(char *), clansp_(char 
00039             *, char *, integer *, complex *, real *);
00040     real ainvnm;
00041 
00042 
00043 /*  -- LAPACK test routine (version 3.1) -- */
00044 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00045 /*     November 2006 */
00046 
00047 /*     .. Scalar Arguments .. */
00048 /*     .. */
00049 /*     .. Array Arguments .. */
00050 /*     .. */
00051 
00052 /*  Purpose */
00053 /*  ======= */
00054 
00055 /*  CSPT03 computes the residual for a complex symmetric packed matrix */
00056 /*  times its inverse: */
00057 /*     norm( I - A*AINV ) / ( N * norm(A) * norm(AINV) * EPS ), */
00058 /*  where EPS is the machine epsilon. */
00059 
00060 /*  Arguments */
00061 /*  ========== */
00062 
00063 /*  UPLO    (input) CHARACTER*1 */
00064 /*          Specifies whether the upper or lower triangular part of the */
00065 /*          complex symmetric matrix A is stored: */
00066 /*          = 'U':  Upper triangular */
00067 /*          = 'L':  Lower triangular */
00068 
00069 /*  N       (input) INTEGER */
00070 /*          The number of rows and columns of the matrix A.  N >= 0. */
00071 
00072 /*  A       (input) COMPLEX array, dimension (N*(N+1)/2) */
00073 /*          The original complex symmetric matrix A, stored as a packed */
00074 /*          triangular matrix. */
00075 
00076 /*  AINV    (input) COMPLEX array, dimension (N*(N+1)/2) */
00077 /*          The (symmetric) inverse of the matrix A, stored as a packed */
00078 /*          triangular matrix. */
00079 
00080 /*  WORK    (workspace) COMPLEX array, dimension (LDWORK,N) */
00081 
00082 /*  LDWORK  (input) INTEGER */
00083 /*          The leading dimension of the array WORK.  LDWORK >= max(1,N). */
00084 
00085 /*  RWORK   (workspace) REAL array, dimension (N) */
00086 
00087 /*  RCOND   (output) REAL */
00088 /*          The reciprocal of the condition number of A, computed as */
00089 /*          ( 1/norm(A) ) / norm(AINV). */
00090 
00091 /*  RESID   (output) REAL */
00092 /*          norm(I - A*AINV) / ( N * norm(A) * norm(AINV) * EPS ) */
00093 
00094 /*  ===================================================================== */
00095 
00096 /*     .. Parameters .. */
00097 /*     .. */
00098 /*     .. Local Scalars .. */
00099 /*     .. */
00100 /*     .. External Functions .. */
00101 /*     .. */
00102 /*     .. Intrinsic Functions .. */
00103 /*     .. */
00104 /*     .. Executable Statements .. */
00105 
00106 /*     Quick exit if N = 0. */
00107 
00108     /* Parameter adjustments */
00109     --a;
00110     --ainv;
00111     work_dim1 = *ldw;
00112     work_offset = 1 + work_dim1;
00113     work -= work_offset;
00114     --rwork;
00115 
00116     /* Function Body */
00117     if (*n <= 0) {
00118         *rcond = 1.f;
00119         *resid = 0.f;
00120         return 0;
00121     }
00122 
00123 /*     Exit with RESID = 1/EPS if ANORM = 0 or AINVNM = 0. */
00124 
00125     eps = slamch_("Epsilon");
00126     anorm = clansp_("1", uplo, n, &a[1], &rwork[1]);
00127     ainvnm = clansp_("1", uplo, n, &ainv[1], &rwork[1]);
00128     if (anorm <= 0.f || ainvnm <= 0.f) {
00129         *rcond = 0.f;
00130         *resid = 1.f / eps;
00131         return 0;
00132     }
00133     *rcond = 1.f / anorm / ainvnm;
00134 
00135 /*     Case where both A and AINV are upper triangular: */
00136 /*     Each element of - A * AINV is computed by taking the dot product */
00137 /*     of a row of A with a column of AINV. */
00138 
00139     if (lsame_(uplo, "U")) {
00140         i__1 = *n;
00141         for (i__ = 1; i__ <= i__1; ++i__) {
00142             icol = (i__ - 1) * i__ / 2 + 1;
00143 
00144 /*           Code when J <= I */
00145 
00146             i__2 = i__;
00147             for (j = 1; j <= i__2; ++j) {
00148                 jcol = (j - 1) * j / 2 + 1;
00149                 cdotu_(&q__1, &j, &a[icol], &c__1, &ainv[jcol], &c__1);
00150                 t.r = q__1.r, t.i = q__1.i;
00151                 jcol = jcol + (j << 1) - 1;
00152                 kcol = icol - 1;
00153                 i__3 = i__;
00154                 for (k = j + 1; k <= i__3; ++k) {
00155                     i__4 = kcol + k;
00156                     i__5 = jcol;
00157                     q__2.r = a[i__4].r * ainv[i__5].r - a[i__4].i * ainv[i__5]
00158                             .i, q__2.i = a[i__4].r * ainv[i__5].i + a[i__4].i 
00159                             * ainv[i__5].r;
00160                     q__1.r = t.r + q__2.r, q__1.i = t.i + q__2.i;
00161                     t.r = q__1.r, t.i = q__1.i;
00162                     jcol += k;
00163 /* L10: */
00164                 }
00165                 kcol += i__ << 1;
00166                 i__3 = *n;
00167                 for (k = i__ + 1; k <= i__3; ++k) {
00168                     i__4 = kcol;
00169                     i__5 = jcol;
00170                     q__2.r = a[i__4].r * ainv[i__5].r - a[i__4].i * ainv[i__5]
00171                             .i, q__2.i = a[i__4].r * ainv[i__5].i + a[i__4].i 
00172                             * ainv[i__5].r;
00173                     q__1.r = t.r + q__2.r, q__1.i = t.i + q__2.i;
00174                     t.r = q__1.r, t.i = q__1.i;
00175                     kcol += k;
00176                     jcol += k;
00177 /* L20: */
00178                 }
00179                 i__3 = i__ + j * work_dim1;
00180                 q__1.r = -t.r, q__1.i = -t.i;
00181                 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00182 /* L30: */
00183             }
00184 
00185 /*           Code when J > I */
00186 
00187             i__2 = *n;
00188             for (j = i__ + 1; j <= i__2; ++j) {
00189                 jcol = (j - 1) * j / 2 + 1;
00190                 cdotu_(&q__1, &i__, &a[icol], &c__1, &ainv[jcol], &c__1);
00191                 t.r = q__1.r, t.i = q__1.i;
00192                 --jcol;
00193                 kcol = icol + (i__ << 1) - 1;
00194                 i__3 = j;
00195                 for (k = i__ + 1; k <= i__3; ++k) {
00196                     i__4 = kcol;
00197                     i__5 = jcol + k;
00198                     q__2.r = a[i__4].r * ainv[i__5].r - a[i__4].i * ainv[i__5]
00199                             .i, q__2.i = a[i__4].r * ainv[i__5].i + a[i__4].i 
00200                             * ainv[i__5].r;
00201                     q__1.r = t.r + q__2.r, q__1.i = t.i + q__2.i;
00202                     t.r = q__1.r, t.i = q__1.i;
00203                     kcol += k;
00204 /* L40: */
00205                 }
00206                 jcol += j << 1;
00207                 i__3 = *n;
00208                 for (k = j + 1; k <= i__3; ++k) {
00209                     i__4 = kcol;
00210                     i__5 = jcol;
00211                     q__2.r = a[i__4].r * ainv[i__5].r - a[i__4].i * ainv[i__5]
00212                             .i, q__2.i = a[i__4].r * ainv[i__5].i + a[i__4].i 
00213                             * ainv[i__5].r;
00214                     q__1.r = t.r + q__2.r, q__1.i = t.i + q__2.i;
00215                     t.r = q__1.r, t.i = q__1.i;
00216                     kcol += k;
00217                     jcol += k;
00218 /* L50: */
00219                 }
00220                 i__3 = i__ + j * work_dim1;
00221                 q__1.r = -t.r, q__1.i = -t.i;
00222                 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00223 /* L60: */
00224             }
00225 /* L70: */
00226         }
00227     } else {
00228 
00229 /*        Case where both A and AINV are lower triangular */
00230 
00231         nall = *n * (*n + 1) / 2;
00232         i__1 = *n;
00233         for (i__ = 1; i__ <= i__1; ++i__) {
00234 
00235 /*           Code when J <= I */
00236 
00237             icol = nall - (*n - i__ + 1) * (*n - i__ + 2) / 2 + 1;
00238             i__2 = i__;
00239             for (j = 1; j <= i__2; ++j) {
00240                 jcol = nall - (*n - j) * (*n - j + 1) / 2 - (*n - i__);
00241                 i__3 = *n - i__ + 1;
00242                 cdotu_(&q__1, &i__3, &a[icol], &c__1, &ainv[jcol], &c__1);
00243                 t.r = q__1.r, t.i = q__1.i;
00244                 kcol = i__;
00245                 jcol = j;
00246                 i__3 = j - 1;
00247                 for (k = 1; k <= i__3; ++k) {
00248                     i__4 = kcol;
00249                     i__5 = jcol;
00250                     q__2.r = a[i__4].r * ainv[i__5].r - a[i__4].i * ainv[i__5]
00251                             .i, q__2.i = a[i__4].r * ainv[i__5].i + a[i__4].i 
00252                             * ainv[i__5].r;
00253                     q__1.r = t.r + q__2.r, q__1.i = t.i + q__2.i;
00254                     t.r = q__1.r, t.i = q__1.i;
00255                     jcol = jcol + *n - k;
00256                     kcol = kcol + *n - k;
00257 /* L80: */
00258                 }
00259                 jcol -= j;
00260                 i__3 = i__ - 1;
00261                 for (k = j; k <= i__3; ++k) {
00262                     i__4 = kcol;
00263                     i__5 = jcol + k;
00264                     q__2.r = a[i__4].r * ainv[i__5].r - a[i__4].i * ainv[i__5]
00265                             .i, q__2.i = a[i__4].r * ainv[i__5].i + a[i__4].i 
00266                             * ainv[i__5].r;
00267                     q__1.r = t.r + q__2.r, q__1.i = t.i + q__2.i;
00268                     t.r = q__1.r, t.i = q__1.i;
00269                     kcol = kcol + *n - k;
00270 /* L90: */
00271                 }
00272                 i__3 = i__ + j * work_dim1;
00273                 q__1.r = -t.r, q__1.i = -t.i;
00274                 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00275 /* L100: */
00276             }
00277 
00278 /*           Code when J > I */
00279 
00280             icol = nall - (*n - i__) * (*n - i__ + 1) / 2;
00281             i__2 = *n;
00282             for (j = i__ + 1; j <= i__2; ++j) {
00283                 jcol = nall - (*n - j + 1) * (*n - j + 2) / 2 + 1;
00284                 i__3 = *n - j + 1;
00285                 cdotu_(&q__1, &i__3, &a[icol - *n + j], &c__1, &ainv[jcol], &
00286                         c__1);
00287                 t.r = q__1.r, t.i = q__1.i;
00288                 kcol = i__;
00289                 jcol = j;
00290                 i__3 = i__ - 1;
00291                 for (k = 1; k <= i__3; ++k) {
00292                     i__4 = kcol;
00293                     i__5 = jcol;
00294                     q__2.r = a[i__4].r * ainv[i__5].r - a[i__4].i * ainv[i__5]
00295                             .i, q__2.i = a[i__4].r * ainv[i__5].i + a[i__4].i 
00296                             * ainv[i__5].r;
00297                     q__1.r = t.r + q__2.r, q__1.i = t.i + q__2.i;
00298                     t.r = q__1.r, t.i = q__1.i;
00299                     jcol = jcol + *n - k;
00300                     kcol = kcol + *n - k;
00301 /* L110: */
00302                 }
00303                 kcol -= i__;
00304                 i__3 = j - 1;
00305                 for (k = i__; k <= i__3; ++k) {
00306                     i__4 = kcol + k;
00307                     i__5 = jcol;
00308                     q__2.r = a[i__4].r * ainv[i__5].r - a[i__4].i * ainv[i__5]
00309                             .i, q__2.i = a[i__4].r * ainv[i__5].i + a[i__4].i 
00310                             * ainv[i__5].r;
00311                     q__1.r = t.r + q__2.r, q__1.i = t.i + q__2.i;
00312                     t.r = q__1.r, t.i = q__1.i;
00313                     jcol = jcol + *n - k;
00314 /* L120: */
00315                 }
00316                 i__3 = i__ + j * work_dim1;
00317                 q__1.r = -t.r, q__1.i = -t.i;
00318                 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00319 /* L130: */
00320             }
00321 /* L140: */
00322         }
00323     }
00324 
00325 /*     Add the identity matrix to WORK . */
00326 
00327     i__1 = *n;
00328     for (i__ = 1; i__ <= i__1; ++i__) {
00329         i__2 = i__ + i__ * work_dim1;
00330         i__3 = i__ + i__ * work_dim1;
00331         q__1.r = work[i__3].r + 1.f, q__1.i = work[i__3].i;
00332         work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00333 /* L150: */
00334     }
00335 
00336 /*     Compute norm(I - A*AINV) / (N * norm(A) * norm(AINV) * EPS) */
00337 
00338     *resid = clange_("1", n, n, &work[work_offset], ldw, &rwork[1])
00339             ;
00340 
00341     *resid = *resid * *rcond / eps / (real) (*n);
00342 
00343     return 0;
00344 
00345 /*     End of CSPT03 */
00346 
00347 } /* cspt03_ */


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