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


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