LAPACK 3.3.0

ztrsv.f

Go to the documentation of this file.
00001       SUBROUTINE ZTRSV(UPLO,TRANS,DIAG,N,A,LDA,X,INCX)
00002 *     .. Scalar Arguments ..
00003       INTEGER INCX,LDA,N
00004       CHARACTER DIAG,TRANS,UPLO
00005 *     ..
00006 *     .. Array Arguments ..
00007       DOUBLE COMPLEX A(LDA,*),X(*)
00008 *     ..
00009 *
00010 *  Purpose
00011 *  =======
00012 *
00013 *  ZTRSV  solves one of the systems of equations
00014 *
00015 *     A*x = b,   or   A'*x = b,   or   conjg( A' )*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.
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'*x = b.
00043 *
00044 *              TRANS = 'C' or 'c'   conjg( A' )*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 *  A      - COMPLEX*16       array of DIMENSION ( LDA, n ).
00065 *           Before entry with  UPLO = 'U' or 'u', the leading n by n
00066 *           upper triangular part of the array A must contain the upper
00067 *           triangular matrix and the strictly lower triangular part of
00068 *           A is not referenced.
00069 *           Before entry with UPLO = 'L' or 'l', the leading n by n
00070 *           lower triangular part of the array A must contain the lower
00071 *           triangular matrix and the strictly upper triangular part of
00072 *           A is not referenced.
00073 *           Note that when  DIAG = 'U' or 'u', the diagonal elements of
00074 *           A are not referenced either, but are assumed to be unity.
00075 *           Unchanged on exit.
00076 *
00077 *  LDA    - INTEGER.
00078 *           On entry, LDA specifies the first dimension of A as declared
00079 *           in the calling (sub) program. LDA must be at least
00080 *           max( 1, n ).
00081 *           Unchanged on exit.
00082 *
00083 *  X      - COMPLEX*16       array of dimension at least
00084 *           ( 1 + ( n - 1 )*abs( INCX ) ).
00085 *           Before entry, the incremented array X must contain the n
00086 *           element right-hand side vector b. On exit, X is overwritten
00087 *           with the solution vector x.
00088 *
00089 *  INCX   - INTEGER.
00090 *           On entry, INCX specifies the increment for the elements of
00091 *           X. INCX must not be zero.
00092 *           Unchanged on exit.
00093 *
00094 *  Further Details
00095 *  ===============
00096 *
00097 *  Level 2 Blas routine.
00098 *
00099 *  -- Written on 22-October-1986.
00100 *     Jack Dongarra, Argonne National Lab.
00101 *     Jeremy Du Croz, Nag Central Office.
00102 *     Sven Hammarling, Nag Central Office.
00103 *     Richard Hanson, Sandia National Labs.
00104 *
00105 *  =====================================================================
00106 *
00107 *     .. Parameters ..
00108       DOUBLE COMPLEX ZERO
00109       PARAMETER (ZERO= (0.0D+0,0.0D+0))
00110 *     ..
00111 *     .. Local Scalars ..
00112       DOUBLE COMPLEX TEMP
00113       INTEGER I,INFO,IX,J,JX,KX
00114       LOGICAL NOCONJ,NOUNIT
00115 *     ..
00116 *     .. External Functions ..
00117       LOGICAL LSAME
00118       EXTERNAL LSAME
00119 *     ..
00120 *     .. External Subroutines ..
00121       EXTERNAL XERBLA
00122 *     ..
00123 *     .. Intrinsic Functions ..
00124       INTRINSIC DCONJG,MAX
00125 *     ..
00126 *
00127 *     Test the input parameters.
00128 *
00129       INFO = 0
00130       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
00131           INFO = 1
00132       ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND.
00133      +         .NOT.LSAME(TRANS,'C')) THEN
00134           INFO = 2
00135       ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN
00136           INFO = 3
00137       ELSE IF (N.LT.0) THEN
00138           INFO = 4
00139       ELSE IF (LDA.LT.MAX(1,N)) THEN
00140           INFO = 6
00141       ELSE IF (INCX.EQ.0) THEN
00142           INFO = 8
00143       END IF
00144       IF (INFO.NE.0) THEN
00145           CALL XERBLA('ZTRSV ',INFO)
00146           RETURN
00147       END IF
00148 *
00149 *     Quick return if possible.
00150 *
00151       IF (N.EQ.0) RETURN
00152 *
00153       NOCONJ = LSAME(TRANS,'T')
00154       NOUNIT = LSAME(DIAG,'N')
00155 *
00156 *     Set up the start point in X if the increment is not unity. This
00157 *     will be  ( N - 1 )*INCX  too small for descending loops.
00158 *
00159       IF (INCX.LE.0) THEN
00160           KX = 1 - (N-1)*INCX
00161       ELSE IF (INCX.NE.1) THEN
00162           KX = 1
00163       END IF
00164 *
00165 *     Start the operations. In this version the elements of A are
00166 *     accessed sequentially with one pass through A.
00167 *
00168       IF (LSAME(TRANS,'N')) THEN
00169 *
00170 *        Form  x := inv( A )*x.
00171 *
00172           IF (LSAME(UPLO,'U')) THEN
00173               IF (INCX.EQ.1) THEN
00174                   DO 20 J = N,1,-1
00175                       IF (X(J).NE.ZERO) THEN
00176                           IF (NOUNIT) X(J) = X(J)/A(J,J)
00177                           TEMP = X(J)
00178                           DO 10 I = J - 1,1,-1
00179                               X(I) = X(I) - TEMP*A(I,J)
00180    10                     CONTINUE
00181                       END IF
00182    20             CONTINUE
00183               ELSE
00184                   JX = KX + (N-1)*INCX
00185                   DO 40 J = N,1,-1
00186                       IF (X(JX).NE.ZERO) THEN
00187                           IF (NOUNIT) X(JX) = X(JX)/A(J,J)
00188                           TEMP = X(JX)
00189                           IX = JX
00190                           DO 30 I = J - 1,1,-1
00191                               IX = IX - INCX
00192                               X(IX) = X(IX) - TEMP*A(I,J)
00193    30                     CONTINUE
00194                       END IF
00195                       JX = JX - INCX
00196    40             CONTINUE
00197               END IF
00198           ELSE
00199               IF (INCX.EQ.1) THEN
00200                   DO 60 J = 1,N
00201                       IF (X(J).NE.ZERO) THEN
00202                           IF (NOUNIT) X(J) = X(J)/A(J,J)
00203                           TEMP = X(J)
00204                           DO 50 I = J + 1,N
00205                               X(I) = X(I) - TEMP*A(I,J)
00206    50                     CONTINUE
00207                       END IF
00208    60             CONTINUE
00209               ELSE
00210                   JX = KX
00211                   DO 80 J = 1,N
00212                       IF (X(JX).NE.ZERO) THEN
00213                           IF (NOUNIT) X(JX) = X(JX)/A(J,J)
00214                           TEMP = X(JX)
00215                           IX = JX
00216                           DO 70 I = J + 1,N
00217                               IX = IX + INCX
00218                               X(IX) = X(IX) - TEMP*A(I,J)
00219    70                     CONTINUE
00220                       END IF
00221                       JX = JX + INCX
00222    80             CONTINUE
00223               END IF
00224           END IF
00225       ELSE
00226 *
00227 *        Form  x := inv( A' )*x  or  x := inv( conjg( A' ) )*x.
00228 *
00229           IF (LSAME(UPLO,'U')) THEN
00230               IF (INCX.EQ.1) THEN
00231                   DO 110 J = 1,N
00232                       TEMP = X(J)
00233                       IF (NOCONJ) THEN
00234                           DO 90 I = 1,J - 1
00235                               TEMP = TEMP - A(I,J)*X(I)
00236    90                     CONTINUE
00237                           IF (NOUNIT) TEMP = TEMP/A(J,J)
00238                       ELSE
00239                           DO 100 I = 1,J - 1
00240                               TEMP = TEMP - DCONJG(A(I,J))*X(I)
00241   100                     CONTINUE
00242                           IF (NOUNIT) TEMP = TEMP/DCONJG(A(J,J))
00243                       END IF
00244                       X(J) = TEMP
00245   110             CONTINUE
00246               ELSE
00247                   JX = KX
00248                   DO 140 J = 1,N
00249                       IX = KX
00250                       TEMP = X(JX)
00251                       IF (NOCONJ) THEN
00252                           DO 120 I = 1,J - 1
00253                               TEMP = TEMP - A(I,J)*X(IX)
00254                               IX = IX + INCX
00255   120                     CONTINUE
00256                           IF (NOUNIT) TEMP = TEMP/A(J,J)
00257                       ELSE
00258                           DO 130 I = 1,J - 1
00259                               TEMP = TEMP - DCONJG(A(I,J))*X(IX)
00260                               IX = IX + INCX
00261   130                     CONTINUE
00262                           IF (NOUNIT) TEMP = TEMP/DCONJG(A(J,J))
00263                       END IF
00264                       X(JX) = TEMP
00265                       JX = JX + INCX
00266   140             CONTINUE
00267               END IF
00268           ELSE
00269               IF (INCX.EQ.1) THEN
00270                   DO 170 J = N,1,-1
00271                       TEMP = X(J)
00272                       IF (NOCONJ) THEN
00273                           DO 150 I = N,J + 1,-1
00274                               TEMP = TEMP - A(I,J)*X(I)
00275   150                     CONTINUE
00276                           IF (NOUNIT) TEMP = TEMP/A(J,J)
00277                       ELSE
00278                           DO 160 I = N,J + 1,-1
00279                               TEMP = TEMP - DCONJG(A(I,J))*X(I)
00280   160                     CONTINUE
00281                           IF (NOUNIT) TEMP = TEMP/DCONJG(A(J,J))
00282                       END IF
00283                       X(J) = TEMP
00284   170             CONTINUE
00285               ELSE
00286                   KX = KX + (N-1)*INCX
00287                   JX = KX
00288                   DO 200 J = N,1,-1
00289                       IX = KX
00290                       TEMP = X(JX)
00291                       IF (NOCONJ) THEN
00292                           DO 180 I = N,J + 1,-1
00293                               TEMP = TEMP - A(I,J)*X(IX)
00294                               IX = IX - INCX
00295   180                     CONTINUE
00296                           IF (NOUNIT) TEMP = TEMP/A(J,J)
00297                       ELSE
00298                           DO 190 I = N,J + 1,-1
00299                               TEMP = TEMP - DCONJG(A(I,J))*X(IX)
00300                               IX = IX - INCX
00301   190                     CONTINUE
00302                           IF (NOUNIT) TEMP = TEMP/DCONJG(A(J,J))
00303                       END IF
00304                       X(JX) = TEMP
00305                       JX = JX - INCX
00306   200             CONTINUE
00307               END IF
00308           END IF
00309       END IF
00310 *
00311       RETURN
00312 *
00313 *     End of ZTRSV .
00314 *
00315       END
 All Files Functions