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


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