00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef TEMPLATE_BLAS_GEMV_HEADER
00038 #define TEMPLATE_BLAS_GEMV_HEADER
00039
00040 #include "template_blas_common.h"
00041
00042 template<class Treal>
00043 int template_blas_gemv(const char *trans, const integer *m, const integer *n, const Treal *
00044 alpha, const Treal *a, const integer *lda, const Treal *x, const integer *incx,
00045 const Treal *beta, Treal *y, const integer *incy)
00046 {
00047
00048 integer a_dim1, a_offset, i__1, i__2;
00049
00050 integer info;
00051 Treal temp;
00052 integer lenx, leny, i__, j;
00053 integer ix, iy, jx, jy, kx, ky;
00054 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 a_dim1 = *lda;
00125 a_offset = 1 + a_dim1 * 1;
00126 a -= a_offset;
00127 --x;
00128 --y;
00129
00130 info = 0;
00131 if (! template_blas_lsame(trans, "N") && ! template_blas_lsame(trans, "T") && ! template_blas_lsame(trans, "C")
00132 ) {
00133 info = 1;
00134 } else if (*m < 0) {
00135 info = 2;
00136 } else if (*n < 0) {
00137 info = 3;
00138 } else if (*lda < maxMACRO(1,*m)) {
00139 info = 6;
00140 } else if (*incx == 0) {
00141 info = 8;
00142 } else if (*incy == 0) {
00143 info = 11;
00144 }
00145 if (info != 0) {
00146 template_blas_erbla("GEMV ", &info);
00147 return 0;
00148 }
00149
00150 if (*m == 0 || *n == 0 || (*alpha == 0. && *beta == 1.) ) {
00151 return 0;
00152 }
00153
00154
00155 if (template_blas_lsame(trans, "N")) {
00156 lenx = *n;
00157 leny = *m;
00158 } else {
00159 lenx = *m;
00160 leny = *n;
00161 }
00162 if (*incx > 0) {
00163 kx = 1;
00164 } else {
00165 kx = 1 - (lenx - 1) * *incx;
00166 }
00167 if (*incy > 0) {
00168 ky = 1;
00169 } else {
00170 ky = 1 - (leny - 1) * *incy;
00171 }
00172
00173
00174
00175 if (*beta != 1.) {
00176 if (*incy == 1) {
00177 if (*beta == 0.) {
00178 i__1 = leny;
00179 for (i__ = 1; i__ <= i__1; ++i__) {
00180 y[i__] = 0.;
00181
00182 }
00183 } else {
00184 i__1 = leny;
00185 for (i__ = 1; i__ <= i__1; ++i__) {
00186 y[i__] = *beta * y[i__];
00187
00188 }
00189 }
00190 } else {
00191 iy = ky;
00192 if (*beta == 0.) {
00193 i__1 = leny;
00194 for (i__ = 1; i__ <= i__1; ++i__) {
00195 y[iy] = 0.;
00196 iy += *incy;
00197
00198 }
00199 } else {
00200 i__1 = leny;
00201 for (i__ = 1; i__ <= i__1; ++i__) {
00202 y[iy] = *beta * y[iy];
00203 iy += *incy;
00204
00205 }
00206 }
00207 }
00208 }
00209 if (*alpha == 0.) {
00210 return 0;
00211 }
00212 if (template_blas_lsame(trans, "N")) {
00213
00214 jx = kx;
00215 if (*incy == 1) {
00216 i__1 = *n;
00217 for (j = 1; j <= i__1; ++j) {
00218 if (x[jx] != 0.) {
00219 temp = *alpha * x[jx];
00220 i__2 = *m;
00221 for (i__ = 1; i__ <= i__2; ++i__) {
00222 y[i__] += temp * a_ref(i__, j);
00223
00224 }
00225 }
00226 jx += *incx;
00227
00228 }
00229 } else {
00230 i__1 = *n;
00231 for (j = 1; j <= i__1; ++j) {
00232 if (x[jx] != 0.) {
00233 temp = *alpha * x[jx];
00234 iy = ky;
00235 i__2 = *m;
00236 for (i__ = 1; i__ <= i__2; ++i__) {
00237 y[iy] += temp * a_ref(i__, j);
00238 iy += *incy;
00239
00240 }
00241 }
00242 jx += *incx;
00243
00244 }
00245 }
00246 } else {
00247
00248 jy = ky;
00249 if (*incx == 1) {
00250 i__1 = *n;
00251 for (j = 1; j <= i__1; ++j) {
00252 temp = 0.;
00253 i__2 = *m;
00254 for (i__ = 1; i__ <= i__2; ++i__) {
00255 temp += a_ref(i__, j) * x[i__];
00256
00257 }
00258 y[jy] += *alpha * temp;
00259 jy += *incy;
00260
00261 }
00262 } else {
00263 i__1 = *n;
00264 for (j = 1; j <= i__1; ++j) {
00265 temp = 0.;
00266 ix = kx;
00267 i__2 = *m;
00268 for (i__ = 1; i__ <= i__2; ++i__) {
00269 temp += a_ref(i__, j) * x[ix];
00270 ix += *incx;
00271
00272 }
00273 y[jy] += *alpha * temp;
00274 jy += *incy;
00275
00276 }
00277 }
00278 }
00279 return 0;
00280
00281 }
00282 #undef a_ref
00283
00284 #endif