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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:06