LAPACK 3.3.1
Linear Algebra PACKage

ctpsv.f

Go to the documentation of this file.
00001       SUBROUTINE CTPSV(UPLO,TRANS,DIAG,N,AP,X,INCX)
00002 *     .. Scalar Arguments ..
00003       INTEGER INCX,N
00004       CHARACTER DIAG,TRANS,UPLO
00005 *     ..
00006 *     .. Array Arguments ..
00007       COMPLEX AP(*),X(*)
00008 *     ..
00009 *
00010 *  Purpose
00011 *  =======
00012 *
00013 *  CTPSV  solves one of the systems of equations
00014 *
00015 *     A*x = b,   or   A**T*x = b,   or   A**H*x = b,
00016 *
00017 *  where b and x are n element vectors and A is an n by n unit, or
00018 *  non-unit, upper or lower triangular matrix, supplied in packed form.
00019 *
00020 *  No test for singularity or near-singularity is included in this
00021 *  routine. Such tests must be performed before calling this routine.
00022 *
00023 *  Arguments
00024 *  ==========
00025 *
00026 *  UPLO   - CHARACTER*1.
00027 *           On entry, UPLO specifies whether the matrix is an upper or
00028 *           lower triangular matrix as follows:
00029 *
00030 *              UPLO = 'U' or 'u'   A is an upper triangular matrix.
00031 *
00032 *              UPLO = 'L' or 'l'   A is a lower triangular matrix.
00033 *
00034 *           Unchanged on exit.
00035 *
00036 *  TRANS  - CHARACTER*1.
00037 *           On entry, TRANS specifies the equations to be solved as
00038 *           follows:
00039 *
00040 *              TRANS = 'N' or 'n'   A*x = b.
00041 *
00042 *              TRANS = 'T' or 't'   A**T*x = b.
00043 *
00044 *              TRANS = 'C' or 'c'   A**H*x = b.
00045 *
00046 *           Unchanged on exit.
00047 *
00048 *  DIAG   - CHARACTER*1.
00049 *           On entry, DIAG specifies whether or not A is unit
00050 *           triangular as follows:
00051 *
00052 *              DIAG = 'U' or 'u'   A is assumed to be unit triangular.
00053 *
00054 *              DIAG = 'N' or 'n'   A is not assumed to be unit
00055 *                                  triangular.
00056 *
00057 *           Unchanged on exit.
00058 *
00059 *  N      - INTEGER.
00060 *           On entry, N specifies the order of the matrix A.
00061 *           N must be at least zero.
00062 *           Unchanged on exit.
00063 *
00064 *  AP     - COMPLEX          array of DIMENSION at least
00065 *           ( ( n*( n + 1 ) )/2 ).
00066 *           Before entry with  UPLO = 'U' or 'u', the array AP must
00067 *           contain the upper triangular matrix packed sequentially,
00068 *           column by column, so that AP( 1 ) contains a( 1, 1 ),
00069 *           AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 )
00070 *           respectively, and so on.
00071 *           Before entry with UPLO = 'L' or 'l', the array AP must
00072 *           contain the lower triangular matrix packed sequentially,
00073 *           column by column, so that AP( 1 ) contains a( 1, 1 ),
00074 *           AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 )
00075 *           respectively, and so on.
00076 *           Note that when  DIAG = 'U' or 'u', the diagonal elements of
00077 *           A are not referenced, but are assumed to be unity.
00078 *           Unchanged on exit.
00079 *
00080 *  X      - COMPLEX          array of dimension at least
00081 *           ( 1 + ( n - 1 )*abs( INCX ) ).
00082 *           Before entry, the incremented array X must contain the n
00083 *           element right-hand side vector b. On exit, X is overwritten
00084 *           with the solution vector x.
00085 *
00086 *  INCX   - INTEGER.
00087 *           On entry, INCX specifies the increment for the elements of
00088 *           X. INCX must not be zero.
00089 *           Unchanged on exit.
00090 *
00091 *  Further Details
00092 *  ===============
00093 *
00094 *  Level 2 Blas routine.
00095 *
00096 *  -- Written on 22-October-1986.
00097 *     Jack Dongarra, Argonne National Lab.
00098 *     Jeremy Du Croz, Nag Central Office.
00099 *     Sven Hammarling, Nag Central Office.
00100 *     Richard Hanson, Sandia National Labs.
00101 *
00102 *  =====================================================================
00103 *
00104 *     .. Parameters ..
00105       COMPLEX ZERO
00106       PARAMETER (ZERO= (0.0E+0,0.0E+0))
00107 *     ..
00108 *     .. Local Scalars ..
00109       COMPLEX TEMP
00110       INTEGER I,INFO,IX,J,JX,K,KK,KX
00111       LOGICAL NOCONJ,NOUNIT
00112 *     ..
00113 *     .. External Functions ..
00114       LOGICAL LSAME
00115       EXTERNAL LSAME
00116 *     ..
00117 *     .. External Subroutines ..
00118       EXTERNAL XERBLA
00119 *     ..
00120 *     .. Intrinsic Functions ..
00121       INTRINSIC CONJG
00122 *     ..
00123 *
00124 *     Test the input parameters.
00125 *
00126       INFO = 0
00127       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
00128           INFO = 1
00129       ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND.
00130      +         .NOT.LSAME(TRANS,'C')) THEN
00131           INFO = 2
00132       ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN
00133           INFO = 3
00134       ELSE IF (N.LT.0) THEN
00135           INFO = 4
00136       ELSE IF (INCX.EQ.0) THEN
00137           INFO = 7
00138       END IF
00139       IF (INFO.NE.0) THEN
00140           CALL XERBLA('CTPSV ',INFO)
00141           RETURN
00142       END IF
00143 *
00144 *     Quick return if possible.
00145 *
00146       IF (N.EQ.0) RETURN
00147 *
00148       NOCONJ = LSAME(TRANS,'T')
00149       NOUNIT = LSAME(DIAG,'N')
00150 *
00151 *     Set up the start point in X if the increment is not unity. This
00152 *     will be  ( N - 1 )*INCX  too small for descending loops.
00153 *
00154       IF (INCX.LE.0) THEN
00155           KX = 1 - (N-1)*INCX
00156       ELSE IF (INCX.NE.1) THEN
00157           KX = 1
00158       END IF
00159 *
00160 *     Start the operations. In this version the elements of AP are
00161 *     accessed sequentially with one pass through AP.
00162 *
00163       IF (LSAME(TRANS,'N')) THEN
00164 *
00165 *        Form  x := inv( A )*x.
00166 *
00167           IF (LSAME(UPLO,'U')) THEN
00168               KK = (N* (N+1))/2
00169               IF (INCX.EQ.1) THEN
00170                   DO 20 J = N,1,-1
00171                       IF (X(J).NE.ZERO) THEN
00172                           IF (NOUNIT) X(J) = X(J)/AP(KK)
00173                           TEMP = X(J)
00174                           K = KK - 1
00175                           DO 10 I = J - 1,1,-1
00176                               X(I) = X(I) - TEMP*AP(K)
00177                               K = K - 1
00178    10                     CONTINUE
00179                       END IF
00180                       KK = KK - J
00181    20             CONTINUE
00182               ELSE
00183                   JX = KX + (N-1)*INCX
00184                   DO 40 J = N,1,-1
00185                       IF (X(JX).NE.ZERO) THEN
00186                           IF (NOUNIT) X(JX) = X(JX)/AP(KK)
00187                           TEMP = X(JX)
00188                           IX = JX
00189                           DO 30 K = KK - 1,KK - J + 1,-1
00190                               IX = IX - INCX
00191                               X(IX) = X(IX) - TEMP*AP(K)
00192    30                     CONTINUE
00193                       END IF
00194                       JX = JX - INCX
00195                       KK = KK - J
00196    40             CONTINUE
00197               END IF
00198           ELSE
00199               KK = 1
00200               IF (INCX.EQ.1) THEN
00201                   DO 60 J = 1,N
00202                       IF (X(J).NE.ZERO) THEN
00203                           IF (NOUNIT) X(J) = X(J)/AP(KK)
00204                           TEMP = X(J)
00205                           K = KK + 1
00206                           DO 50 I = J + 1,N
00207                               X(I) = X(I) - TEMP*AP(K)
00208                               K = K + 1
00209    50                     CONTINUE
00210                       END IF
00211                       KK = KK + (N-J+1)
00212    60             CONTINUE
00213               ELSE
00214                   JX = KX
00215                   DO 80 J = 1,N
00216                       IF (X(JX).NE.ZERO) THEN
00217                           IF (NOUNIT) X(JX) = X(JX)/AP(KK)
00218                           TEMP = X(JX)
00219                           IX = JX
00220                           DO 70 K = KK + 1,KK + N - J
00221                               IX = IX + INCX
00222                               X(IX) = X(IX) - TEMP*AP(K)
00223    70                     CONTINUE
00224                       END IF
00225                       JX = JX + INCX
00226                       KK = KK + (N-J+1)
00227    80             CONTINUE
00228               END IF
00229           END IF
00230       ELSE
00231 *
00232 *        Form  x := inv( A**T )*x  or  x := inv( A**H )*x.
00233 *
00234           IF (LSAME(UPLO,'U')) THEN
00235               KK = 1
00236               IF (INCX.EQ.1) THEN
00237                   DO 110 J = 1,N
00238                       TEMP = X(J)
00239                       K = KK
00240                       IF (NOCONJ) THEN
00241                           DO 90 I = 1,J - 1
00242                               TEMP = TEMP - AP(K)*X(I)
00243                               K = K + 1
00244    90                     CONTINUE
00245                           IF (NOUNIT) TEMP = TEMP/AP(KK+J-1)
00246                       ELSE
00247                           DO 100 I = 1,J - 1
00248                               TEMP = TEMP - CONJG(AP(K))*X(I)
00249                               K = K + 1
00250   100                     CONTINUE
00251                           IF (NOUNIT) TEMP = TEMP/CONJG(AP(KK+J-1))
00252                       END IF
00253                       X(J) = TEMP
00254                       KK = KK + J
00255   110             CONTINUE
00256               ELSE
00257                   JX = KX
00258                   DO 140 J = 1,N
00259                       TEMP = X(JX)
00260                       IX = KX
00261                       IF (NOCONJ) THEN
00262                           DO 120 K = KK,KK + J - 2
00263                               TEMP = TEMP - AP(K)*X(IX)
00264                               IX = IX + INCX
00265   120                     CONTINUE
00266                           IF (NOUNIT) TEMP = TEMP/AP(KK+J-1)
00267                       ELSE
00268                           DO 130 K = KK,KK + J - 2
00269                               TEMP = TEMP - CONJG(AP(K))*X(IX)
00270                               IX = IX + INCX
00271   130                     CONTINUE
00272                           IF (NOUNIT) TEMP = TEMP/CONJG(AP(KK+J-1))
00273                       END IF
00274                       X(JX) = TEMP
00275                       JX = JX + INCX
00276                       KK = KK + J
00277   140             CONTINUE
00278               END IF
00279           ELSE
00280               KK = (N* (N+1))/2
00281               IF (INCX.EQ.1) THEN
00282                   DO 170 J = N,1,-1
00283                       TEMP = X(J)
00284                       K = KK
00285                       IF (NOCONJ) THEN
00286                           DO 150 I = N,J + 1,-1
00287                               TEMP = TEMP - AP(K)*X(I)
00288                               K = K - 1
00289   150                     CONTINUE
00290                           IF (NOUNIT) TEMP = TEMP/AP(KK-N+J)
00291                       ELSE
00292                           DO 160 I = N,J + 1,-1
00293                               TEMP = TEMP - CONJG(AP(K))*X(I)
00294                               K = K - 1
00295   160                     CONTINUE
00296                           IF (NOUNIT) TEMP = TEMP/CONJG(AP(KK-N+J))
00297                       END IF
00298                       X(J) = TEMP
00299                       KK = KK - (N-J+1)
00300   170             CONTINUE
00301               ELSE
00302                   KX = KX + (N-1)*INCX
00303                   JX = KX
00304                   DO 200 J = N,1,-1
00305                       TEMP = X(JX)
00306                       IX = KX
00307                       IF (NOCONJ) THEN
00308                           DO 180 K = KK,KK - (N- (J+1)),-1
00309                               TEMP = TEMP - AP(K)*X(IX)
00310                               IX = IX - INCX
00311   180                     CONTINUE
00312                           IF (NOUNIT) TEMP = TEMP/AP(KK-N+J)
00313                       ELSE
00314                           DO 190 K = KK,KK - (N- (J+1)),-1
00315                               TEMP = TEMP - CONJG(AP(K))*X(IX)
00316                               IX = IX - INCX
00317   190                     CONTINUE
00318                           IF (NOUNIT) TEMP = TEMP/CONJG(AP(KK-N+J))
00319                       END IF
00320                       X(JX) = TEMP
00321                       JX = JX - INCX
00322                       KK = KK - (N-J+1)
00323   200             CONTINUE
00324               END IF
00325           END IF
00326       END IF
00327 *
00328       RETURN
00329 *
00330 *     End of CTPSV .
00331 *
00332       END
 All Files Functions