/usr/include/linbox/fflas/fflas_fgemv.inl is in liblinbox-dev 1.1.6~rc0-4.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | /* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* fflas/fflas_fgemv.inl
* Copyright (C) 2005 Clement Pernet
*
* Written by Clement Pernet <Clement.Pernet@imag.fr>
*
* See COPYING for license information.
*/
//---------------------------------------------------------------------
// fgemv: GEneral Matrix Vector Multiplication
// Computes Y <- alpha.op(A).X + beta.Y
// A is M*N,
//---------------------------------------------------------------------
template<class Field>
inline void
FFLAS::fgemv (const Field& F, const FFLAS_TRANSPOSE TransA,
const size_t M, const size_t N,
const typename Field::Element alpha,
const typename Field::Element * A, const size_t lda,
const typename Field::Element * X, const size_t incX,
const typename Field::Element beta,
typename Field::Element * Y, const size_t incY)
{
static typename Field::Element one, mone, zero;
F.init(one,1UL);
F.neg(mone,one);
F.init(zero,0UL);
if (F.isZero (alpha)){
for (typename Field::Element * Yi = Y; Yi != Y+((TransA == FflasNoTrans)?M:N)*incY; Yi+=incY)
F.mulin(*Yi, beta);
return;
}
FFLAS_BASE base = BaseCompute (F, 0);
size_t kmax = DotProdBound (F, 0, beta, base);
if (kmax > 1) {
if (TransA == FflasNoTrans) {
size_t nblock = N / kmax;
size_t remblock = N % kmax;
// To ensure the initial computation with beta
if (!remblock){
remblock = kmax;
--nblock;
}
MatVectProd (F, FflasNoTrans, M, remblock, alpha,
A+kmax*nblock, lda, X+kmax*nblock*incX, incX, beta,
Y, incY);
for (size_t i = 0; i < nblock; ++i){
MatVectProd (F, FflasNoTrans, M, kmax, alpha,
A+i*kmax, lda, X+i*kmax*incX, incX, one,
Y, incY);
}
}
else{ // FflasTrans
size_t nblock = M / kmax;
size_t remblock = M % kmax;
// To ensure the initial computation with beta
if (!remblock){
remblock = kmax;
--nblock;
}
MatVectProd (F, FflasTrans, remblock, N, alpha,
A+kmax*nblock*lda, lda, X+kmax*nblock*incX, incX, beta,
Y, incY);
for (size_t i = 0; i < nblock; ++i){
MatVectProd (F, FflasTrans, kmax, N, alpha,
A+i*kmax*lda, lda, X+i*kmax*incX, incX, one,
Y, incY);
}
}
} else {
if (TransA == FflasNoTrans) {
if (F.isZero (beta))
for (size_t i = 0; i < M; ++i)
F.assign( *(Y+i*incY), zero);
else {
typename Field::Element betadivalpha;
F.div (betadivalpha, beta, alpha);
for (size_t i = 0; i < M; ++i)
F.mulin( *(Y+i*incY), betadivalpha);
}
for (size_t i = 0; i < M; ++i)
for (size_t j = 0; j < N; ++j)
F.axpyin (*(Y+i*incY), *(A+i*lda+j), *(X+j*incX));
if (! F.isOne(alpha))
for (size_t i = 0; i < M; ++i)
F.mulin (*(Y+i*incY), alpha);
} else {
if (F.isZero (beta))
for (size_t i = 0; i < N; ++i)
F.assign( *(Y+i*incY), zero);
else {
typename Field::Element betadivalpha;
F.div (betadivalpha, beta, alpha);
for (size_t i = 0; i < N; ++i)
F.mulin( *(Y+i*incY), betadivalpha);
}
for (size_t i = 0; i < M; ++i)
for (size_t j = 0; j < N; ++j){
F.axpyin (*(Y+j*incY), *(A+i*lda+j), *(X+i*incX));
}
if (! F.isOne(alpha))
for (size_t i = 0; i < N; ++i)
F.mulin (*(Y+i*incY), alpha);
}
}
}
// MatVectProd: computes y <- alpha.op(A)*x + beta.y.
// Assumes that the condition k(p-1)^2 <2^53 is satisfied
template<class Field>
inline void
FFLAS::MatVectProd (const Field& F, const FFLAS_TRANSPOSE TransA,
const size_t M, const size_t N,
const typename Field::Element alpha,
const typename Field::Element * A, const size_t lda,
const typename Field::Element * X, const size_t incX,
const typename Field::Element beta,
typename Field::Element * Y, const size_t incY){
typename Field::Element one, mone;
typename Field::Element tmp;
F.init(one,1.0);
F.init(mone,-1.0);
size_t Xl, Yl;
if (TransA == FflasNoTrans){Xl = N;Yl = M;}
else {Xl = M; Yl = N;}
double* Ad = new double[M*N];
double* Xd = new double[Xl];
double* Yd = new double[Yl];
double alphad, betad;
if (F.areEqual (mone, alpha)){
alphad = -1.0;
F.convert (betad, beta);
} else {
if (! F.areEqual (one, alpha)){
// Compute C = A*B + beta/alpha.C
// and after C *= alpha
F.div (tmp, beta, alpha);
F.convert (betad, tmp);
} else
F.convert (betad, beta);
alphad = 1.0;
}
MatF2MatD (F, Ad, N, A, lda, M, N);
double *Xdi=Xd;
for (const typename Field::Element* Xi=X; Xi != X+Xl*incX; Xi+=incX, Xdi++)
F.convert (*(Xdi), *Xi);
double *Ydi=Yd;
if (!F.isZero(beta))
for (typename Field::Element* Yi = Y; Yi != Y+Yl*incY; Yi+=incY, Ydi++)
F.convert (*(Ydi), *Yi);
cblas_dgemv (CblasRowMajor, (CBLAS_TRANSPOSE) TransA, M, N, alphad,
Ad, N, Xd, 1, betad, Yd, 1);
Ydi=Yd;
for (typename Field::Element* Yi = Y; Yi != Y+Yl*incY; Yi+=incY, Ydi++)
F.init (*Yi, *(Ydi));
if (!F.areEqual (one, alpha) && !F.areEqual (mone, alpha)){
// Fix-up: compute Y *= alpha
for (typename Field::Element* Yi = Y; Yi != Y+Yl*incY; Yi += incY)
F.mulin (*Yi , alpha);
}
delete[] Ad;
delete[] Xd;
delete[] Yd;
}
template<>
inline void FFLAS::MatVectProd (const ModularBalanced<double>& F,
const FFLAS_TRANSPOSE TransA,
const size_t M, const size_t N,
const double alpha,
const double * A, const size_t lda,
const double * X, const size_t incX,
const double beta,
double * Y, const size_t incY){
double Mone, one, _alpha, _beta;
F.init(one, 1UL);
F.neg(Mone, one);
if (F.areEqual (Mone, beta)) _beta = -1.0;
else _beta = beta;
if (F.areEqual (Mone, alpha)) _alpha = -1.0;
else{
_alpha = 1.0;
if (! F.areEqual (one, alpha))
// Compute y = A*x + beta/alpha.y
// and after y *= alpha
F.divin (_beta, alpha);
}
cblas_dgemv (CblasRowMajor, (CBLAS_TRANSPOSE) TransA, M, N,
_alpha, A, lda, X, incX, _beta, Y, incY);
for (double * Yi = Y; Yi != Y+((TransA == FflasNoTrans)?M:N)*incY; Yi+=incY)
F.init (*Yi, *Yi);
if ( (!F.areEqual (one, alpha)) && (!F.areEqual (Mone, alpha))){
// Fix-up: compute y *= alpha
for (double* Yi = Y; Yi != Y+((TransA == FflasNoTrans)?M:N)*incY; Yi += incY)
F.mulin (*Yi , alpha);
}
}
template<>
inline void FFLAS::MatVectProd (const ModularBalanced<float>& F,
const FFLAS_TRANSPOSE TransA,
const size_t M, const size_t N,
const float alpha,
const float * A, const size_t lda,
const float * X, const size_t incX,
const float beta,
float * Y, const size_t incY){
float Mone, one, _alpha, _beta;
F.init(one, 1UL);
F.neg(Mone, one);
if (F.areEqual (Mone, beta)) _beta = -1.0;
else _beta = beta;
if (F.areEqual (Mone, alpha)) _alpha = -1.0;
else{
_alpha = 1.0;
if (! F.areEqual (one, alpha)){
// Compute y = A*x + beta/alpha.y
// and after y *= alpha
F.divin (_beta, alpha);
}
}
cblas_sgemv (CblasRowMajor, (CBLAS_TRANSPOSE) TransA, M, N,
_alpha, A, lda, X, incX, _beta, Y, incY);
for (float * Yi = Y; Yi != Y+((TransA == FflasNoTrans)?M:N)*incY; Yi+=incY)
F.init (*Yi, *Yi);
if ( (!F.areEqual (one, alpha)) && (!F.areEqual (Mone, alpha))){
// Fix-up: compute y *= alpha
for (float* Yi = Y; Yi != Y+((TransA == FflasNoTrans)?M:N)*incY; Yi += incY)
F.mulin (*Yi , alpha);
}
}
template<>
inline void FFLAS::MatVectProd (const Modular<double>& F,
const FFLAS_TRANSPOSE TransA,
const size_t M, const size_t N,
const double alpha,
const double * A, const size_t lda,
const double * X, const size_t incX,
const double beta,
double * Y, const size_t incY){
double Mone, one, _alpha, _beta;
F.init(one, 1UL);
F.neg(Mone, one);
if (F.areEqual (Mone, beta)) _beta = -1.0;
else _beta = beta;
if (F.areEqual (Mone, alpha)) _alpha = -1.0;
else{
_alpha = 1.0;
if (! F.areEqual (one, alpha))
// Compute y = A*x + beta/alpha.y
// and after y *= alpha
F.divin (_beta, alpha);
}
cblas_dgemv (CblasRowMajor, (CBLAS_TRANSPOSE) TransA, M, N,
_alpha, A, lda, X, incX, _beta, Y, incY);
for (double * Yi = Y; Yi != Y+((TransA == FflasNoTrans)?M:N)*incY; Yi+=incY)
F.init (*Yi, *Yi);
if ( (!F.areEqual (one, alpha)) && (!F.areEqual (Mone, alpha))){
// Fix-up: compute y *= alpha
for (double* Yi = Y; Yi != Y+((TransA == FflasNoTrans)?M:N)*incY; Yi += incY)
F.mulin (*Yi , alpha);
}
}
template<>
inline void FFLAS::MatVectProd (const Modular<float>& F,
const FFLAS_TRANSPOSE TransA,
const size_t M, const size_t N,
const float alpha,
const float * A, const size_t lda,
const float * X, const size_t incX,
const float beta,
float * Y, const size_t incY){
float Mone, one, _alpha, _beta;
F.init(one, 1UL);
F.neg(Mone, one);
if (F.areEqual (Mone, beta)) _beta = -1.0;
else _beta = beta;
if (F.areEqual (Mone, alpha)) _alpha = -1.0;
else{
_alpha = 1.0;
if (! F.areEqual (one, alpha)){
// Compute y = A*x + beta/alpha.y
// and after y *= alpha
F.divin (_beta, alpha);
}
}
cblas_sgemv (CblasRowMajor, (CBLAS_TRANSPOSE) TransA, M, N,
_alpha, A, lda, X, incX, _beta, Y, incY);
for (float * Yi = Y; Yi != Y+((TransA == FflasNoTrans)?M:N)*incY; Yi+=incY)
F.init (*Yi, *Yi);
if ( (!F.areEqual (one, alpha)) && (!F.areEqual (Mone, alpha))){
// Fix-up: compute y *= alpha
for (float* Yi = Y; Yi != Y+((TransA == FflasNoTrans)?M:N)*incY; Yi += incY)
F.mulin (*Yi , alpha);
}
}
template<>
inline void
FFLAS::fgemv (const DoubleDomain& D, const FFLAS_TRANSPOSE TransA,
const size_t M, const size_t N,
const DoubleDomain::Element alpha,
const DoubleDomain::Element * A, const size_t lda,
const DoubleDomain::Element * X, const size_t incX,
const DoubleDomain::Element beta,
DoubleDomain::Element * Y, const size_t incY) {
cblas_dgemv (CblasRowMajor, (CBLAS_TRANSPOSE) TransA, M, N,
alpha, A, lda, X, incX, beta, Y, incY);
}
template<>
inline void
FFLAS::fgemv (const FloatDomain& F, const FFLAS_TRANSPOSE TransA,
const size_t M, const size_t N,
const FloatDomain::Element alpha,
const FloatDomain::Element * A, const size_t lda,
const FloatDomain::Element * X, const size_t incX,
const FloatDomain::Element beta,
FloatDomain::Element * Y, const size_t incY)
{
cblas_sgemv (CblasRowMajor, (CBLAS_TRANSPOSE) TransA, M, N,
alpha, A, lda, X, incX, beta, Y, incY);
}
|