dsyr2k.c
Go to the documentation of this file.
00001 /* dsyr2k.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 dsyr2k_(char *uplo, char *trans, integer *n, integer *k, 
00017         doublereal *alpha, doublereal *a, integer *lda, doublereal *b, 
00018         integer *ldb, doublereal *beta, doublereal *c__, integer *ldc)
00019 {
00020     /* System generated locals */
00021     integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, i__1, i__2, 
00022             i__3;
00023 
00024     /* Local variables */
00025     integer i__, j, l, info;
00026     doublereal temp1, temp2;
00027     extern logical lsame_(char *, char *);
00028     integer nrowa;
00029     logical upper;
00030     extern /* Subroutine */ int xerbla_(char *, integer *);
00031 
00032 /*     .. Scalar Arguments .. */
00033 /*     .. */
00034 /*     .. Array Arguments .. */
00035 /*     .. */
00036 
00037 /*  Purpose */
00038 /*  ======= */
00039 
00040 /*  DSYR2K  performs one of the symmetric rank 2k operations */
00041 
00042 /*     C := alpha*A*B' + alpha*B*A' + beta*C, */
00043 
00044 /*  or */
00045 
00046 /*     C := alpha*A'*B + alpha*B'*A + beta*C, */
00047 
00048 /*  where  alpha and beta  are scalars, C is an  n by n  symmetric matrix */
00049 /*  and  A and B  are  n by k  matrices  in the  first  case  and  k by n */
00050 /*  matrices in the second case. */
00051 
00052 /*  Arguments */
00053 /*  ========== */
00054 
00055 /*  UPLO   - CHARACTER*1. */
00056 /*           On  entry,   UPLO  specifies  whether  the  upper  or  lower */
00057 /*           triangular  part  of the  array  C  is to be  referenced  as */
00058 /*           follows: */
00059 
00060 /*              UPLO = 'U' or 'u'   Only the  upper triangular part of  C */
00061 /*                                  is to be referenced. */
00062 
00063 /*              UPLO = 'L' or 'l'   Only the  lower triangular part of  C */
00064 /*                                  is to be referenced. */
00065 
00066 /*           Unchanged on exit. */
00067 
00068 /*  TRANS  - CHARACTER*1. */
00069 /*           On entry,  TRANS  specifies the operation to be performed as */
00070 /*           follows: */
00071 
00072 /*              TRANS = 'N' or 'n'   C := alpha*A*B' + alpha*B*A' + */
00073 /*                                        beta*C. */
00074 
00075 /*              TRANS = 'T' or 't'   C := alpha*A'*B + alpha*B'*A + */
00076 /*                                        beta*C. */
00077 
00078 /*              TRANS = 'C' or 'c'   C := alpha*A'*B + alpha*B'*A + */
00079 /*                                        beta*C. */
00080 
00081 /*           Unchanged on exit. */
00082 
00083 /*  N      - INTEGER. */
00084 /*           On entry,  N specifies the order of the matrix C.  N must be */
00085 /*           at least zero. */
00086 /*           Unchanged on exit. */
00087 
00088 /*  K      - INTEGER. */
00089 /*           On entry with  TRANS = 'N' or 'n',  K  specifies  the number */
00090 /*           of  columns  of the  matrices  A and B,  and on  entry  with */
00091 /*           TRANS = 'T' or 't' or 'C' or 'c',  K  specifies  the  number */
00092 /*           of rows of the matrices  A and B.  K must be at least  zero. */
00093 /*           Unchanged on exit. */
00094 
00095 /*  ALPHA  - DOUBLE PRECISION. */
00096 /*           On entry, ALPHA specifies the scalar alpha. */
00097 /*           Unchanged on exit. */
00098 
00099 /*  A      - DOUBLE PRECISION array of DIMENSION ( LDA, ka ), where ka is */
00100 /*           k  when  TRANS = 'N' or 'n',  and is  n  otherwise. */
00101 /*           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k */
00102 /*           part of the array  A  must contain the matrix  A,  otherwise */
00103 /*           the leading  k by n  part of the array  A  must contain  the */
00104 /*           matrix A. */
00105 /*           Unchanged on exit. */
00106 
00107 /*  LDA    - INTEGER. */
00108 /*           On entry, LDA specifies the first dimension of A as declared */
00109 /*           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n' */
00110 /*           then  LDA must be at least  max( 1, n ), otherwise  LDA must */
00111 /*           be at least  max( 1, k ). */
00112 /*           Unchanged on exit. */
00113 
00114 /*  B      - DOUBLE PRECISION array of DIMENSION ( LDB, kb ), where kb is */
00115 /*           k  when  TRANS = 'N' or 'n',  and is  n  otherwise. */
00116 /*           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k */
00117 /*           part of the array  B  must contain the matrix  B,  otherwise */
00118 /*           the leading  k by n  part of the array  B  must contain  the */
00119 /*           matrix B. */
00120 /*           Unchanged on exit. */
00121 
00122 /*  LDB    - INTEGER. */
00123 /*           On entry, LDB specifies the first dimension of B as declared */
00124 /*           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n' */
00125 /*           then  LDB must be at least  max( 1, n ), otherwise  LDB must */
00126 /*           be at least  max( 1, k ). */
00127 /*           Unchanged on exit. */
00128 
00129 /*  BETA   - DOUBLE PRECISION. */
00130 /*           On entry, BETA specifies the scalar beta. */
00131 /*           Unchanged on exit. */
00132 
00133 /*  C      - DOUBLE PRECISION array of DIMENSION ( LDC, n ). */
00134 /*           Before entry  with  UPLO = 'U' or 'u',  the leading  n by n */
00135 /*           upper triangular part of the array C must contain the upper */
00136 /*           triangular part  of the  symmetric matrix  and the strictly */
00137 /*           lower triangular part of C is not referenced.  On exit, the */
00138 /*           upper triangular part of the array  C is overwritten by the */
00139 /*           upper triangular part of the updated matrix. */
00140 /*           Before entry  with  UPLO = 'L' or 'l',  the leading  n by n */
00141 /*           lower triangular part of the array C must contain the lower */
00142 /*           triangular part  of the  symmetric matrix  and the strictly */
00143 /*           upper triangular part of C is not referenced.  On exit, the */
00144 /*           lower triangular part of the array  C is overwritten by the */
00145 /*           lower triangular part of the updated matrix. */
00146 
00147 /*  LDC    - INTEGER. */
00148 /*           On entry, LDC specifies the first dimension of C as declared */
00149 /*           in  the  calling  (sub)  program.   LDC  must  be  at  least */
00150 /*           max( 1, n ). */
00151 /*           Unchanged on exit. */
00152 
00153 
00154 /*  Level 3 Blas routine. */
00155 
00156 
00157 /*  -- Written on 8-February-1989. */
00158 /*     Jack Dongarra, Argonne National Laboratory. */
00159 /*     Iain Duff, AERE Harwell. */
00160 /*     Jeremy Du Croz, Numerical Algorithms Group Ltd. */
00161 /*     Sven Hammarling, Numerical Algorithms Group Ltd. */
00162 
00163 
00164 /*     .. External Functions .. */
00165 /*     .. */
00166 /*     .. External Subroutines .. */
00167 /*     .. */
00168 /*     .. Intrinsic Functions .. */
00169 /*     .. */
00170 /*     .. Local Scalars .. */
00171 /*     .. */
00172 /*     .. Parameters .. */
00173 /*     .. */
00174 
00175 /*     Test the input parameters. */
00176 
00177     /* Parameter adjustments */
00178     a_dim1 = *lda;
00179     a_offset = 1 + a_dim1;
00180     a -= a_offset;
00181     b_dim1 = *ldb;
00182     b_offset = 1 + b_dim1;
00183     b -= b_offset;
00184     c_dim1 = *ldc;
00185     c_offset = 1 + c_dim1;
00186     c__ -= c_offset;
00187 
00188     /* Function Body */
00189     if (lsame_(trans, "N")) {
00190         nrowa = *n;
00191     } else {
00192         nrowa = *k;
00193     }
00194     upper = lsame_(uplo, "U");
00195 
00196     info = 0;
00197     if (! upper && ! lsame_(uplo, "L")) {
00198         info = 1;
00199     } else if (! lsame_(trans, "N") && ! lsame_(trans, 
00200             "T") && ! lsame_(trans, "C")) {
00201         info = 2;
00202     } else if (*n < 0) {
00203         info = 3;
00204     } else if (*k < 0) {
00205         info = 4;
00206     } else if (*lda < max(1,nrowa)) {
00207         info = 7;
00208     } else if (*ldb < max(1,nrowa)) {
00209         info = 9;
00210     } else if (*ldc < max(1,*n)) {
00211         info = 12;
00212     }
00213     if (info != 0) {
00214         xerbla_("DSYR2K", &info);
00215         return 0;
00216     }
00217 
00218 /*     Quick return if possible. */
00219 
00220     if (*n == 0 || (*alpha == 0. || *k == 0) && *beta == 1.) {
00221         return 0;
00222     }
00223 
00224 /*     And when  alpha.eq.zero. */
00225 
00226     if (*alpha == 0.) {
00227         if (upper) {
00228             if (*beta == 0.) {
00229                 i__1 = *n;
00230                 for (j = 1; j <= i__1; ++j) {
00231                     i__2 = j;
00232                     for (i__ = 1; i__ <= i__2; ++i__) {
00233                         c__[i__ + j * c_dim1] = 0.;
00234 /* L10: */
00235                     }
00236 /* L20: */
00237                 }
00238             } else {
00239                 i__1 = *n;
00240                 for (j = 1; j <= i__1; ++j) {
00241                     i__2 = j;
00242                     for (i__ = 1; i__ <= i__2; ++i__) {
00243                         c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
00244 /* L30: */
00245                     }
00246 /* L40: */
00247                 }
00248             }
00249         } else {
00250             if (*beta == 0.) {
00251                 i__1 = *n;
00252                 for (j = 1; j <= i__1; ++j) {
00253                     i__2 = *n;
00254                     for (i__ = j; i__ <= i__2; ++i__) {
00255                         c__[i__ + j * c_dim1] = 0.;
00256 /* L50: */
00257                     }
00258 /* L60: */
00259                 }
00260             } else {
00261                 i__1 = *n;
00262                 for (j = 1; j <= i__1; ++j) {
00263                     i__2 = *n;
00264                     for (i__ = j; i__ <= i__2; ++i__) {
00265                         c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
00266 /* L70: */
00267                     }
00268 /* L80: */
00269                 }
00270             }
00271         }
00272         return 0;
00273     }
00274 
00275 /*     Start the operations. */
00276 
00277     if (lsame_(trans, "N")) {
00278 
00279 /*        Form  C := alpha*A*B' + alpha*B*A' + C. */
00280 
00281         if (upper) {
00282             i__1 = *n;
00283             for (j = 1; j <= i__1; ++j) {
00284                 if (*beta == 0.) {
00285                     i__2 = j;
00286                     for (i__ = 1; i__ <= i__2; ++i__) {
00287                         c__[i__ + j * c_dim1] = 0.;
00288 /* L90: */
00289                     }
00290                 } else if (*beta != 1.) {
00291                     i__2 = j;
00292                     for (i__ = 1; i__ <= i__2; ++i__) {
00293                         c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
00294 /* L100: */
00295                     }
00296                 }
00297                 i__2 = *k;
00298                 for (l = 1; l <= i__2; ++l) {
00299                     if (a[j + l * a_dim1] != 0. || b[j + l * b_dim1] != 0.) {
00300                         temp1 = *alpha * b[j + l * b_dim1];
00301                         temp2 = *alpha * a[j + l * a_dim1];
00302                         i__3 = j;
00303                         for (i__ = 1; i__ <= i__3; ++i__) {
00304                             c__[i__ + j * c_dim1] = c__[i__ + j * c_dim1] + a[
00305                                     i__ + l * a_dim1] * temp1 + b[i__ + l * 
00306                                     b_dim1] * temp2;
00307 /* L110: */
00308                         }
00309                     }
00310 /* L120: */
00311                 }
00312 /* L130: */
00313             }
00314         } else {
00315             i__1 = *n;
00316             for (j = 1; j <= i__1; ++j) {
00317                 if (*beta == 0.) {
00318                     i__2 = *n;
00319                     for (i__ = j; i__ <= i__2; ++i__) {
00320                         c__[i__ + j * c_dim1] = 0.;
00321 /* L140: */
00322                     }
00323                 } else if (*beta != 1.) {
00324                     i__2 = *n;
00325                     for (i__ = j; i__ <= i__2; ++i__) {
00326                         c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
00327 /* L150: */
00328                     }
00329                 }
00330                 i__2 = *k;
00331                 for (l = 1; l <= i__2; ++l) {
00332                     if (a[j + l * a_dim1] != 0. || b[j + l * b_dim1] != 0.) {
00333                         temp1 = *alpha * b[j + l * b_dim1];
00334                         temp2 = *alpha * a[j + l * a_dim1];
00335                         i__3 = *n;
00336                         for (i__ = j; i__ <= i__3; ++i__) {
00337                             c__[i__ + j * c_dim1] = c__[i__ + j * c_dim1] + a[
00338                                     i__ + l * a_dim1] * temp1 + b[i__ + l * 
00339                                     b_dim1] * temp2;
00340 /* L160: */
00341                         }
00342                     }
00343 /* L170: */
00344                 }
00345 /* L180: */
00346             }
00347         }
00348     } else {
00349 
00350 /*        Form  C := alpha*A'*B + alpha*B'*A + C. */
00351 
00352         if (upper) {
00353             i__1 = *n;
00354             for (j = 1; j <= i__1; ++j) {
00355                 i__2 = j;
00356                 for (i__ = 1; i__ <= i__2; ++i__) {
00357                     temp1 = 0.;
00358                     temp2 = 0.;
00359                     i__3 = *k;
00360                     for (l = 1; l <= i__3; ++l) {
00361                         temp1 += a[l + i__ * a_dim1] * b[l + j * b_dim1];
00362                         temp2 += b[l + i__ * b_dim1] * a[l + j * a_dim1];
00363 /* L190: */
00364                     }
00365                     if (*beta == 0.) {
00366                         c__[i__ + j * c_dim1] = *alpha * temp1 + *alpha * 
00367                                 temp2;
00368                     } else {
00369                         c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1] 
00370                                 + *alpha * temp1 + *alpha * temp2;
00371                     }
00372 /* L200: */
00373                 }
00374 /* L210: */
00375             }
00376         } else {
00377             i__1 = *n;
00378             for (j = 1; j <= i__1; ++j) {
00379                 i__2 = *n;
00380                 for (i__ = j; i__ <= i__2; ++i__) {
00381                     temp1 = 0.;
00382                     temp2 = 0.;
00383                     i__3 = *k;
00384                     for (l = 1; l <= i__3; ++l) {
00385                         temp1 += a[l + i__ * a_dim1] * b[l + j * b_dim1];
00386                         temp2 += b[l + i__ * b_dim1] * a[l + j * a_dim1];
00387 /* L220: */
00388                     }
00389                     if (*beta == 0.) {
00390                         c__[i__ + j * c_dim1] = *alpha * temp1 + *alpha * 
00391                                 temp2;
00392                     } else {
00393                         c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1] 
00394                                 + *alpha * temp1 + *alpha * temp2;
00395                     }
00396 /* L230: */
00397                 }
00398 /* L240: */
00399             }
00400         }
00401     }
00402 
00403     return 0;
00404 
00405 /*     End of DSYR2K. */
00406 
00407 } /* dsyr2k_ */


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