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


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