LAPACK 3.3.0

cher2.f

Go to the documentation of this file.
00001       SUBROUTINE CHER2(UPLO,N,ALPHA,X,INCX,Y,INCY,A,LDA)
00002 *     .. Scalar Arguments ..
00003       COMPLEX ALPHA
00004       INTEGER INCX,INCY,LDA,N
00005       CHARACTER UPLO
00006 *     ..
00007 *     .. Array Arguments ..
00008       COMPLEX A(LDA,*),X(*),Y(*)
00009 *     ..
00010 *
00011 *  Purpose
00012 *  =======
00013 *
00014 *  CHER2  performs the hermitian rank 2 operation
00015 *
00016 *     A := alpha*x*conjg( y' ) + conjg( alpha )*y*conjg( x' ) + A,
00017 *
00018 *  where alpha is a scalar, x and y are n element vectors and A is an n
00019 *  by n hermitian matrix.
00020 *
00021 *  Arguments
00022 *  ==========
00023 *
00024 *  UPLO   - CHARACTER*1.
00025 *           On entry, UPLO specifies whether the upper or lower
00026 *           triangular part of the array A is to be referenced as
00027 *           follows:
00028 *
00029 *              UPLO = 'U' or 'u'   Only the upper triangular part of A
00030 *                                  is to be referenced.
00031 *
00032 *              UPLO = 'L' or 'l'   Only the lower triangular part of A
00033 *                                  is to be referenced.
00034 *
00035 *           Unchanged on exit.
00036 *
00037 *  N      - INTEGER.
00038 *           On entry, N specifies the order of the matrix A.
00039 *           N must be at least zero.
00040 *           Unchanged on exit.
00041 *
00042 *  ALPHA  - COMPLEX         .
00043 *           On entry, ALPHA specifies the scalar alpha.
00044 *           Unchanged on exit.
00045 *
00046 *  X      - COMPLEX          array of dimension at least
00047 *           ( 1 + ( n - 1 )*abs( INCX ) ).
00048 *           Before entry, the incremented array X must contain the n
00049 *           element vector x.
00050 *           Unchanged on exit.
00051 *
00052 *  INCX   - INTEGER.
00053 *           On entry, INCX specifies the increment for the elements of
00054 *           X. INCX must not be zero.
00055 *           Unchanged on exit.
00056 *
00057 *  Y      - COMPLEX          array of dimension at least
00058 *           ( 1 + ( n - 1 )*abs( INCY ) ).
00059 *           Before entry, the incremented array Y must contain the n
00060 *           element vector y.
00061 *           Unchanged on exit.
00062 *
00063 *  INCY   - INTEGER.
00064 *           On entry, INCY specifies the increment for the elements of
00065 *           Y. INCY must not be zero.
00066 *           Unchanged on exit.
00067 *
00068 *  A      - COMPLEX          array of DIMENSION ( LDA, n ).
00069 *           Before entry with  UPLO = 'U' or 'u', the leading n by n
00070 *           upper triangular part of the array A must contain the upper
00071 *           triangular part of the hermitian matrix and the strictly
00072 *           lower triangular part of A is not referenced. On exit, the
00073 *           upper triangular part of the array A is overwritten by the
00074 *           upper triangular part of the updated matrix.
00075 *           Before entry with UPLO = 'L' or 'l', the leading n by n
00076 *           lower triangular part of the array A must contain the lower
00077 *           triangular part of the hermitian matrix and the strictly
00078 *           upper triangular part of A is not referenced. On exit, the
00079 *           lower triangular part of the array A is overwritten by the
00080 *           lower triangular part of the updated matrix.
00081 *           Note that the imaginary parts of the diagonal elements need
00082 *           not be set, they are assumed to be zero, and on exit they
00083 *           are set to zero.
00084 *
00085 *  LDA    - INTEGER.
00086 *           On entry, LDA specifies the first dimension of A as declared
00087 *           in the calling (sub) program. LDA must be at least
00088 *           max( 1, n ).
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 TEMP1,TEMP2
00110       INTEGER I,INFO,IX,IY,J,JX,JY,KX,KY
00111 *     ..
00112 *     .. External Functions ..
00113       LOGICAL LSAME
00114       EXTERNAL LSAME
00115 *     ..
00116 *     .. External Subroutines ..
00117       EXTERNAL XERBLA
00118 *     ..
00119 *     .. Intrinsic Functions ..
00120       INTRINSIC CONJG,MAX,REAL
00121 *     ..
00122 *
00123 *     Test the input parameters.
00124 *
00125       INFO = 0
00126       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
00127           INFO = 1
00128       ELSE IF (N.LT.0) THEN
00129           INFO = 2
00130       ELSE IF (INCX.EQ.0) THEN
00131           INFO = 5
00132       ELSE IF (INCY.EQ.0) THEN
00133           INFO = 7
00134       ELSE IF (LDA.LT.MAX(1,N)) THEN
00135           INFO = 9
00136       END IF
00137       IF (INFO.NE.0) THEN
00138           CALL XERBLA('CHER2 ',INFO)
00139           RETURN
00140       END IF
00141 *
00142 *     Quick return if possible.
00143 *
00144       IF ((N.EQ.0) .OR. (ALPHA.EQ.ZERO)) RETURN
00145 *
00146 *     Set up the start points in X and Y if the increments are not both
00147 *     unity.
00148 *
00149       IF ((INCX.NE.1) .OR. (INCY.NE.1)) THEN
00150           IF (INCX.GT.0) THEN
00151               KX = 1
00152           ELSE
00153               KX = 1 - (N-1)*INCX
00154           END IF
00155           IF (INCY.GT.0) THEN
00156               KY = 1
00157           ELSE
00158               KY = 1 - (N-1)*INCY
00159           END IF
00160           JX = KX
00161           JY = KY
00162       END IF
00163 *
00164 *     Start the operations. In this version the elements of A are
00165 *     accessed sequentially with one pass through the triangular part
00166 *     of A.
00167 *
00168       IF (LSAME(UPLO,'U')) THEN
00169 *
00170 *        Form  A  when A is stored in the upper triangle.
00171 *
00172           IF ((INCX.EQ.1) .AND. (INCY.EQ.1)) THEN
00173               DO 20 J = 1,N
00174                   IF ((X(J).NE.ZERO) .OR. (Y(J).NE.ZERO)) THEN
00175                       TEMP1 = ALPHA*CONJG(Y(J))
00176                       TEMP2 = CONJG(ALPHA*X(J))
00177                       DO 10 I = 1,J - 1
00178                           A(I,J) = A(I,J) + X(I)*TEMP1 + Y(I)*TEMP2
00179    10                 CONTINUE
00180                       A(J,J) = REAL(A(J,J)) +
00181      +                         REAL(X(J)*TEMP1+Y(J)*TEMP2)
00182                   ELSE
00183                       A(J,J) = REAL(A(J,J))
00184                   END IF
00185    20         CONTINUE
00186           ELSE
00187               DO 40 J = 1,N
00188                   IF ((X(JX).NE.ZERO) .OR. (Y(JY).NE.ZERO)) THEN
00189                       TEMP1 = ALPHA*CONJG(Y(JY))
00190                       TEMP2 = CONJG(ALPHA*X(JX))
00191                       IX = KX
00192                       IY = KY
00193                       DO 30 I = 1,J - 1
00194                           A(I,J) = A(I,J) + X(IX)*TEMP1 + Y(IY)*TEMP2
00195                           IX = IX + INCX
00196                           IY = IY + INCY
00197    30                 CONTINUE
00198                       A(J,J) = REAL(A(J,J)) +
00199      +                         REAL(X(JX)*TEMP1+Y(JY)*TEMP2)
00200                   ELSE
00201                       A(J,J) = REAL(A(J,J))
00202                   END IF
00203                   JX = JX + INCX
00204                   JY = JY + INCY
00205    40         CONTINUE
00206           END IF
00207       ELSE
00208 *
00209 *        Form  A  when A is stored in the lower triangle.
00210 *
00211           IF ((INCX.EQ.1) .AND. (INCY.EQ.1)) THEN
00212               DO 60 J = 1,N
00213                   IF ((X(J).NE.ZERO) .OR. (Y(J).NE.ZERO)) THEN
00214                       TEMP1 = ALPHA*CONJG(Y(J))
00215                       TEMP2 = CONJG(ALPHA*X(J))
00216                       A(J,J) = REAL(A(J,J)) +
00217      +                         REAL(X(J)*TEMP1+Y(J)*TEMP2)
00218                       DO 50 I = J + 1,N
00219                           A(I,J) = A(I,J) + X(I)*TEMP1 + Y(I)*TEMP2
00220    50                 CONTINUE
00221                   ELSE
00222                       A(J,J) = REAL(A(J,J))
00223                   END IF
00224    60         CONTINUE
00225           ELSE
00226               DO 80 J = 1,N
00227                   IF ((X(JX).NE.ZERO) .OR. (Y(JY).NE.ZERO)) THEN
00228                       TEMP1 = ALPHA*CONJG(Y(JY))
00229                       TEMP2 = CONJG(ALPHA*X(JX))
00230                       A(J,J) = REAL(A(J,J)) +
00231      +                         REAL(X(JX)*TEMP1+Y(JY)*TEMP2)
00232                       IX = JX
00233                       IY = JY
00234                       DO 70 I = J + 1,N
00235                           IX = IX + INCX
00236                           IY = IY + INCY
00237                           A(I,J) = A(I,J) + X(IX)*TEMP1 + Y(IY)*TEMP2
00238    70                 CONTINUE
00239                   ELSE
00240                       A(J,J) = REAL(A(J,J))
00241                   END IF
00242                   JX = JX + INCX
00243                   JY = JY + INCY
00244    80         CONTINUE
00245           END IF
00246       END IF
00247 *
00248       RETURN
00249 *
00250 *     End of CHER2 .
00251 *
00252       END
 All Files Functions