ztpsv.c
Go to the documentation of this file.
00001 /* ztpsv.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 ztpsv_(char *uplo, char *trans, char *diag, integer *n, 
00017         doublecomplex *ap, doublecomplex *x, integer *incx)
00018 {
00019     /* System generated locals */
00020     integer 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, k, kk, 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 /*  ZTPSV  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, supplied in packed form. */
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 /*  AP     - COMPLEX*16       array of DIMENSION at least */
00094 /*           ( ( n*( n + 1 ) )/2 ). */
00095 /*           Before entry with  UPLO = 'U' or 'u', the array AP must */
00096 /*           contain the upper triangular matrix packed sequentially, */
00097 /*           column by column, so that AP( 1 ) contains a( 1, 1 ), */
00098 /*           AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 ) */
00099 /*           respectively, and so on. */
00100 /*           Before entry with UPLO = 'L' or 'l', the array AP must */
00101 /*           contain the lower triangular matrix packed sequentially, */
00102 /*           column by column, so that AP( 1 ) contains a( 1, 1 ), */
00103 /*           AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 ) */
00104 /*           respectively, and so on. */
00105 /*           Note that when  DIAG = 'U' or 'u', the diagonal elements of */
00106 /*           A are not referenced, but are assumed to be unity. */
00107 /*           Unchanged on exit. */
00108 
00109 /*  X      - COMPLEX*16       array of dimension at least */
00110 /*           ( 1 + ( n - 1 )*abs( INCX ) ). */
00111 /*           Before entry, the incremented array X must contain the n */
00112 /*           element right-hand side vector b. On exit, X is overwritten */
00113 /*           with the solution vector x. */
00114 
00115 /*  INCX   - INTEGER. */
00116 /*           On entry, INCX specifies the increment for the elements of */
00117 /*           X. INCX must not be zero. */
00118 /*           Unchanged on exit. */
00119 
00120 
00121 /*  Level 2 Blas routine. */
00122 
00123 /*  -- Written on 22-October-1986. */
00124 /*     Jack Dongarra, Argonne National Lab. */
00125 /*     Jeremy Du Croz, Nag Central Office. */
00126 /*     Sven Hammarling, Nag Central Office. */
00127 /*     Richard Hanson, Sandia National Labs. */
00128 
00129 
00130 /*     .. Parameters .. */
00131 /*     .. */
00132 /*     .. Local Scalars .. */
00133 /*     .. */
00134 /*     .. External Functions .. */
00135 /*     .. */
00136 /*     .. External Subroutines .. */
00137 /*     .. */
00138 /*     .. Intrinsic Functions .. */
00139 /*     .. */
00140 
00141 /*     Test the input parameters. */
00142 
00143     /* Parameter adjustments */
00144     --x;
00145     --ap;
00146 
00147     /* Function Body */
00148     info = 0;
00149     if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
00150         info = 1;
00151     } else if (! lsame_(trans, "N") && ! lsame_(trans, 
00152             "T") && ! lsame_(trans, "C")) {
00153         info = 2;
00154     } else if (! lsame_(diag, "U") && ! lsame_(diag, 
00155             "N")) {
00156         info = 3;
00157     } else if (*n < 0) {
00158         info = 4;
00159     } else if (*incx == 0) {
00160         info = 7;
00161     }
00162     if (info != 0) {
00163         xerbla_("ZTPSV ", &info);
00164         return 0;
00165     }
00166 
00167 /*     Quick return if possible. */
00168 
00169     if (*n == 0) {
00170         return 0;
00171     }
00172 
00173     noconj = lsame_(trans, "T");
00174     nounit = lsame_(diag, "N");
00175 
00176 /*     Set up the start point in X if the increment is not unity. This */
00177 /*     will be  ( N - 1 )*INCX  too small for descending loops. */
00178 
00179     if (*incx <= 0) {
00180         kx = 1 - (*n - 1) * *incx;
00181     } else if (*incx != 1) {
00182         kx = 1;
00183     }
00184 
00185 /*     Start the operations. In this version the elements of AP are */
00186 /*     accessed sequentially with one pass through AP. */
00187 
00188     if (lsame_(trans, "N")) {
00189 
00190 /*        Form  x := inv( A )*x. */
00191 
00192         if (lsame_(uplo, "U")) {
00193             kk = *n * (*n + 1) / 2;
00194             if (*incx == 1) {
00195                 for (j = *n; j >= 1; --j) {
00196                     i__1 = j;
00197                     if (x[i__1].r != 0. || x[i__1].i != 0.) {
00198                         if (nounit) {
00199                             i__1 = j;
00200                             z_div(&z__1, &x[j], &ap[kk]);
00201                             x[i__1].r = z__1.r, x[i__1].i = z__1.i;
00202                         }
00203                         i__1 = j;
00204                         temp.r = x[i__1].r, temp.i = x[i__1].i;
00205                         k = kk - 1;
00206                         for (i__ = j - 1; i__ >= 1; --i__) {
00207                             i__1 = i__;
00208                             i__2 = i__;
00209                             i__3 = k;
00210                             z__2.r = temp.r * ap[i__3].r - temp.i * ap[i__3]
00211                                     .i, z__2.i = temp.r * ap[i__3].i + temp.i 
00212                                     * ap[i__3].r;
00213                             z__1.r = x[i__2].r - z__2.r, z__1.i = x[i__2].i - 
00214                                     z__2.i;
00215                             x[i__1].r = z__1.r, x[i__1].i = z__1.i;
00216                             --k;
00217 /* L10: */
00218                         }
00219                     }
00220                     kk -= j;
00221 /* L20: */
00222                 }
00223             } else {
00224                 jx = kx + (*n - 1) * *incx;
00225                 for (j = *n; j >= 1; --j) {
00226                     i__1 = jx;
00227                     if (x[i__1].r != 0. || x[i__1].i != 0.) {
00228                         if (nounit) {
00229                             i__1 = jx;
00230                             z_div(&z__1, &x[jx], &ap[kk]);
00231                             x[i__1].r = z__1.r, x[i__1].i = z__1.i;
00232                         }
00233                         i__1 = jx;
00234                         temp.r = x[i__1].r, temp.i = x[i__1].i;
00235                         ix = jx;
00236                         i__1 = kk - j + 1;
00237                         for (k = kk - 1; k >= i__1; --k) {
00238                             ix -= *incx;
00239                             i__2 = ix;
00240                             i__3 = ix;
00241                             i__4 = k;
00242                             z__2.r = temp.r * ap[i__4].r - temp.i * ap[i__4]
00243                                     .i, z__2.i = temp.r * ap[i__4].i + temp.i 
00244                                     * ap[i__4].r;
00245                             z__1.r = x[i__3].r - z__2.r, z__1.i = x[i__3].i - 
00246                                     z__2.i;
00247                             x[i__2].r = z__1.r, x[i__2].i = z__1.i;
00248 /* L30: */
00249                         }
00250                     }
00251                     jx -= *incx;
00252                     kk -= j;
00253 /* L40: */
00254                 }
00255             }
00256         } else {
00257             kk = 1;
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], &ap[kk]);
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                         k = kk + 1;
00271                         i__2 = *n;
00272                         for (i__ = j + 1; i__ <= i__2; ++i__) {
00273                             i__3 = i__;
00274                             i__4 = i__;
00275                             i__5 = k;
00276                             z__2.r = temp.r * ap[i__5].r - temp.i * ap[i__5]
00277                                     .i, z__2.i = temp.r * ap[i__5].i + temp.i 
00278                                     * ap[i__5].r;
00279                             z__1.r = x[i__4].r - z__2.r, z__1.i = x[i__4].i - 
00280                                     z__2.i;
00281                             x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00282                             ++k;
00283 /* L50: */
00284                         }
00285                     }
00286                     kk += *n - j + 1;
00287 /* L60: */
00288                 }
00289             } else {
00290                 jx = kx;
00291                 i__1 = *n;
00292                 for (j = 1; j <= i__1; ++j) {
00293                     i__2 = jx;
00294                     if (x[i__2].r != 0. || x[i__2].i != 0.) {
00295                         if (nounit) {
00296                             i__2 = jx;
00297                             z_div(&z__1, &x[jx], &ap[kk]);
00298                             x[i__2].r = z__1.r, x[i__2].i = z__1.i;
00299                         }
00300                         i__2 = jx;
00301                         temp.r = x[i__2].r, temp.i = x[i__2].i;
00302                         ix = jx;
00303                         i__2 = kk + *n - j;
00304                         for (k = kk + 1; k <= i__2; ++k) {
00305                             ix += *incx;
00306                             i__3 = ix;
00307                             i__4 = ix;
00308                             i__5 = k;
00309                             z__2.r = temp.r * ap[i__5].r - temp.i * ap[i__5]
00310                                     .i, z__2.i = temp.r * ap[i__5].i + temp.i 
00311                                     * ap[i__5].r;
00312                             z__1.r = x[i__4].r - z__2.r, z__1.i = x[i__4].i - 
00313                                     z__2.i;
00314                             x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00315 /* L70: */
00316                         }
00317                     }
00318                     jx += *incx;
00319                     kk += *n - j + 1;
00320 /* L80: */
00321                 }
00322             }
00323         }
00324     } else {
00325 
00326 /*        Form  x := inv( A' )*x  or  x := inv( conjg( A' ) )*x. */
00327 
00328         if (lsame_(uplo, "U")) {
00329             kk = 1;
00330             if (*incx == 1) {
00331                 i__1 = *n;
00332                 for (j = 1; j <= i__1; ++j) {
00333                     i__2 = j;
00334                     temp.r = x[i__2].r, temp.i = x[i__2].i;
00335                     k = kk;
00336                     if (noconj) {
00337                         i__2 = j - 1;
00338                         for (i__ = 1; i__ <= i__2; ++i__) {
00339                             i__3 = k;
00340                             i__4 = i__;
00341                             z__2.r = ap[i__3].r * x[i__4].r - ap[i__3].i * x[
00342                                     i__4].i, z__2.i = ap[i__3].r * x[i__4].i 
00343                                     + ap[i__3].i * x[i__4].r;
00344                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00345                                     z__2.i;
00346                             temp.r = z__1.r, temp.i = z__1.i;
00347                             ++k;
00348 /* L90: */
00349                         }
00350                         if (nounit) {
00351                             z_div(&z__1, &temp, &ap[kk + j - 1]);
00352                             temp.r = z__1.r, temp.i = z__1.i;
00353                         }
00354                     } else {
00355                         i__2 = j - 1;
00356                         for (i__ = 1; i__ <= i__2; ++i__) {
00357                             d_cnjg(&z__3, &ap[k]);
00358                             i__3 = i__;
00359                             z__2.r = z__3.r * x[i__3].r - z__3.i * x[i__3].i, 
00360                                     z__2.i = z__3.r * x[i__3].i + z__3.i * x[
00361                                     i__3].r;
00362                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00363                                     z__2.i;
00364                             temp.r = z__1.r, temp.i = z__1.i;
00365                             ++k;
00366 /* L100: */
00367                         }
00368                         if (nounit) {
00369                             d_cnjg(&z__2, &ap[kk + j - 1]);
00370                             z_div(&z__1, &temp, &z__2);
00371                             temp.r = z__1.r, temp.i = z__1.i;
00372                         }
00373                     }
00374                     i__2 = j;
00375                     x[i__2].r = temp.r, x[i__2].i = temp.i;
00376                     kk += j;
00377 /* L110: */
00378                 }
00379             } else {
00380                 jx = kx;
00381                 i__1 = *n;
00382                 for (j = 1; j <= i__1; ++j) {
00383                     i__2 = jx;
00384                     temp.r = x[i__2].r, temp.i = x[i__2].i;
00385                     ix = kx;
00386                     if (noconj) {
00387                         i__2 = kk + j - 2;
00388                         for (k = kk; k <= i__2; ++k) {
00389                             i__3 = k;
00390                             i__4 = ix;
00391                             z__2.r = ap[i__3].r * x[i__4].r - ap[i__3].i * x[
00392                                     i__4].i, z__2.i = ap[i__3].r * x[i__4].i 
00393                                     + ap[i__3].i * x[i__4].r;
00394                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00395                                     z__2.i;
00396                             temp.r = z__1.r, temp.i = z__1.i;
00397                             ix += *incx;
00398 /* L120: */
00399                         }
00400                         if (nounit) {
00401                             z_div(&z__1, &temp, &ap[kk + j - 1]);
00402                             temp.r = z__1.r, temp.i = z__1.i;
00403                         }
00404                     } else {
00405                         i__2 = kk + j - 2;
00406                         for (k = kk; k <= i__2; ++k) {
00407                             d_cnjg(&z__3, &ap[k]);
00408                             i__3 = ix;
00409                             z__2.r = z__3.r * x[i__3].r - z__3.i * x[i__3].i, 
00410                                     z__2.i = z__3.r * x[i__3].i + z__3.i * x[
00411                                     i__3].r;
00412                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00413                                     z__2.i;
00414                             temp.r = z__1.r, temp.i = z__1.i;
00415                             ix += *incx;
00416 /* L130: */
00417                         }
00418                         if (nounit) {
00419                             d_cnjg(&z__2, &ap[kk + j - 1]);
00420                             z_div(&z__1, &temp, &z__2);
00421                             temp.r = z__1.r, temp.i = z__1.i;
00422                         }
00423                     }
00424                     i__2 = jx;
00425                     x[i__2].r = temp.r, x[i__2].i = temp.i;
00426                     jx += *incx;
00427                     kk += j;
00428 /* L140: */
00429                 }
00430             }
00431         } else {
00432             kk = *n * (*n + 1) / 2;
00433             if (*incx == 1) {
00434                 for (j = *n; j >= 1; --j) {
00435                     i__1 = j;
00436                     temp.r = x[i__1].r, temp.i = x[i__1].i;
00437                     k = kk;
00438                     if (noconj) {
00439                         i__1 = j + 1;
00440                         for (i__ = *n; i__ >= i__1; --i__) {
00441                             i__2 = k;
00442                             i__3 = i__;
00443                             z__2.r = ap[i__2].r * x[i__3].r - ap[i__2].i * x[
00444                                     i__3].i, z__2.i = ap[i__2].r * x[i__3].i 
00445                                     + ap[i__2].i * x[i__3].r;
00446                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00447                                     z__2.i;
00448                             temp.r = z__1.r, temp.i = z__1.i;
00449                             --k;
00450 /* L150: */
00451                         }
00452                         if (nounit) {
00453                             z_div(&z__1, &temp, &ap[kk - *n + j]);
00454                             temp.r = z__1.r, temp.i = z__1.i;
00455                         }
00456                     } else {
00457                         i__1 = j + 1;
00458                         for (i__ = *n; i__ >= i__1; --i__) {
00459                             d_cnjg(&z__3, &ap[k]);
00460                             i__2 = i__;
00461                             z__2.r = z__3.r * x[i__2].r - z__3.i * x[i__2].i, 
00462                                     z__2.i = z__3.r * x[i__2].i + z__3.i * x[
00463                                     i__2].r;
00464                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00465                                     z__2.i;
00466                             temp.r = z__1.r, temp.i = z__1.i;
00467                             --k;
00468 /* L160: */
00469                         }
00470                         if (nounit) {
00471                             d_cnjg(&z__2, &ap[kk - *n + j]);
00472                             z_div(&z__1, &temp, &z__2);
00473                             temp.r = z__1.r, temp.i = z__1.i;
00474                         }
00475                     }
00476                     i__1 = j;
00477                     x[i__1].r = temp.r, x[i__1].i = temp.i;
00478                     kk -= *n - j + 1;
00479 /* L170: */
00480                 }
00481             } else {
00482                 kx += (*n - 1) * *incx;
00483                 jx = kx;
00484                 for (j = *n; j >= 1; --j) {
00485                     i__1 = jx;
00486                     temp.r = x[i__1].r, temp.i = x[i__1].i;
00487                     ix = kx;
00488                     if (noconj) {
00489                         i__1 = kk - (*n - (j + 1));
00490                         for (k = kk; k >= i__1; --k) {
00491                             i__2 = k;
00492                             i__3 = ix;
00493                             z__2.r = ap[i__2].r * x[i__3].r - ap[i__2].i * x[
00494                                     i__3].i, z__2.i = ap[i__2].r * x[i__3].i 
00495                                     + ap[i__2].i * x[i__3].r;
00496                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00497                                     z__2.i;
00498                             temp.r = z__1.r, temp.i = z__1.i;
00499                             ix -= *incx;
00500 /* L180: */
00501                         }
00502                         if (nounit) {
00503                             z_div(&z__1, &temp, &ap[kk - *n + j]);
00504                             temp.r = z__1.r, temp.i = z__1.i;
00505                         }
00506                     } else {
00507                         i__1 = kk - (*n - (j + 1));
00508                         for (k = kk; k >= i__1; --k) {
00509                             d_cnjg(&z__3, &ap[k]);
00510                             i__2 = ix;
00511                             z__2.r = z__3.r * x[i__2].r - z__3.i * x[i__2].i, 
00512                                     z__2.i = z__3.r * x[i__2].i + z__3.i * x[
00513                                     i__2].r;
00514                             z__1.r = temp.r - z__2.r, z__1.i = temp.i - 
00515                                     z__2.i;
00516                             temp.r = z__1.r, temp.i = z__1.i;
00517                             ix -= *incx;
00518 /* L190: */
00519                         }
00520                         if (nounit) {
00521                             d_cnjg(&z__2, &ap[kk - *n + j]);
00522                             z_div(&z__1, &temp, &z__2);
00523                             temp.r = z__1.r, temp.i = z__1.i;
00524                         }
00525                     }
00526                     i__1 = jx;
00527                     x[i__1].r = temp.r, x[i__1].i = temp.i;
00528                     jx -= *incx;
00529                     kk -= *n - j + 1;
00530 /* L200: */
00531                 }
00532             }
00533         }
00534     }
00535 
00536     return 0;
00537 
00538 /*     End of ZTPSV . */
00539 
00540 } /* ztpsv_ */


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