cher2.c
Go to the documentation of this file.
00001 /* cher2.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 cher2_(char *uplo, integer *n, complex *alpha, complex *
00017         x, integer *incx, complex *y, integer *incy, complex *a, integer *lda)
00018 {
00019     /* System generated locals */
00020     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
00021     real r__1;
00022     complex q__1, q__2, q__3, q__4;
00023 
00024     /* Builtin functions */
00025     void r_cnjg(complex *, complex *);
00026 
00027     /* Local variables */
00028     integer i__, j, ix, iy, jx, jy, kx, ky, info;
00029     complex temp1, temp2;
00030     extern logical lsame_(char *, char *);
00031     extern /* Subroutine */ int xerbla_(char *, integer *);
00032 
00033 /*     .. Scalar Arguments .. */
00034 /*     .. */
00035 /*     .. Array Arguments .. */
00036 /*     .. */
00037 
00038 /*  Purpose */
00039 /*  ======= */
00040 
00041 /*  CHER2  performs the hermitian rank 2 operation */
00042 
00043 /*     A := alpha*x*conjg( y' ) + conjg( alpha )*y*conjg( x' ) + A, */
00044 
00045 /*  where alpha is a scalar, x and y are n element vectors and A is an n */
00046 /*  by n hermitian matrix. */
00047 
00048 /*  Arguments */
00049 /*  ========== */
00050 
00051 /*  UPLO   - CHARACTER*1. */
00052 /*           On entry, UPLO specifies whether the upper or lower */
00053 /*           triangular part of the array A is to be referenced as */
00054 /*           follows: */
00055 
00056 /*              UPLO = 'U' or 'u'   Only the upper triangular part of A */
00057 /*                                  is to be referenced. */
00058 
00059 /*              UPLO = 'L' or 'l'   Only the lower triangular part of A */
00060 /*                                  is to be referenced. */
00061 
00062 /*           Unchanged on exit. */
00063 
00064 /*  N      - INTEGER. */
00065 /*           On entry, N specifies the order of the matrix A. */
00066 /*           N must be at least zero. */
00067 /*           Unchanged on exit. */
00068 
00069 /*  ALPHA  - COMPLEX         . */
00070 /*           On entry, ALPHA specifies the scalar alpha. */
00071 /*           Unchanged on exit. */
00072 
00073 /*  X      - COMPLEX          array of dimension at least */
00074 /*           ( 1 + ( n - 1 )*abs( INCX ) ). */
00075 /*           Before entry, the incremented array X must contain the n */
00076 /*           element vector x. */
00077 /*           Unchanged on exit. */
00078 
00079 /*  INCX   - INTEGER. */
00080 /*           On entry, INCX specifies the increment for the elements of */
00081 /*           X. INCX must not be zero. */
00082 /*           Unchanged on exit. */
00083 
00084 /*  Y      - COMPLEX          array of dimension at least */
00085 /*           ( 1 + ( n - 1 )*abs( INCY ) ). */
00086 /*           Before entry, the incremented array Y must contain the n */
00087 /*           element vector y. */
00088 /*           Unchanged on exit. */
00089 
00090 /*  INCY   - INTEGER. */
00091 /*           On entry, INCY specifies the increment for the elements of */
00092 /*           Y. INCY must not be zero. */
00093 /*           Unchanged on exit. */
00094 
00095 /*  A      - COMPLEX          array of DIMENSION ( LDA, n ). */
00096 /*           Before entry with  UPLO = 'U' or 'u', the leading n by n */
00097 /*           upper triangular part of the array A must contain the upper */
00098 /*           triangular part of the hermitian matrix and the strictly */
00099 /*           lower triangular part of A is not referenced. On exit, the */
00100 /*           upper triangular part of the array A is overwritten by the */
00101 /*           upper triangular part of the updated matrix. */
00102 /*           Before entry with UPLO = 'L' or 'l', the leading n by n */
00103 /*           lower triangular part of the array A must contain the lower */
00104 /*           triangular part of the hermitian matrix and the strictly */
00105 /*           upper triangular part of A is not referenced. On exit, the */
00106 /*           lower triangular part of the array A is overwritten by the */
00107 /*           lower triangular part of the updated matrix. */
00108 /*           Note that the imaginary parts of the diagonal elements need */
00109 /*           not be set, they are assumed to be zero, and on exit they */
00110 /*           are set to zero. */
00111 
00112 /*  LDA    - INTEGER. */
00113 /*           On entry, LDA specifies the first dimension of A as declared */
00114 /*           in the calling (sub) program. LDA must be at least */
00115 /*           max( 1, n ). */
00116 /*           Unchanged on exit. */
00117 
00118 
00119 /*  Level 2 Blas routine. */
00120 
00121 /*  -- Written on 22-October-1986. */
00122 /*     Jack Dongarra, Argonne National Lab. */
00123 /*     Jeremy Du Croz, Nag Central Office. */
00124 /*     Sven Hammarling, Nag Central Office. */
00125 /*     Richard Hanson, Sandia National Labs. */
00126 
00127 
00128 /*     .. Parameters .. */
00129 /*     .. */
00130 /*     .. Local Scalars .. */
00131 /*     .. */
00132 /*     .. External Functions .. */
00133 /*     .. */
00134 /*     .. External Subroutines .. */
00135 /*     .. */
00136 /*     .. Intrinsic Functions .. */
00137 /*     .. */
00138 
00139 /*     Test the input parameters. */
00140 
00141     /* Parameter adjustments */
00142     --x;
00143     --y;
00144     a_dim1 = *lda;
00145     a_offset = 1 + a_dim1;
00146     a -= a_offset;
00147 
00148     /* Function Body */
00149     info = 0;
00150     if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
00151         info = 1;
00152     } else if (*n < 0) {
00153         info = 2;
00154     } else if (*incx == 0) {
00155         info = 5;
00156     } else if (*incy == 0) {
00157         info = 7;
00158     } else if (*lda < max(1,*n)) {
00159         info = 9;
00160     }
00161     if (info != 0) {
00162         xerbla_("CHER2 ", &info);
00163         return 0;
00164     }
00165 
00166 /*     Quick return if possible. */
00167 
00168     if (*n == 0 || alpha->r == 0.f && alpha->i == 0.f) {
00169         return 0;
00170     }
00171 
00172 /*     Set up the start points in X and Y if the increments are not both */
00173 /*     unity. */
00174 
00175     if (*incx != 1 || *incy != 1) {
00176         if (*incx > 0) {
00177             kx = 1;
00178         } else {
00179             kx = 1 - (*n - 1) * *incx;
00180         }
00181         if (*incy > 0) {
00182             ky = 1;
00183         } else {
00184             ky = 1 - (*n - 1) * *incy;
00185         }
00186         jx = kx;
00187         jy = ky;
00188     }
00189 
00190 /*     Start the operations. In this version the elements of A are */
00191 /*     accessed sequentially with one pass through the triangular part */
00192 /*     of A. */
00193 
00194     if (lsame_(uplo, "U")) {
00195 
00196 /*        Form  A  when A is stored in the upper triangle. */
00197 
00198         if (*incx == 1 && *incy == 1) {
00199             i__1 = *n;
00200             for (j = 1; j <= i__1; ++j) {
00201                 i__2 = j;
00202                 i__3 = j;
00203                 if (x[i__2].r != 0.f || x[i__2].i != 0.f || (y[i__3].r != 0.f 
00204                         || y[i__3].i != 0.f)) {
00205                     r_cnjg(&q__2, &y[j]);
00206                     q__1.r = alpha->r * q__2.r - alpha->i * q__2.i, q__1.i = 
00207                             alpha->r * q__2.i + alpha->i * q__2.r;
00208                     temp1.r = q__1.r, temp1.i = q__1.i;
00209                     i__2 = j;
00210                     q__2.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i, 
00211                             q__2.i = alpha->r * x[i__2].i + alpha->i * x[i__2]
00212                             .r;
00213                     r_cnjg(&q__1, &q__2);
00214                     temp2.r = q__1.r, temp2.i = q__1.i;
00215                     i__2 = j - 1;
00216                     for (i__ = 1; i__ <= i__2; ++i__) {
00217                         i__3 = i__ + j * a_dim1;
00218                         i__4 = i__ + j * a_dim1;
00219                         i__5 = i__;
00220                         q__3.r = x[i__5].r * temp1.r - x[i__5].i * temp1.i, 
00221                                 q__3.i = x[i__5].r * temp1.i + x[i__5].i * 
00222                                 temp1.r;
00223                         q__2.r = a[i__4].r + q__3.r, q__2.i = a[i__4].i + 
00224                                 q__3.i;
00225                         i__6 = i__;
00226                         q__4.r = y[i__6].r * temp2.r - y[i__6].i * temp2.i, 
00227                                 q__4.i = y[i__6].r * temp2.i + y[i__6].i * 
00228                                 temp2.r;
00229                         q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
00230                         a[i__3].r = q__1.r, a[i__3].i = q__1.i;
00231 /* L10: */
00232                     }
00233                     i__2 = j + j * a_dim1;
00234                     i__3 = j + j * a_dim1;
00235                     i__4 = j;
00236                     q__2.r = x[i__4].r * temp1.r - x[i__4].i * temp1.i, 
00237                             q__2.i = x[i__4].r * temp1.i + x[i__4].i * 
00238                             temp1.r;
00239                     i__5 = j;
00240                     q__3.r = y[i__5].r * temp2.r - y[i__5].i * temp2.i, 
00241                             q__3.i = y[i__5].r * temp2.i + y[i__5].i * 
00242                             temp2.r;
00243                     q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
00244                     r__1 = a[i__3].r + q__1.r;
00245                     a[i__2].r = r__1, a[i__2].i = 0.f;
00246                 } else {
00247                     i__2 = j + j * a_dim1;
00248                     i__3 = j + j * a_dim1;
00249                     r__1 = a[i__3].r;
00250                     a[i__2].r = r__1, a[i__2].i = 0.f;
00251                 }
00252 /* L20: */
00253             }
00254         } else {
00255             i__1 = *n;
00256             for (j = 1; j <= i__1; ++j) {
00257                 i__2 = jx;
00258                 i__3 = jy;
00259                 if (x[i__2].r != 0.f || x[i__2].i != 0.f || (y[i__3].r != 0.f 
00260                         || y[i__3].i != 0.f)) {
00261                     r_cnjg(&q__2, &y[jy]);
00262                     q__1.r = alpha->r * q__2.r - alpha->i * q__2.i, q__1.i = 
00263                             alpha->r * q__2.i + alpha->i * q__2.r;
00264                     temp1.r = q__1.r, temp1.i = q__1.i;
00265                     i__2 = jx;
00266                     q__2.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i, 
00267                             q__2.i = alpha->r * x[i__2].i + alpha->i * x[i__2]
00268                             .r;
00269                     r_cnjg(&q__1, &q__2);
00270                     temp2.r = q__1.r, temp2.i = q__1.i;
00271                     ix = kx;
00272                     iy = ky;
00273                     i__2 = j - 1;
00274                     for (i__ = 1; i__ <= i__2; ++i__) {
00275                         i__3 = i__ + j * a_dim1;
00276                         i__4 = i__ + j * a_dim1;
00277                         i__5 = ix;
00278                         q__3.r = x[i__5].r * temp1.r - x[i__5].i * temp1.i, 
00279                                 q__3.i = x[i__5].r * temp1.i + x[i__5].i * 
00280                                 temp1.r;
00281                         q__2.r = a[i__4].r + q__3.r, q__2.i = a[i__4].i + 
00282                                 q__3.i;
00283                         i__6 = iy;
00284                         q__4.r = y[i__6].r * temp2.r - y[i__6].i * temp2.i, 
00285                                 q__4.i = y[i__6].r * temp2.i + y[i__6].i * 
00286                                 temp2.r;
00287                         q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
00288                         a[i__3].r = q__1.r, a[i__3].i = q__1.i;
00289                         ix += *incx;
00290                         iy += *incy;
00291 /* L30: */
00292                     }
00293                     i__2 = j + j * a_dim1;
00294                     i__3 = j + j * a_dim1;
00295                     i__4 = jx;
00296                     q__2.r = x[i__4].r * temp1.r - x[i__4].i * temp1.i, 
00297                             q__2.i = x[i__4].r * temp1.i + x[i__4].i * 
00298                             temp1.r;
00299                     i__5 = jy;
00300                     q__3.r = y[i__5].r * temp2.r - y[i__5].i * temp2.i, 
00301                             q__3.i = y[i__5].r * temp2.i + y[i__5].i * 
00302                             temp2.r;
00303                     q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
00304                     r__1 = a[i__3].r + q__1.r;
00305                     a[i__2].r = r__1, a[i__2].i = 0.f;
00306                 } else {
00307                     i__2 = j + j * a_dim1;
00308                     i__3 = j + j * a_dim1;
00309                     r__1 = a[i__3].r;
00310                     a[i__2].r = r__1, a[i__2].i = 0.f;
00311                 }
00312                 jx += *incx;
00313                 jy += *incy;
00314 /* L40: */
00315             }
00316         }
00317     } else {
00318 
00319 /*        Form  A  when A is stored in the lower triangle. */
00320 
00321         if (*incx == 1 && *incy == 1) {
00322             i__1 = *n;
00323             for (j = 1; j <= i__1; ++j) {
00324                 i__2 = j;
00325                 i__3 = j;
00326                 if (x[i__2].r != 0.f || x[i__2].i != 0.f || (y[i__3].r != 0.f 
00327                         || y[i__3].i != 0.f)) {
00328                     r_cnjg(&q__2, &y[j]);
00329                     q__1.r = alpha->r * q__2.r - alpha->i * q__2.i, q__1.i = 
00330                             alpha->r * q__2.i + alpha->i * q__2.r;
00331                     temp1.r = q__1.r, temp1.i = q__1.i;
00332                     i__2 = j;
00333                     q__2.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i, 
00334                             q__2.i = alpha->r * x[i__2].i + alpha->i * x[i__2]
00335                             .r;
00336                     r_cnjg(&q__1, &q__2);
00337                     temp2.r = q__1.r, temp2.i = q__1.i;
00338                     i__2 = j + j * a_dim1;
00339                     i__3 = j + j * a_dim1;
00340                     i__4 = j;
00341                     q__2.r = x[i__4].r * temp1.r - x[i__4].i * temp1.i, 
00342                             q__2.i = x[i__4].r * temp1.i + x[i__4].i * 
00343                             temp1.r;
00344                     i__5 = j;
00345                     q__3.r = y[i__5].r * temp2.r - y[i__5].i * temp2.i, 
00346                             q__3.i = y[i__5].r * temp2.i + y[i__5].i * 
00347                             temp2.r;
00348                     q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
00349                     r__1 = a[i__3].r + q__1.r;
00350                     a[i__2].r = r__1, a[i__2].i = 0.f;
00351                     i__2 = *n;
00352                     for (i__ = j + 1; i__ <= i__2; ++i__) {
00353                         i__3 = i__ + j * a_dim1;
00354                         i__4 = i__ + j * a_dim1;
00355                         i__5 = i__;
00356                         q__3.r = x[i__5].r * temp1.r - x[i__5].i * temp1.i, 
00357                                 q__3.i = x[i__5].r * temp1.i + x[i__5].i * 
00358                                 temp1.r;
00359                         q__2.r = a[i__4].r + q__3.r, q__2.i = a[i__4].i + 
00360                                 q__3.i;
00361                         i__6 = i__;
00362                         q__4.r = y[i__6].r * temp2.r - y[i__6].i * temp2.i, 
00363                                 q__4.i = y[i__6].r * temp2.i + y[i__6].i * 
00364                                 temp2.r;
00365                         q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
00366                         a[i__3].r = q__1.r, a[i__3].i = q__1.i;
00367 /* L50: */
00368                     }
00369                 } else {
00370                     i__2 = j + j * a_dim1;
00371                     i__3 = j + j * a_dim1;
00372                     r__1 = a[i__3].r;
00373                     a[i__2].r = r__1, a[i__2].i = 0.f;
00374                 }
00375 /* L60: */
00376             }
00377         } else {
00378             i__1 = *n;
00379             for (j = 1; j <= i__1; ++j) {
00380                 i__2 = jx;
00381                 i__3 = jy;
00382                 if (x[i__2].r != 0.f || x[i__2].i != 0.f || (y[i__3].r != 0.f 
00383                         || y[i__3].i != 0.f)) {
00384                     r_cnjg(&q__2, &y[jy]);
00385                     q__1.r = alpha->r * q__2.r - alpha->i * q__2.i, q__1.i = 
00386                             alpha->r * q__2.i + alpha->i * q__2.r;
00387                     temp1.r = q__1.r, temp1.i = q__1.i;
00388                     i__2 = jx;
00389                     q__2.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i, 
00390                             q__2.i = alpha->r * x[i__2].i + alpha->i * x[i__2]
00391                             .r;
00392                     r_cnjg(&q__1, &q__2);
00393                     temp2.r = q__1.r, temp2.i = q__1.i;
00394                     i__2 = j + j * a_dim1;
00395                     i__3 = j + j * a_dim1;
00396                     i__4 = jx;
00397                     q__2.r = x[i__4].r * temp1.r - x[i__4].i * temp1.i, 
00398                             q__2.i = x[i__4].r * temp1.i + x[i__4].i * 
00399                             temp1.r;
00400                     i__5 = jy;
00401                     q__3.r = y[i__5].r * temp2.r - y[i__5].i * temp2.i, 
00402                             q__3.i = y[i__5].r * temp2.i + y[i__5].i * 
00403                             temp2.r;
00404                     q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
00405                     r__1 = a[i__3].r + q__1.r;
00406                     a[i__2].r = r__1, a[i__2].i = 0.f;
00407                     ix = jx;
00408                     iy = jy;
00409                     i__2 = *n;
00410                     for (i__ = j + 1; i__ <= i__2; ++i__) {
00411                         ix += *incx;
00412                         iy += *incy;
00413                         i__3 = i__ + j * a_dim1;
00414                         i__4 = i__ + j * a_dim1;
00415                         i__5 = ix;
00416                         q__3.r = x[i__5].r * temp1.r - x[i__5].i * temp1.i, 
00417                                 q__3.i = x[i__5].r * temp1.i + x[i__5].i * 
00418                                 temp1.r;
00419                         q__2.r = a[i__4].r + q__3.r, q__2.i = a[i__4].i + 
00420                                 q__3.i;
00421                         i__6 = iy;
00422                         q__4.r = y[i__6].r * temp2.r - y[i__6].i * temp2.i, 
00423                                 q__4.i = y[i__6].r * temp2.i + y[i__6].i * 
00424                                 temp2.r;
00425                         q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
00426                         a[i__3].r = q__1.r, a[i__3].i = q__1.i;
00427 /* L70: */
00428                     }
00429                 } else {
00430                     i__2 = j + j * a_dim1;
00431                     i__3 = j + j * a_dim1;
00432                     r__1 = a[i__3].r;
00433                     a[i__2].r = r__1, a[i__2].i = 0.f;
00434                 }
00435                 jx += *incx;
00436                 jy += *incy;
00437 /* L80: */
00438             }
00439         }
00440     }
00441 
00442     return 0;
00443 
00444 /*     End of CHER2 . */
00445 
00446 } /* cher2_ */


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