clattr.c
Go to the documentation of this file.
00001 /* clattr.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__5 = 5;
00019 static integer c__2 = 2;
00020 static integer c__1 = 1;
00021 static integer c__4 = 4;
00022 static real c_b92 = 2.f;
00023 static integer c_n1 = -1;
00024 
00025 /* Subroutine */ int clattr_(integer *imat, char *uplo, char *trans, char *
00026         diag, integer *iseed, integer *n, complex *a, integer *lda, complex *
00027         b, complex *work, real *rwork, integer *info)
00028 {
00029     /* System generated locals */
00030     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
00031     real r__1, r__2;
00032     doublereal d__1, d__2;
00033     complex q__1, q__2;
00034 
00035     /* Builtin functions */
00036     /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
00037     void c_div(complex *, complex *, complex *);
00038     double pow_dd(doublereal *, doublereal *), sqrt(doublereal);
00039     void r_cnjg(complex *, complex *);
00040     double c_abs(complex *);
00041 
00042     /* Local variables */
00043     real c__;
00044     integer i__, j;
00045     complex s;
00046     real x, y, z__;
00047     complex ra, rb;
00048     integer kl, ku, iy;
00049     real ulp, sfac;
00050     integer mode;
00051     char path[3], dist[1];
00052     real unfl;
00053     extern /* Subroutine */ int crot_(integer *, complex *, integer *, 
00054             complex *, integer *, real *, complex *);
00055     real rexp;
00056     char type__[1];
00057     real texp;
00058     complex star1, plus1, plus2;
00059     real bscal;
00060     extern logical lsame_(char *, char *);
00061     real tscal, anorm, bnorm, tleft;
00062     extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 
00063             complex *, integer *), crotg_(complex *, complex *, real *, 
00064             complex *), cswap_(integer *, complex *, integer *, complex *, 
00065             integer *);
00066     logical upper;
00067     extern /* Subroutine */ int clatb4_(char *, integer *, integer *, integer 
00068             *, char *, integer *, integer *, real *, integer *, real *, char *
00069 ), slabad_(real *, real *);
00070     extern integer icamax_(integer *, complex *, integer *);
00071     extern /* Complex */ VOID clarnd_(complex *, integer *, integer *);
00072     extern doublereal slamch_(char *);
00073     extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer 
00074             *);
00075     real bignum;
00076     extern doublereal slarnd_(integer *, integer *);
00077     real cndnum;
00078     extern /* Subroutine */ int clarnv_(integer *, integer *, integer *, 
00079             complex *), clatms_(integer *, integer *, char *, integer *, char 
00080             *, real *, integer *, real *, real *, integer *, integer *, char *
00081 , complex *, integer *, complex *, integer *);
00082     integer jcount;
00083     extern /* Subroutine */ int slarnv_(integer *, integer *, integer *, real 
00084             *);
00085     real smlnum;
00086 
00087 
00088 /*  -- LAPACK test routine (version 3.1) -- */
00089 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00090 /*     November 2006 */
00091 
00092 /*     .. Scalar Arguments .. */
00093 /*     .. */
00094 /*     .. Array Arguments .. */
00095 /*     .. */
00096 
00097 /*  Purpose */
00098 /*  ======= */
00099 
00100 /*  CLATTR generates a triangular test matrix in 2-dimensional storage. */
00101 /*  IMAT and UPLO uniquely specify the properties of the test matrix, */
00102 /*  which is returned in the array A. */
00103 
00104 /*  Arguments */
00105 /*  ========= */
00106 
00107 /*  IMAT    (input) INTEGER */
00108 /*          An integer key describing which matrix to generate for this */
00109 /*          path. */
00110 
00111 /*  UPLO    (input) CHARACTER*1 */
00112 /*          Specifies whether the matrix A will be upper or lower */
00113 /*          triangular. */
00114 /*          = 'U':  Upper triangular */
00115 /*          = 'L':  Lower triangular */
00116 
00117 /*  TRANS   (input) CHARACTER*1 */
00118 /*          Specifies whether the matrix or its transpose will be used. */
00119 /*          = 'N':  No transpose */
00120 /*          = 'T':  Transpose */
00121 /*          = 'C':  Conjugate transpose */
00122 
00123 /*  DIAG    (output) CHARACTER*1 */
00124 /*          Specifies whether or not the matrix A is unit triangular. */
00125 /*          = 'N':  Non-unit triangular */
00126 /*          = 'U':  Unit triangular */
00127 
00128 /*  ISEED   (input/output) INTEGER array, dimension (4) */
00129 /*          The seed vector for the random number generator (used in */
00130 /*          CLATMS).  Modified on exit. */
00131 
00132 /*  N       (input) INTEGER */
00133 /*          The order of the matrix to be generated. */
00134 
00135 /*  A       (output) COMPLEX array, dimension (LDA,N) */
00136 /*          The triangular matrix A.  If UPLO = 'U', the leading N x N */
00137 /*          upper triangular part of the array A contains the upper */
00138 /*          triangular matrix, and the strictly lower triangular part of */
00139 /*          A is not referenced.  If UPLO = 'L', the leading N x N lower */
00140 /*          triangular part of the array A contains the lower triangular */
00141 /*          matrix and the strictly upper triangular part of A is not */
00142 /*          referenced. */
00143 
00144 /*  LDA     (input) INTEGER */
00145 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00146 
00147 /*  B       (output) COMPLEX array, dimension (N) */
00148 /*          The right hand side vector, if IMAT > 10. */
00149 
00150 /*  WORK    (workspace) COMPLEX array, dimension (2*N) */
00151 
00152 /*  RWORK   (workspace) REAL array, dimension (N) */
00153 
00154 /*  INFO    (output) INTEGER */
00155 /*          = 0:  successful exit */
00156 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00157 
00158 /*  ===================================================================== */
00159 
00160 /*     .. Parameters .. */
00161 /*     .. */
00162 /*     .. Local Scalars .. */
00163 /*     .. */
00164 /*     .. External Functions .. */
00165 /*     .. */
00166 /*     .. External Subroutines .. */
00167 /*     .. */
00168 /*     .. Intrinsic Functions .. */
00169 /*     .. */
00170 /*     .. Executable Statements .. */
00171 
00172     /* Parameter adjustments */
00173     --iseed;
00174     a_dim1 = *lda;
00175     a_offset = 1 + a_dim1;
00176     a -= a_offset;
00177     --b;
00178     --work;
00179     --rwork;
00180 
00181     /* Function Body */
00182     s_copy(path, "Complex precision", (ftnlen)1, (ftnlen)17);
00183     s_copy(path + 1, "TR", (ftnlen)2, (ftnlen)2);
00184     unfl = slamch_("Safe minimum");
00185     ulp = slamch_("Epsilon") * slamch_("Base");
00186     smlnum = unfl;
00187     bignum = (1.f - ulp) / smlnum;
00188     slabad_(&smlnum, &bignum);
00189     if (*imat >= 7 && *imat <= 10 || *imat == 18) {
00190         *(unsigned char *)diag = 'U';
00191     } else {
00192         *(unsigned char *)diag = 'N';
00193     }
00194     *info = 0;
00195 
00196 /*     Quick return if N.LE.0. */
00197 
00198     if (*n <= 0) {
00199         return 0;
00200     }
00201 
00202 /*     Call CLATB4 to set parameters for CLATMS. */
00203 
00204     upper = lsame_(uplo, "U");
00205     if (upper) {
00206         clatb4_(path, imat, n, n, type__, &kl, &ku, &anorm, &mode, &cndnum, 
00207                 dist);
00208     } else {
00209         i__1 = -(*imat);
00210         clatb4_(path, &i__1, n, n, type__, &kl, &ku, &anorm, &mode, &cndnum, 
00211                 dist);
00212     }
00213 
00214 /*     IMAT <= 6:  Non-unit triangular matrix */
00215 
00216     if (*imat <= 6) {
00217         clatms_(n, n, dist, &iseed[1], type__, &rwork[1], &mode, &cndnum, &
00218                 anorm, &kl, &ku, "No packing", &a[a_offset], lda, &work[1], 
00219                 info);
00220 
00221 /*     IMAT > 6:  Unit triangular matrix */
00222 /*     The diagonal is deliberately set to something other than 1. */
00223 
00224 /*     IMAT = 7:  Matrix is the identity */
00225 
00226     } else if (*imat == 7) {
00227         if (upper) {
00228             i__1 = *n;
00229             for (j = 1; j <= i__1; ++j) {
00230                 i__2 = j - 1;
00231                 for (i__ = 1; i__ <= i__2; ++i__) {
00232                     i__3 = i__ + j * a_dim1;
00233                     a[i__3].r = 0.f, a[i__3].i = 0.f;
00234 /* L10: */
00235                 }
00236                 i__2 = j + j * a_dim1;
00237                 a[i__2].r = (real) j, a[i__2].i = 0.f;
00238 /* L20: */
00239             }
00240         } else {
00241             i__1 = *n;
00242             for (j = 1; j <= i__1; ++j) {
00243                 i__2 = j + j * a_dim1;
00244                 a[i__2].r = (real) j, a[i__2].i = 0.f;
00245                 i__2 = *n;
00246                 for (i__ = j + 1; i__ <= i__2; ++i__) {
00247                     i__3 = i__ + j * a_dim1;
00248                     a[i__3].r = 0.f, a[i__3].i = 0.f;
00249 /* L30: */
00250                 }
00251 /* L40: */
00252             }
00253         }
00254 
00255 /*     IMAT > 7:  Non-trivial unit triangular matrix */
00256 
00257 /*     Generate a unit triangular matrix T with condition CNDNUM by */
00258 /*     forming a triangular matrix with known singular values and */
00259 /*     filling in the zero entries with Givens rotations. */
00260 
00261     } else if (*imat <= 10) {
00262         if (upper) {
00263             i__1 = *n;
00264             for (j = 1; j <= i__1; ++j) {
00265                 i__2 = j - 1;
00266                 for (i__ = 1; i__ <= i__2; ++i__) {
00267                     i__3 = i__ + j * a_dim1;
00268                     a[i__3].r = 0.f, a[i__3].i = 0.f;
00269 /* L50: */
00270                 }
00271                 i__2 = j + j * a_dim1;
00272                 a[i__2].r = (real) j, a[i__2].i = 0.f;
00273 /* L60: */
00274             }
00275         } else {
00276             i__1 = *n;
00277             for (j = 1; j <= i__1; ++j) {
00278                 i__2 = j + j * a_dim1;
00279                 a[i__2].r = (real) j, a[i__2].i = 0.f;
00280                 i__2 = *n;
00281                 for (i__ = j + 1; i__ <= i__2; ++i__) {
00282                     i__3 = i__ + j * a_dim1;
00283                     a[i__3].r = 0.f, a[i__3].i = 0.f;
00284 /* L70: */
00285                 }
00286 /* L80: */
00287             }
00288         }
00289 
00290 /*        Since the trace of a unit triangular matrix is 1, the product */
00291 /*        of its singular values must be 1.  Let s = sqrt(CNDNUM), */
00292 /*        x = sqrt(s) - 1/sqrt(s), y = sqrt(2/(n-2))*x, and z = x**2. */
00293 /*        The following triangular matrix has singular values s, 1, 1, */
00294 /*        ..., 1, 1/s: */
00295 
00296 /*        1  y  y  y  ...  y  y  z */
00297 /*           1  0  0  ...  0  0  y */
00298 /*              1  0  ...  0  0  y */
00299 /*                 .  ...  .  .  . */
00300 /*                     .   .  .  . */
00301 /*                         1  0  y */
00302 /*                            1  y */
00303 /*                               1 */
00304 
00305 /*        To fill in the zeros, we first multiply by a matrix with small */
00306 /*        condition number of the form */
00307 
00308 /*        1  0  0  0  0  ... */
00309 /*           1  +  *  0  0  ... */
00310 /*              1  +  0  0  0 */
00311 /*                 1  +  *  0  0 */
00312 /*                    1  +  0  0 */
00313 /*                       ... */
00314 /*                          1  +  0 */
00315 /*                             1  0 */
00316 /*                                1 */
00317 
00318 /*        Each element marked with a '*' is formed by taking the product */
00319 /*        of the adjacent elements marked with '+'.  The '*'s can be */
00320 /*        chosen freely, and the '+'s are chosen so that the inverse of */
00321 /*        T will have elements of the same magnitude as T.  If the *'s in */
00322 /*        both T and inv(T) have small magnitude, T is well conditioned. */
00323 /*        The two offdiagonals of T are stored in WORK. */
00324 
00325 /*        The product of these two matrices has the form */
00326 
00327 /*        1  y  y  y  y  y  .  y  y  z */
00328 /*           1  +  *  0  0  .  0  0  y */
00329 /*              1  +  0  0  .  0  0  y */
00330 /*                 1  +  *  .  .  .  . */
00331 /*                    1  +  .  .  .  . */
00332 /*                       .  .  .  .  . */
00333 /*                          .  .  .  . */
00334 /*                             1  +  y */
00335 /*                                1  y */
00336 /*                                   1 */
00337 
00338 /*        Now we multiply by Givens rotations, using the fact that */
00339 
00340 /*              [  c   s ] [  1   w ] [ -c  -s ] =  [  1  -w ] */
00341 /*              [ -s   c ] [  0   1 ] [  s  -c ]    [  0   1 ] */
00342 /*        and */
00343 /*              [ -c  -s ] [  1   0 ] [  c   s ] =  [  1   0 ] */
00344 /*              [  s  -c ] [  w   1 ] [ -s   c ]    [ -w   1 ] */
00345 
00346 /*        where c = w / sqrt(w**2+4) and s = 2 / sqrt(w**2+4). */
00347 
00348         clarnd_(&q__2, &c__5, &iseed[1]);
00349         q__1.r = q__2.r * .25f, q__1.i = q__2.i * .25f;
00350         star1.r = q__1.r, star1.i = q__1.i;
00351         sfac = .5f;
00352         clarnd_(&q__2, &c__5, &iseed[1]);
00353         q__1.r = sfac * q__2.r, q__1.i = sfac * q__2.i;
00354         plus1.r = q__1.r, plus1.i = q__1.i;
00355         i__1 = *n;
00356         for (j = 1; j <= i__1; j += 2) {
00357             c_div(&q__1, &star1, &plus1);
00358             plus2.r = q__1.r, plus2.i = q__1.i;
00359             i__2 = j;
00360             work[i__2].r = plus1.r, work[i__2].i = plus1.i;
00361             i__2 = *n + j;
00362             work[i__2].r = star1.r, work[i__2].i = star1.i;
00363             if (j + 1 <= *n) {
00364                 i__2 = j + 1;
00365                 work[i__2].r = plus2.r, work[i__2].i = plus2.i;
00366                 i__2 = *n + j + 1;
00367                 work[i__2].r = 0.f, work[i__2].i = 0.f;
00368                 c_div(&q__1, &star1, &plus2);
00369                 plus1.r = q__1.r, plus1.i = q__1.i;
00370                 rexp = slarnd_(&c__2, &iseed[1]);
00371                 if (rexp < 0.f) {
00372                     d__1 = (doublereal) sfac;
00373                     d__2 = (doublereal) (1.f - rexp);
00374                     r__1 = -pow_dd(&d__1, &d__2);
00375                     clarnd_(&q__2, &c__5, &iseed[1]);
00376                     q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
00377                     star1.r = q__1.r, star1.i = q__1.i;
00378                 } else {
00379                     d__1 = (doublereal) sfac;
00380                     d__2 = (doublereal) (rexp + 1.f);
00381                     r__1 = pow_dd(&d__1, &d__2);
00382                     clarnd_(&q__2, &c__5, &iseed[1]);
00383                     q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
00384                     star1.r = q__1.r, star1.i = q__1.i;
00385                 }
00386             }
00387 /* L90: */
00388         }
00389 
00390         x = sqrt(cndnum) - 1 / sqrt(cndnum);
00391         if (*n > 2) {
00392             y = sqrt(2.f / (*n - 2)) * x;
00393         } else {
00394             y = 0.f;
00395         }
00396         z__ = x * x;
00397 
00398         if (upper) {
00399             if (*n > 3) {
00400                 i__1 = *n - 3;
00401                 i__2 = *lda + 1;
00402                 ccopy_(&i__1, &work[1], &c__1, &a[a_dim1 * 3 + 2], &i__2);
00403                 if (*n > 4) {
00404                     i__1 = *n - 4;
00405                     i__2 = *lda + 1;
00406                     ccopy_(&i__1, &work[*n + 1], &c__1, &a[(a_dim1 << 2) + 2], 
00407                              &i__2);
00408                 }
00409             }
00410             i__1 = *n - 1;
00411             for (j = 2; j <= i__1; ++j) {
00412                 i__2 = j * a_dim1 + 1;
00413                 a[i__2].r = y, a[i__2].i = 0.f;
00414                 i__2 = j + *n * a_dim1;
00415                 a[i__2].r = y, a[i__2].i = 0.f;
00416 /* L100: */
00417             }
00418             i__1 = *n * a_dim1 + 1;
00419             a[i__1].r = z__, a[i__1].i = 0.f;
00420         } else {
00421             if (*n > 3) {
00422                 i__1 = *n - 3;
00423                 i__2 = *lda + 1;
00424                 ccopy_(&i__1, &work[1], &c__1, &a[(a_dim1 << 1) + 3], &i__2);
00425                 if (*n > 4) {
00426                     i__1 = *n - 4;
00427                     i__2 = *lda + 1;
00428                     ccopy_(&i__1, &work[*n + 1], &c__1, &a[(a_dim1 << 1) + 4], 
00429                              &i__2);
00430                 }
00431             }
00432             i__1 = *n - 1;
00433             for (j = 2; j <= i__1; ++j) {
00434                 i__2 = j + a_dim1;
00435                 a[i__2].r = y, a[i__2].i = 0.f;
00436                 i__2 = *n + j * a_dim1;
00437                 a[i__2].r = y, a[i__2].i = 0.f;
00438 /* L110: */
00439             }
00440             i__1 = *n + a_dim1;
00441             a[i__1].r = z__, a[i__1].i = 0.f;
00442         }
00443 
00444 /*        Fill in the zeros using Givens rotations. */
00445 
00446         if (upper) {
00447             i__1 = *n - 1;
00448             for (j = 1; j <= i__1; ++j) {
00449                 i__2 = j + (j + 1) * a_dim1;
00450                 ra.r = a[i__2].r, ra.i = a[i__2].i;
00451                 rb.r = 2.f, rb.i = 0.f;
00452                 crotg_(&ra, &rb, &c__, &s);
00453 
00454 /*              Multiply by [ c  s; -conjg(s)  c] on the left. */
00455 
00456                 if (*n > j + 1) {
00457                     i__2 = *n - j - 1;
00458                     crot_(&i__2, &a[j + (j + 2) * a_dim1], lda, &a[j + 1 + (j 
00459                             + 2) * a_dim1], lda, &c__, &s);
00460                 }
00461 
00462 /*              Multiply by [-c -s;  conjg(s) -c] on the right. */
00463 
00464                 if (j > 1) {
00465                     i__2 = j - 1;
00466                     r__1 = -c__;
00467                     q__1.r = -s.r, q__1.i = -s.i;
00468                     crot_(&i__2, &a[(j + 1) * a_dim1 + 1], &c__1, &a[j * 
00469                             a_dim1 + 1], &c__1, &r__1, &q__1);
00470                 }
00471 
00472 /*              Negate A(J,J+1). */
00473 
00474                 i__2 = j + (j + 1) * a_dim1;
00475                 i__3 = j + (j + 1) * a_dim1;
00476                 q__1.r = -a[i__3].r, q__1.i = -a[i__3].i;
00477                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00478 /* L120: */
00479             }
00480         } else {
00481             i__1 = *n - 1;
00482             for (j = 1; j <= i__1; ++j) {
00483                 i__2 = j + 1 + j * a_dim1;
00484                 ra.r = a[i__2].r, ra.i = a[i__2].i;
00485                 rb.r = 2.f, rb.i = 0.f;
00486                 crotg_(&ra, &rb, &c__, &s);
00487                 r_cnjg(&q__1, &s);
00488                 s.r = q__1.r, s.i = q__1.i;
00489 
00490 /*              Multiply by [ c -s;  conjg(s) c] on the right. */
00491 
00492                 if (*n > j + 1) {
00493                     i__2 = *n - j - 1;
00494                     q__1.r = -s.r, q__1.i = -s.i;
00495                     crot_(&i__2, &a[j + 2 + (j + 1) * a_dim1], &c__1, &a[j + 
00496                             2 + j * a_dim1], &c__1, &c__, &q__1);
00497                 }
00498 
00499 /*              Multiply by [-c  s; -conjg(s) -c] on the left. */
00500 
00501                 if (j > 1) {
00502                     i__2 = j - 1;
00503                     r__1 = -c__;
00504                     crot_(&i__2, &a[j + a_dim1], lda, &a[j + 1 + a_dim1], lda, 
00505                              &r__1, &s);
00506                 }
00507 
00508 /*              Negate A(J+1,J). */
00509 
00510                 i__2 = j + 1 + j * a_dim1;
00511                 i__3 = j + 1 + j * a_dim1;
00512                 q__1.r = -a[i__3].r, q__1.i = -a[i__3].i;
00513                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00514 /* L130: */
00515             }
00516         }
00517 
00518 /*     IMAT > 10:  Pathological test cases.  These triangular matrices */
00519 /*     are badly scaled or badly conditioned, so when used in solving a */
00520 /*     triangular system they may cause overflow in the solution vector. */
00521 
00522     } else if (*imat == 11) {
00523 
00524 /*        Type 11:  Generate a triangular matrix with elements between */
00525 /*        -1 and 1. Give the diagonal norm 2 to make it well-conditioned. */
00526 /*        Make the right hand side large so that it requires scaling. */
00527 
00528         if (upper) {
00529             i__1 = *n;
00530             for (j = 1; j <= i__1; ++j) {
00531                 i__2 = j - 1;
00532                 clarnv_(&c__4, &iseed[1], &i__2, &a[j * a_dim1 + 1]);
00533                 i__2 = j + j * a_dim1;
00534                 clarnd_(&q__2, &c__5, &iseed[1]);
00535                 q__1.r = q__2.r * 2.f, q__1.i = q__2.i * 2.f;
00536                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00537 /* L140: */
00538             }
00539         } else {
00540             i__1 = *n;
00541             for (j = 1; j <= i__1; ++j) {
00542                 if (j < *n) {
00543                     i__2 = *n - j;
00544                     clarnv_(&c__4, &iseed[1], &i__2, &a[j + 1 + j * a_dim1]);
00545                 }
00546                 i__2 = j + j * a_dim1;
00547                 clarnd_(&q__2, &c__5, &iseed[1]);
00548                 q__1.r = q__2.r * 2.f, q__1.i = q__2.i * 2.f;
00549                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00550 /* L150: */
00551             }
00552         }
00553 
00554 /*        Set the right hand side so that the largest value is BIGNUM. */
00555 
00556         clarnv_(&c__2, &iseed[1], n, &b[1]);
00557         iy = icamax_(n, &b[1], &c__1);
00558         bnorm = c_abs(&b[iy]);
00559         bscal = bignum / dmax(1.f,bnorm);
00560         csscal_(n, &bscal, &b[1], &c__1);
00561 
00562     } else if (*imat == 12) {
00563 
00564 /*        Type 12:  Make the first diagonal element in the solve small to */
00565 /*        cause immediate overflow when dividing by T(j,j). */
00566 /*        In type 12, the offdiagonal elements are small (CNORM(j) < 1). */
00567 
00568         clarnv_(&c__2, &iseed[1], n, &b[1]);
00569 /* Computing MAX */
00570         r__1 = 1.f, r__2 = (real) (*n - 1);
00571         tscal = 1.f / dmax(r__1,r__2);
00572         if (upper) {
00573             i__1 = *n;
00574             for (j = 1; j <= i__1; ++j) {
00575                 i__2 = j - 1;
00576                 clarnv_(&c__4, &iseed[1], &i__2, &a[j * a_dim1 + 1]);
00577                 i__2 = j - 1;
00578                 csscal_(&i__2, &tscal, &a[j * a_dim1 + 1], &c__1);
00579                 i__2 = j + j * a_dim1;
00580                 clarnd_(&q__1, &c__5, &iseed[1]);
00581                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00582 /* L160: */
00583             }
00584             i__1 = *n + *n * a_dim1;
00585             i__2 = *n + *n * a_dim1;
00586             q__1.r = smlnum * a[i__2].r, q__1.i = smlnum * a[i__2].i;
00587             a[i__1].r = q__1.r, a[i__1].i = q__1.i;
00588         } else {
00589             i__1 = *n;
00590             for (j = 1; j <= i__1; ++j) {
00591                 if (j < *n) {
00592                     i__2 = *n - j;
00593                     clarnv_(&c__4, &iseed[1], &i__2, &a[j + 1 + j * a_dim1]);
00594                     i__2 = *n - j;
00595                     csscal_(&i__2, &tscal, &a[j + 1 + j * a_dim1], &c__1);
00596                 }
00597                 i__2 = j + j * a_dim1;
00598                 clarnd_(&q__1, &c__5, &iseed[1]);
00599                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00600 /* L170: */
00601             }
00602             i__1 = a_dim1 + 1;
00603             i__2 = a_dim1 + 1;
00604             q__1.r = smlnum * a[i__2].r, q__1.i = smlnum * a[i__2].i;
00605             a[i__1].r = q__1.r, a[i__1].i = q__1.i;
00606         }
00607 
00608     } else if (*imat == 13) {
00609 
00610 /*        Type 13:  Make the first diagonal element in the solve small to */
00611 /*        cause immediate overflow when dividing by T(j,j). */
00612 /*        In type 13, the offdiagonal elements are O(1) (CNORM(j) > 1). */
00613 
00614         clarnv_(&c__2, &iseed[1], n, &b[1]);
00615         if (upper) {
00616             i__1 = *n;
00617             for (j = 1; j <= i__1; ++j) {
00618                 i__2 = j - 1;
00619                 clarnv_(&c__4, &iseed[1], &i__2, &a[j * a_dim1 + 1]);
00620                 i__2 = j + j * a_dim1;
00621                 clarnd_(&q__1, &c__5, &iseed[1]);
00622                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00623 /* L180: */
00624             }
00625             i__1 = *n + *n * a_dim1;
00626             i__2 = *n + *n * a_dim1;
00627             q__1.r = smlnum * a[i__2].r, q__1.i = smlnum * a[i__2].i;
00628             a[i__1].r = q__1.r, a[i__1].i = q__1.i;
00629         } else {
00630             i__1 = *n;
00631             for (j = 1; j <= i__1; ++j) {
00632                 if (j < *n) {
00633                     i__2 = *n - j;
00634                     clarnv_(&c__4, &iseed[1], &i__2, &a[j + 1 + j * a_dim1]);
00635                 }
00636                 i__2 = j + j * a_dim1;
00637                 clarnd_(&q__1, &c__5, &iseed[1]);
00638                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00639 /* L190: */
00640             }
00641             i__1 = a_dim1 + 1;
00642             i__2 = a_dim1 + 1;
00643             q__1.r = smlnum * a[i__2].r, q__1.i = smlnum * a[i__2].i;
00644             a[i__1].r = q__1.r, a[i__1].i = q__1.i;
00645         }
00646 
00647     } else if (*imat == 14) {
00648 
00649 /*        Type 14:  T is diagonal with small numbers on the diagonal to */
00650 /*        make the growth factor underflow, but a small right hand side */
00651 /*        chosen so that the solution does not overflow. */
00652 
00653         if (upper) {
00654             jcount = 1;
00655             for (j = *n; j >= 1; --j) {
00656                 i__1 = j - 1;
00657                 for (i__ = 1; i__ <= i__1; ++i__) {
00658                     i__2 = i__ + j * a_dim1;
00659                     a[i__2].r = 0.f, a[i__2].i = 0.f;
00660 /* L200: */
00661                 }
00662                 if (jcount <= 2) {
00663                     i__1 = j + j * a_dim1;
00664                     clarnd_(&q__2, &c__5, &iseed[1]);
00665                     q__1.r = smlnum * q__2.r, q__1.i = smlnum * q__2.i;
00666                     a[i__1].r = q__1.r, a[i__1].i = q__1.i;
00667                 } else {
00668                     i__1 = j + j * a_dim1;
00669                     clarnd_(&q__1, &c__5, &iseed[1]);
00670                     a[i__1].r = q__1.r, a[i__1].i = q__1.i;
00671                 }
00672                 ++jcount;
00673                 if (jcount > 4) {
00674                     jcount = 1;
00675                 }
00676 /* L210: */
00677             }
00678         } else {
00679             jcount = 1;
00680             i__1 = *n;
00681             for (j = 1; j <= i__1; ++j) {
00682                 i__2 = *n;
00683                 for (i__ = j + 1; i__ <= i__2; ++i__) {
00684                     i__3 = i__ + j * a_dim1;
00685                     a[i__3].r = 0.f, a[i__3].i = 0.f;
00686 /* L220: */
00687                 }
00688                 if (jcount <= 2) {
00689                     i__2 = j + j * a_dim1;
00690                     clarnd_(&q__2, &c__5, &iseed[1]);
00691                     q__1.r = smlnum * q__2.r, q__1.i = smlnum * q__2.i;
00692                     a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00693                 } else {
00694                     i__2 = j + j * a_dim1;
00695                     clarnd_(&q__1, &c__5, &iseed[1]);
00696                     a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00697                 }
00698                 ++jcount;
00699                 if (jcount > 4) {
00700                     jcount = 1;
00701                 }
00702 /* L230: */
00703             }
00704         }
00705 
00706 /*        Set the right hand side alternately zero and small. */
00707 
00708         if (upper) {
00709             b[1].r = 0.f, b[1].i = 0.f;
00710             for (i__ = *n; i__ >= 2; i__ += -2) {
00711                 i__1 = i__;
00712                 b[i__1].r = 0.f, b[i__1].i = 0.f;
00713                 i__1 = i__ - 1;
00714                 clarnd_(&q__2, &c__5, &iseed[1]);
00715                 q__1.r = smlnum * q__2.r, q__1.i = smlnum * q__2.i;
00716                 b[i__1].r = q__1.r, b[i__1].i = q__1.i;
00717 /* L240: */
00718             }
00719         } else {
00720             i__1 = *n;
00721             b[i__1].r = 0.f, b[i__1].i = 0.f;
00722             i__1 = *n - 1;
00723             for (i__ = 1; i__ <= i__1; i__ += 2) {
00724                 i__2 = i__;
00725                 b[i__2].r = 0.f, b[i__2].i = 0.f;
00726                 i__2 = i__ + 1;
00727                 clarnd_(&q__2, &c__5, &iseed[1]);
00728                 q__1.r = smlnum * q__2.r, q__1.i = smlnum * q__2.i;
00729                 b[i__2].r = q__1.r, b[i__2].i = q__1.i;
00730 /* L250: */
00731             }
00732         }
00733 
00734     } else if (*imat == 15) {
00735 
00736 /*        Type 15:  Make the diagonal elements small to cause gradual */
00737 /*        overflow when dividing by T(j,j).  To control the amount of */
00738 /*        scaling needed, the matrix is bidiagonal. */
00739 
00740 /* Computing MAX */
00741         r__1 = 1.f, r__2 = (real) (*n - 1);
00742         texp = 1.f / dmax(r__1,r__2);
00743         d__1 = (doublereal) smlnum;
00744         d__2 = (doublereal) texp;
00745         tscal = pow_dd(&d__1, &d__2);
00746         clarnv_(&c__4, &iseed[1], n, &b[1]);
00747         if (upper) {
00748             i__1 = *n;
00749             for (j = 1; j <= i__1; ++j) {
00750                 i__2 = j - 2;
00751                 for (i__ = 1; i__ <= i__2; ++i__) {
00752                     i__3 = i__ + j * a_dim1;
00753                     a[i__3].r = 0.f, a[i__3].i = 0.f;
00754 /* L260: */
00755                 }
00756                 if (j > 1) {
00757                     i__2 = j - 1 + j * a_dim1;
00758                     a[i__2].r = -1.f, a[i__2].i = -1.f;
00759                 }
00760                 i__2 = j + j * a_dim1;
00761                 clarnd_(&q__2, &c__5, &iseed[1]);
00762                 q__1.r = tscal * q__2.r, q__1.i = tscal * q__2.i;
00763                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00764 /* L270: */
00765             }
00766             i__1 = *n;
00767             b[i__1].r = 1.f, b[i__1].i = 1.f;
00768         } else {
00769             i__1 = *n;
00770             for (j = 1; j <= i__1; ++j) {
00771                 i__2 = *n;
00772                 for (i__ = j + 2; i__ <= i__2; ++i__) {
00773                     i__3 = i__ + j * a_dim1;
00774                     a[i__3].r = 0.f, a[i__3].i = 0.f;
00775 /* L280: */
00776                 }
00777                 if (j < *n) {
00778                     i__2 = j + 1 + j * a_dim1;
00779                     a[i__2].r = -1.f, a[i__2].i = -1.f;
00780                 }
00781                 i__2 = j + j * a_dim1;
00782                 clarnd_(&q__2, &c__5, &iseed[1]);
00783                 q__1.r = tscal * q__2.r, q__1.i = tscal * q__2.i;
00784                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00785 /* L290: */
00786             }
00787             b[1].r = 1.f, b[1].i = 1.f;
00788         }
00789 
00790     } else if (*imat == 16) {
00791 
00792 /*        Type 16:  One zero diagonal element. */
00793 
00794         iy = *n / 2 + 1;
00795         if (upper) {
00796             i__1 = *n;
00797             for (j = 1; j <= i__1; ++j) {
00798                 i__2 = j - 1;
00799                 clarnv_(&c__4, &iseed[1], &i__2, &a[j * a_dim1 + 1]);
00800                 if (j != iy) {
00801                     i__2 = j + j * a_dim1;
00802                     clarnd_(&q__2, &c__5, &iseed[1]);
00803                     q__1.r = q__2.r * 2.f, q__1.i = q__2.i * 2.f;
00804                     a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00805                 } else {
00806                     i__2 = j + j * a_dim1;
00807                     a[i__2].r = 0.f, a[i__2].i = 0.f;
00808                 }
00809 /* L300: */
00810             }
00811         } else {
00812             i__1 = *n;
00813             for (j = 1; j <= i__1; ++j) {
00814                 if (j < *n) {
00815                     i__2 = *n - j;
00816                     clarnv_(&c__4, &iseed[1], &i__2, &a[j + 1 + j * a_dim1]);
00817                 }
00818                 if (j != iy) {
00819                     i__2 = j + j * a_dim1;
00820                     clarnd_(&q__2, &c__5, &iseed[1]);
00821                     q__1.r = q__2.r * 2.f, q__1.i = q__2.i * 2.f;
00822                     a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00823                 } else {
00824                     i__2 = j + j * a_dim1;
00825                     a[i__2].r = 0.f, a[i__2].i = 0.f;
00826                 }
00827 /* L310: */
00828             }
00829         }
00830         clarnv_(&c__2, &iseed[1], n, &b[1]);
00831         csscal_(n, &c_b92, &b[1], &c__1);
00832 
00833     } else if (*imat == 17) {
00834 
00835 /*        Type 17:  Make the offdiagonal elements large to cause overflow */
00836 /*        when adding a column of T.  In the non-transposed case, the */
00837 /*        matrix is constructed to cause overflow when adding a column in */
00838 /*        every other step. */
00839 
00840         tscal = unfl / ulp;
00841         tscal = (1.f - ulp) / tscal;
00842         i__1 = *n;
00843         for (j = 1; j <= i__1; ++j) {
00844             i__2 = *n;
00845             for (i__ = 1; i__ <= i__2; ++i__) {
00846                 i__3 = i__ + j * a_dim1;
00847                 a[i__3].r = 0.f, a[i__3].i = 0.f;
00848 /* L320: */
00849             }
00850 /* L330: */
00851         }
00852         texp = 1.f;
00853         if (upper) {
00854             for (j = *n; j >= 2; j += -2) {
00855                 i__1 = j * a_dim1 + 1;
00856                 r__1 = -tscal / (real) (*n + 1);
00857                 a[i__1].r = r__1, a[i__1].i = 0.f;
00858                 i__1 = j + j * a_dim1;
00859                 a[i__1].r = 1.f, a[i__1].i = 0.f;
00860                 i__1 = j;
00861                 r__1 = texp * (1.f - ulp);
00862                 b[i__1].r = r__1, b[i__1].i = 0.f;
00863                 i__1 = (j - 1) * a_dim1 + 1;
00864                 r__1 = -(tscal / (real) (*n + 1)) / (real) (*n + 2);
00865                 a[i__1].r = r__1, a[i__1].i = 0.f;
00866                 i__1 = j - 1 + (j - 1) * a_dim1;
00867                 a[i__1].r = 1.f, a[i__1].i = 0.f;
00868                 i__1 = j - 1;
00869                 r__1 = texp * (real) (*n * *n + *n - 1);
00870                 b[i__1].r = r__1, b[i__1].i = 0.f;
00871                 texp *= 2.f;
00872 /* L340: */
00873             }
00874             r__1 = (real) (*n + 1) / (real) (*n + 2) * tscal;
00875             b[1].r = r__1, b[1].i = 0.f;
00876         } else {
00877             i__1 = *n - 1;
00878             for (j = 1; j <= i__1; j += 2) {
00879                 i__2 = *n + j * a_dim1;
00880                 r__1 = -tscal / (real) (*n + 1);
00881                 a[i__2].r = r__1, a[i__2].i = 0.f;
00882                 i__2 = j + j * a_dim1;
00883                 a[i__2].r = 1.f, a[i__2].i = 0.f;
00884                 i__2 = j;
00885                 r__1 = texp * (1.f - ulp);
00886                 b[i__2].r = r__1, b[i__2].i = 0.f;
00887                 i__2 = *n + (j + 1) * a_dim1;
00888                 r__1 = -(tscal / (real) (*n + 1)) / (real) (*n + 2);
00889                 a[i__2].r = r__1, a[i__2].i = 0.f;
00890                 i__2 = j + 1 + (j + 1) * a_dim1;
00891                 a[i__2].r = 1.f, a[i__2].i = 0.f;
00892                 i__2 = j + 1;
00893                 r__1 = texp * (real) (*n * *n + *n - 1);
00894                 b[i__2].r = r__1, b[i__2].i = 0.f;
00895                 texp *= 2.f;
00896 /* L350: */
00897             }
00898             i__1 = *n;
00899             r__1 = (real) (*n + 1) / (real) (*n + 2) * tscal;
00900             b[i__1].r = r__1, b[i__1].i = 0.f;
00901         }
00902 
00903     } else if (*imat == 18) {
00904 
00905 /*        Type 18:  Generate a unit triangular matrix with elements */
00906 /*        between -1 and 1, and make the right hand side large so that it */
00907 /*        requires scaling. */
00908 
00909         if (upper) {
00910             i__1 = *n;
00911             for (j = 1; j <= i__1; ++j) {
00912                 i__2 = j - 1;
00913                 clarnv_(&c__4, &iseed[1], &i__2, &a[j * a_dim1 + 1]);
00914                 i__2 = j + j * a_dim1;
00915                 a[i__2].r = 0.f, a[i__2].i = 0.f;
00916 /* L360: */
00917             }
00918         } else {
00919             i__1 = *n;
00920             for (j = 1; j <= i__1; ++j) {
00921                 if (j < *n) {
00922                     i__2 = *n - j;
00923                     clarnv_(&c__4, &iseed[1], &i__2, &a[j + 1 + j * a_dim1]);
00924                 }
00925                 i__2 = j + j * a_dim1;
00926                 a[i__2].r = 0.f, a[i__2].i = 0.f;
00927 /* L370: */
00928             }
00929         }
00930 
00931 /*        Set the right hand side so that the largest value is BIGNUM. */
00932 
00933         clarnv_(&c__2, &iseed[1], n, &b[1]);
00934         iy = icamax_(n, &b[1], &c__1);
00935         bnorm = c_abs(&b[iy]);
00936         bscal = bignum / dmax(1.f,bnorm);
00937         csscal_(n, &bscal, &b[1], &c__1);
00938 
00939     } else if (*imat == 19) {
00940 
00941 /*        Type 19:  Generate a triangular matrix with elements between */
00942 /*        BIGNUM/(n-1) and BIGNUM so that at least one of the column */
00943 /*        norms will exceed BIGNUM. */
00944 /*        1/3/91:  CLATRS no longer can handle this case */
00945 
00946 /* Computing MAX */
00947         r__1 = 1.f, r__2 = (real) (*n - 1);
00948         tleft = bignum / dmax(r__1,r__2);
00949 /* Computing MAX */
00950         r__1 = 1.f, r__2 = (real) (*n);
00951         tscal = bignum * ((real) (*n - 1) / dmax(r__1,r__2));
00952         if (upper) {
00953             i__1 = *n;
00954             for (j = 1; j <= i__1; ++j) {
00955                 clarnv_(&c__5, &iseed[1], &j, &a[j * a_dim1 + 1]);
00956                 slarnv_(&c__1, &iseed[1], &j, &rwork[1]);
00957                 i__2 = j;
00958                 for (i__ = 1; i__ <= i__2; ++i__) {
00959                     i__3 = i__ + j * a_dim1;
00960                     i__4 = i__ + j * a_dim1;
00961                     r__1 = tleft + rwork[i__] * tscal;
00962                     q__1.r = r__1 * a[i__4].r, q__1.i = r__1 * a[i__4].i;
00963                     a[i__3].r = q__1.r, a[i__3].i = q__1.i;
00964 /* L380: */
00965                 }
00966 /* L390: */
00967             }
00968         } else {
00969             i__1 = *n;
00970             for (j = 1; j <= i__1; ++j) {
00971                 i__2 = *n - j + 1;
00972                 clarnv_(&c__5, &iseed[1], &i__2, &a[j + j * a_dim1]);
00973                 i__2 = *n - j + 1;
00974                 slarnv_(&c__1, &iseed[1], &i__2, &rwork[1]);
00975                 i__2 = *n;
00976                 for (i__ = j; i__ <= i__2; ++i__) {
00977                     i__3 = i__ + j * a_dim1;
00978                     i__4 = i__ + j * a_dim1;
00979                     r__1 = tleft + rwork[i__ - j + 1] * tscal;
00980                     q__1.r = r__1 * a[i__4].r, q__1.i = r__1 * a[i__4].i;
00981                     a[i__3].r = q__1.r, a[i__3].i = q__1.i;
00982 /* L400: */
00983                 }
00984 /* L410: */
00985             }
00986         }
00987         clarnv_(&c__2, &iseed[1], n, &b[1]);
00988         csscal_(n, &c_b92, &b[1], &c__1);
00989     }
00990 
00991 /*     Flip the matrix if the transpose will be used. */
00992 
00993     if (! lsame_(trans, "N")) {
00994         if (upper) {
00995             i__1 = *n / 2;
00996             for (j = 1; j <= i__1; ++j) {
00997                 i__2 = *n - (j << 1) + 1;
00998                 cswap_(&i__2, &a[j + j * a_dim1], lda, &a[j + 1 + (*n - j + 1)
00999                          * a_dim1], &c_n1);
01000 /* L420: */
01001             }
01002         } else {
01003             i__1 = *n / 2;
01004             for (j = 1; j <= i__1; ++j) {
01005                 i__2 = *n - (j << 1) + 1;
01006                 i__3 = -(*lda);
01007                 cswap_(&i__2, &a[j + j * a_dim1], &c__1, &a[*n - j + 1 + (j + 
01008                         1) * a_dim1], &i__3);
01009 /* L430: */
01010             }
01011         }
01012     }
01013 
01014     return 0;
01015 
01016 /*     End of CLATTR */
01017 
01018 } /* clattr_ */


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