ztrsv.c
Go to the documentation of this file.
00001 /* ztrsv.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 /* Subroutine */ int ztrsv_(char *uplo, char *trans, char *diag, integer *n, 
00017         doublecomplex *a, integer *lda, doublecomplex *x, integer *incx)
00018 {
00019     /* System generated locals */
00020     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
00021     doublecomplex z__1, z__2, z__3;
00022 
00023     /* Builtin functions */
00024     void z_div(doublecomplex *, doublecomplex *, doublecomplex *), d_cnjg(
00025             doublecomplex *, doublecomplex *);
00026 
00027     /* Local variables */
00028     integer i__, j, ix, jx, kx, info;
00029     doublecomplex temp;
00030     extern logical lsame_(char *, char *);
00031     extern /* Subroutine */ int xerbla_(char *, integer *);
00032     logical noconj, nounit;
00033 
00034 /*     .. Scalar Arguments .. */
00035 /*     .. */
00036 /*     .. Array Arguments .. */
00037 /*     .. */
00038 
00039 /*  Purpose */
00040 /*  ======= */
00041 
00042 /*  ZTRSV  solves one of the systems of equations */
00043 
00044 /*     A*x = b,   or   A'*x = b,   or   conjg( A' )*x = b, */
00045 
00046 /*  where b and x are n element vectors and A is an n by n unit, or */
00047 /*  non-unit, upper or lower triangular matrix. */
00048 
00049 /*  No test for singularity or near-singularity is included in this */
00050 /*  routine. Such tests must be performed before calling this routine. */
00051 
00052 /*  Arguments */
00053 /*  ========== */
00054 
00055 /*  UPLO   - CHARACTER*1. */
00056 /*           On entry, UPLO specifies whether the matrix is an upper or */
00057 /*           lower triangular matrix as follows: */
00058 
00059 /*              UPLO = 'U' or 'u'   A is an upper triangular matrix. */
00060 
00061 /*              UPLO = 'L' or 'l'   A is a lower triangular matrix. */
00062 
00063 /*           Unchanged on exit. */
00064 
00065 /*  TRANS  - CHARACTER*1. */
00066 /*           On entry, TRANS specifies the equations to be solved as */
00067 /*           follows: */
00068 
00069 /*              TRANS = 'N' or 'n'   A*x = b. */
00070 
00071 /*              TRANS = 'T' or 't'   A'*x = b. */
00072 
00073 /*              TRANS = 'C' or 'c'   conjg( A' )*x = b. */
00074 
00075 /*           Unchanged on exit. */
00076 
00077 /*  DIAG   - CHARACTER*1. */
00078 /*           On entry, DIAG specifies whether or not A is unit */
00079 /*           triangular as follows: */
00080 
00081 /*              DIAG = 'U' or 'u'   A is assumed to be unit triangular. */
00082 
00083 /*              DIAG = 'N' or 'n'   A is not assumed to be unit */
00084 /*                                  triangular. */
00085 
00086 /*           Unchanged on exit. */
00087 
00088 /*  N      - INTEGER. */
00089 /*           On entry, N specifies the order of the matrix A. */
00090 /*           N must be at least zero. */
00091 /*           Unchanged on exit. */
00092 
00093 /*  A      - COMPLEX*16       array of DIMENSION ( LDA, n ). */
00094 /*           Before entry with  UPLO = 'U' or 'u', the leading n by n */
00095 /*           upper triangular part of the array A must contain the upper */
00096 /*           triangular matrix and the strictly lower triangular part of */
00097 /*           A is not referenced. */
00098 /*           Before entry with UPLO = 'L' or 'l', the leading n by n */
00099 /*           lower triangular part of the array A must contain the lower */
00100 /*           triangular matrix and the strictly upper triangular part of */
00101 /*           A is not referenced. */
00102 /*           Note that when  DIAG = 'U' or 'u', the diagonal elements of */
00103 /*           A are not referenced either, but are assumed to be unity. */
00104 /*           Unchanged on exit. */
00105 
00106 /*  LDA    - INTEGER. */
00107 /*           On entry, LDA specifies the first dimension of A as declared */
00108 /*           in the calling (sub) program. LDA must be at least */
00109 /*           max( 1, n ). */
00110 /*           Unchanged on exit. */
00111 
00112 /*  X      - COMPLEX*16       array of dimension at least */
00113 /*           ( 1 + ( n - 1 )*abs( INCX ) ). */
00114 /*           Before entry, the incremented array X must contain the n */
00115 /*           element right-hand side vector b. On exit, X is overwritten */
00116 /*           with the solution vector x. */
00117 
00118 /*  INCX   - INTEGER. */
00119 /*           On entry, INCX specifies the increment for the elements of */
00120 /*           X. INCX must not be zero. */
00121 /*           Unchanged on exit. */
00122 
00123 
00124 /*  Level 2 Blas routine. */
00125 
00126 /*  -- Written on 22-October-1986. */
00127 /*     Jack Dongarra, Argonne National Lab. */
00128 /*     Jeremy Du Croz, Nag Central Office. */
00129 /*     Sven Hammarling, Nag Central Office. */
00130 /*     Richard Hanson, Sandia National Labs. */
00131 
00132 
00133 /*     .. Parameters .. */
00134 /*     .. */
00135 /*     .. Local Scalars .. */
00136 /*     .. */
00137 /*     .. External Functions .. */
00138 /*     .. */
00139 /*     .. External Subroutines .. */
00140 /*     .. */
00141 /*     .. Intrinsic Functions .. */
00142 /*     .. */
00143 
00144 /*     Test the input parameters. */
00145 
00146     /* Parameter adjustments */
00147     a_dim1 = *lda;
00148     a_offset = 1 + a_dim1;
00149     a -= a_offset;
00150     --x;
00151 
00152     /* Function Body */
00153     info = 0;
00154     if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
00155         info = 1;
00156     } else if (! lsame_(trans, "N") && ! lsame_(trans, 
00157             "T") && ! lsame_(trans, "C")) {
00158         info = 2;
00159     } else if (! lsame_(diag, "U") && ! lsame_(diag, 
00160             "N")) {
00161         info = 3;
00162     } else if (*n < 0) {
00163         info = 4;
00164     } else if (*lda < max(1,*n)) {
00165         info = 6;
00166     } else if (*incx == 0) {
00167         info = 8;
00168     }
00169     if (info != 0) {
00170         xerbla_("ZTRSV ", &info);
00171         return 0;
00172     }
00173 
00174 /*     Quick return if possible. */
00175 
00176     if (*n == 0) {
00177         return 0;
00178     }
00179 
00180     noconj = lsame_(trans, "T");
00181     nounit = lsame_(diag, "N");
00182 
00183 /*     Set up the start point in X if the increment is not unity. This */
00184 /*     will be  ( N - 1 )*INCX  too small for descending loops. */
00185 
00186     if (*incx <= 0) {
00187         kx = 1 - (*n - 1) * *incx;
00188     } else if (*incx != 1) {
00189         kx = 1;
00190     }
00191 
00192 /*     Start the operations. In this version the elements of A are */
00193 /*     accessed sequentially with one pass through A. */
00194 
00195     if (lsame_(trans, "N")) {
00196 
00197 /*        Form  x := inv( A )*x. */
00198 
00199         if (lsame_(uplo, "U")) {
00200             if (*incx == 1) {
00201                 for (j = *n; j >= 1; --j) {
00202                     i__1 = j;
00203                     if (x[i__1].r != 0. || x[i__1].i != 0.) {
00204                         if (nounit) {
00205                             i__1 = j;
00206                             z_div(&z__1, &x[j], &a[j + j * a_dim1]);
00207                             x[i__1].r = z__1.r, x[i__1].i = z__1.i;
00208                         }
00209                         i__1 = j;
00210                         temp.r = x[i__1].r, temp.i = x[i__1].i;
00211                         for (i__ = j - 1; i__ >= 1; --i__) {
00212                             i__1 = i__;
00213                             i__2 = i__;
00214                             i__3 = i__ + j * a_dim1;
00215                             z__2.r = temp.r * a[i__3].r - temp.i * a[i__3].i, 
00216                                     z__2.i = temp.r * a[i__3].i + temp.i * a[
00217                                     i__3].r;
00218                             z__1.r = x[i__2].r - z__2.r, z__1.i = x[i__2].i - 
00219                                     z__2.i;
00220                             x[i__1].r = z__1.r, x[i__1].i = z__1.i;
00221 /* L10: */
00222                         }
00223                     }
00224 /* L20: */
00225                 }
00226             } else {
00227                 jx = kx + (*n - 1) * *incx;
00228                 for (j = *n; j >= 1; --j) {
00229                     i__1 = jx;
00230                     if (x[i__1].r != 0. || x[i__1].i != 0.) {
00231                         if (nounit) {
00232                             i__1 = jx;
00233                             z_div(&z__1, &x[jx], &a[j + j * a_dim1]);
00234                             x[i__1].r = z__1.r, x[i__1].i = z__1.i;
00235                         }
00236                         i__1 = jx;
00237                         temp.r = x[i__1].r, temp.i = x[i__1].i;
00238                         ix = jx;
00239                         for (i__ = j - 1; i__ >= 1; --i__) {
00240                             ix -= *incx;
00241                             i__1 = ix;
00242                             i__2 = ix;
00243                             i__3 = i__ + j * a_dim1;
00244                             z__2.r = temp.r * a[i__3].r - temp.i * a[i__3].i, 
00245                                     z__2.i = temp.r * a[i__3].i + temp.i * a[
00246                                     i__3].r;
00247                             z__1.r = x[i__2].r - z__2.r, z__1.i = x[i__2].i - 
00248                                     z__2.i;
00249                             x[i__1].r = z__1.r, x[i__1].i = z__1.i;
00250 /* L30: */
00251                         }
00252                     }
00253                     jx -= *incx;
00254 /* L40: */
00255                 }
00256             }
00257         } else {
00258             if (*incx == 1) {
00259                 i__1 = *n;
00260                 for (j = 1; j <= i__1; ++j) {
00261                     i__2 = j;
00262                     if (x[i__2].r != 0. || x[i__2].i != 0.) {
00263                         if (nounit) {
00264                             i__2 = j;
00265                             z_div(&z__1, &x[j], &a[j + j * a_dim1]);
00266                             x[i__2].r = z__1.r, x[i__2].i = z__1.i;
00267                         }
00268                         i__2 = j;
00269                         temp.r = x[i__2].r, temp.i = x[i__2].i;
00270                         i__2 = *n;
00271                         for (i__ = j + 1; i__ <= i__2; ++i__) {
00272                             i__3 = i__;
00273                             i__4 = i__;
00274                             i__5 = i__ + j * a_dim1;
00275                             z__2.r = temp.r * a[i__5].r - temp.i * a[i__5].i, 
00276                                     z__2.i = temp.r * a[i__5].i + temp.i * a[
00277                                     i__5].r;
00278                             z__1.r = x[i__4].r - z__2.r, z__1.i = x[i__4].i - 
00279                                     z__2.i;
00280                             x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00281 /* L50: */
00282                         }
00283                     }
00284 /* L60: */
00285                 }
00286             } else {
00287                 jx = kx;
00288                 i__1 = *n;
00289                 for (j = 1; j <= i__1; ++j) {
00290                     i__2 = jx;
00291                     if (x[i__2].r != 0. || x[i__2].i != 0.) {
00292                         if (nounit) {
00293                             i__2 = jx;
00294                             z_div(&z__1, &x[jx], &a[j + j * a_dim1]);
00295                             x[i__2].r = z__1.r, x[i__2].i = z__1.i;
00296                         }
00297                         i__2 = jx;
00298                         temp.r = x[i__2].r, temp.i = x[i__2].i;
00299                         ix = jx;
00300                         i__2 = *n;
00301                         for (i__ = j + 1; i__ <= i__2; ++i__) {
00302                             ix += *incx;
00303                             i__3 = ix;
00304                             i__4 = ix;
00305                             i__5 = i__ + j * a_dim1;
00306                             z__2.r = temp.r * a[i__5].r - temp.i * a[i__5].i, 
00307                                     z__2.i = temp.r * a[i__5].i + temp.i * a[
00308                                     i__5].r;
00309                             z__1.r = x[i__4].r - z__2.r, z__1.i = x[i__4].i - 
00310                                     z__2.i;
00311                             x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00312 /* L70: */
00313                         }
00314                     }
00315                     jx += *incx;
00316 /* L80: */
00317                 }
00318             }
00319         }
00320     } else {
00321 
00322 /*        Form  x := inv( A' )*x  or  x := inv( conjg( A' ) )*x. */
00323 
00324         if (lsame_(uplo, "U")) {
00325             if (*incx == 1) {
00326                 i__1 = *n;
00327                 for (j = 1; j <= i__1; ++j) {
00328                     i__2 = j;
00329                     temp.r = x[i__2].r, temp.i = x[i__2].i;
00330                     if (noconj) {
00331                         i__2 = j - 1;
00332                         for (i__ = 1; i__ <= i__2; ++i__) {
00333                             i__3 = i__ + j * a_dim1;
00334                             i__4 = i__;
00335                             z__2.r = a[i__3].r * x[i__4].r - a[i__3].i * x[
00336                                     i__4].i, z__2.i = a[i__3].r * x[i__4].i + 
00337                                     a[i__3].i * x[i__4].r;
00338                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00339                                     z__2.i;
00340                             temp.r = z__1.r, temp.i = z__1.i;
00341 /* L90: */
00342                         }
00343                         if (nounit) {
00344                             z_div(&z__1, &temp, &a[j + j * a_dim1]);
00345                             temp.r = z__1.r, temp.i = z__1.i;
00346                         }
00347                     } else {
00348                         i__2 = j - 1;
00349                         for (i__ = 1; i__ <= i__2; ++i__) {
00350                             d_cnjg(&z__3, &a[i__ + j * a_dim1]);
00351                             i__3 = i__;
00352                             z__2.r = z__3.r * x[i__3].r - z__3.i * x[i__3].i, 
00353                                     z__2.i = z__3.r * x[i__3].i + z__3.i * x[
00354                                     i__3].r;
00355                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00356                                     z__2.i;
00357                             temp.r = z__1.r, temp.i = z__1.i;
00358 /* L100: */
00359                         }
00360                         if (nounit) {
00361                             d_cnjg(&z__2, &a[j + j * a_dim1]);
00362                             z_div(&z__1, &temp, &z__2);
00363                             temp.r = z__1.r, temp.i = z__1.i;
00364                         }
00365                     }
00366                     i__2 = j;
00367                     x[i__2].r = temp.r, x[i__2].i = temp.i;
00368 /* L110: */
00369                 }
00370             } else {
00371                 jx = kx;
00372                 i__1 = *n;
00373                 for (j = 1; j <= i__1; ++j) {
00374                     ix = kx;
00375                     i__2 = jx;
00376                     temp.r = x[i__2].r, temp.i = x[i__2].i;
00377                     if (noconj) {
00378                         i__2 = j - 1;
00379                         for (i__ = 1; i__ <= i__2; ++i__) {
00380                             i__3 = i__ + j * a_dim1;
00381                             i__4 = ix;
00382                             z__2.r = a[i__3].r * x[i__4].r - a[i__3].i * x[
00383                                     i__4].i, z__2.i = a[i__3].r * x[i__4].i + 
00384                                     a[i__3].i * x[i__4].r;
00385                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00386                                     z__2.i;
00387                             temp.r = z__1.r, temp.i = z__1.i;
00388                             ix += *incx;
00389 /* L120: */
00390                         }
00391                         if (nounit) {
00392                             z_div(&z__1, &temp, &a[j + j * a_dim1]);
00393                             temp.r = z__1.r, temp.i = z__1.i;
00394                         }
00395                     } else {
00396                         i__2 = j - 1;
00397                         for (i__ = 1; i__ <= i__2; ++i__) {
00398                             d_cnjg(&z__3, &a[i__ + j * a_dim1]);
00399                             i__3 = ix;
00400                             z__2.r = z__3.r * x[i__3].r - z__3.i * x[i__3].i, 
00401                                     z__2.i = z__3.r * x[i__3].i + z__3.i * x[
00402                                     i__3].r;
00403                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00404                                     z__2.i;
00405                             temp.r = z__1.r, temp.i = z__1.i;
00406                             ix += *incx;
00407 /* L130: */
00408                         }
00409                         if (nounit) {
00410                             d_cnjg(&z__2, &a[j + j * a_dim1]);
00411                             z_div(&z__1, &temp, &z__2);
00412                             temp.r = z__1.r, temp.i = z__1.i;
00413                         }
00414                     }
00415                     i__2 = jx;
00416                     x[i__2].r = temp.r, x[i__2].i = temp.i;
00417                     jx += *incx;
00418 /* L140: */
00419                 }
00420             }
00421         } else {
00422             if (*incx == 1) {
00423                 for (j = *n; j >= 1; --j) {
00424                     i__1 = j;
00425                     temp.r = x[i__1].r, temp.i = x[i__1].i;
00426                     if (noconj) {
00427                         i__1 = j + 1;
00428                         for (i__ = *n; i__ >= i__1; --i__) {
00429                             i__2 = i__ + j * a_dim1;
00430                             i__3 = i__;
00431                             z__2.r = a[i__2].r * x[i__3].r - a[i__2].i * x[
00432                                     i__3].i, z__2.i = a[i__2].r * x[i__3].i + 
00433                                     a[i__2].i * x[i__3].r;
00434                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00435                                     z__2.i;
00436                             temp.r = z__1.r, temp.i = z__1.i;
00437 /* L150: */
00438                         }
00439                         if (nounit) {
00440                             z_div(&z__1, &temp, &a[j + j * a_dim1]);
00441                             temp.r = z__1.r, temp.i = z__1.i;
00442                         }
00443                     } else {
00444                         i__1 = j + 1;
00445                         for (i__ = *n; i__ >= i__1; --i__) {
00446                             d_cnjg(&z__3, &a[i__ + j * a_dim1]);
00447                             i__2 = i__;
00448                             z__2.r = z__3.r * x[i__2].r - z__3.i * x[i__2].i, 
00449                                     z__2.i = z__3.r * x[i__2].i + z__3.i * x[
00450                                     i__2].r;
00451                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00452                                     z__2.i;
00453                             temp.r = z__1.r, temp.i = z__1.i;
00454 /* L160: */
00455                         }
00456                         if (nounit) {
00457                             d_cnjg(&z__2, &a[j + j * a_dim1]);
00458                             z_div(&z__1, &temp, &z__2);
00459                             temp.r = z__1.r, temp.i = z__1.i;
00460                         }
00461                     }
00462                     i__1 = j;
00463                     x[i__1].r = temp.r, x[i__1].i = temp.i;
00464 /* L170: */
00465                 }
00466             } else {
00467                 kx += (*n - 1) * *incx;
00468                 jx = kx;
00469                 for (j = *n; j >= 1; --j) {
00470                     ix = kx;
00471                     i__1 = jx;
00472                     temp.r = x[i__1].r, temp.i = x[i__1].i;
00473                     if (noconj) {
00474                         i__1 = j + 1;
00475                         for (i__ = *n; i__ >= i__1; --i__) {
00476                             i__2 = i__ + j * a_dim1;
00477                             i__3 = ix;
00478                             z__2.r = a[i__2].r * x[i__3].r - a[i__2].i * x[
00479                                     i__3].i, z__2.i = a[i__2].r * x[i__3].i + 
00480                                     a[i__2].i * x[i__3].r;
00481                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00482                                     z__2.i;
00483                             temp.r = z__1.r, temp.i = z__1.i;
00484                             ix -= *incx;
00485 /* L180: */
00486                         }
00487                         if (nounit) {
00488                             z_div(&z__1, &temp, &a[j + j * a_dim1]);
00489                             temp.r = z__1.r, temp.i = z__1.i;
00490                         }
00491                     } else {
00492                         i__1 = j + 1;
00493                         for (i__ = *n; i__ >= i__1; --i__) {
00494                             d_cnjg(&z__3, &a[i__ + j * a_dim1]);
00495                             i__2 = ix;
00496                             z__2.r = z__3.r * x[i__2].r - z__3.i * x[i__2].i, 
00497                                     z__2.i = z__3.r * x[i__2].i + z__3.i * x[
00498                                     i__2].r;
00499                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00500                                     z__2.i;
00501                             temp.r = z__1.r, temp.i = z__1.i;
00502                             ix -= *incx;
00503 /* L190: */
00504                         }
00505                         if (nounit) {
00506                             d_cnjg(&z__2, &a[j + j * a_dim1]);
00507                             z_div(&z__1, &temp, &z__2);
00508                             temp.r = z__1.r, temp.i = z__1.i;
00509                         }
00510                     }
00511                     i__1 = jx;
00512                     x[i__1].r = temp.r, x[i__1].i = temp.i;
00513                     jx -= *incx;
00514 /* L200: */
00515                 }
00516             }
00517         }
00518     }
00519 
00520     return 0;
00521 
00522 /*     End of ZTRSV . */
00523 
00524 } /* ztrsv_ */


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