| 1 |
/*! \file blas.cpp |
| 2 |
\brief BLAS function interface |
| 3 |
\author Xavier Juvigny, ONERA |
| 4 |
\date Jan. 12th 2005 |
| 5 |
\modification function from NETLIB source with BLAS and CBLAS wrapper |
| 6 |
\author Atsushi Suzuki, Laboratoire Jacques-Louis Lions |
| 7 |
\date Mar. 16th 2015 |
| 8 |
\date Jul. 17th 2015 |
| 9 |
\date Nov. 30th 2016 |
| 10 |
*/ |
| 11 |
|
| 12 |
// This file is part of Dissection |
| 13 |
// |
| 14 |
// Dissection is free software: you can redistribute it and/or modify |
| 15 |
// it under the terms of the GNU General Public License as published by |
| 16 |
// the Free Software Foundation, either version 3 of the License, or |
| 17 |
// (at your option) any later version. |
| 18 |
// |
| 19 |
// Linking Dissection statically or dynamically with other modules is making |
| 20 |
// a combined work based on Disssection. Thus, the terms and conditions of |
| 21 |
// the GNU General Public License cover the whole combination. |
| 22 |
// |
| 23 |
// As a special exception, the copyright holders of Dissection give you |
| 24 |
// permission to combine Dissection program with free software programs or |
| 25 |
// libraries that are released under the GNU LGPL and with independent modules |
| 26 |
// that communicate with Dissection solely through the Dissection-fortran |
| 27 |
// interface. You may copy and distribute such a system following the terms of |
| 28 |
// the GNU GPL for Dissection and the licenses of the other code concerned, |
| 29 |
// provided that you include the source code of that other code when and as |
| 30 |
// the GNU GPL requires distribution of source code and provided that you do |
| 31 |
// not modify the Dissection-fortran interface. |
| 32 |
// |
| 33 |
// Note that people who make modified versions of Dissection are not obligated |
| 34 |
// to grant this special exception for their modified versions; it is their |
| 35 |
// choice whether to do so. The GNU General Public License gives permission to |
| 36 |
// release a modified version without this exception; this exception also makes |
| 37 |
// it possible to release a modified version which carries forward this |
| 38 |
// exception. If you modify the Dissection-fortran interface, this exception |
| 39 |
// does not apply to your modified version of Dissection, and you must remove |
| 40 |
// this exception when you distribute your modified version. |
| 41 |
// |
| 42 |
// This exception is an additional permission under section 7 of the GNU |
| 43 |
// General Public License, version 3 ("GPLv3") |
| 44 |
// |
| 45 |
// Dissection is distributed in the hope that it will be useful, |
| 46 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 47 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 48 |
// GNU General Public License for more details. |
| 49 |
// |
| 50 |
// You should have received a copy of the GNU General Public License |
| 51 |
// along with Dissection. If not, see <http://www.gnu.org/licenses/>. |
| 52 |
// |
| 53 |
|
| 54 |
#include "Compiler/blas.hpp" |
| 55 |
#include <cstdio> |
| 56 |
#include <cstring> |
| 57 |
|
| 58 |
#define FORCE_EXPLICIT_INSTANTIATION |
| 59 |
#if __clang_major__ == 4 |
| 60 |
#undef FORCE_EXPLICIT_INSTANTIATION |
| 61 |
#endif |
| 62 |
|
| 63 |
#ifdef BLAS_FORTRAN |
| 64 |
|
| 65 |
extern "C" { |
| 66 |
// double precision |
| 67 |
extern int FORTRAN_DECL(idamax)(const int &n, // return Fortran index |
| 68 |
const double *x, |
| 69 |
const int &incx); |
| 70 |
|
| 71 |
extern int FORTRAN_DECL(izamax)(const int &n, // retrun Fortran index |
| 72 |
const double *x, |
| 73 |
const int &incx); |
| 74 |
|
| 75 |
extern void FORTRAN_DECL(dcopy)(const int &n, |
| 76 |
const double *x, const int &incx, |
| 77 |
double *y, const int &incy); |
| 78 |
|
| 79 |
extern void FORTRAN_DECL(zcopy)(const int &n, |
| 80 |
const double *x, const int &incx, |
| 81 |
double *y, const int &incy); |
| 82 |
|
| 83 |
extern void FORTRAN_DECL(daxpy)(const int &n, const double &alpha, |
| 84 |
const double *x, const int &incx, |
| 85 |
double *y, const int &incy); |
| 86 |
|
| 87 |
extern void FORTRAN_DECL(zaxpy)(const int &n, const double *alpha, |
| 88 |
const double *x, const int &incx, |
| 89 |
double *y, const int &incy); |
| 90 |
|
| 91 |
extern double FORTRAN_DECL(ddot)(const int &n, |
| 92 |
const double *x, const int &incx, |
| 93 |
const double *y, const int &incy); |
| 94 |
|
| 95 |
extern void FORTRAN_DECL(zdotc)(double *z, |
| 96 |
const int &n, |
| 97 |
const double *x, const int &incx, |
| 98 |
const double *y, const int &incy); |
| 99 |
|
| 100 |
extern void FORTRAN_DECL(dscal)(const int &N, const double &alpha, |
| 101 |
double *X, const int &incX); |
| 102 |
|
| 103 |
extern void FORTRAN_DECL(zscal)(const int &N, const double *alpha, |
| 104 |
double *X, const int &incX); |
| 105 |
|
| 106 |
extern void FORTRAN_DECL(dgemv)(unsigned char &tra_, |
| 107 |
const int &m, |
| 108 |
const int &n, |
| 109 |
const double &alpha, |
| 110 |
const double *A, |
| 111 |
const int &lda, |
| 112 |
const double *x, |
| 113 |
const int &incx, |
| 114 |
const double &beta, |
| 115 |
double *y, |
| 116 |
const int &incy); |
| 117 |
extern void FORTRAN_DECL(zgemv)(unsigned char &tra_, |
| 118 |
const int &m, |
| 119 |
const int &n, |
| 120 |
const double *alpha, |
| 121 |
const double *A, |
| 122 |
const int &lda, |
| 123 |
const double *x, |
| 124 |
const int &incx, |
| 125 |
const double *beta, |
| 126 |
double *y, |
| 127 |
const int &incy); |
| 128 |
|
| 129 |
extern void FORTRAN_DECL(dtrsv)(unsigned char &uplo_, |
| 130 |
unsigned char &transa_, |
| 131 |
unsigned char &diag_, |
| 132 |
const int &N, |
| 133 |
const double *A, |
| 134 |
const int &lda, |
| 135 |
double *X, |
| 136 |
const int &incX); |
| 137 |
|
| 138 |
extern void FORTRAN_DECL(ztrsv)(unsigned char &uplo_, |
| 139 |
unsigned char &transa_, |
| 140 |
unsigned char &diag_, |
| 141 |
const int &N, |
| 142 |
const double *A, |
| 143 |
const int &lda, |
| 144 |
double *X, |
| 145 |
const int &incX); |
| 146 |
|
| 147 |
extern void FORTRAN_DECL(dsyr)(unsigned char &uplo_, |
| 148 |
const int &N, |
| 149 |
const double &alpha, |
| 150 |
const double *X, |
| 151 |
const int &incX, |
| 152 |
double *A, |
| 153 |
const int &lda); |
| 154 |
|
| 155 |
extern void FORTRAN_DECL(dsyr2)(unsigned char &uplo_, |
| 156 |
const int &N, |
| 157 |
const double &alpha, |
| 158 |
const double *X, |
| 159 |
const int &incX, |
| 160 |
const double *Y, |
| 161 |
const int &incY, |
| 162 |
double *A, |
| 163 |
const int &lda); |
| 164 |
extern void FORTRAN_DECL(dger)(const int &M, const int &N, |
| 165 |
const double &alpha, |
| 166 |
const double *X, const int &incX, |
| 167 |
const double *Y, const int &incY, |
| 168 |
double *A, const int &lda); |
| 169 |
|
| 170 |
extern void FORTRAN_DECL(zgeru)(const int &M, const int &N, |
| 171 |
const double *alpha, |
| 172 |
double *X, const int &incX, |
| 173 |
double *Y, const int &incY, |
| 174 |
double *A, const int &lda); |
| 175 |
|
| 176 |
extern void FORTRAN_DECL(zgerc)(const int &M, const int &N, |
| 177 |
const double *alpha, |
| 178 |
const double *X, const int &incX, |
| 179 |
const double *Y, const int &incY, |
| 180 |
double *A, const int &lda); |
| 181 |
|
| 182 |
extern void FORTRAN_DECL(dtrsm)(unsigned char &side_, unsigned char &uplo_, |
| 183 |
unsigned char &transa_, unsigned char &diag_, |
| 184 |
const int &M, const int &N, |
| 185 |
const double &alpha, |
| 186 |
const double *A, const int &lda, |
| 187 |
double *B, const int &ldb); |
| 188 |
|
| 189 |
extern void FORTRAN_DECL(ztrsm)(unsigned char &side_, unsigned char &uplo_, |
| 190 |
unsigned char &transa_, unsigned char &diag_, |
| 191 |
const int &M, const int &N, |
| 192 |
const double *alpha, |
| 193 |
const double *A, const int &lda, |
| 194 |
double *B, const int &ldb); |
| 195 |
|
| 196 |
extern void FORTRAN_DECL(dgemm)(unsigned char &tra_, unsigned char &trb_, |
| 197 |
const int &m, const int &n, const int &k, |
| 198 |
const double &alpha, |
| 199 |
const double *A, const int &lda, |
| 200 |
const double *B, const int &ldb, |
| 201 |
const double &beta, |
| 202 |
double *C, const int &ldc); |
| 203 |
|
| 204 |
extern void FORTRAN_DECL(zgemm)(unsigned char &tra_, unsigned char &trb_, |
| 205 |
const int &m, const int &n, const int &k, |
| 206 |
const double *alpha, |
| 207 |
const double *A, const int &lda, |
| 208 |
const double *B, const int &ldb, |
| 209 |
const double *beta, |
| 210 |
double *C, const int &ldc); |
| 211 |
|
| 212 |
// single precision |
| 213 |
extern int FORTRAN_DECL(isamax)(const int &n, // return Fortran index |
| 214 |
const float *x, |
| 215 |
const int &incx); |
| 216 |
|
| 217 |
extern int FORTRAN_DECL(icamax)(const int &n, // retrun Fortran index |
| 218 |
const float *x, |
| 219 |
const int &incx); |
| 220 |
|
| 221 |
extern void FORTRAN_DECL(scopy)(const int &n, |
| 222 |
const float *x, const int &incx, |
| 223 |
float *y, const int &incy); |
| 224 |
|
| 225 |
extern void FORTRAN_DECL(ccopy)(const int &n, |
| 226 |
const float *x, const int &incx, |
| 227 |
float *y, const int &incy); |
| 228 |
|
| 229 |
extern void FORTRAN_DECL(saxpy)(const int &n, const float &alpha, |
| 230 |
const float *x, const int &incx, |
| 231 |
float *y, const int &incy); |
| 232 |
|
| 233 |
extern void FORTRAN_DECL(caxpy)(const int &n, const float *alpha, |
| 234 |
const float *x, const int &incx, |
| 235 |
float *y, const int &incy); |
| 236 |
|
| 237 |
extern float FORTRAN_DECL(sdot)(const int &n, |
| 238 |
const float *x, const int &incx, |
| 239 |
const float *y, const int &incy); |
| 240 |
|
| 241 |
extern void FORTRAN_DECL(cdotc)(float *z, |
| 242 |
const int &n, |
| 243 |
const float *x, const int &incx, |
| 244 |
const float *y, const int &incy); |
| 245 |
|
| 246 |
extern void FORTRAN_DECL(sscal)(const int &N, const float &alpha, |
| 247 |
float *X, const int &incX); |
| 248 |
|
| 249 |
extern void FORTRAN_DECL(cscal)(const int &N, const float *alpha, |
| 250 |
float *X, const int &incX); |
| 251 |
|
| 252 |
extern void FORTRAN_DECL(sgemv)(unsigned char &tra_, |
| 253 |
const int &m, |
| 254 |
const int &n, |
| 255 |
const float &alpha, |
| 256 |
const float *A, |
| 257 |
const int &lda, |
| 258 |
const float *x, |
| 259 |
const int &incx, |
| 260 |
const float &beta, |
| 261 |
float *y, |
| 262 |
const int &incy); |
| 263 |
extern void FORTRAN_DECL(cgemv)(unsigned char &tra_, |
| 264 |
const int &m, |
| 265 |
const int &n, |
| 266 |
const float *alpha, |
| 267 |
const float *A, |
| 268 |
const int &lda, |
| 269 |
const float *x, |
| 270 |
const int &incx, |
| 271 |
const float *beta, |
| 272 |
float *y, |
| 273 |
const int &incy); |
| 274 |
|
| 275 |
extern void FORTRAN_DECL(strsv)(unsigned char &uplo_, |
| 276 |
unsigned char &transa_, |
| 277 |
unsigned char &diag_, |
| 278 |
const int &N, |
| 279 |
const float *A, |
| 280 |
const int &lda, |
| 281 |
float *X, |
| 282 |
const int &incX); |
| 283 |
|
| 284 |
extern void FORTRAN_DECL(ctrsv)(unsigned char &uplo_, |
| 285 |
unsigned char &transa_, |
| 286 |
unsigned char &diag_, |
| 287 |
const int &N, |
| 288 |
const float *A, |
| 289 |
const int &lda, |
| 290 |
float *X, |
| 291 |
const int &incX); |
| 292 |
|
| 293 |
extern void FORTRAN_DECL(ssyr)(unsigned char &uplo_, |
| 294 |
const int &N, |
| 295 |
const float &alpha, |
| 296 |
const float *X, |
| 297 |
const int &incX, |
| 298 |
float *A, |
| 299 |
const int &lda); |
| 300 |
|
| 301 |
extern void FORTRAN_DECL(ssyr2)(unsigned char &uplo_, |
| 302 |
const int &N, |
| 303 |
const float &alpha, |
| 304 |
const float *X, |
| 305 |
const int &incX, |
| 306 |
const float *Y, |
| 307 |
const int &incY, |
| 308 |
float *A, |
| 309 |
const int &lda); |
| 310 |
extern void FORTRAN_DECL(sger)(const int &M, const int &N, |
| 311 |
const float &alpha, |
| 312 |
const float *X, const int &incX, |
| 313 |
const float *Y, const int &incY, |
| 314 |
float *A, const int &lda); |
| 315 |
|
| 316 |
extern void FORTRAN_DECL(cgeru)(const int &M, const int &N, |
| 317 |
const float *alpha, |
| 318 |
float *X, const int &incX, |
| 319 |
float *Y, const int &incY, |
| 320 |
float *A, const int &lda); |
| 321 |
|
| 322 |
extern void FORTRAN_DECL(cgerc)(const int &M, const int &N, |
| 323 |
const float *alpha, |
| 324 |
const float *X, const int &incX, |
| 325 |
const float *Y, const int &incY, |
| 326 |
float *A, const int &lda); |
| 327 |
|
| 328 |
extern void FORTRAN_DECL(strsm)(unsigned char &side_, unsigned char &uplo_, |
| 329 |
unsigned char &transa_, unsigned char &diag_, |
| 330 |
const int &M, const int &N, |
| 331 |
const float &alpha, |
| 332 |
const float *A, const int &lda, |
| 333 |
float *B, const int &ldb); |
| 334 |
|
| 335 |
extern void FORTRAN_DECL(ctrsm)(unsigned char &side_, unsigned char &uplo_, |
| 336 |
unsigned char &transa_, unsigned char &diag_, |
| 337 |
const int &M, const int &N, |
| 338 |
const float *alpha, |
| 339 |
const float *A, const int &lda, |
| 340 |
float *B, const int &ldb); |
| 341 |
|
| 342 |
extern void FORTRAN_DECL(sgemm)(unsigned char &tra_, unsigned char &trb_, |
| 343 |
const int &m, const int &n, const int &k, |
| 344 |
const float &alpha, |
| 345 |
const float *A, const int &lda, |
| 346 |
const float *B, const int &ldb, |
| 347 |
const float &beta, |
| 348 |
float *C, const int &ldc); |
| 349 |
|
| 350 |
extern void FORTRAN_DECL(cgemm)(unsigned char &tra_, unsigned char &trb_, |
| 351 |
const int &m, const int &n, const int &k, |
| 352 |
const float *alpha, |
| 353 |
const float *A, const int &lda, |
| 354 |
const float *B, const int &ldb, |
| 355 |
const float *beta, |
| 356 |
float *C, const int &ldc); |
| 357 |
|
| 358 |
} |
| 359 |
#endif |
| 360 |
// BLAS 1 |
| 361 |
// dz copy |
| 362 |
#ifndef BLAS_GENERIC |
| 363 |
template<> |
| 364 |
void |
| 365 |
blas_copy<double>(const int n, const double* x, const int incx, double* y, |
| 366 |
const int incy) |
| 367 |
{ |
| 368 |
if ((incx == 1) && (incy == 1)) { |
| 369 |
memcpy((void *)y, (void *)x, n * sizeof(double)); |
| 370 |
} |
| 371 |
else { |
| 372 |
#ifdef BLAS_FORTRAN |
| 373 |
FORTRAN_DECL(dcopy)(n, x, incx, y, incy); |
| 374 |
#else |
| 375 |
cblas_dcopy((BLAS_INT)n, x, (BLAS_INT)incx, y, (BLAS_INT)incy); |
| 376 |
#endif |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
template<> |
| 381 |
void |
| 382 |
blas_copy<complex<double> >(const int n, |
| 383 |
const complex<double>* x, const int incx, |
| 384 |
complex<double>* y, const int incy) |
| 385 |
{ |
| 386 |
if ((incx == 1) && (incy == 1)) { |
| 387 |
memcpy((void *)y, (void *)x, n * sizeof(complex<double>)); |
| 388 |
} |
| 389 |
else { |
| 390 |
#ifdef BLAS_FORTRAN |
| 391 |
FORTRAN_DECL(zcopy)(n, (double *)x, incx, (double *)y, incy); |
| 392 |
#else |
| 393 |
cblas_zcopy((BLAS_INT)n, (void *)x, (BLAS_INT)incx, |
| 394 |
(BLAS_VOID *)y, (BLAS_INT)incy); |
| 395 |
#endif |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
template<> |
| 400 |
void |
| 401 |
blas_copy<float>(const int n, const float* x, const int incx, float* y, |
| 402 |
const int incy) |
| 403 |
{ |
| 404 |
if ((incx == 1) && (incy == 1)) { |
| 405 |
memcpy((void *)y, (void *)x, n * sizeof(float)); |
| 406 |
} |
| 407 |
else { |
| 408 |
#ifdef BLAS_FORTRAN |
| 409 |
FORTRAN_DECL(scopy)(n, x, incx, y, incy); |
| 410 |
#else |
| 411 |
cblas_scopy((BLAS_INT)n, x, (BLAS_INT)incx, y, (BLAS_INT)incy); |
| 412 |
#endif |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
template<> |
| 417 |
void |
| 418 |
blas_copy<complex<float> >(const int n, |
| 419 |
const complex<float>* x, const int incx, |
| 420 |
complex<float>* y, const int incy) |
| 421 |
{ |
| 422 |
if ((incx == 1) && (incy == 1)) { |
| 423 |
memcpy((void *)y, (void *)x, n * sizeof(complex<float>)); |
| 424 |
} |
| 425 |
else { |
| 426 |
#ifdef BLAS_FORTRAN |
| 427 |
FORTRAN_DECL(ccopy)(n, (float *)x, incx, (float *)y, incy); |
| 428 |
#else |
| 429 |
cblas_ccopy((BLAS_INT)n, (void *)x, (BLAS_INT)incx, |
| 430 |
(BLAS_VOID *)y, (BLAS_INT)incy); |
| 431 |
#endif |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
#endif |
| 436 |
template<typename T> |
| 437 |
void |
| 438 |
blas_copy(const int n, const T* x, const int incx, T *y, const int incy) |
| 439 |
{ |
| 440 |
if ((incx == 1) && (incy == 1)) { |
| 441 |
memcpy((void *)y, (void *)x, n * sizeof(T)); |
| 442 |
} |
| 443 |
else { |
| 444 |
int ix = 0; |
| 445 |
int iy = 0; |
| 446 |
for (int i = 0; i < n; i++, ix += incx, iy += incy) { |
| 447 |
y[iy] = x[ix]; |
| 448 |
} |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 453 |
template |
| 454 |
void |
| 455 |
blas_copy<double>(const int n, const double* x, const int incx, |
| 456 |
double *y, const int incy); |
| 457 |
|
| 458 |
template |
| 459 |
void |
| 460 |
blas_copy<complex<double> > (const int n, |
| 461 |
const complex<double>* x, const int incx, |
| 462 |
complex<double> *y, const int incy); |
| 463 |
template |
| 464 |
void |
| 465 |
blas_copy<float>(const int n, const float* x, const int incx, |
| 466 |
float *y, const int incy); |
| 467 |
|
| 468 |
template |
| 469 |
void |
| 470 |
blas_copy<complex<float> > (const int n, |
| 471 |
const complex<float>* x, const int incx, |
| 472 |
complex<float> *y, const int incy); |
| 473 |
#endif |
| 474 |
template |
| 475 |
void |
| 476 |
blas_copy<quadruple>(const int n, const quadruple* x, const int incx, |
| 477 |
quadruple *y, const int incy); |
| 478 |
template |
| 479 |
void |
| 480 |
blas_copy<complex<quadruple> > (const int n, |
| 481 |
const complex<quadruple>* x, const int incx, |
| 482 |
complex<quadruple> *y, const int incy); |
| 483 |
|
| 484 |
template |
| 485 |
void |
| 486 |
blas_copy<octruple>(const int n, const octruple* x, const int incx, |
| 487 |
octruple *y, const int incy); |
| 488 |
|
| 489 |
template |
| 490 |
void |
| 491 |
blas_copy<complex<octruple> > (const int n, |
| 492 |
const complex<octruple>* x, const int incx, |
| 493 |
complex<octruple> *y, const int incy); |
| 494 |
|
| 495 |
// dz axpy |
| 496 |
#ifndef BLAS_GENERIC |
| 497 |
template<> |
| 498 |
void |
| 499 |
blas_axpy<double>(const int n, const double &alpha, |
| 500 |
const double* x, const int incx, |
| 501 |
double* y, const int incy) |
| 502 |
{ |
| 503 |
#ifdef BLAS_FORTRAN |
| 504 |
FORTRAN_DECL(daxpy)(n, alpha, x, incx, y, incy); |
| 505 |
#else |
| 506 |
cblas_daxpy((BLAS_INT)n, alpha, x, (BLAS_INT)incx, y, (BLAS_INT)incy); |
| 507 |
#endif |
| 508 |
} |
| 509 |
|
| 510 |
template<> |
| 511 |
void |
| 512 |
blas_axpy<complex<double> >(const int n, const complex<double> &alpha, |
| 513 |
const complex<double>* x, const int incx, |
| 514 |
complex<double>* y, int incy) |
| 515 |
{ |
| 516 |
#ifdef BLAS_FORTRAN |
| 517 |
FORTRAN_DECL(zaxpy)(n, (double *)&alpha, (double *)x, incx, (double *)y, incy); |
| 518 |
#else |
| 519 |
cblas_zaxpy((BLAS_INT)n, (BLAS_VOID *)&alpha, (BLAS_VOID *)x, (BLAS_INT)incx, |
| 520 |
(BLAS_VOID *)y, (BLAS_INT)incy); |
| 521 |
#endif |
| 522 |
} |
| 523 |
|
| 524 |
template<> |
| 525 |
void |
| 526 |
blas_axpy<float>(const int n, const float &alpha, |
| 527 |
const float* x, const int incx, |
| 528 |
float* y, const int incy) |
| 529 |
{ |
| 530 |
#ifdef BLAS_FORTRAN |
| 531 |
FORTRAN_DECL(saxpy)(n, alpha, x, incx, y, incy); |
| 532 |
#else |
| 533 |
cblas_saxpy((BLAS_INT)n, alpha, x, (BLAS_INT)incx, y, (BLAS_INT)incy); |
| 534 |
#endif |
| 535 |
} |
| 536 |
|
| 537 |
template<> |
| 538 |
void |
| 539 |
blas_axpy<complex<float> >(const int n, const complex<float> &alpha, |
| 540 |
const complex<float>* x, const int incx, |
| 541 |
complex<float>* y, int incy) |
| 542 |
{ |
| 543 |
#ifdef BLAS_FORTRAN |
| 544 |
FORTRAN_DECL(caxpy)(n, (float *)&alpha, (float *)x, incx, (float *)y, incy); |
| 545 |
#else |
| 546 |
cblas_caxpy((BLAS_INT)n, (BLAS_VOID *)&alpha, (BLAS_VOID *)x, (BLAS_INT)incx, |
| 547 |
(BLAS_VOID *)y, (BLAS_INT)incy); |
| 548 |
#endif |
| 549 |
} |
| 550 |
#endif |
| 551 |
|
| 552 |
template<typename T> |
| 553 |
void |
| 554 |
blas_axpy(const int n, const T &alpha, |
| 555 |
const T* x, const int incx, |
| 556 |
T* y, int incy) |
| 557 |
{ |
| 558 |
int ix = 0; |
| 559 |
int iy = 0; |
| 560 |
for (int i = 0; i < n; i++, ix += incx, iy += incy) { |
| 561 |
y[iy] += alpha * x[ix]; |
| 562 |
} |
| 563 |
} |
| 564 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 565 |
template |
| 566 |
void |
| 567 |
blas_axpy<double>(const int n, const double &alpha, |
| 568 |
const double* x, const int incx, |
| 569 |
double* y, int incy); |
| 570 |
template |
| 571 |
void |
| 572 |
blas_axpy<complex<double> >(const int n, const complex<double> &alpha, |
| 573 |
const complex<double>* x, const int incx, |
| 574 |
complex<double>* y, int incy); |
| 575 |
|
| 576 |
template |
| 577 |
void |
| 578 |
blas_axpy<float>(const int n, const float &alpha, |
| 579 |
const float* x, const int incx, |
| 580 |
float* y, int incy); |
| 581 |
template |
| 582 |
void |
| 583 |
blas_axpy<complex<float> >(const int n, const complex<float> &alpha, |
| 584 |
const complex<float>* x, const int incx, |
| 585 |
complex<float>* y, int incy); |
| 586 |
#endif |
| 587 |
template |
| 588 |
void |
| 589 |
blas_axpy<quadruple>(const int n, const quadruple &alpha, |
| 590 |
const quadruple* x, const int incx, |
| 591 |
quadruple* y, int incy); |
| 592 |
template |
| 593 |
void |
| 594 |
blas_axpy<complex<quadruple> >(const int n, const complex<quadruple> &alpha, |
| 595 |
const complex<quadruple>* x, const int incx, |
| 596 |
complex<quadruple>* y, int incy); |
| 597 |
|
| 598 |
// dz dot |
| 599 |
#ifndef BLAS_GENERIC |
| 600 |
template<> |
| 601 |
double |
| 602 |
blas_dot<double>(const int n, const double* x, const int incx, |
| 603 |
const double* y, const int incy) |
| 604 |
{ |
| 605 |
#ifdef BLAS_FORTRAN |
| 606 |
return FORTRAN_DECL(ddot)(n, x, incx, y, incy); // ? |
| 607 |
#else |
| 608 |
return cblas_ddot((BLAS_INT)n, x, (BLAS_INT)incx, y, (BLAS_INT)incy); |
| 609 |
#endif |
| 610 |
} |
| 611 |
|
| 612 |
template<> |
| 613 |
complex<double> |
| 614 |
blas_dot<complex<double> >(const int n, |
| 615 |
const complex<double>* x, const int incx, |
| 616 |
const complex<double>* y, const int incy) |
| 617 |
{ |
| 618 |
complex<double> val; |
| 619 |
#ifdef BLAS_FORTRAN |
| 620 |
// fortran function that returns complex is called as C void function |
| 621 |
FORTRAN_DECL(zdotc)((double*) &val, n, (double *)x, incx, (double *)y, incy); |
| 622 |
#else |
| 623 |
cblas_zdotc_sub((BLAS_INT)n, (BLAS_VOID *)x, (BLAS_INT)incx, |
| 624 |
(BLAS_VOID *)y, (BLAS_INT)incy, (BLAS_VOID *)&val); |
| 625 |
#endif |
| 626 |
return val; |
| 627 |
} |
| 628 |
|
| 629 |
template<> |
| 630 |
float |
| 631 |
blas_dot<float>(const int n, const float* x, const int incx, |
| 632 |
const float* y, const int incy) |
| 633 |
{ |
| 634 |
#ifdef BLAS_FORTRAN |
| 635 |
return FORTRAN_DECL(sdot)(n, x, incx, y, incy); // ? |
| 636 |
#else |
| 637 |
return cblas_sdot((BLAS_INT)n, x, (BLAS_INT)incx, y, (BLAS_INT)incy); |
| 638 |
#endif |
| 639 |
} |
| 640 |
|
| 641 |
template<> |
| 642 |
complex<float> |
| 643 |
blas_dot<complex<float> >(const int n, |
| 644 |
const complex<float>* x, const int incx, |
| 645 |
const complex<float>* y, const int incy) |
| 646 |
{ |
| 647 |
complex<float> val; |
| 648 |
#ifdef BLAS_FORTRAN |
| 649 |
// fortran function that returns complex is called as C void function |
| 650 |
FORTRAN_DECL(cdotc)((float*) &val, n, (float *)x, incx, (float *)y, incy); |
| 651 |
#else |
| 652 |
cblas_cdotc_sub((BLAS_INT)n, (BLAS_VOID *)x, (BLAS_INT)incx, |
| 653 |
(BLAS_VOID *)y, (BLAS_INT)incy, (BLAS_VOID *)&val); |
| 654 |
#endif |
| 655 |
return val; |
| 656 |
} |
| 657 |
|
| 658 |
#endif |
| 659 |
|
| 660 |
template<typename T> |
| 661 |
T |
| 662 |
blas_dot(const int n, const T* x, const int incx, |
| 663 |
const T* y, const int incy) |
| 664 |
{ |
| 665 |
int ix, iy; |
| 666 |
T temp; |
| 667 |
temp = T(0.0); |
| 668 |
if (n <= 0) { |
| 669 |
return temp; |
| 670 |
} |
| 671 |
if ((incx == 1) && (incy == 1)) { |
| 672 |
for (int i = 0; i < n; i++) { |
| 673 |
temp += blas_conj(x[i]) * y[i]; |
| 674 |
} |
| 675 |
} |
| 676 |
else { |
| 677 |
ix = 0; |
| 678 |
iy = 0; |
| 679 |
if (incx < 0) { |
| 680 |
ix = (n - 1)* (-incx); // decrement form the last index |
| 681 |
} |
| 682 |
if (incy < 0) { |
| 683 |
iy = (n - 1)* (-incy); // decrement form the last index |
| 684 |
} |
| 685 |
for (int i = 0; i < n; i++) { |
| 686 |
temp += blas_conj(x[i]) * y[i]; |
| 687 |
ix += incx; |
| 688 |
iy += incy; |
| 689 |
} |
| 690 |
} |
| 691 |
return temp; |
| 692 |
} |
| 693 |
// explicit instantiation of blas_dot |
| 694 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 695 |
template |
| 696 |
double |
| 697 |
blas_dot<double>(const int n, const double* x, const int incx, |
| 698 |
const double* y, const int incy); |
| 699 |
template |
| 700 |
complex<double> |
| 701 |
blas_dot<complex<double> >(const int n, |
| 702 |
const complex<double>* x, const int incx, |
| 703 |
const complex<double>* y, const int incy); |
| 704 |
template |
| 705 |
float |
| 706 |
blas_dot<float>(const int n, const float* x, const int incx, |
| 707 |
const float* y, const int incy); |
| 708 |
template |
| 709 |
complex<float> |
| 710 |
blas_dot<complex<float> >(const int n, |
| 711 |
const complex<float>* x, const int incx, |
| 712 |
const complex<float>* y, const int incy); |
| 713 |
#endif |
| 714 |
template |
| 715 |
quadruple |
| 716 |
blas_dot<quadruple>(const int n, const quadruple* x, const int incx, |
| 717 |
const quadruple* y, const int incy); |
| 718 |
template |
| 719 |
complex<quadruple> |
| 720 |
blas_dot<complex<quadruple> >(const int n, |
| 721 |
const complex<quadruple>* x, const int incx, |
| 722 |
const complex<quadruple>* y, const int incy); |
| 723 |
#ifndef NO_OCTRUPLE |
| 724 |
template |
| 725 |
octruple |
| 726 |
blas_dot<octruple>(const int n, const octruple* x, const int incx, |
| 727 |
const octruple* y, const int incy); |
| 728 |
template |
| 729 |
complex<octruple> |
| 730 |
blas_dot<complex<octruple> >(const int n, |
| 731 |
const complex<octruple>* x, const int incx, |
| 732 |
const complex<octruple>* y, const int incy); |
| 733 |
#endif |
| 734 |
// dz scal |
| 735 |
#ifndef BLAS_GENERIC |
| 736 |
template<> |
| 737 |
void |
| 738 |
blas_scal<double>(const int N, const double &alpha, double *X, const int incX) |
| 739 |
{ |
| 740 |
#ifdef BLAS_FORTRAN |
| 741 |
FORTRAN_DECL(dscal)(N, alpha, X, incX); |
| 742 |
#else |
| 743 |
cblas_dscal((BLAS_INT)N, alpha, X, (BLAS_INT)incX); |
| 744 |
#endif |
| 745 |
} |
| 746 |
|
| 747 |
template<> |
| 748 |
void |
| 749 |
blas_scal<complex<double> >(const int N, const complex<double> &alpha, |
| 750 |
complex<double> *X, const int incX) |
| 751 |
{ |
| 752 |
#ifdef BLAS_FORTRAN |
| 753 |
FORTRAN_DECL(zscal)(N, (double *)&alpha, (double *)X, incX); |
| 754 |
#else |
| 755 |
cblas_zscal((BLAS_INT)N, (BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX); |
| 756 |
#endif |
| 757 |
} |
| 758 |
|
| 759 |
template<> |
| 760 |
void |
| 761 |
blas_scal<float>(const int N, const float &alpha, float *X, const int incX) |
| 762 |
{ |
| 763 |
#ifdef BLAS_FORTRAN |
| 764 |
FORTRAN_DECL(sscal)(N, alpha, X, incX); |
| 765 |
#else |
| 766 |
cblas_sscal((BLAS_INT)N, alpha, X, (BLAS_INT)incX); |
| 767 |
#endif |
| 768 |
} |
| 769 |
|
| 770 |
template<> |
| 771 |
void |
| 772 |
blas_scal<complex<float> >(const int N, const complex<float> &alpha, |
| 773 |
complex<float> *X, const int incX) |
| 774 |
{ |
| 775 |
#ifdef BLAS_FORTRAN |
| 776 |
FORTRAN_DECL(cscal)(N, (float *)&alpha, (float *)X, incX); |
| 777 |
#else |
| 778 |
cblas_cscal((BLAS_INT)N, (BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX); |
| 779 |
#endif |
| 780 |
} |
| 781 |
#endif // #ifdef BLAS_GENERIC |
| 782 |
|
| 783 |
template<typename T> |
| 784 |
void |
| 785 |
blas_scal(const int N, const T &alpha, |
| 786 |
T *X, const int incX) |
| 787 |
{ |
| 788 |
if ((N <= 0) || (incX <= 0)) { |
| 789 |
return; |
| 790 |
} |
| 791 |
if (incX == 1) { |
| 792 |
for (int i = 0; i < N; i++) { |
| 793 |
X[i] *= alpha; |
| 794 |
} |
| 795 |
} |
| 796 |
else { |
| 797 |
int nincx = N * incX; |
| 798 |
for (int i = 0; i < nincx; i += incX) { |
| 799 |
X[i] *= alpha; |
| 800 |
} |
| 801 |
} |
| 802 |
} |
| 803 |
// explicit instantiation of blas_scal |
| 804 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 805 |
template |
| 806 |
void |
| 807 |
blas_scal<double>(const int N, const double &alpha, |
| 808 |
double *X, const int incX); |
| 809 |
|
| 810 |
template |
| 811 |
void |
| 812 |
blas_scal<complex<double> >(const int N, const complex<double> &alpha, |
| 813 |
complex<double> *X, const int incX); |
| 814 |
|
| 815 |
template |
| 816 |
void |
| 817 |
blas_scal<float>(const int N, const float &alpha, |
| 818 |
float *X, const int incX); |
| 819 |
|
| 820 |
template |
| 821 |
void |
| 822 |
blas_scal<complex<float> >(const int N, const complex<float> &alpha, |
| 823 |
complex<float> *X, const int incX); |
| 824 |
#endif |
| 825 |
template |
| 826 |
void |
| 827 |
blas_scal<quadruple>(const int N, const quadruple &alpha, |
| 828 |
quadruple *X, const int incX); |
| 829 |
|
| 830 |
template |
| 831 |
void |
| 832 |
blas_scal<complex<quadruple> >(const int N, const complex<quadruple> &alpha, |
| 833 |
complex<quadruple> *X, const int incX); |
| 834 |
|
| 835 |
#ifndef NO_OCTRUPLE |
| 836 |
template |
| 837 |
void |
| 838 |
blas_scal<octruple>(const int N, const octruple &alpha, |
| 839 |
octruple *X, const int incX); |
| 840 |
|
| 841 |
template |
| 842 |
void |
| 843 |
blas_scal<complex<octruple> >(const int N, const complex<octruple> &alpha, |
| 844 |
complex<octruple> *X, const int incX); |
| 845 |
#endif |
| 846 |
// scaling with magnitude represented by real valued |
| 847 |
#ifndef BLAS_GENERIC |
| 848 |
template<> |
| 849 |
void |
| 850 |
blas_scal2<double, double>(const int N, const double &alpha, |
| 851 |
double *X, const int incX) |
| 852 |
{ |
| 853 |
#ifdef BLAS_FORTRAN |
| 854 |
FORTRAN_DECL(dscal)(N, alpha, X, incX); |
| 855 |
#else |
| 856 |
cblas_dscal((BLAS_INT)N, alpha, X, (BLAS_INT)incX); |
| 857 |
#endif |
| 858 |
} |
| 859 |
|
| 860 |
template<> |
| 861 |
void |
| 862 |
blas_scal2<complex<double>, double>(const int N, const double &alpha_, |
| 863 |
complex<double> *X, const int incX) |
| 864 |
{ |
| 865 |
const complex<double> alpha = complex<double>(alpha_, 0.0); |
| 866 |
#ifdef BLAS_FORTRAN |
| 867 |
FORTRAN_DECL(zscal)(N, (double *)&alpha, (double *)X, incX); |
| 868 |
#else |
| 869 |
cblas_zscal((BLAS_INT)N, (BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX); |
| 870 |
#endif |
| 871 |
} |
| 872 |
template<> |
| 873 |
void |
| 874 |
blas_scal2<float, float>(const int N, const float &alpha, |
| 875 |
float *X, const int incX) |
| 876 |
{ |
| 877 |
#ifdef BLAS_FORTRAN |
| 878 |
FORTRAN_DECL(sscal)(N, alpha, X, incX); |
| 879 |
#else |
| 880 |
cblas_sscal((BLAS_INT)N, alpha, X, (BLAS_INT)incX); |
| 881 |
#endif |
| 882 |
} |
| 883 |
|
| 884 |
template<> |
| 885 |
void |
| 886 |
blas_scal2<complex<float>, float>(const int N, const float &alpha_, |
| 887 |
complex<float> *X, const int incX) |
| 888 |
{ |
| 889 |
const complex<float> alpha = complex<float>(alpha_, 0.0); |
| 890 |
#ifdef BLAS_FORTRAN |
| 891 |
FORTRAN_DECL(cscal)(N, (float *)&alpha, (float *)X, incX); |
| 892 |
#else |
| 893 |
cblas_cscal((BLAS_INT)N, (BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX); |
| 894 |
#endif |
| 895 |
} |
| 896 |
|
| 897 |
template<> |
| 898 |
void |
| 899 |
blas_scal2<quadruple, quadruple>(const int N, const quadruple &alpha, |
| 900 |
quadruple *X, const int incX) |
| 901 |
{ |
| 902 |
blas_scal<quadruple>(N, alpha, X, incX); |
| 903 |
} |
| 904 |
|
| 905 |
template<> |
| 906 |
void |
| 907 |
blas_scal2<complex<quadruple>, quadruple>(const int N, const quadruple &alpha_, |
| 908 |
complex<quadruple> *X, const int incX) |
| 909 |
{ |
| 910 |
complex<quadruple> alpha = complex<quadruple>(alpha_, quadruple(0.0)); |
| 911 |
blas_scal<complex<quadruple> >(N, alpha, X, incX); |
| 912 |
} |
| 913 |
|
| 914 |
#ifndef NO_OCTRUPLE |
| 915 |
template<> |
| 916 |
void |
| 917 |
blas_scal2<octruple, octruple>(const int N, const octruple &alpha, |
| 918 |
octruple *X, const int incX) |
| 919 |
{ |
| 920 |
blas_scal<octruple>(N, alpha, X, incX); |
| 921 |
} |
| 922 |
|
| 923 |
template<> |
| 924 |
void |
| 925 |
blas_scal2<complex<octruple>, octruple>(const int N, const octruple &alpha_, |
| 926 |
complex<octruple> *X, const int incX) |
| 927 |
{ |
| 928 |
complex<octruple> alpha = complex<octruple>(alpha_, octruple(0.0)); |
| 929 |
blas_scal<complex<octruple> >(N, alpha, X, incX); |
| 930 |
} |
| 931 |
|
| 932 |
#endif |
| 933 |
#endif // ifndef BLAS_GENERIC |
| 934 |
template<typename T, typename U> |
| 935 |
void |
| 936 |
blas_scal2(const int N, const U &alpha_, |
| 937 |
T *X, const int incX) |
| 938 |
{ |
| 939 |
T alpha = tocomplex<T, U>(alpha_); |
| 940 |
if ((N <= 0) || (incX <= 0)) { |
| 941 |
return; |
| 942 |
} |
| 943 |
if (incX == 1) { |
| 944 |
for (int i = 0; i < N; i++) { |
| 945 |
X[i] *= alpha; |
| 946 |
} |
| 947 |
} |
| 948 |
else { |
| 949 |
int nincx = N * incX; |
| 950 |
for (int i = 0; i < nincx; i += incX) { |
| 951 |
X[i] *= alpha; |
| 952 |
} |
| 953 |
} |
| 954 |
} |
| 955 |
|
| 956 |
// explicit instantiation blas_scal with real number saling |
| 957 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 958 |
template void |
| 959 |
blas_scal2<double, double>(const int N, const double &alpha, |
| 960 |
double *X, const int incX); |
| 961 |
|
| 962 |
template void |
| 963 |
blas_scal2<complex<double>, double>(const int N, const double &alpha_, |
| 964 |
complex<double> *X, const int incX); |
| 965 |
|
| 966 |
template void |
| 967 |
blas_scal2<float, float>(const int N, const float &alpha, |
| 968 |
float *X, const int incX); |
| 969 |
|
| 970 |
template void |
| 971 |
blas_scal2<complex<float>, float>(const int N, const float &alpha_, |
| 972 |
complex<float> *X, const int incX); |
| 973 |
|
| 974 |
|
| 975 |
template void |
| 976 |
blas_scal2<quadruple, quadruple>(const int N, const quadruple &alpha, |
| 977 |
quadruple *X, const int incX); |
| 978 |
template void |
| 979 |
blas_scal2<complex<quadruple>, quadruple>(const int N, const quadruple &alpha_, |
| 980 |
complex<quadruple> *X, const int incX); |
| 981 |
|
| 982 |
#ifndef NO_OCTRUPLE |
| 983 |
template void |
| 984 |
blas_scal2<octruple, octruple>(const int N, const octruple &alpha, |
| 985 |
octruple *X, const int incX); |
| 986 |
template void |
| 987 |
blas_scal2<complex<octruple>, octruple>(const int N, const octruple &alpha, |
| 988 |
complex<octruple> *X, const int incX); |
| 989 |
#endif |
| 990 |
#endif |
| 991 |
template<typename T, typename U> |
| 992 |
int blas_iamax(const int n, const T *x, const int incx) |
| 993 |
{ |
| 994 |
U umax; |
| 995 |
int ix, iamax; |
| 996 |
iamax = (-1); |
| 997 |
if ((n < 1) || incx <= 0) { |
| 998 |
return iamax; |
| 999 |
} |
| 1000 |
iamax = 0; |
| 1001 |
if (n == 1) { |
| 1002 |
return iamax; |
| 1003 |
} |
| 1004 |
if (incx == 1) { |
| 1005 |
umax = blas_abs<T, U>(x[0]); |
| 1006 |
for (int i = 1; i < n; i++) { |
| 1007 |
U tmax = blas_abs<T, U>(x[0]); |
| 1008 |
if (tmax > umax) { |
| 1009 |
iamax = i; |
| 1010 |
umax = tmax; |
| 1011 |
} |
| 1012 |
} |
| 1013 |
} |
| 1014 |
else { |
| 1015 |
ix = 0; |
| 1016 |
umax = blas_abs<T, U>(x[0]); |
| 1017 |
for (int i = 1; i < n; i++) { |
| 1018 |
ix += incx; |
| 1019 |
U tmax = blas_abs<T, U>(x[ix]); |
| 1020 |
if (tmax > umax) { |
| 1021 |
iamax = i; |
| 1022 |
umax = tmax; |
| 1023 |
} |
| 1024 |
} |
| 1025 |
} |
| 1026 |
return iamax; |
| 1027 |
} |
| 1028 |
|
| 1029 |
#ifndef BLAS_GENERIC |
| 1030 |
template<> |
| 1031 |
int blas_iamax<double, double>(const int n, const double *x, const int incx) |
| 1032 |
{ |
| 1033 |
#ifdef BLAS_FORTRAN |
| 1034 |
return (FORTRAN_DECL(idamax)(n, x, incx) - 1); // Fortran to C index |
| 1035 |
#else |
| 1036 |
return cblas_idamax((BLAS_INT)n, x, (BLAS_INT)incx); |
| 1037 |
#endif |
| 1038 |
} |
| 1039 |
|
| 1040 |
template<> |
| 1041 |
int blas_iamax<complex<double>, double>(const int n, |
| 1042 |
const complex<double> *x, |
| 1043 |
const int incx) |
| 1044 |
{ |
| 1045 |
#ifdef BLAS_FORTRAN // Fortran to C index |
| 1046 |
return (FORTRAN_DECL(izamax)(n, (double *)x, incx) - 1); |
| 1047 |
#else |
| 1048 |
return cblas_izamax((BLAS_INT)n, (double *)x, (BLAS_INT)incx); |
| 1049 |
#endif |
| 1050 |
} |
| 1051 |
|
| 1052 |
template<> |
| 1053 |
int blas_iamax<float, float>(const int n, const float *x, const int incx) |
| 1054 |
{ |
| 1055 |
#ifdef BLAS_FORTRAN |
| 1056 |
return (FORTRAN_DECL(isamax)(n, x, incx) - 1); // Fortran to C index |
| 1057 |
#else |
| 1058 |
return cblas_isamax((BLAS_INT)n, x, (BLAS_INT)incx); |
| 1059 |
#endif |
| 1060 |
} |
| 1061 |
|
| 1062 |
template<> |
| 1063 |
int blas_iamax<complex<float>, float>(const int n, |
| 1064 |
const complex<float> *x, |
| 1065 |
const int incx) |
| 1066 |
{ |
| 1067 |
#ifdef BLAS_FORTRAN // Fortran to C index |
| 1068 |
return (FORTRAN_DECL(icamax)(n, (float *)x, incx) - 1); |
| 1069 |
#else |
| 1070 |
return cblas_icamax((BLAS_INT)n, (float *)x, (BLAS_INT)incx); |
| 1071 |
#endif |
| 1072 |
} |
| 1073 |
|
| 1074 |
#endif |
| 1075 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 1076 |
template |
| 1077 |
int blas_iamax<double, double>(const int n, const double *x, const int incx); |
| 1078 |
template |
| 1079 |
int blas_iamax<complex<double>, double>(const int n, const complex<double> *x, |
| 1080 |
const int incx); |
| 1081 |
template |
| 1082 |
int blas_iamax<float, float>(const int n, const float *x, const int incx); |
| 1083 |
template |
| 1084 |
int blas_iamax<complex<float>, float>(const int n, const complex<float> *x, |
| 1085 |
const int incx); |
| 1086 |
#endif |
| 1087 |
template |
| 1088 |
int blas_iamax<quadruple, quadruple>(const int n, const quadruple *x, const int incx); |
| 1089 |
template |
| 1090 |
int blas_iamax<complex<quadruple>, quadruple>(const int n, |
| 1091 |
const complex<quadruple> *x, |
| 1092 |
const int incx); |
| 1093 |
template |
| 1094 |
int blas_iamax<octruple, octruple>(const int n, const octruple *x, const int incx); |
| 1095 |
template |
| 1096 |
int blas_iamax<complex<octruple>, octruple>(const int n, |
| 1097 |
const complex<octruple> *x, |
| 1098 |
const int incx); |
| 1099 |
// |
| 1100 |
// BLAS 2 |
| 1101 |
// dz gemv |
| 1102 |
#ifndef BLAS_GENERIC |
| 1103 |
template<> |
| 1104 |
void |
| 1105 |
blas_gemv<double>(const CBLAS_TRANSPOSE trA, |
| 1106 |
const int m, const int n, const double &alpha, |
| 1107 |
const double* A, const int lda, const double* x, |
| 1108 |
const int incx, |
| 1109 |
const double &beta, double* y, const int incy) |
| 1110 |
{ |
| 1111 |
#ifdef BLAS_FORTRAN |
| 1112 |
unsigned char tra_ = 0; |
| 1113 |
switch(trA) { |
| 1114 |
case CblasNoTrans : |
| 1115 |
tra_ = 'n'; |
| 1116 |
break; |
| 1117 |
case CblasTrans : |
| 1118 |
tra_ = 't'; |
| 1119 |
break; |
| 1120 |
case CblasConjTrans: |
| 1121 |
tra_ = 'c'; |
| 1122 |
break; |
| 1123 |
} |
| 1124 |
FORTRAN_DECL(dgemv)(tra_, m, n, alpha, A, lda, x, incx, beta, y, incy); // |
| 1125 |
#else |
| 1126 |
cblas_dgemv(CblasColMajor, trA, (BLAS_INT)m, (BLAS_INT)n, alpha, |
| 1127 |
A, (BLAS_INT)lda, x, (BLAS_INT)incx, beta, y, (BLAS_INT)incy); |
| 1128 |
#endif |
| 1129 |
} |
| 1130 |
|
| 1131 |
template<> |
| 1132 |
void |
| 1133 |
blas_gemv<complex<double> >(const CBLAS_TRANSPOSE trA, |
| 1134 |
const int m, const int n, |
| 1135 |
const complex<double> &alpha, |
| 1136 |
const complex<double>* A, const int lda, |
| 1137 |
const complex<double>* x, const int incx, |
| 1138 |
const complex<double> &beta, |
| 1139 |
complex<double>* y, const int incy) |
| 1140 |
{ |
| 1141 |
#ifdef BLAS_FORTRAN |
| 1142 |
unsigned char tra_ = 0; |
| 1143 |
switch(trA) { |
| 1144 |
case CblasNoTrans: |
| 1145 |
tra_ = 'n'; |
| 1146 |
break; |
| 1147 |
case CblasTrans: |
| 1148 |
tra_ = 't'; |
| 1149 |
break; |
| 1150 |
case CblasConjTrans: |
| 1151 |
tra_ = 'c'; |
| 1152 |
break; |
| 1153 |
} |
| 1154 |
FORTRAN_DECL(zgemv)(tra_, m, n, (double *)&alpha, (double *)A, lda, |
| 1155 |
(double *)x, incx, (double *)&beta, (double *)y, incy); |
| 1156 |
#else |
| 1157 |
cblas_zgemv(CblasColMajor, trA, (BLAS_INT)m, (BLAS_INT)n, (BLAS_VOID *)&alpha, |
| 1158 |
(BLAS_VOID *)A, (BLAS_INT)lda, (BLAS_VOID *)x, (BLAS_INT)incx, |
| 1159 |
(BLAS_VOID *)&beta, (void *)y, (BLAS_INT)incy); |
| 1160 |
#endif |
| 1161 |
} |
| 1162 |
|
| 1163 |
template<> |
| 1164 |
void |
| 1165 |
blas_gemv<float>(const CBLAS_TRANSPOSE trA, |
| 1166 |
const int m, const int n, const float &alpha, |
| 1167 |
const float* A, const int lda, const float* x, |
| 1168 |
const int incx, |
| 1169 |
const float &beta, float* y, const int incy) |
| 1170 |
{ |
| 1171 |
#ifdef BLAS_FORTRAN |
| 1172 |
unsigned char tra_ = 0; |
| 1173 |
switch(trA) { |
| 1174 |
case CblasNoTrans : |
| 1175 |
tra_ = 'n'; |
| 1176 |
break; |
| 1177 |
case CblasTrans : |
| 1178 |
tra_ = 't'; |
| 1179 |
break; |
| 1180 |
case CblasConjTrans: |
| 1181 |
tra_ = 'c'; |
| 1182 |
break; |
| 1183 |
} |
| 1184 |
FORTRAN_DECL(sgemv)(tra_, m, n, alpha, A, lda, x, incx, beta, y, incy); // |
| 1185 |
#else |
| 1186 |
cblas_sgemv(CblasColMajor, trA, (BLAS_INT)m, (BLAS_INT)n, alpha, |
| 1187 |
A, (BLAS_INT)lda, x, (BLAS_INT)incx, beta, y, (BLAS_INT)incy); |
| 1188 |
#endif |
| 1189 |
} |
| 1190 |
|
| 1191 |
template<> |
| 1192 |
void |
| 1193 |
blas_gemv<complex<float> >(const CBLAS_TRANSPOSE trA, |
| 1194 |
const int m, const int n, |
| 1195 |
const complex<float> &alpha, |
| 1196 |
const complex<float>* A, const int lda, |
| 1197 |
const complex<float>* x, const int incx, |
| 1198 |
const complex<float> &beta, |
| 1199 |
complex<float>* y, const int incy) |
| 1200 |
{ |
| 1201 |
#ifdef BLAS_FORTRAN |
| 1202 |
unsigned char tra_ = 0; |
| 1203 |
switch(trA) { |
| 1204 |
case CblasNoTrans: |
| 1205 |
tra_ = 'n'; |
| 1206 |
break; |
| 1207 |
case CblasTrans: |
| 1208 |
tra_ = 't'; |
| 1209 |
break; |
| 1210 |
case CblasConjTrans: |
| 1211 |
tra_ = 'c'; |
| 1212 |
break; |
| 1213 |
} |
| 1214 |
FORTRAN_DECL(cgemv)(tra_, m, n, (float *)&alpha, (float *)A, lda, |
| 1215 |
(float *)x, incx, (float *)&beta, (float *)y, incy); |
| 1216 |
#else |
| 1217 |
cblas_cgemv(CblasColMajor, trA, (BLAS_INT)m, (BLAS_INT)n, (BLAS_VOID *)&alpha, |
| 1218 |
(BLAS_VOID *)A, (BLAS_INT)lda, (BLAS_VOID *)x, (BLAS_INT)incx, |
| 1219 |
(BLAS_VOID *)&beta, (void *)y, (BLAS_INT)incy); |
| 1220 |
#endif |
| 1221 |
} |
| 1222 |
|
| 1223 |
#endif |
| 1224 |
|
| 1225 |
template<typename T> |
| 1226 |
void |
| 1227 |
blas_gemv(const CBLAS_TRANSPOSE trA, |
| 1228 |
const int m, const int n, const T &alpha, |
| 1229 |
const T* A, const int lda, |
| 1230 |
const T* x, const int incx, |
| 1231 |
const T &beta, T* y, const int incy) |
| 1232 |
{ |
| 1233 |
const T zero(0.0); |
| 1234 |
const T one(1.0); |
| 1235 |
int lenx, leny, ix, iy, jx, jy, kx, ky; |
| 1236 |
bool noconj; |
| 1237 |
|
| 1238 |
if ((m == 0) || (n == 0) || |
| 1239 |
((alpha == zero) && (beta == one))) { |
| 1240 |
return; |
| 1241 |
} |
| 1242 |
|
| 1243 |
noconj = (trA == CblasTrans); |
| 1244 |
|
| 1245 |
if (trA == CblasNoTrans) { |
| 1246 |
lenx = n; |
| 1247 |
leny = m; |
| 1248 |
} |
| 1249 |
else { |
| 1250 |
lenx = m; |
| 1251 |
leny = n; |
| 1252 |
} |
| 1253 |
if (incx > 0) { |
| 1254 |
kx = 0; |
| 1255 |
} |
| 1256 |
else { |
| 1257 |
kx = (lenx - 1) * (-incx); // |
| 1258 |
} |
| 1259 |
if (incy > 0) { |
| 1260 |
ky = 0; |
| 1261 |
} |
| 1262 |
else { |
| 1263 |
ky = (leny - 1) * (-incy); // |
| 1264 |
} |
| 1265 |
if (beta != one) { |
| 1266 |
if (incy == 1) { |
| 1267 |
if (beta == zero) { |
| 1268 |
for (int i = 0; i < leny; i++) { |
| 1269 |
y[i] = zero; |
| 1270 |
} // loop 10 : i |
| 1271 |
} |
| 1272 |
else { |
| 1273 |
for (int i = 0; i < leny; i++) { |
| 1274 |
y[i] *= beta; |
| 1275 |
} // loop 20 : i |
| 1276 |
} |
| 1277 |
} |
| 1278 |
else { |
| 1279 |
iy = ky; |
| 1280 |
if (beta == zero) { |
| 1281 |
for (int i = 0; i < leny; i++) { |
| 1282 |
y[iy] = zero; |
| 1283 |
iy += incy; |
| 1284 |
} // loop 30 : i |
| 1285 |
} |
| 1286 |
else { |
| 1287 |
for (int i = 0; i < leny; i++) { |
| 1288 |
y[iy] *= beta; |
| 1289 |
iy += incy; |
| 1290 |
} // loop 40 : i |
| 1291 |
} |
| 1292 |
} |
| 1293 |
} // if (beta != one) |
| 1294 |
if (alpha == zero) { |
| 1295 |
return; |
| 1296 |
} |
| 1297 |
if (trA == CblasNoTrans) { |
| 1298 |
// Form y := alpha*A*x + y. |
| 1299 |
jx = kx; |
| 1300 |
if (incy == 1) { |
| 1301 |
for (int j = 0; j < n; j++) { |
| 1302 |
if (x[jx] != zero) { |
| 1303 |
T temp = alpha * x[jx]; |
| 1304 |
for (int i = 0; i < m; i++) { |
| 1305 |
y[i] += temp * A[i + j * lda]; |
| 1306 |
} // loop 50 : i |
| 1307 |
} // end if |
| 1308 |
jx += incx; |
| 1309 |
} // loop 60 : j |
| 1310 |
} |
| 1311 |
else { |
| 1312 |
for (int j = 0; j < n; j++) { |
| 1313 |
if (x[jx] != zero) { |
| 1314 |
T temp = alpha * x[jx]; |
| 1315 |
iy = ky; |
| 1316 |
for (int i = 0; i < m; i++) { |
| 1317 |
y[iy] += temp * A[i + j * lda]; |
| 1318 |
iy += incy; |
| 1319 |
} // loop 70 : i |
| 1320 |
} |
| 1321 |
jx += incx; |
| 1322 |
} // loop 80 : j |
| 1323 |
} |
| 1324 |
} |
| 1325 |
else { |
| 1326 |
// Form y := alpha*A**T*x + y or y := alpha*conjg( A' )*x + y. |
| 1327 |
jy = ky; |
| 1328 |
if (incx == 1) { |
| 1329 |
for (int j = 0; j < n; j++) { |
| 1330 |
T temp = zero; |
| 1331 |
if (noconj) { |
| 1332 |
for (int i = 0; i < m; i++) { |
| 1333 |
temp += A[i + j * lda] * x[i]; |
| 1334 |
} // loop 90 : i |
| 1335 |
} |
| 1336 |
else { |
| 1337 |
for (int i = 0; i < m; i++) { |
| 1338 |
temp += blas_conj(A[i + j * lda]) * x[i]; |
| 1339 |
} // loop 100 : j |
| 1340 |
} |
| 1341 |
y[jy] += alpha * temp; |
| 1342 |
jy += incy; |
| 1343 |
} // loop 110 : j |
| 1344 |
} |
| 1345 |
else { |
| 1346 |
for (int j = 0; j < n; j++) { |
| 1347 |
T temp = zero; |
| 1348 |
ix = kx; |
| 1349 |
if (noconj) { |
| 1350 |
for (int i = 0; i < m; i++) { |
| 1351 |
temp += A[i + j * lda] * x[ix]; |
| 1352 |
ix += incx; |
| 1353 |
} // loop 120 : i |
| 1354 |
} |
| 1355 |
else { |
| 1356 |
for (int i = 0; i < m; i++) { |
| 1357 |
temp += blas_conj(A[i + j * lda]) * x[ix]; |
| 1358 |
ix += incx; |
| 1359 |
} // loop 130 : i |
| 1360 |
} |
| 1361 |
y[jy] += alpha * temp; |
| 1362 |
jy += incy; |
| 1363 |
} // loop 140 : j |
| 1364 |
} // if (incx != 1) |
| 1365 |
} |
| 1366 |
} |
| 1367 |
|
| 1368 |
// explicit instantiation of blas_gemv |
| 1369 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 1370 |
template |
| 1371 |
void |
| 1372 |
blas_gemv<double>(const CBLAS_TRANSPOSE trA, |
| 1373 |
const int m, const int n, const double &alpha, |
| 1374 |
const double* A, const int lda, |
| 1375 |
const double* x, const int incx, |
| 1376 |
const double &beta, double* y, const int incy); |
| 1377 |
|
| 1378 |
template |
| 1379 |
void |
| 1380 |
blas_gemv<complex<double> >(const CBLAS_TRANSPOSE trA, |
| 1381 |
const int m, const int n, |
| 1382 |
const complex<double> &alpha, |
| 1383 |
const complex<double>* A, const int lda, |
| 1384 |
const complex<double>* x, const int incx, |
| 1385 |
const complex<double> &beta, |
| 1386 |
complex<double>* y, const int incy); |
| 1387 |
|
| 1388 |
template |
| 1389 |
void |
| 1390 |
blas_gemv<float>(const CBLAS_TRANSPOSE trA, |
| 1391 |
const int m, const int n, const float &alpha, |
| 1392 |
const float* A, const int lda, |
| 1393 |
const float* x, const int incx, |
| 1394 |
const float &beta, float* y, const int incy); |
| 1395 |
|
| 1396 |
template |
| 1397 |
void |
| 1398 |
blas_gemv<complex<float> >(const CBLAS_TRANSPOSE trA, |
| 1399 |
const int m, const int n, |
| 1400 |
const complex<float> &alpha, |
| 1401 |
const complex<float>* A, const int lda, |
| 1402 |
const complex<float>* x, const int incx, |
| 1403 |
const complex<float> &beta, |
| 1404 |
complex<float>* y, const int incy); |
| 1405 |
#endif |
| 1406 |
template |
| 1407 |
void |
| 1408 |
blas_gemv<quadruple>(const CBLAS_TRANSPOSE trA, |
| 1409 |
const int m, const int n, const quadruple &alpha, |
| 1410 |
const quadruple* A, const int lda, |
| 1411 |
const quadruple* x, const int incx, |
| 1412 |
const quadruple &beta, quadruple* y, const int incy); |
| 1413 |
#ifndef NO_OCTRUPLE |
| 1414 |
template |
| 1415 |
void |
| 1416 |
blas_gemv<octruple>(const CBLAS_TRANSPOSE trA, |
| 1417 |
const int m, const int n, const octruple &alpha, |
| 1418 |
const octruple* A, const int lda, |
| 1419 |
const octruple* x, const int incx, |
| 1420 |
const octruple &beta, octruple* y, const int incy); |
| 1421 |
#endif |
| 1422 |
template |
| 1423 |
void |
| 1424 |
blas_gemv<complex<quadruple> >(const CBLAS_TRANSPOSE trA, |
| 1425 |
const int m, const int n, |
| 1426 |
const complex<quadruple> &alpha, |
| 1427 |
const complex<quadruple>* A, const int lda, |
| 1428 |
const complex<quadruple>* x, const int incx, |
| 1429 |
const complex<quadruple> &beta, |
| 1430 |
complex<quadruple>* y, const int incy); |
| 1431 |
#ifndef NO_OCTRUPLE |
| 1432 |
template |
| 1433 |
void |
| 1434 |
blas_gemv<complex<octruple> >(const CBLAS_TRANSPOSE trA, |
| 1435 |
const int m, const int n, |
| 1436 |
const complex<octruple> &alpha, |
| 1437 |
const complex<octruple>* A, const int lda, |
| 1438 |
const complex<octruple>* x, const int incx, |
| 1439 |
const complex<octruple> &beta, |
| 1440 |
complex<octruple>* y, const int incy); |
| 1441 |
#endif |
| 1442 |
|
| 1443 |
// dz trsv |
| 1444 |
#ifndef BLAS_GENERIC |
| 1445 |
template<> |
| 1446 |
void |
| 1447 |
blas_trsv<double>(const CBLAS_UPLO Uplo, |
| 1448 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1449 |
const int N, const double *A, const int lda, double *X, |
| 1450 |
const int incX) |
| 1451 |
{ |
| 1452 |
#ifdef BLAS_FORTRAN |
| 1453 |
unsigned char uplo_ = 0; |
| 1454 |
unsigned char transa_ = 0; |
| 1455 |
unsigned char diag_ = 0; |
| 1456 |
switch(Uplo) { |
| 1457 |
case CblasUpper: |
| 1458 |
uplo_ = 'u'; |
| 1459 |
break; |
| 1460 |
case CblasLower: |
| 1461 |
uplo_ = 'l'; |
| 1462 |
break; |
| 1463 |
} |
| 1464 |
switch(TransA) { |
| 1465 |
case CblasNoTrans: |
| 1466 |
transa_ = 'n'; |
| 1467 |
break; |
| 1468 |
case CblasTrans: |
| 1469 |
transa_ = 't'; |
| 1470 |
break; |
| 1471 |
case CblasConjTrans: |
| 1472 |
transa_ = 'c'; |
| 1473 |
break; |
| 1474 |
} |
| 1475 |
switch(Diag) { |
| 1476 |
case CblasNonUnit: |
| 1477 |
diag_ = 'n'; |
| 1478 |
break; |
| 1479 |
case CblasUnit: |
| 1480 |
diag_ = 'u'; |
| 1481 |
break; |
| 1482 |
} |
| 1483 |
FORTRAN_DECL(dtrsv)(uplo_, transa_, diag_, N, A, lda, X, incX); |
| 1484 |
#else |
| 1485 |
cblas_dtrsv(CblasColMajor, Uplo, TransA, Diag, (BLAS_INT)N, |
| 1486 |
A, (BLAS_INT)lda, X, (BLAS_INT)incX); |
| 1487 |
#endif |
| 1488 |
} |
| 1489 |
|
| 1490 |
template<> |
| 1491 |
void |
| 1492 |
blas_trsv<complex<double> >(const CBLAS_UPLO Uplo, |
| 1493 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1494 |
const int N, const complex<double>* A, |
| 1495 |
const int lda, |
| 1496 |
complex<double> *X, const int incX) |
| 1497 |
{ |
| 1498 |
#ifdef BLAS_FORTRAN |
| 1499 |
unsigned char uplo_ = 0; |
| 1500 |
unsigned char transa_ = 0; |
| 1501 |
unsigned char diag_ = 0; |
| 1502 |
switch(Uplo) { |
| 1503 |
case CblasUpper: |
| 1504 |
uplo_ = 'u'; |
| 1505 |
break; |
| 1506 |
case CblasLower: |
| 1507 |
uplo_ = 'l'; |
| 1508 |
break; |
| 1509 |
} |
| 1510 |
switch(TransA) { |
| 1511 |
case CblasNoTrans: |
| 1512 |
transa_ = 'n'; |
| 1513 |
break; |
| 1514 |
case CblasTrans: |
| 1515 |
transa_ = 't'; |
| 1516 |
break; |
| 1517 |
case CblasConjTrans: |
| 1518 |
transa_ = 'c'; |
| 1519 |
break; |
| 1520 |
} |
| 1521 |
switch(Diag) { |
| 1522 |
case CblasNonUnit: |
| 1523 |
diag_ = 'n'; |
| 1524 |
break; |
| 1525 |
case CblasUnit: |
| 1526 |
diag_ = 'u'; |
| 1527 |
break; |
| 1528 |
} |
| 1529 |
FORTRAN_DECL(ztrsv)(uplo_, transa_, diag_, N, (double *)A, lda, |
| 1530 |
(double *)X, incX); |
| 1531 |
#else |
| 1532 |
cblas_ztrsv(CblasColMajor, Uplo, TransA, Diag, (BLAS_INT)N, |
| 1533 |
(BLAS_VOID *)A, (BLAS_INT)lda, (BLAS_VOID *)X, (BLAS_INT)incX); |
| 1534 |
#endif |
| 1535 |
} |
| 1536 |
|
| 1537 |
template<> |
| 1538 |
void |
| 1539 |
blas_trsv<float>(const CBLAS_UPLO Uplo, |
| 1540 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1541 |
const int N, const float *A, const int lda, float *X, |
| 1542 |
const int incX) |
| 1543 |
{ |
| 1544 |
#ifdef BLAS_FORTRAN |
| 1545 |
unsigned char uplo_ = 0; |
| 1546 |
unsigned char transa_ = 0; |
| 1547 |
unsigned char diag_ = 0; |
| 1548 |
switch(Uplo) { |
| 1549 |
case CblasUpper: |
| 1550 |
uplo_ = 'u'; |
| 1551 |
break; |
| 1552 |
case CblasLower: |
| 1553 |
uplo_ = 'l'; |
| 1554 |
break; |
| 1555 |
} |
| 1556 |
switch(TransA) { |
| 1557 |
case CblasNoTrans: |
| 1558 |
transa_ = 'n'; |
| 1559 |
break; |
| 1560 |
case CblasTrans: |
| 1561 |
transa_ = 't'; |
| 1562 |
break; |
| 1563 |
case CblasConjTrans: |
| 1564 |
transa_ = 'c'; |
| 1565 |
break; |
| 1566 |
} |
| 1567 |
switch(Diag) { |
| 1568 |
case CblasNonUnit: |
| 1569 |
diag_ = 'n'; |
| 1570 |
break; |
| 1571 |
case CblasUnit: |
| 1572 |
diag_ = 'u'; |
| 1573 |
break; |
| 1574 |
} |
| 1575 |
FORTRAN_DECL(strsv)(uplo_, transa_, diag_, N, A, lda, X, incX); |
| 1576 |
#else |
| 1577 |
cblas_strsv(CblasColMajor, Uplo, TransA, Diag, (BLAS_INT)N, |
| 1578 |
A, (BLAS_INT)lda, X, (BLAS_INT)incX); |
| 1579 |
#endif |
| 1580 |
} |
| 1581 |
|
| 1582 |
template<> |
| 1583 |
void |
| 1584 |
blas_trsv<complex<float> >(const CBLAS_UPLO Uplo, |
| 1585 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1586 |
const int N, const complex<float>* A, |
| 1587 |
const int lda, |
| 1588 |
complex<float> *X, const int incX) |
| 1589 |
{ |
| 1590 |
#ifdef BLAS_FORTRAN |
| 1591 |
unsigned char uplo_ = 0; |
| 1592 |
unsigned char transa_ = 0; |
| 1593 |
unsigned char diag_ = 0; |
| 1594 |
switch(Uplo) { |
| 1595 |
case CblasUpper: |
| 1596 |
uplo_ = 'u'; |
| 1597 |
break; |
| 1598 |
case CblasLower: |
| 1599 |
uplo_ = 'l'; |
| 1600 |
break; |
| 1601 |
} |
| 1602 |
switch(TransA) { |
| 1603 |
case CblasNoTrans: |
| 1604 |
transa_ = 'n'; |
| 1605 |
break; |
| 1606 |
case CblasTrans: |
| 1607 |
transa_ = 't'; |
| 1608 |
break; |
| 1609 |
case CblasConjTrans: |
| 1610 |
transa_ = 'c'; |
| 1611 |
break; |
| 1612 |
} |
| 1613 |
switch(Diag) { |
| 1614 |
case CblasNonUnit: |
| 1615 |
diag_ = 'n'; |
| 1616 |
break; |
| 1617 |
case CblasUnit: |
| 1618 |
diag_ = 'u'; |
| 1619 |
break; |
| 1620 |
} |
| 1621 |
FORTRAN_DECL(ctrsv)(uplo_, transa_, diag_, N, (float *)A, lda, |
| 1622 |
(float *)X, incX); |
| 1623 |
#else |
| 1624 |
cblas_ctrsv(CblasColMajor, Uplo, TransA, Diag, (BLAS_INT)N, |
| 1625 |
(BLAS_VOID *)A, (BLAS_INT)lda, (BLAS_VOID *)X, (BLAS_INT)incX); |
| 1626 |
#endif |
| 1627 |
} |
| 1628 |
#endif |
| 1629 |
|
| 1630 |
template<typename T> |
| 1631 |
void |
| 1632 |
blas_trsv(const CBLAS_UPLO Uplo, |
| 1633 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1634 |
const int N, const T *A, const int lda, T *X, |
| 1635 |
const int incX) |
| 1636 |
{ |
| 1637 |
const T zero(0.0); |
| 1638 |
bool noconj, nounit; |
| 1639 |
int ix, jx, kx; |
| 1640 |
if (N == 0) { |
| 1641 |
return; |
| 1642 |
} |
| 1643 |
noconj = (TransA == CblasTrans); |
| 1644 |
nounit = (Diag == CblasNonUnit); |
| 1645 |
if (incX < 0) { |
| 1646 |
kx = (N - 1) * (-incX); // decrement form the last index |
| 1647 |
} |
| 1648 |
else { |
| 1649 |
kx = 0; |
| 1650 |
} |
| 1651 |
if (TransA == CblasNoTrans) { |
| 1652 |
// Form x := inv( A )*x. |
| 1653 |
if (Uplo == CblasUpper) { |
| 1654 |
if (incX == 1) { |
| 1655 |
for (int j = (N - 1); j >= 0; j--) { |
| 1656 |
if (X[j] != zero) { |
| 1657 |
if (nounit) { |
| 1658 |
X[j] /= A[j + j * lda]; |
| 1659 |
} |
| 1660 |
T temp = X[j]; |
| 1661 |
for (int i = (j - 1); i >= 0; i--) { |
| 1662 |
X[i] -= temp * A[i + j * lda]; |
| 1663 |
} // loop 10 : i |
| 1664 |
} |
| 1665 |
} // loop 20 : j |
| 1666 |
} |
| 1667 |
else { |
| 1668 |
jx = kx + (N - 1) * incX; |
| 1669 |
for (int j = (N - 1); j >= 0; j--) { |
| 1670 |
if (X[jx] != zero) { |
| 1671 |
if (nounit) { |
| 1672 |
X[jx] /= A[j + j * lda]; |
| 1673 |
} |
| 1674 |
T temp = X[jx]; |
| 1675 |
ix = jx; |
| 1676 |
for (int i = (j - 1); j >= 0; j--) { |
| 1677 |
ix -= incX; |
| 1678 |
X[ix] -= temp * A[i + j * lda]; |
| 1679 |
} // loop 30 : i |
| 1680 |
} |
| 1681 |
jx -= incX; |
| 1682 |
} // loop 40 : j |
| 1683 |
} // if (incX == 1) |
| 1684 |
} |
| 1685 |
else { |
| 1686 |
if (incX == 1) { |
| 1687 |
for (int j = 0; j < N; j++) { |
| 1688 |
if (X[j] != zero) { |
| 1689 |
if (nounit) { |
| 1690 |
X[j] /= A[j + j * lda]; |
| 1691 |
} |
| 1692 |
T temp = X[j]; |
| 1693 |
for (int i = j + 1; i < N; i++) { |
| 1694 |
X[i] -= temp * A[i + j * lda]; |
| 1695 |
} // loop 50 : i |
| 1696 |
} |
| 1697 |
} // loop 60 : j |
| 1698 |
} |
| 1699 |
else { |
| 1700 |
jx = kx; |
| 1701 |
for (int j = 0; j < N; j++) { |
| 1702 |
if (X[jx] != zero) { |
| 1703 |
if (nounit) { |
| 1704 |
X[jx] /= A[j + j * lda]; |
| 1705 |
} |
| 1706 |
T temp = X[jx]; |
| 1707 |
ix = jx; |
| 1708 |
for (int i = j + 1; i < N; i++) { |
| 1709 |
ix += incX; |
| 1710 |
X[ix] -= temp * A[i + j * lda]; |
| 1711 |
} // loop 70 : i |
| 1712 |
} |
| 1713 |
jx += incX; |
| 1714 |
} // loop 80 : j |
| 1715 |
} // if (incX == 1) |
| 1716 |
} // if (Uplo == CblasUpper) |
| 1717 |
} |
| 1718 |
else { |
| 1719 |
// Form x := inv( A **T )*x or x := inv( A **H ) *x. |
| 1720 |
if (Uplo == CblasUpper) { |
| 1721 |
if (incX == 1) { |
| 1722 |
for (int j = 0; j < N; j++) { |
| 1723 |
T temp = X[j]; |
| 1724 |
if (noconj) { |
| 1725 |
for (int i = 0; i < j; i++) { |
| 1726 |
temp -= A[i + j * lda] * X[i]; |
| 1727 |
} // loop 90 : i |
| 1728 |
if (nounit) { |
| 1729 |
temp /= A[j + j * lda]; |
| 1730 |
} |
| 1731 |
} |
| 1732 |
else { |
| 1733 |
for (int i = 0; i < j; i++) { |
| 1734 |
temp -= blas_conj(A[i + j * lda]) * X[i]; |
| 1735 |
} // loop 100 : i |
| 1736 |
if (nounit) { |
| 1737 |
temp /= blas_conj(A[j + j * lda]); |
| 1738 |
} |
| 1739 |
} |
| 1740 |
X[j] = temp; |
| 1741 |
} // loop 110 : j |
| 1742 |
} |
| 1743 |
else { |
| 1744 |
jx = kx; |
| 1745 |
for (int j = 0; j < N; j++) { |
| 1746 |
ix = kx; |
| 1747 |
T temp = X[jx]; |
| 1748 |
if (noconj) { |
| 1749 |
for (int i = 0; i < j; i++) { |
| 1750 |
temp -= A[i + j * lda] * X[ix]; |
| 1751 |
ix += incX; |
| 1752 |
} // loop 120 : i |
| 1753 |
if (nounit) { |
| 1754 |
temp /= A[j + j * lda]; |
| 1755 |
} |
| 1756 |
} |
| 1757 |
else { |
| 1758 |
for (int i = 0; i < j; i++) { |
| 1759 |
temp -= blas_conj(A[i + j * lda]) * X[ix]; |
| 1760 |
ix += incX; |
| 1761 |
} // loop 120 : i |
| 1762 |
if (nounit) { |
| 1763 |
temp /= blas_conj(A[j + j * lda]); |
| 1764 |
} |
| 1765 |
} |
| 1766 |
X[jx] = temp; |
| 1767 |
jx += incX; |
| 1768 |
} |
| 1769 |
} |
| 1770 |
} |
| 1771 |
else { |
| 1772 |
if (incX == 1) { |
| 1773 |
for (int j = (N - 1); j >= 0; j--) { |
| 1774 |
T temp = X[j]; |
| 1775 |
if (noconj) { |
| 1776 |
for (int i = (N - 1); i > j; i--) { |
| 1777 |
temp -= A[i + j * lda] * X[i]; |
| 1778 |
} // loop 150 : i |
| 1779 |
if (nounit) { |
| 1780 |
temp /= A[j + j * lda]; |
| 1781 |
} |
| 1782 |
} |
| 1783 |
else { |
| 1784 |
for (int i = 0; i < j; i++) { |
| 1785 |
temp -= blas_conj(A[i + j * lda]) * X[i]; |
| 1786 |
} // loop 160 : i |
| 1787 |
if (nounit) { |
| 1788 |
temp /= blas_conj(A[j + j * lda]); |
| 1789 |
} |
| 1790 |
} |
| 1791 |
X[j] = temp; |
| 1792 |
} // loop 170 : j |
| 1793 |
} |
| 1794 |
else { |
| 1795 |
kx = kx + N * incX; |
| 1796 |
jx = kx; |
| 1797 |
for (int j = (N - 1); j >= 0; j--) { |
| 1798 |
ix = kx; |
| 1799 |
T temp = X[jx]; |
| 1800 |
if (noconj) { |
| 1801 |
for (int i = (N - 1); i > j; i--) { |
| 1802 |
temp -= A[i + j * lda] * X[ix]; |
| 1803 |
ix -= incX; |
| 1804 |
} // loop 180 : i |
| 1805 |
if (nounit) { |
| 1806 |
temp /= A[j + j * lda]; |
| 1807 |
} |
| 1808 |
} |
| 1809 |
else { |
| 1810 |
for (int i = (N - 1); i > j; i--) { |
| 1811 |
temp -= blas_conj(A[i + j * lda]) * X[ix]; |
| 1812 |
ix -= incX; |
| 1813 |
} // loop 190 : i |
| 1814 |
if (nounit) { |
| 1815 |
temp /= blas_conj(A[j + j * lda]); |
| 1816 |
} |
| 1817 |
} |
| 1818 |
X[jx] = temp; |
| 1819 |
jx -= incX; |
| 1820 |
} // loop 200 : j |
| 1821 |
} |
| 1822 |
} // if (Uplo == CblasUpper) |
| 1823 |
} |
| 1824 |
} |
| 1825 |
|
| 1826 |
// explicit instantiation of blas_trsv |
| 1827 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 1828 |
template |
| 1829 |
void |
| 1830 |
blas_trsv<double>(const CBLAS_UPLO Uplo, |
| 1831 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1832 |
const int N, const double *A, const int lda, |
| 1833 |
double *X, const int incX); |
| 1834 |
|
| 1835 |
template |
| 1836 |
void |
| 1837 |
blas_trsv<complex<double> >(const CBLAS_UPLO Uplo, |
| 1838 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1839 |
const int N, |
| 1840 |
const complex<double> *A, const int lda, |
| 1841 |
complex<double> *X, const int incX); |
| 1842 |
|
| 1843 |
template |
| 1844 |
void |
| 1845 |
blas_trsv<float>(const CBLAS_UPLO Uplo, |
| 1846 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1847 |
const int N, const float *A, const int lda, |
| 1848 |
float *X, const int incX); |
| 1849 |
|
| 1850 |
template |
| 1851 |
void |
| 1852 |
blas_trsv<complex<float> >(const CBLAS_UPLO Uplo, |
| 1853 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1854 |
const int N, |
| 1855 |
const complex<float> *A, const int lda, |
| 1856 |
complex<float> *X, const int incX); |
| 1857 |
#endif |
| 1858 |
template |
| 1859 |
void |
| 1860 |
blas_trsv<quadruple>(const CBLAS_UPLO Uplo, |
| 1861 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1862 |
const int N, const quadruple *A, const int lda, |
| 1863 |
quadruple *X, const int incX); |
| 1864 |
#ifndef NO_OCTRUPLE |
| 1865 |
template |
| 1866 |
void |
| 1867 |
blas_trsv<octruple>(const CBLAS_UPLO Uplo, |
| 1868 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1869 |
const int N, const octruple *A, const int lda, |
| 1870 |
octruple *X, const int incX); |
| 1871 |
#endif |
| 1872 |
template |
| 1873 |
void |
| 1874 |
blas_trsv<complex<quadruple> >(const CBLAS_UPLO Uplo, |
| 1875 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1876 |
const int N, |
| 1877 |
const complex<quadruple> *A, const int lda, |
| 1878 |
complex<quadruple> *X, const int incX); |
| 1879 |
#ifndef NO_OCTRUPLE |
| 1880 |
template |
| 1881 |
void |
| 1882 |
blas_trsv<complex<octruple> >(const CBLAS_UPLO Uplo, |
| 1883 |
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, |
| 1884 |
const int N, |
| 1885 |
const complex<octruple> *A, const int lda, |
| 1886 |
complex<octruple> *X, const int incX); |
| 1887 |
#endif |
| 1888 |
|
| 1889 |
// dz syr : symmetric rank-1 update |
| 1890 |
template<typename T> |
| 1891 |
void |
| 1892 |
blas_syr(const CBLAS_UPLO Uplo, |
| 1893 |
const int N, const T &alpha, |
| 1894 |
const T *X, const int incX, |
| 1895 |
T *A, const int lda) |
| 1896 |
{ |
| 1897 |
const T zero(0.0); |
| 1898 |
int ix, jx, kx; |
| 1899 |
if ((N == 0) || (alpha == zero)) { |
| 1900 |
return; |
| 1901 |
} |
| 1902 |
if (incX > 0) { |
| 1903 |
kx = 0; |
| 1904 |
} |
| 1905 |
else { |
| 1906 |
kx = (N - 1) * (-incX); // decrement form the last index |
| 1907 |
} |
| 1908 |
if (Uplo == CblasUpper) { |
| 1909 |
// Form A when A is stored in upper triangle. |
| 1910 |
if (incX == 1) { |
| 1911 |
for (int j = 0; j < N; j++) { |
| 1912 |
if (X[j] != zero) { |
| 1913 |
T temp = alpha * X[j]; |
| 1914 |
for (int i = 0; i <= j; i++) { |
| 1915 |
A[i + j * lda] += X[i] * temp; |
| 1916 |
} // loop 10 : i |
| 1917 |
} |
| 1918 |
} // loop 20 : j |
| 1919 |
} |
| 1920 |
else { |
| 1921 |
jx = kx; |
| 1922 |
for (int j = 0; j < N; j++) { |
| 1923 |
if (X[jx] != zero) { |
| 1924 |
T temp = alpha * X[jx]; |
| 1925 |
ix = kx; |
| 1926 |
for (int i = 0; i <= j; i++) { |
| 1927 |
A[i + j * lda] += X[ix] * temp; |
| 1928 |
ix += incX; |
| 1929 |
} // loop 30 : i |
| 1930 |
} |
| 1931 |
jx += incX; |
| 1932 |
} // loop 40 : j |
| 1933 |
} |
| 1934 |
} |
| 1935 |
else { |
| 1936 |
// Form A when A is stored in lower triangle. |
| 1937 |
if (incX == 1) { |
| 1938 |
for (int j = 0; j < N; j++) { |
| 1939 |
if (X[j] != zero) { |
| 1940 |
T temp = alpha * X[j]; |
| 1941 |
for (int i = j; i < N; i++) { |
| 1942 |
A[i + j * lda] += X[i] * temp; |
| 1943 |
} // loop 50 : i |
| 1944 |
} |
| 1945 |
} // loop 60 : j |
| 1946 |
} |
| 1947 |
else { |
| 1948 |
jx = kx; |
| 1949 |
for (int j = 0; j < N; j++) { |
| 1950 |
if (X[jx] != zero) { |
| 1951 |
T temp = alpha * X[jx]; |
| 1952 |
ix = jx; |
| 1953 |
for (int i = j; i < N; i++) { |
| 1954 |
A[i + j * lda] += X[ix] * temp; |
| 1955 |
ix += incX; |
| 1956 |
} // loop 70 : i |
| 1957 |
} |
| 1958 |
jx += incX; |
| 1959 |
} // loop 80 : j |
| 1960 |
} |
| 1961 |
} |
| 1962 |
} |
| 1963 |
#ifndef BLAS_GENERIC |
| 1964 |
template<> |
| 1965 |
void |
| 1966 |
blas_syr<double>(const CBLAS_UPLO Uplo, |
| 1967 |
const int N, const double &alpha, |
| 1968 |
const double *X, const int incX, |
| 1969 |
double *A, const int lda) |
| 1970 |
{ |
| 1971 |
#ifdef BLAS_FORTRAN |
| 1972 |
unsigned char uplo_ = 0; |
| 1973 |
switch(Uplo) { |
| 1974 |
case CblasUpper: |
| 1975 |
uplo_ = 'u'; |
| 1976 |
break; |
| 1977 |
case CblasLower: |
| 1978 |
uplo_ = 'l'; |
| 1979 |
break; |
| 1980 |
} |
| 1981 |
FORTRAN_DECL(dsyr)(uplo_, N, alpha, X, incX, A, lda); |
| 1982 |
#else |
| 1983 |
cblas_dsyr(CblasColMajor, Uplo, (BLAS_INT)N, alpha, |
| 1984 |
X, (BLAS_INT)incX, A, (BLAS_INT)lda); |
| 1985 |
#endif |
| 1986 |
} |
| 1987 |
|
| 1988 |
template<> |
| 1989 |
void |
| 1990 |
blas_syr<complex<double> >(const CBLAS_UPLO Uplo, |
| 1991 |
const int N, const complex<double> &alpha, |
| 1992 |
const complex<double> *X, const int incX, |
| 1993 |
complex<double> *A, const int lda) |
| 1994 |
{ |
| 1995 |
#ifdef BLAS_FORTRAN |
| 1996 |
FORTRAN_DECL(zgeru)(N, N, |
| 1997 |
(double *)&alpha, (double *)X, incX, (double *)X, incX, |
| 1998 |
(double *)A, lda); // no zsyr in BLAS! : Uplo is ignored |
| 1999 |
#else |
| 2000 |
cblas_zgeru(CblasColMajor, N, N, |
| 2001 |
(BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX, |
| 2002 |
(BLAS_VOID *)X, (BLAS_INT)incX, |
| 2003 |
(BLAS_VOID *)A, (BLAS_INT)lda); // no zsyr in BLAS! : Uplo is ignored |
| 2004 |
#endif |
| 2005 |
} |
| 2006 |
|
| 2007 |
template<> |
| 2008 |
void |
| 2009 |
blas_syr<float>(const CBLAS_UPLO Uplo, |
| 2010 |
const int N, const float &alpha, |
| 2011 |
const float *X, const int incX, |
| 2012 |
float *A, const int lda) |
| 2013 |
{ |
| 2014 |
#ifdef BLAS_FORTRAN |
| 2015 |
unsigned char uplo_ = 0; |
| 2016 |
switch(Uplo) { |
| 2017 |
case CblasUpper: |
| 2018 |
uplo_ = 'u'; |
| 2019 |
break; |
| 2020 |
case CblasLower: |
| 2021 |
uplo_ = 'l'; |
| 2022 |
break; |
| 2023 |
} |
| 2024 |
FORTRAN_DECL(ssyr)(uplo_, N, alpha, X, incX, A, lda); |
| 2025 |
#else |
| 2026 |
cblas_ssyr(CblasColMajor, Uplo, (BLAS_INT)N, alpha, |
| 2027 |
X, (BLAS_INT)incX, A, (BLAS_INT)lda); |
| 2028 |
#endif |
| 2029 |
} |
| 2030 |
|
| 2031 |
template<> |
| 2032 |
void |
| 2033 |
blas_syr<complex<float> >(const CBLAS_UPLO Uplo, |
| 2034 |
const int N, const complex<float> &alpha, |
| 2035 |
const complex<float> *X, const int incX, |
| 2036 |
complex<float> *A, const int lda) |
| 2037 |
{ |
| 2038 |
#ifdef BLAS_FORTRAN |
| 2039 |
FORTRAN_DECL(cgeru)(N, N, |
| 2040 |
(float *)&alpha, (float *)X, incX, (float *)X, incX, |
| 2041 |
(float *)A, lda); // no zsyr in BLAS! : Uplo is ignored |
| 2042 |
#else |
| 2043 |
cblas_cgeru(CblasColMajor, N, N, |
| 2044 |
(BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX, |
| 2045 |
(BLAS_VOID *)X, (BLAS_INT)incX, |
| 2046 |
(BLAS_VOID *)A, (BLAS_INT)lda); // no zsyr in BLAS! : Uplo is ignored |
| 2047 |
#endif |
| 2048 |
} |
| 2049 |
#endif |
| 2050 |
|
| 2051 |
// explicit instantiation of blas_syr |
| 2052 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 2053 |
template |
| 2054 |
void |
| 2055 |
blas_syr<double>(const CBLAS_UPLO Uplo, const int N, |
| 2056 |
const double &alpha, |
| 2057 |
const double *X, const int incX, |
| 2058 |
double *A, const int lda); |
| 2059 |
|
| 2060 |
template |
| 2061 |
void |
| 2062 |
blas_syr<complex<double> >(const CBLAS_UPLO Uplo, const int N, |
| 2063 |
const complex<double> &alpha, |
| 2064 |
const complex<double> *X, const int incX, |
| 2065 |
complex<double> *A, const int lda); |
| 2066 |
|
| 2067 |
template |
| 2068 |
void |
| 2069 |
blas_syr<float>(const CBLAS_UPLO Uplo, const int N, |
| 2070 |
const float &alpha, |
| 2071 |
const float *X, const int incX, |
| 2072 |
float *A, const int lda); |
| 2073 |
|
| 2074 |
template |
| 2075 |
void |
| 2076 |
blas_syr<complex<float> >(const CBLAS_UPLO Uplo, const int N, |
| 2077 |
const complex<float> &alpha, |
| 2078 |
const complex<float> *X, const int incX, |
| 2079 |
complex<float> *A, const int lda); |
| 2080 |
#endif |
| 2081 |
template |
| 2082 |
void |
| 2083 |
blas_syr<quadruple>(const CBLAS_UPLO Uplo, const int N, |
| 2084 |
const quadruple &alpha, |
| 2085 |
const quadruple *X, const int incX, |
| 2086 |
quadruple *A, const int lda); |
| 2087 |
#ifndef NO_OCTRUPLE |
| 2088 |
template |
| 2089 |
void |
| 2090 |
blas_syr<octruple>(const CBLAS_UPLO Uplo, const int N, |
| 2091 |
const octruple &alpha, |
| 2092 |
const octruple *X, const int incX, |
| 2093 |
octruple *A, const int lda); |
| 2094 |
#endif |
| 2095 |
template |
| 2096 |
void |
| 2097 |
blas_syr<complex<quadruple> >(const CBLAS_UPLO Uplo, const int N, |
| 2098 |
const complex<quadruple> &alpha, |
| 2099 |
const complex<quadruple> *X, const int incX, |
| 2100 |
complex<quadruple> *A, const int lda); |
| 2101 |
#ifndef NO_OCTRUPLE |
| 2102 |
template |
| 2103 |
void |
| 2104 |
blas_syr<complex<octruple> >(const CBLAS_UPLO Uplo, const int N, |
| 2105 |
const complex<octruple> &alpha, |
| 2106 |
const complex<octruple> *X, const int incX, |
| 2107 |
complex<octruple> *A, const int lda); |
| 2108 |
#endif |
| 2109 |
|
| 2110 |
// dz syrc : with complex conjugate |
| 2111 |
template<typename T> |
| 2112 |
void |
| 2113 |
blas_syrc(const CBLAS_UPLO Uplo, |
| 2114 |
const int N, const T &alpha, |
| 2115 |
const T *X, const int incX, |
| 2116 |
T *A, const int lda) |
| 2117 |
{ |
| 2118 |
const T zero(0.0); |
| 2119 |
int ix, jx, kx; |
| 2120 |
if ((N == 0) || (alpha == zero)) { |
| 2121 |
return; |
| 2122 |
} |
| 2123 |
if (incX > 0) { |
| 2124 |
kx = 0; |
| 2125 |
} |
| 2126 |
else { |
| 2127 |
kx = (N - 1) * (-incX); // decrement form the last index |
| 2128 |
} |
| 2129 |
if (Uplo == CblasUpper) { |
| 2130 |
// Form A when A is stored in upper triangle. |
| 2131 |
if (incX == 1) { |
| 2132 |
for (int j = 0; j < N; j++) { |
| 2133 |
if (X[j] != zero) { |
| 2134 |
T temp = alpha * blas_conj(X[j]); |
| 2135 |
for (int i = 0; i <= j; i++) { |
| 2136 |
A[i + j * lda] += X[i] * temp; |
| 2137 |
} // loop 10 : i |
| 2138 |
} |
| 2139 |
} // loop 20 : j |
| 2140 |
} |
| 2141 |
else { |
| 2142 |
jx = kx; |
| 2143 |
for (int j = 0; j < N; j++) { |
| 2144 |
if (X[jx] != zero) { |
| 2145 |
T temp = alpha * blas_conj(X[jx]); |
| 2146 |
ix = kx; |
| 2147 |
for (int i = 0; i <= j; i++) { |
| 2148 |
A[i + j * lda] += X[ix] * temp; |
| 2149 |
ix += incX; |
| 2150 |
} // loop 30 : i |
| 2151 |
} |
| 2152 |
jx += incX; |
| 2153 |
} // loop 40 : j |
| 2154 |
} |
| 2155 |
} |
| 2156 |
else { |
| 2157 |
// Form A when A is stored in lower triangle. |
| 2158 |
if (incX == 1) { |
| 2159 |
for (int j = 0; j < N; j++) { |
| 2160 |
if (X[j] != zero) { |
| 2161 |
T temp = alpha * blas_conj(X[j]); |
| 2162 |
for (int i = j; i < N; i++) { |
| 2163 |
A[i + j * lda] += X[i] * temp; |
| 2164 |
} // loop 50 : i |
| 2165 |
} |
| 2166 |
} // loop 60 : j |
| 2167 |
} |
| 2168 |
else { |
| 2169 |
jx = kx; |
| 2170 |
for (int j = 0; j < N; j++) { |
| 2171 |
if (X[jx] != zero) { |
| 2172 |
T temp = alpha * blas_conj(X[jx]); |
| 2173 |
ix = jx; |
| 2174 |
for (int i = j; i < N; i++) { |
| 2175 |
A[i + j * lda] += X[ix] * temp; |
| 2176 |
ix += incX; |
| 2177 |
} // loop 70 : i |
| 2178 |
} |
| 2179 |
jx += incX; |
| 2180 |
} // loop 80 : j |
| 2181 |
} |
| 2182 |
} |
| 2183 |
} |
| 2184 |
// explicit instantiation of blas_syrc |
| 2185 |
template |
| 2186 |
void |
| 2187 |
blas_syrc<complex<double> >(const CBLAS_UPLO Uplo, |
| 2188 |
const int N, const complex<double> &alpha, |
| 2189 |
const complex<double> *X, const int incX, |
| 2190 |
complex<double> *A, const int lda); |
| 2191 |
|
| 2192 |
template |
| 2193 |
void |
| 2194 |
blas_syrc<complex<float> >(const CBLAS_UPLO Uplo, |
| 2195 |
const int N, const complex<float> &alpha, |
| 2196 |
const complex<float> *X, const int incX, |
| 2197 |
complex<float> *A, const int lda); |
| 2198 |
|
| 2199 |
template |
| 2200 |
void |
| 2201 |
blas_syrc<complex<quadruple> >(const CBLAS_UPLO Uplo, |
| 2202 |
const int N, const complex<quadruple> &alpha, |
| 2203 |
const complex<quadruple> *X, const int incX, |
| 2204 |
complex<quadruple> *A, const int lda); |
| 2205 |
#ifndef NO_OCTRUPLE |
| 2206 |
template |
| 2207 |
void |
| 2208 |
blas_syrc<complex<octruple> >(const CBLAS_UPLO Uplo, |
| 2209 |
const int N, const complex<octruple> &alpha, |
| 2210 |
const complex<octruple> *X, const int incX, |
| 2211 |
complex<octruple> *A, const int lda); |
| 2212 |
#endif |
| 2213 |
|
| 2214 |
// dz syr2 symmetric rank-2 update : DSYR2 only exists in BLAS |
| 2215 |
#ifndef BLAS_GENERIC |
| 2216 |
template<> |
| 2217 |
void |
| 2218 |
blas_syr2<double>(const CBLAS_UPLO Uplo, const int N, |
| 2219 |
const double &alpha, |
| 2220 |
const double *X, const int incX, |
| 2221 |
const double *Y, const int incY, |
| 2222 |
double *A, const int lda) |
| 2223 |
{ |
| 2224 |
#ifdef BLAS_FORTRAN |
| 2225 |
unsigned char uplo_ = 0; |
| 2226 |
switch(Uplo) { |
| 2227 |
case CblasUpper: |
| 2228 |
uplo_ = 'u'; |
| 2229 |
break; |
| 2230 |
case CblasLower: |
| 2231 |
uplo_ = 'l'; |
| 2232 |
break; |
| 2233 |
} |
| 2234 |
FORTRAN_DECL(dsyr2)(uplo_, N, alpha, X, incX, Y, incY, A, lda); |
| 2235 |
#else |
| 2236 |
cblas_dsyr2(CblasColMajor, Uplo, (BLAS_INT)N, alpha, |
| 2237 |
X, (BLAS_INT)incX, Y, (BLAS_INT)incY, A, (BLAS_INT)lda); |
| 2238 |
#endif |
| 2239 |
} |
| 2240 |
|
| 2241 |
template<> |
| 2242 |
void |
| 2243 |
blas_syr2<float>(const CBLAS_UPLO Uplo, const int N, |
| 2244 |
const float &alpha, |
| 2245 |
const float *X, const int incX, |
| 2246 |
const float *Y, const int incY, |
| 2247 |
float *A, const int lda) |
| 2248 |
{ |
| 2249 |
#ifdef BLAS_FORTRAN |
| 2250 |
unsigned char uplo_ = 0; |
| 2251 |
switch(Uplo) { |
| 2252 |
case CblasUpper: |
| 2253 |
uplo_ = 'u'; |
| 2254 |
break; |
| 2255 |
case CblasLower: |
| 2256 |
uplo_ = 'l'; |
| 2257 |
break; |
| 2258 |
} |
| 2259 |
FORTRAN_DECL(ssyr2)(uplo_, N, alpha, X, incX, Y, incY, A, lda); |
| 2260 |
#else |
| 2261 |
cblas_ssyr2(CblasColMajor, Uplo, (BLAS_INT)N, alpha, |
| 2262 |
X, (BLAS_INT)incX, Y, (BLAS_INT)incY, A, (BLAS_INT)lda); |
| 2263 |
#endif |
| 2264 |
} |
| 2265 |
#endif |
| 2266 |
|
| 2267 |
template<typename T> |
| 2268 |
void |
| 2269 |
blas_syr2(const CBLAS_UPLO Uplo, |
| 2270 |
const int N, const T &alpha, |
| 2271 |
const T *X, const int incX, |
| 2272 |
const T *Y, const int incY, |
| 2273 |
T *A, const int lda) |
| 2274 |
{ |
| 2275 |
const T zero(0.0); |
| 2276 |
int ix, iy, jx, jy, kx, ky; |
| 2277 |
if ((N == 0) || (alpha == zero)) { |
| 2278 |
return; |
| 2279 |
} |
| 2280 |
if ((incX != 1) || (incY != 1)) { |
| 2281 |
if (incX > 0) { |
| 2282 |
kx = 0; |
| 2283 |
} |
| 2284 |
else { |
| 2285 |
kx = (N - 1) * (-incX); // decrement form the last index |
| 2286 |
} |
| 2287 |
if (incY > 0) { |
| 2288 |
ky = 0; |
| 2289 |
} |
| 2290 |
else { |
| 2291 |
ky = (N - 1) * (-incY); // decrement form the last index |
| 2292 |
} |
| 2293 |
jx = kx; |
| 2294 |
jy = ky; |
| 2295 |
} |
| 2296 |
if (Uplo == CblasUpper) { |
| 2297 |
// Form A when A is stored in upper triangle. |
| 2298 |
if ((incX == 1) && (incY == 1)) { |
| 2299 |
for (int j = 0; j < N; j++) { |
| 2300 |
if ((X[j] != zero) || (Y[j] != zero)) { |
| 2301 |
T temp1 = alpha * Y[j]; |
| 2302 |
T temp2 = alpha * X[j]; |
| 2303 |
for (int i = 0; i < j; i++) { |
| 2304 |
A[i + j * lda] += X[i] * temp1 + Y[i] * temp2; |
| 2305 |
} // loop 10 : i |
| 2306 |
} |
| 2307 |
} // loop 20 : j |
| 2308 |
} |
| 2309 |
else { |
| 2310 |
for (int j = 0; j < N; j++) { |
| 2311 |
if ((X[jx] != zero) || (Y[jy] != zero)) { |
| 2312 |
T temp1 = alpha * Y[jy]; |
| 2313 |
T temp2 = alpha * X[jx]; |
| 2314 |
ix = kx; |
| 2315 |
iy = ky; // 1st Nov.2015 bug fund : ky = ky; |
| 2316 |
for (int i = 0; i < j; i++) { |
| 2317 |
A[i + j * lda] += X[ix] * temp1 + Y[iy] * temp2; |
| 2318 |
ix += incX; |
| 2319 |
iy += incY; |
| 2320 |
} // loop 30 : i |
| 2321 |
} |
| 2322 |
jx += incX; |
| 2323 |
jx += incY; |
| 2324 |
} // loop 40 : j |
| 2325 |
} |
| 2326 |
} |
| 2327 |
else { |
| 2328 |
// Form A when A is stored in lower triangle. |
| 2329 |
if ((incX == 1) && (incY == 1)) { |
| 2330 |
for (int j = 0; j < N; j++) { |
| 2331 |
if ((X[j] != zero) || (Y[j] != zero)) { |
| 2332 |
T temp1 = alpha * Y[j]; |
| 2333 |
T temp2 = alpha * X[j]; |
| 2334 |
for (int i = j; i < N; i++) { |
| 2335 |
A[i + j * lda] += X[i] * temp1 + Y[i] * temp2; |
| 2336 |
} // loop 50 : i |
| 2337 |
} |
| 2338 |
} // loop 60 : j |
| 2339 |
} |
| 2340 |
else { |
| 2341 |
for (int j = 0; j < N; j++) { |
| 2342 |
if ((X[jx] != zero) || (Y[jy] != zero)) { |
| 2343 |
T temp1 = alpha * Y[jy]; |
| 2344 |
T temp2 = alpha * X[jx]; |
| 2345 |
ix = jx; |
| 2346 |
iy = jy; |
| 2347 |
for (int i = j; i < N; i++) { |
| 2348 |
A[i + j * lda] += X[ix] * temp1 + Y[iy] * temp2; |
| 2349 |
ix += incX; |
| 2350 |
iy += incY; |
| 2351 |
} // loop 70 : i |
| 2352 |
} |
| 2353 |
jx += incX; |
| 2354 |
jy += incY; |
| 2355 |
} // loop 80 : j |
| 2356 |
} |
| 2357 |
} |
| 2358 |
} |
| 2359 |
// explicit instantiation of blas_syr2 |
| 2360 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 2361 |
template |
| 2362 |
void |
| 2363 |
blas_syr2<double>(const CBLAS_UPLO Uplo, const int N, |
| 2364 |
const double &alpha, |
| 2365 |
const double *X, const int incX, |
| 2366 |
const double *Y, const int incY, |
| 2367 |
double *A, const int lda); |
| 2368 |
|
| 2369 |
template |
| 2370 |
void |
| 2371 |
blas_syr2<float>(const CBLAS_UPLO Uplo, const int N, |
| 2372 |
const float &alpha, |
| 2373 |
const float *X, const int incX, |
| 2374 |
const float *Y, const int incY, |
| 2375 |
float *A, const int lda); |
| 2376 |
#endif |
| 2377 |
template |
| 2378 |
void |
| 2379 |
blas_syr2<complex<double> >(const CBLAS_UPLO Uplo, const int N, |
| 2380 |
const complex<double> &alpha, |
| 2381 |
const complex<double> *X, const int incX, |
| 2382 |
const complex<double> *Y, const int incY, |
| 2383 |
complex<double> *A, const int lda); |
| 2384 |
// there is no cblas_syr2 |
| 2385 |
|
| 2386 |
template |
| 2387 |
void |
| 2388 |
blas_syr2<quadruple>(const CBLAS_UPLO Uplo, const int N, |
| 2389 |
const quadruple &nalpha, |
| 2390 |
const quadruple *X, const int incX, |
| 2391 |
const quadruple *Y, const int incY, |
| 2392 |
quadruple *A, const int lda); |
| 2393 |
|
| 2394 |
template |
| 2395 |
void |
| 2396 |
blas_syr2<complex<quadruple> >(const CBLAS_UPLO Uplo, const int N, |
| 2397 |
const complex<quadruple> &alpha, |
| 2398 |
const complex<quadruple> *X, const int incX, |
| 2399 |
const complex<quadruple> *Y, const int incY, |
| 2400 |
complex<quadruple> *A, const int lda); |
| 2401 |
|
| 2402 |
// dz ger |
| 2403 |
#ifndef BLAS_GENERIC |
| 2404 |
template<> |
| 2405 |
void |
| 2406 |
blas_ger<double>(const int M, const int N, const double &alpha, |
| 2407 |
const double *X, const int incX, |
| 2408 |
const double *Y, const int incY, |
| 2409 |
double *A, const int lda) |
| 2410 |
{ |
| 2411 |
#ifdef BLAS_FORTRAN |
| 2412 |
FORTRAN_DECL(dger)(M, N, alpha, X, incX, Y, incY, A, lda); |
| 2413 |
#else |
| 2414 |
cblas_dger(CblasColMajor, (BLAS_INT)M, (BLAS_INT)N, alpha, |
| 2415 |
X, (BLAS_INT)incX, Y, (BLAS_INT)incY, A, (BLAS_INT)lda); |
| 2416 |
#endif |
| 2417 |
} |
| 2418 |
|
| 2419 |
template<> |
| 2420 |
void |
| 2421 |
blas_ger<complex<double> >(const int M, const int N, |
| 2422 |
const complex<double> &alpha, |
| 2423 |
const complex<double> *X, const int incX, |
| 2424 |
const complex<double> *Y, const int incY, |
| 2425 |
complex<double> *A, const int lda) |
| 2426 |
{ |
| 2427 |
#ifdef BLAS_FORTRAN |
| 2428 |
FORTRAN_DECL(zgeru)(M, N, (double *)&alpha, |
| 2429 |
(double *)X, incX, (double *)Y, incY, |
| 2430 |
(double *)A, lda); |
| 2431 |
#else |
| 2432 |
cblas_zgeru(CblasColMajor, (BLAS_INT)M, (BLAS_INT)N, (BLAS_VOID *)&alpha, |
| 2433 |
(BLAS_VOID *)X, (BLAS_INT)incX, (BLAS_VOID *)Y, (BLAS_INT)incY, |
| 2434 |
(BLAS_VOID *)A, (BLAS_INT)lda); |
| 2435 |
#endif |
| 2436 |
} |
| 2437 |
|
| 2438 |
template<> |
| 2439 |
void |
| 2440 |
blas_ger<float>(const int M, const int N, const float &alpha, |
| 2441 |
const float *X, const int incX, |
| 2442 |
const float *Y, const int incY, |
| 2443 |
float *A, const int lda) |
| 2444 |
{ |
| 2445 |
#ifdef BLAS_FORTRAN |
| 2446 |
FORTRAN_DECL(sger)(M, N, alpha, X, incX, Y, incY, A, lda); |
| 2447 |
#else |
| 2448 |
cblas_sger(CblasColMajor, (BLAS_INT)M, (BLAS_INT)N, alpha, |
| 2449 |
X, (BLAS_INT)incX, Y, (BLAS_INT)incY, A, (BLAS_INT)lda); |
| 2450 |
#endif |
| 2451 |
} |
| 2452 |
|
| 2453 |
template<> |
| 2454 |
void |
| 2455 |
blas_ger<complex<float> >(const int M, const int N, |
| 2456 |
const complex<float> &alpha, |
| 2457 |
const complex<float> *X, const int incX, |
| 2458 |
const complex<float> *Y, const int incY, |
| 2459 |
complex<float> *A, const int lda) |
| 2460 |
{ |
| 2461 |
#ifdef BLAS_FORTRAN |
| 2462 |
FORTRAN_DECL(cgeru)(M, N, (float *)&alpha, |
| 2463 |
(float *)X, incX, (float *)Y, incY, |
| 2464 |
(float *)A, lda); |
| 2465 |
#else |
| 2466 |
cblas_cgeru(CblasColMajor, (BLAS_INT)M, (BLAS_INT)N, (BLAS_VOID *)&alpha, |
| 2467 |
(BLAS_VOID *)X, (BLAS_INT)incX, (BLAS_VOID *)Y, (BLAS_INT)incY, |
| 2468 |
(BLAS_VOID *)A, (BLAS_INT)lda); |
| 2469 |
#endif |
| 2470 |
} |
| 2471 |
#endif |
| 2472 |
|
| 2473 |
template<typename T> |
| 2474 |
void |
| 2475 |
blas_ger(const int M, const int N, const T &alpha, |
| 2476 |
const T *X, const int incX, |
| 2477 |
const T *Y, const int incY, |
| 2478 |
T *A, const int lda) |
| 2479 |
{ |
| 2480 |
const T zero(0.0); |
| 2481 |
|
| 2482 |
int ix, jy, kx; |
| 2483 |
if ((M == 0) || (N == 0) || (alpha == zero)) { |
| 2484 |
return; |
| 2485 |
} |
| 2486 |
if (incY > 0) { |
| 2487 |
jy = 0; |
| 2488 |
} |
| 2489 |
else { |
| 2490 |
jy = (N - 1) * (-incY); // decrement form the last index |
| 2491 |
} |
| 2492 |
if (incX == 1) { |
| 2493 |
for (int j = 0; j < N; j++) { |
| 2494 |
if (Y[jy] != zero) { |
| 2495 |
T temp = alpha * Y[jy]; |
| 2496 |
for (int i = 0; i < M; i++) { |
| 2497 |
A[i + j * lda] += X[i] * temp; |
| 2498 |
} // loop 10 : i |
| 2499 |
} |
| 2500 |
jy += incY; |
| 2501 |
} // loop 20 : j |
| 2502 |
} |
| 2503 |
else { |
| 2504 |
if (incX > 0) { |
| 2505 |
kx = 0; |
| 2506 |
} |
| 2507 |
else { |
| 2508 |
kx = (M - 1) * (-incX); // decrement form the last index |
| 2509 |
} |
| 2510 |
for (int j = 0; j < N; j++) { |
| 2511 |
if (Y[jy] != zero) { |
| 2512 |
T temp = alpha * Y[jy]; |
| 2513 |
ix = kx; |
| 2514 |
for (int i = 0; i < M; i++) { |
| 2515 |
A[i + j * lda] += X[ix] * temp; |
| 2516 |
ix += incX; |
| 2517 |
} // loop 30 : i |
| 2518 |
} |
| 2519 |
jy += incY; |
| 2520 |
} // loop 40 : j |
| 2521 |
} |
| 2522 |
} |
| 2523 |
|
| 2524 |
// explicit instantiation of blas_ger |
| 2525 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 2526 |
template |
| 2527 |
void |
| 2528 |
blas_ger<double>(const int M, const int N, const double &alpha, |
| 2529 |
const double *X, const int incX, |
| 2530 |
const double *Y, const int incY, |
| 2531 |
double *A, const int lda); |
| 2532 |
|
| 2533 |
template |
| 2534 |
void |
| 2535 |
blas_ger<complex<double> >(const int M, const int N, |
| 2536 |
const complex<double> &alpha, |
| 2537 |
const complex<double> *X, const int incX, |
| 2538 |
const complex<double> *Y, const int incY, |
| 2539 |
complex<double> *A, const int lda); |
| 2540 |
|
| 2541 |
template |
| 2542 |
void |
| 2543 |
blas_ger<float>(const int M, const int N, const float &alpha, |
| 2544 |
const float *X, const int incX, |
| 2545 |
const float *Y, const int incY, |
| 2546 |
float *A, const int lda); |
| 2547 |
|
| 2548 |
template |
| 2549 |
void |
| 2550 |
blas_ger<complex<float> >(const int M, const int N, |
| 2551 |
const complex<float> &alpha, |
| 2552 |
const complex<float> *X, const int incX, |
| 2553 |
const complex<float> *Y, const int incY, |
| 2554 |
complex<float> *A, const int lda); |
| 2555 |
#endif |
| 2556 |
template |
| 2557 |
void |
| 2558 |
blas_ger<quadruple>(const int M, const int N, const quadruple &alpha, |
| 2559 |
const quadruple *X, const int incX, |
| 2560 |
const quadruple *Y, const int incY, |
| 2561 |
quadruple *A, const int lda); |
| 2562 |
template |
| 2563 |
void |
| 2564 |
blas_ger<complex<quadruple> >(const int M, const int N, |
| 2565 |
const complex<quadruple> &alpha, |
| 2566 |
const complex<quadruple> *X, const int incX, |
| 2567 |
const complex<quadruple> *Y, const int incY, |
| 2568 |
complex<quadruple> *A, const int lda); |
| 2569 |
#ifndef NO_OCTRUPLE |
| 2570 |
template |
| 2571 |
void |
| 2572 |
blas_ger<octruple>(const int M, const int N, const octruple &alpha, |
| 2573 |
const octruple *X, const int incX, |
| 2574 |
const octruple *Y, const int incY, |
| 2575 |
octruple *A, const int lda); |
| 2576 |
template |
| 2577 |
void |
| 2578 |
blas_ger<complex<octruple> >(const int M, const int N, |
| 2579 |
const complex<octruple> &alpha, |
| 2580 |
const complex<octruple> *X, const int incX, |
| 2581 |
const complex<octruple> *Y, const int incY, |
| 2582 |
complex<octruple> *A, const int lda); |
| 2583 |
#endif |
| 2584 |
// dz gerc : rank-1 update with complex conjugate |
| 2585 |
#ifndef BLAS_GENERIC |
| 2586 |
template<> |
| 2587 |
void |
| 2588 |
blas_gerc<double>(const int M, const int N, const double &alpha, |
| 2589 |
const double *X, const int incX, |
| 2590 |
const double *Y, const int incY, |
| 2591 |
double *A, const int lda) |
| 2592 |
{ |
| 2593 |
#ifdef BLAS_FORTRAN |
| 2594 |
FORTRAN_DECL(dger)(M, N, alpha, X, incX, Y, incY, A, lda); |
| 2595 |
#else |
| 2596 |
cblas_dger(CblasColMajor, (BLAS_INT)M, (BLAS_INT)N, |
| 2597 |
alpha, X, (BLAS_INT)incX, Y, (BLAS_INT)incY, A, (BLAS_INT)lda); |
| 2598 |
#endif |
| 2599 |
} |
| 2600 |
|
| 2601 |
template<> |
| 2602 |
void |
| 2603 |
blas_gerc<complex<double> >(const int M, const int N, |
| 2604 |
const complex<double> &alpha, |
| 2605 |
const complex<double> *X, const int incX, |
| 2606 |
const complex<double> *Y, const int incY, |
| 2607 |
complex<double> *A, const int lda) |
| 2608 |
{ |
| 2609 |
#ifdef BLAS_FORTRAN |
| 2610 |
FORTRAN_DECL(zgerc)(M, N, (double *)&alpha, |
| 2611 |
(double *)X, incX, (double *)Y, incY, |
| 2612 |
(double *)A, lda); // no zsyr in BLAS! |
| 2613 |
#else |
| 2614 |
cblas_zgerc(CblasColMajor, (BLAS_INT)M, (BLAS_INT)N, (BLAS_VOID *)&alpha, |
| 2615 |
(BLAS_VOID *)X, (BLAS_INT)incX, (void *)Y, (BLAS_INT)incY, |
| 2616 |
(BLAS_VOID *)A, (BLAS_INT)lda); // no zsyr in BLAS! |
| 2617 |
#endif |
| 2618 |
} |
| 2619 |
|
| 2620 |
template<> |
| 2621 |
void |
| 2622 |
blas_gerc<float>(const int M, const int N, const float &alpha, |
| 2623 |
const float *X, const int incX, |
| 2624 |
const float *Y, const int incY, |
| 2625 |
float *A, const int lda) |
| 2626 |
{ |
| 2627 |
#ifdef BLAS_FORTRAN |
| 2628 |
FORTRAN_DECL(sger)(M, N, alpha, X, incX, Y, incY, A, lda); |
| 2629 |
#else |
| 2630 |
cblas_sger(CblasColMajor, (BLAS_INT)M, (BLAS_INT)N, |
| 2631 |
alpha, X, (BLAS_INT)incX, Y, (BLAS_INT)incY, A, (BLAS_INT)lda); |
| 2632 |
#endif |
| 2633 |
} |
| 2634 |
|
| 2635 |
template<> |
| 2636 |
void |
| 2637 |
blas_gerc<complex<float> >(const int M, const int N, |
| 2638 |
const complex<float> &alpha, |
| 2639 |
const complex<float> *X, const int incX, |
| 2640 |
const complex<float> *Y, const int incY, |
| 2641 |
complex<float> *A, const int lda) |
| 2642 |
{ |
| 2643 |
#ifdef BLAS_FORTRAN |
| 2644 |
FORTRAN_DECL(cgerc)(M, N, (float *)&alpha, |
| 2645 |
(float *)X, incX, (float *)Y, incY, |
| 2646 |
(float *)A, lda); // no zsyr in BLAS! |
| 2647 |
#else |
| 2648 |
cblas_cgerc(CblasColMajor, (BLAS_INT)M, (BLAS_INT)N, (BLAS_VOID *)&alpha, |
| 2649 |
(BLAS_VOID *)X, (BLAS_INT)incX, (void *)Y, (BLAS_INT)incY, |
| 2650 |
(BLAS_VOID *)A, (BLAS_INT)lda); // no zsyr in BLAS! |
| 2651 |
#endif |
| 2652 |
} |
| 2653 |
|
| 2654 |
#endif |
| 2655 |
|
| 2656 |
template<typename T> |
| 2657 |
void |
| 2658 |
blas_gerc(const int M, const int N, const T &alpha, |
| 2659 |
const T *X, const int incX, |
| 2660 |
const T *Y, const int incY, |
| 2661 |
T *A, const int lda) |
| 2662 |
{ |
| 2663 |
const T zero(0.0); |
| 2664 |
int ix, jy, kx; |
| 2665 |
if ((M == 0) || (N == 0) || (alpha == zero)) { |
| 2666 |
return; |
| 2667 |
} |
| 2668 |
if (incY > 0) { |
| 2669 |
jy = 0; |
| 2670 |
} |
| 2671 |
else { |
| 2672 |
jy = (N - 1) * (-incY); // decrement form the last index |
| 2673 |
} |
| 2674 |
if (incX == 1) { |
| 2675 |
for (int j = 0; j < N; j++) { |
| 2676 |
if (Y[jy] != zero) { |
| 2677 |
T temp = alpha * blas_conj(Y[jy]); |
| 2678 |
for (int i = 0; i < M; i++) { |
| 2679 |
A[i + j * lda] += X[i] * temp; |
| 2680 |
} // loop 10 : i |
| 2681 |
} |
| 2682 |
jy += incY; |
| 2683 |
} // loop 20 : j |
| 2684 |
} |
| 2685 |
else { |
| 2686 |
if (incX > 0) { |
| 2687 |
kx = 0; |
| 2688 |
} |
| 2689 |
else { |
| 2690 |
kx = (M - 1) * (-incX); // decrement form the last index |
| 2691 |
} |
| 2692 |
for (int j = 0; j < N; j++) { |
| 2693 |
if (Y[jy] != zero) { |
| 2694 |
T temp = alpha * blas_conj(Y[jy]); |
| 2695 |
ix = kx; |
| 2696 |
for (int i = 0; i < M; i++) { |
| 2697 |
A[i + j * lda] += X[ix] * temp; |
| 2698 |
ix += incX; |
| 2699 |
} // loop 30 : i |
| 2700 |
} |
| 2701 |
jy += incY; |
| 2702 |
} // loop 40 : j |
| 2703 |
} |
| 2704 |
} |
| 2705 |
|
| 2706 |
// explicit instantiation of blas_gerc |
| 2707 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 2708 |
template |
| 2709 |
void |
| 2710 |
blas_gerc<double>(const int M, const int N, const double &alpha, |
| 2711 |
const double *X, const int incX, |
| 2712 |
const double *Y, const int incY, |
| 2713 |
double *A, const int lda); |
| 2714 |
|
| 2715 |
template |
| 2716 |
void |
| 2717 |
blas_gerc<complex<double> >(const int M, const int N, |
| 2718 |
const complex<double> &alpha, |
| 2719 |
const complex<double> *X, const int incX, |
| 2720 |
const complex<double> *Y, const int incY, |
| 2721 |
complex<double> *A, const int lda); |
| 2722 |
|
| 2723 |
template |
| 2724 |
void |
| 2725 |
blas_gerc<float>(const int M, const int N, const float &alpha, |
| 2726 |
const float *X, const int incX, |
| 2727 |
const float *Y, const int incY, |
| 2728 |
float *A, const int lda); |
| 2729 |
|
| 2730 |
template |
| 2731 |
void |
| 2732 |
blas_gerc<complex<float> >(const int M, const int N, |
| 2733 |
const complex<float> &alpha, |
| 2734 |
const complex<float> *X, const int incX, |
| 2735 |
const complex<float> *Y, const int incY, |
| 2736 |
complex<float> *A, const int lda); |
| 2737 |
#endif |
| 2738 |
template |
| 2739 |
void |
| 2740 |
blas_gerc<quadruple>(const int M, const int N, const quadruple &alpha, |
| 2741 |
const quadruple *X, const int incX, |
| 2742 |
const quadruple *Y, const int incY, |
| 2743 |
quadruple *A, const int lda); |
| 2744 |
|
| 2745 |
template |
| 2746 |
void |
| 2747 |
blas_gerc<complex<quadruple> >(const int M, const int N, |
| 2748 |
const complex<quadruple> &alpha, |
| 2749 |
const complex<quadruple> *X, const int incX, |
| 2750 |
const complex<quadruple> *Y, const int incY, |
| 2751 |
complex<quadruple> *A, const int lda); |
| 2752 |
|
| 2753 |
template |
| 2754 |
void |
| 2755 |
blas_gerc<octruple>(const int M, const int N, const octruple &alpha, |
| 2756 |
const octruple *X, const int incX, |
| 2757 |
const octruple *Y, const int incY, |
| 2758 |
octruple *A, const int lda); |
| 2759 |
|
| 2760 |
template |
| 2761 |
void |
| 2762 |
blas_gerc<complex<octruple> >(const int M, const int N, |
| 2763 |
const complex<octruple> &alpha, |
| 2764 |
const complex<octruple> *X, const int incX, |
| 2765 |
const complex<octruple> *Y, const int incY, |
| 2766 |
complex<octruple> *A, const int lda); |
| 2767 |
|
| 2768 |
// BLAS 3 |
| 2769 |
|
| 2770 |
// dz trsm |
| 2771 |
#ifndef BLAS_GENERIC |
| 2772 |
template<> |
| 2773 |
void |
| 2774 |
blas_trsm<double>(const CBLAS_SIDE Side, |
| 2775 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 2776 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 2777 |
const double &alpha, const double *A, const int lda, |
| 2778 |
double *B, const int ldb) |
| 2779 |
{ |
| 2780 |
#ifdef BLAS_FORTRAN |
| 2781 |
unsigned char side_ = 0; |
| 2782 |
unsigned char uplo_ = 0; |
| 2783 |
unsigned char transa_ = 0; |
| 2784 |
unsigned char diag_ = 0; |
| 2785 |
switch(Side) { |
| 2786 |
case CblasLeft: |
| 2787 |
side_ = 'l'; |
| 2788 |
break; |
| 2789 |
case CblasRight: |
| 2790 |
side_ = 'r'; |
| 2791 |
break; |
| 2792 |
} |
| 2793 |
switch(Uplo) { |
| 2794 |
case CblasUpper: |
| 2795 |
uplo_ = 'u'; |
| 2796 |
break; |
| 2797 |
case CblasLower: |
| 2798 |
uplo_ = 'l'; |
| 2799 |
break; |
| 2800 |
} |
| 2801 |
switch(TransA) { |
| 2802 |
case CblasNoTrans: |
| 2803 |
transa_ = 'n'; |
| 2804 |
break; |
| 2805 |
case CblasTrans: |
| 2806 |
transa_ = 't'; |
| 2807 |
break; |
| 2808 |
case CblasConjTrans: |
| 2809 |
transa_ = 'c'; |
| 2810 |
break; |
| 2811 |
} |
| 2812 |
switch(Diag) { |
| 2813 |
case CblasNonUnit: |
| 2814 |
diag_ = 'n'; |
| 2815 |
break; |
| 2816 |
case CblasUnit: |
| 2817 |
diag_ = 'u'; |
| 2818 |
break; |
| 2819 |
} |
| 2820 |
FORTRAN_DECL(dtrsm)(side_, uplo_, transa_, |
| 2821 |
diag_, M, N, |
| 2822 |
alpha, A, lda, |
| 2823 |
B, ldb); |
| 2824 |
#else |
| 2825 |
cblas_dtrsm(CblasColMajor, Side, Uplo, TransA, |
| 2826 |
Diag, (BLAS_INT)M, (BLAS_INT)N, |
| 2827 |
alpha, A, (BLAS_INT)lda, |
| 2828 |
B, (BLAS_INT)ldb); |
| 2829 |
#endif |
| 2830 |
} |
| 2831 |
|
| 2832 |
template<> |
| 2833 |
void |
| 2834 |
blas_trsm<complex<double> >(const CBLAS_SIDE Side, |
| 2835 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 2836 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 2837 |
const complex<double> &alpha, |
| 2838 |
const complex<double> *A, const int lda, |
| 2839 |
complex<double> *B, const int ldb) |
| 2840 |
{ |
| 2841 |
#ifdef BLAS_FORTRAN |
| 2842 |
unsigned char side_ = 0; |
| 2843 |
unsigned char uplo_ = 0; |
| 2844 |
unsigned char transa_ = 0; |
| 2845 |
unsigned char diag_ = 0; |
| 2846 |
switch(Side) { |
| 2847 |
case CblasLeft: |
| 2848 |
side_ = 'l'; |
| 2849 |
break; |
| 2850 |
case CblasRight: |
| 2851 |
side_ = 'r'; |
| 2852 |
break; |
| 2853 |
} |
| 2854 |
switch(Uplo) { |
| 2855 |
case CblasUpper: |
| 2856 |
uplo_ = 'u'; |
| 2857 |
break; |
| 2858 |
case CblasLower: |
| 2859 |
uplo_ = 'l'; |
| 2860 |
break; |
| 2861 |
} |
| 2862 |
switch(TransA) { |
| 2863 |
case CblasNoTrans: |
| 2864 |
transa_ = 'n'; |
| 2865 |
break; |
| 2866 |
case CblasTrans: |
| 2867 |
transa_ = 't'; |
| 2868 |
break; |
| 2869 |
case CblasConjTrans: |
| 2870 |
transa_ = 'c'; |
| 2871 |
break; |
| 2872 |
} |
| 2873 |
switch(Diag) { |
| 2874 |
case CblasNonUnit: |
| 2875 |
diag_ = 'u'; |
| 2876 |
break; |
| 2877 |
case CblasUnit: |
| 2878 |
diag_ = 'n'; |
| 2879 |
break; |
| 2880 |
} |
| 2881 |
FORTRAN_DECL(ztrsm)(side_, uplo_, transa_, |
| 2882 |
diag_, M, N, |
| 2883 |
(double *)&alpha, (double *)A, lda, |
| 2884 |
(double *)B, ldb); |
| 2885 |
|
| 2886 |
#else |
| 2887 |
cblas_ztrsm(CblasColMajor, Side, Uplo, TransA, |
| 2888 |
Diag, (BLAS_INT)M, (BLAS_INT)N, |
| 2889 |
(BLAS_VOID *)&alpha, (BLAS_VOID *)A, (BLAS_INT)lda, |
| 2890 |
(BLAS_VOID *)B, (BLAS_INT)ldb); |
| 2891 |
#endif |
| 2892 |
} |
| 2893 |
|
| 2894 |
template<> |
| 2895 |
void |
| 2896 |
blas_trsm<float>(const CBLAS_SIDE Side, |
| 2897 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 2898 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 2899 |
const float &alpha, const float *A, const int lda, |
| 2900 |
float *B, const int ldb) |
| 2901 |
{ |
| 2902 |
#ifdef BLAS_FORTRAN |
| 2903 |
unsigned char side_ = 0; |
| 2904 |
unsigned char uplo_ = 0; |
| 2905 |
unsigned char transa_ = 0; |
| 2906 |
unsigned char diag_ = 0; |
| 2907 |
switch(Side) { |
| 2908 |
case CblasLeft: |
| 2909 |
side_ = 'l'; |
| 2910 |
break; |
| 2911 |
case CblasRight: |
| 2912 |
side_ = 'r'; |
| 2913 |
break; |
| 2914 |
} |
| 2915 |
switch(Uplo) { |
| 2916 |
case CblasUpper: |
| 2917 |
uplo_ = 'u'; |
| 2918 |
break; |
| 2919 |
case CblasLower: |
| 2920 |
uplo_ = 'l'; |
| 2921 |
break; |
| 2922 |
} |
| 2923 |
switch(TransA) { |
| 2924 |
case CblasNoTrans: |
| 2925 |
transa_ = 'n'; |
| 2926 |
break; |
| 2927 |
case CblasTrans: |
| 2928 |
transa_ = 't'; |
| 2929 |
break; |
| 2930 |
case CblasConjTrans: |
| 2931 |
transa_ = 'c'; |
| 2932 |
break; |
| 2933 |
} |
| 2934 |
switch(Diag) { |
| 2935 |
case CblasNonUnit: |
| 2936 |
diag_ = 'n'; |
| 2937 |
break; |
| 2938 |
case CblasUnit: |
| 2939 |
diag_ = 'u'; |
| 2940 |
break; |
| 2941 |
} |
| 2942 |
FORTRAN_DECL(strsm)(side_, uplo_, transa_, |
| 2943 |
diag_, M, N, |
| 2944 |
alpha, A, lda, |
| 2945 |
B, ldb); |
| 2946 |
#else |
| 2947 |
cblas_strsm(CblasColMajor, Side, Uplo, TransA, |
| 2948 |
Diag, (BLAS_INT)M, (BLAS_INT)N, |
| 2949 |
alpha, A, (BLAS_INT)lda, |
| 2950 |
B, (BLAS_INT)ldb); |
| 2951 |
#endif |
| 2952 |
} |
| 2953 |
|
| 2954 |
template<> |
| 2955 |
void |
| 2956 |
blas_trsm<complex<float> >(const CBLAS_SIDE Side, |
| 2957 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 2958 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 2959 |
const complex<float> &alpha, |
| 2960 |
const complex<float> *A, const int lda, |
| 2961 |
complex<float> *B, const int ldb) |
| 2962 |
{ |
| 2963 |
#ifdef BLAS_FORTRAN |
| 2964 |
unsigned char side_ = 0; |
| 2965 |
unsigned char uplo_ = 0; |
| 2966 |
unsigned char transa_ = 0; |
| 2967 |
unsigned char diag_ = 0; |
| 2968 |
switch(Side) { |
| 2969 |
case CblasLeft: |
| 2970 |
side_ = 'l'; |
| 2971 |
break; |
| 2972 |
case CblasRight: |
| 2973 |
side_ = 'r'; |
| 2974 |
break; |
| 2975 |
} |
| 2976 |
switch(Uplo) { |
| 2977 |
case CblasUpper: |
| 2978 |
uplo_ = 'u'; |
| 2979 |
break; |
| 2980 |
case CblasLower: |
| 2981 |
uplo_ = 'l'; |
| 2982 |
break; |
| 2983 |
} |
| 2984 |
switch(TransA) { |
| 2985 |
case CblasNoTrans: |
| 2986 |
transa_ = 'n'; |
| 2987 |
break; |
| 2988 |
case CblasTrans: |
| 2989 |
transa_ = 't'; |
| 2990 |
break; |
| 2991 |
case CblasConjTrans: |
| 2992 |
transa_ = 'c'; |
| 2993 |
break; |
| 2994 |
} |
| 2995 |
switch(Diag) { |
| 2996 |
case CblasNonUnit: |
| 2997 |
diag_ = 'u'; |
| 2998 |
break; |
| 2999 |
case CblasUnit: |
| 3000 |
diag_ = 'n'; |
| 3001 |
break; |
| 3002 |
} |
| 3003 |
FORTRAN_DECL(cztrsm)(side_, uplo_, transa_, |
| 3004 |
diag_, M, N, |
| 3005 |
(float *)&alpha, (float *)A, lda, |
| 3006 |
(float *)B, ldb); |
| 3007 |
|
| 3008 |
#else |
| 3009 |
cblas_ctrsm(CblasColMajor, Side, Uplo, TransA, |
| 3010 |
Diag, (BLAS_INT)M, (BLAS_INT)N, |
| 3011 |
(BLAS_VOID *)&alpha, (BLAS_VOID *)A, (BLAS_INT)lda, |
| 3012 |
(BLAS_VOID *)B, (BLAS_INT)ldb); |
| 3013 |
#endif |
| 3014 |
} |
| 3015 |
#endif |
| 3016 |
|
| 3017 |
template<typename T> |
| 3018 |
void |
| 3019 |
blas_trsm(const CBLAS_SIDE Side, |
| 3020 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 3021 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 3022 |
const T &alpha, |
| 3023 |
const T *A, const int lda, |
| 3024 |
T *B, const int ldb) |
| 3025 |
{ |
| 3026 |
const T zero(0.0); |
| 3027 |
const T one(1.0); |
| 3028 |
bool lside, noconj, nounit, upper; |
| 3029 |
lside = (Side == CblasLeft); |
| 3030 |
noconj = (TransA == CblasTrans); |
| 3031 |
nounit = (Diag == CblasNonUnit); |
| 3032 |
upper = (Uplo == CblasUpper); |
| 3033 |
|
| 3034 |
if ((M == 0) || (N == 0)) { |
| 3035 |
return; |
| 3036 |
} |
| 3037 |
if (alpha == zero) { |
| 3038 |
for (int j = 0; j < N; j++) { |
| 3039 |
for (int i = 0; i < M; i++) { |
| 3040 |
B[i + j * ldb] = zero; |
| 3041 |
}// loop 10 : i |
| 3042 |
} // loop 10 : j |
| 3043 |
} |
| 3044 |
if (lside) { |
| 3045 |
if (TransA == CblasNoTrans) { |
| 3046 |
// Form B := alpha*inv( A )*B. |
| 3047 |
if (upper) { |
| 3048 |
for (int j = 0; j < N; j++) { |
| 3049 |
if (alpha != one) { |
| 3050 |
for (int i = 0; i < M; i++) { |
| 3051 |
B[i + j * ldb] *= alpha; |
| 3052 |
} // loop 30 : i |
| 3053 |
} |
| 3054 |
for (int k = (M - 1); k >= 0; k--) { |
| 3055 |
if (B[k + j * ldb] != zero) { |
| 3056 |
if (nounit) { |
| 3057 |
B[k + j * ldb] /= A[k + k * lda]; |
| 3058 |
} |
| 3059 |
for (int i = 0; i < k; i++) { |
| 3060 |
B[i + j * ldb] -= B[k + j *ldb] * A[i + k * lda]; |
| 3061 |
} // loop 40 : i |
| 3062 |
} |
| 3063 |
} // loop 50 : k |
| 3064 |
} // loop 60 : j |
| 3065 |
} // if (upper) |
| 3066 |
else { |
| 3067 |
for (int j = 0; j < N; j++) { |
| 3068 |
if (alpha != one) { |
| 3069 |
for (int i = 0; i < M; i++) { |
| 3070 |
B[i + j * ldb] *= alpha; |
| 3071 |
} // loop 70 : i |
| 3072 |
} |
| 3073 |
for (int k = 0; k < M; k++) { |
| 3074 |
if (B[k + j * ldb] != zero) { |
| 3075 |
if (nounit) { |
| 3076 |
B[k + j * ldb] /= A[k + k * lda]; |
| 3077 |
} |
| 3078 |
for (int i = (k + 1); i < M; i++) { |
| 3079 |
B[i + j * ldb] -= B[k + j * ldb] * A[i + k * lda]; |
| 3080 |
} // loop 80 : i |
| 3081 |
} |
| 3082 |
} //loop 90 : k |
| 3083 |
} // loop 100 : j |
| 3084 |
} // if (upper) |
| 3085 |
} // if (TransA == CblasNoTrans) |
| 3086 |
else { |
| 3087 |
// Form B := alpha*inv( A**T )*B |
| 3088 |
// or B := alpha*inv( A**H )*B. |
| 3089 |
if (upper) { |
| 3090 |
for (int j = 0; j < N; j++) { |
| 3091 |
for (int i = 0; i < M; i++) { |
| 3092 |
T temp = alpha * B[i + j * ldb]; |
| 3093 |
if (noconj) { |
| 3094 |
for (int k = 0; k < i; k++) { |
| 3095 |
temp -= A[k + i * lda] * B[k + j * ldb]; |
| 3096 |
} // loop 110 : k |
| 3097 |
if (nounit) { |
| 3098 |
temp /= A[i + i * lda]; |
| 3099 |
} |
| 3100 |
} |
| 3101 |
else { |
| 3102 |
for (int k = 0; k < i; k++) { |
| 3103 |
temp -= blas_conj(A[k + i * lda]) * B[k + j * ldb]; |
| 3104 |
} // loop 120 : k |
| 3105 |
if (nounit) { |
| 3106 |
temp /= blas_conj(A[i + i * lda]); |
| 3107 |
} |
| 3108 |
} |
| 3109 |
B[i + j * ldb] = temp; |
| 3110 |
} // loop 130 : i |
| 3111 |
} // loop 140 : j |
| 3112 |
} // if (upper) |
| 3113 |
else { |
| 3114 |
for (int j = 0; j < N; j++) { |
| 3115 |
for (int i = (M - 1); i >= 0; i--) { |
| 3116 |
T temp = alpha * B[i + j * ldb]; |
| 3117 |
if (noconj) { |
| 3118 |
for (int k = (i + 1); k < M; k++) { |
| 3119 |
temp -= A[k + i * lda] * B[k + j * ldb]; |
| 3120 |
} // loop 150 : k |
| 3121 |
if (nounit) { |
| 3122 |
temp /= A[i + i * lda]; |
| 3123 |
} |
| 3124 |
} |
| 3125 |
else { |
| 3126 |
for (int k = (i + 1); k < M; k++) { |
| 3127 |
temp -= blas_conj(A[k + i * lda]) * B[k + j * ldb]; |
| 3128 |
} // loop 160 : k |
| 3129 |
if (nounit) { |
| 3130 |
temp /= blas_conj(A[i + i * lda]); |
| 3131 |
} |
| 3132 |
} |
| 3133 |
B[i + j * ldb] = temp; |
| 3134 |
} // loop 170 : i |
| 3135 |
} // loop 180 : j |
| 3136 |
} // if (upper) |
| 3137 |
} // if (TransA == CblasNoTrans) |
| 3138 |
} // if (lsdie) |
| 3139 |
else { |
| 3140 |
if (TransA == CblasNoTrans) { |
| 3141 |
// Form B := alpha*B*inv( A ). |
| 3142 |
if (upper) { |
| 3143 |
for (int j = 0; j < N; j++) { |
| 3144 |
if (alpha != one) { |
| 3145 |
for (int i = 0; i < M; i++) { |
| 3146 |
B[i + j * ldb] *= alpha; |
| 3147 |
} // loop 190 : i |
| 3148 |
} |
| 3149 |
for (int k = 0; k < j; k++) { |
| 3150 |
if (A[k + j * lda] != zero) { |
| 3151 |
for (int i = 0; i < M; i++) { |
| 3152 |
B[i + j * ldb] -= A[k + j * lda] * B[i + k * ldb]; |
| 3153 |
} // loop 200 : i |
| 3154 |
} |
| 3155 |
} // loop 210 : k |
| 3156 |
if (nounit) { |
| 3157 |
T temp = one / A[j + j * lda]; |
| 3158 |
for (int i = 0; i < M; i++) { |
| 3159 |
B[i + j * ldb] *= temp; |
| 3160 |
} // loop 220 : i |
| 3161 |
} |
| 3162 |
} // loop 230 : j |
| 3163 |
} |
| 3164 |
else { |
| 3165 |
for (int j = (N - 1); j >= 0; j--) { |
| 3166 |
if (alpha != one) { |
| 3167 |
for (int i = 0; i < M; i++) { |
| 3168 |
B[i + j * ldb] *= alpha; |
| 3169 |
} // loop 240 : i |
| 3170 |
} |
| 3171 |
for (int k = (j + 1); k < N; k++) { |
| 3172 |
if (A[k + j * lda] != zero) { |
| 3173 |
for (int i = 0; i < M; i++) { |
| 3174 |
B[i + j * ldb] -= A[k + j * lda] * B[i + k * ldb]; |
| 3175 |
} // loop 2500 : i |
| 3176 |
} |
| 3177 |
} // loop 260 : k |
| 3178 |
if (nounit) { |
| 3179 |
T temp = one / A[j + j * lda]; |
| 3180 |
for (int i = 0; i < M; i++) { |
| 3181 |
B[i + j * ldb] *= temp; |
| 3182 |
} // loop 270 : i |
| 3183 |
} |
| 3184 |
} // loop 280 : j |
| 3185 |
} |
| 3186 |
} // if (TransA == CblasNoTrans) { |
| 3187 |
else { |
| 3188 |
// Form B := alpha*B*inv( A**T ) |
| 3189 |
// or B := alpha*B*inv( A**H ). |
| 3190 |
if (upper) { |
| 3191 |
for (int k = (N - 1); k >= 0; k--) { |
| 3192 |
if (nounit) { |
| 3193 |
T temp; |
| 3194 |
if (noconj) { |
| 3195 |
temp = one / A[k + k * lda]; |
| 3196 |
} |
| 3197 |
else { |
| 3198 |
temp = one / blas_conj(A[k + k * lda]); |
| 3199 |
} |
| 3200 |
for (int i = 0; i < M; i++) { |
| 3201 |
B[i + k * ldb] *= temp; |
| 3202 |
} // loop 290 : i |
| 3203 |
} |
| 3204 |
for (int j = 0; j < k; j++) { |
| 3205 |
if (A[j + k * lda] != zero) { |
| 3206 |
T temp; |
| 3207 |
if (noconj) { |
| 3208 |
temp = A[j + k * lda]; |
| 3209 |
} |
| 3210 |
else { |
| 3211 |
temp = blas_conj(A[j + k * lda]); |
| 3212 |
} |
| 3213 |
for (int i = 0; i < M; i++) { |
| 3214 |
B[i + j * ldb] -= temp * B[i + k * ldb]; |
| 3215 |
} //loop 300 : i |
| 3216 |
} |
| 3217 |
} // loop 310 : j |
| 3218 |
if (alpha != one) { |
| 3219 |
for (int i = 0; i < M; i++) { |
| 3220 |
B[i + k + ldb] *= alpha; |
| 3221 |
} // loop 320 : i |
| 3222 |
} |
| 3223 |
} // loop 330 : k |
| 3224 |
} // if (upper) |
| 3225 |
else { |
| 3226 |
for (int k = 0; k < N; k++) { |
| 3227 |
if (nounit) { |
| 3228 |
T temp; |
| 3229 |
if (noconj) { |
| 3230 |
temp = one / A[k + k * lda]; |
| 3231 |
} |
| 3232 |
else { |
| 3233 |
temp = one / blas_conj(A[k + k * lda]); |
| 3234 |
} |
| 3235 |
for (int i = 0; i < M; i++) { |
| 3236 |
B[i + k * ldb] *= temp; |
| 3237 |
} // loop 340 : i |
| 3238 |
} // if (nounit) |
| 3239 |
for (int j = (k + 1); j < N; j++) { |
| 3240 |
if (A[j + k * lda] != zero) { |
| 3241 |
T temp; |
| 3242 |
if (noconj) { |
| 3243 |
temp = A[j + k * lda]; |
| 3244 |
} |
| 3245 |
else { |
| 3246 |
temp = blas_conj(A[j + k * lda]); |
| 3247 |
} |
| 3248 |
for (int i = 0; i < M; i++) { |
| 3249 |
B[i + j * ldb] -= temp * B[i + k * ldb]; |
| 3250 |
} //loop 350 : i |
| 3251 |
} |
| 3252 |
} // loop 360 : j |
| 3253 |
if (alpha != one) { |
| 3254 |
for (int i = 0; i < M; i++) { |
| 3255 |
B[i + k + ldb] *= alpha; |
| 3256 |
} // loop 370 : i |
| 3257 |
} |
| 3258 |
} // loop 380 : k |
| 3259 |
} |
| 3260 |
} |
| 3261 |
} // if (lside) |
| 3262 |
} |
| 3263 |
//#endif |
| 3264 |
// explicit instantiation of blas_trsm |
| 3265 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 3266 |
template |
| 3267 |
void |
| 3268 |
blas_trsm<double>(const CBLAS_SIDE Side, |
| 3269 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 3270 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 3271 |
const double &alpha, |
| 3272 |
const double *A, const int lda, |
| 3273 |
double *B, const int ldb); |
| 3274 |
|
| 3275 |
template |
| 3276 |
void |
| 3277 |
blas_trsm<complex<double> >(const CBLAS_SIDE Side, |
| 3278 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 3279 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 3280 |
const complex<double> &alpha, |
| 3281 |
const complex<double> *A, const int lda, |
| 3282 |
complex<double> *B, const int ldb); |
| 3283 |
|
| 3284 |
template |
| 3285 |
void |
| 3286 |
blas_trsm<float>(const CBLAS_SIDE Side, |
| 3287 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 3288 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 3289 |
const float &alpha, |
| 3290 |
const float *A, const int lda, |
| 3291 |
float *B, const int ldb); |
| 3292 |
|
| 3293 |
template |
| 3294 |
void |
| 3295 |
blas_trsm<complex<float> >(const CBLAS_SIDE Side, |
| 3296 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 3297 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 3298 |
const complex<float> &alpha, |
| 3299 |
const complex<float> *A, const int lda, |
| 3300 |
complex<float> *B, const int ldb); |
| 3301 |
#endif |
| 3302 |
template |
| 3303 |
void |
| 3304 |
blas_trsm<quadruple>(const CBLAS_SIDE Side, |
| 3305 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 3306 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 3307 |
const quadruple &alpha, |
| 3308 |
const quadruple *A, const int lda, |
| 3309 |
quadruple *B, const int ldb); |
| 3310 |
#ifndef NO_OCTRUPLE |
| 3311 |
template |
| 3312 |
void |
| 3313 |
blas_trsm<octruple>(const CBLAS_SIDE Side, |
| 3314 |
const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, |
| 3315 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 3316 |
const octruple &alpha, |
| 3317 |
const octruple *A, const int lda, |
| 3318 |
octruple *B, const int ldb); |
| 3319 |
#endif |
| 3320 |
template |
| 3321 |
void |
| 3322 |
blas_trsm<complex<quadruple> >(const CBLAS_SIDE Side, |
| 3323 |
const CBLAS_UPLO Uplo, |
| 3324 |
const CBLAS_TRANSPOSE TransA, |
| 3325 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 3326 |
const complex<quadruple> &alpha, |
| 3327 |
const complex<quadruple> *A, const int lda, |
| 3328 |
complex<quadruple> *B, const int ldb); |
| 3329 |
#ifndef NO_OCTRUPLE |
| 3330 |
template |
| 3331 |
void |
| 3332 |
blas_trsm<complex<octruple> >(const CBLAS_SIDE Side, |
| 3333 |
const CBLAS_UPLO Uplo, |
| 3334 |
const CBLAS_TRANSPOSE TransA, |
| 3335 |
const CBLAS_DIAG Diag, const int M, const int N, |
| 3336 |
const complex<octruple> &alpha, |
| 3337 |
const complex<octruple> *A, const int lda, |
| 3338 |
complex<octruple> *B, const int ldb); |
| 3339 |
#endif |
| 3340 |
|
| 3341 |
// dz gemm |
| 3342 |
#ifndef BLAS_GENERIC |
| 3343 |
template<> |
| 3344 |
void |
| 3345 |
blas_gemm<double>(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3346 |
int m, int n, int k, |
| 3347 |
const double &alpha, const double* A, int lda, |
| 3348 |
const double* B, int ldb, const double &beta, |
| 3349 |
double* C, int ldc ) |
| 3350 |
{ |
| 3351 |
#ifdef BLAS_FORTRAN |
| 3352 |
unsigned char tra_ = 0; |
| 3353 |
unsigned char trb_ = 0; |
| 3354 |
switch(trA) { |
| 3355 |
case CblasNoTrans: |
| 3356 |
tra_ = 'n'; |
| 3357 |
break; |
| 3358 |
case CblasTrans: |
| 3359 |
tra_ = 't'; |
| 3360 |
break; |
| 3361 |
case CblasConjTrans: |
| 3362 |
tra_ = 'c'; |
| 3363 |
break; |
| 3364 |
} |
| 3365 |
switch(trB) { |
| 3366 |
case CblasNoTrans: |
| 3367 |
trb_ = 'n'; |
| 3368 |
break; |
| 3369 |
case CblasTrans: |
| 3370 |
trb_ = 't'; |
| 3371 |
break; |
| 3372 |
case CblasConjTrans: |
| 3373 |
trb_ = 'c'; |
| 3374 |
break; |
| 3375 |
} |
| 3376 |
FORTRAN_DECL(dgemm)(tra_, trb_, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc ); |
| 3377 |
#else |
| 3378 |
cblas_dgemm(CblasColMajor, |
| 3379 |
trA, trB, (BLAS_INT)m, (BLAS_INT)n, k, alpha, |
| 3380 |
A, (BLAS_INT)lda, B, (BLAS_INT)ldb, beta, C, (BLAS_INT)ldc ); |
| 3381 |
#endif |
| 3382 |
} |
| 3383 |
|
| 3384 |
template<> |
| 3385 |
void |
| 3386 |
blas_gemm<complex<double> >(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3387 |
int m, int n, int k, const complex<double> &alpha, |
| 3388 |
const complex<double>* A, int lda, |
| 3389 |
const complex<double>* B, int ldb, |
| 3390 |
const complex<double> &beta, |
| 3391 |
complex<double>* C, int ldc ) |
| 3392 |
{ |
| 3393 |
#ifdef BLAS_FORTRAN |
| 3394 |
unsigned char tra_ = 0; |
| 3395 |
unsigned char trb_ = 0; |
| 3396 |
switch(trA) { |
| 3397 |
case CblasNoTrans: |
| 3398 |
tra_ = 'n'; |
| 3399 |
break; |
| 3400 |
case CblasTrans: |
| 3401 |
tra_ = 't'; |
| 3402 |
break; |
| 3403 |
case CblasConjTrans: |
| 3404 |
tra_ = 'c'; |
| 3405 |
break; |
| 3406 |
} |
| 3407 |
switch(trB) { |
| 3408 |
case CblasNoTrans: |
| 3409 |
trb_ = 'n'; |
| 3410 |
break; |
| 3411 |
case CblasTrans: |
| 3412 |
trb_ = 't'; |
| 3413 |
break; |
| 3414 |
case CblasConjTrans: |
| 3415 |
trb_ = 'c'; |
| 3416 |
break; |
| 3417 |
} |
| 3418 |
FORTRAN_DECL(zgemm)(tra_, trb_, m, n, k, (const double *)&alpha, |
| 3419 |
(const double *)A, lda, (const double *)B, ldb, |
| 3420 |
(const double *)&beta, (double *)C, ldc ); |
| 3421 |
#else |
| 3422 |
cblas_zgemm(CblasColMajor, |
| 3423 |
trA, trB, (BLAS_INT)m, (BLAS_INT)n, (BLAS_INT)k, |
| 3424 |
(const BLAS_VOID *)&alpha, (const BLAS_VOID *)A, (BLAS_INT)lda, |
| 3425 |
(const BLAS_VOID *)B, (BLAS_INT)ldb, |
| 3426 |
(const BLAS_VOID *)&beta, C, (BLAS_INT)ldc ); |
| 3427 |
#endif |
| 3428 |
} |
| 3429 |
|
| 3430 |
template<> |
| 3431 |
void |
| 3432 |
blas_gemm<float>(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3433 |
int m, int n, int k, |
| 3434 |
const float &alpha, const float* A, int lda, |
| 3435 |
const float* B, int ldb, const float &beta, |
| 3436 |
float* C, int ldc ) |
| 3437 |
{ |
| 3438 |
#ifdef BLAS_FORTRAN |
| 3439 |
unsigned char tra_ = 0; |
| 3440 |
unsigned char trb_ = 0; |
| 3441 |
switch(trA) { |
| 3442 |
case CblasNoTrans: |
| 3443 |
tra_ = 'n'; |
| 3444 |
break; |
| 3445 |
case CblasTrans: |
| 3446 |
tra_ = 't'; |
| 3447 |
break; |
| 3448 |
case CblasConjTrans: |
| 3449 |
tra_ = 'c'; |
| 3450 |
break; |
| 3451 |
} |
| 3452 |
switch(trB) { |
| 3453 |
case CblasNoTrans: |
| 3454 |
trb_ = 'n'; |
| 3455 |
break; |
| 3456 |
case CblasTrans: |
| 3457 |
trb_ = 't'; |
| 3458 |
break; |
| 3459 |
case CblasConjTrans: |
| 3460 |
trb_ = 'c'; |
| 3461 |
break; |
| 3462 |
} |
| 3463 |
FORTRAN_DECL(sgemm)(tra_, trb_, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc ); |
| 3464 |
#else |
| 3465 |
cblas_sgemm(CblasColMajor, |
| 3466 |
trA, trB, (BLAS_INT)m, (BLAS_INT)n, k, alpha, |
| 3467 |
A, (BLAS_INT)lda, B, (BLAS_INT)ldb, beta, C, (BLAS_INT)ldc ); |
| 3468 |
#endif |
| 3469 |
} |
| 3470 |
|
| 3471 |
template<> |
| 3472 |
void |
| 3473 |
blas_gemm<complex<float> >(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3474 |
int m, int n, int k, const complex<float> &alpha, |
| 3475 |
const complex<float>* A, int lda, |
| 3476 |
const complex<float>* B, int ldb, |
| 3477 |
const complex<float> &beta, |
| 3478 |
complex<float>* C, int ldc ) |
| 3479 |
{ |
| 3480 |
#ifdef BLAS_FORTRAN |
| 3481 |
unsigned char tra_ = 0; |
| 3482 |
unsigned char trb_ = 0; |
| 3483 |
switch(trA) { |
| 3484 |
case CblasNoTrans: |
| 3485 |
tra_ = 'n'; |
| 3486 |
break; |
| 3487 |
case CblasTrans: |
| 3488 |
tra_ = 't'; |
| 3489 |
break; |
| 3490 |
case CblasConjTrans: |
| 3491 |
tra_ = 'c'; |
| 3492 |
break; |
| 3493 |
} |
| 3494 |
switch(trB) { |
| 3495 |
case CblasNoTrans: |
| 3496 |
trb_ = 'n'; |
| 3497 |
break; |
| 3498 |
case CblasTrans: |
| 3499 |
trb_ = 't'; |
| 3500 |
break; |
| 3501 |
case CblasConjTrans: |
| 3502 |
trb_ = 'c'; |
| 3503 |
break; |
| 3504 |
} |
| 3505 |
FORTRAN_DECL(cgemm)(tra_, trb_, m, n, k, (const float *)&alpha, |
| 3506 |
(const float *)A, lda, (const float *)B, ldb, |
| 3507 |
(const float *)&beta, (float *)C, ldc ); |
| 3508 |
#else |
| 3509 |
cblas_cgemm(CblasColMajor, |
| 3510 |
trA, trB, (BLAS_INT)m, (BLAS_INT)n, (BLAS_INT)k, |
| 3511 |
(const BLAS_VOID *)&alpha, (const BLAS_VOID *)A, (BLAS_INT)lda, |
| 3512 |
(const BLAS_VOID *)B, (BLAS_INT)ldb, |
| 3513 |
(const BLAS_VOID *)&beta, C, (BLAS_INT)ldc ); |
| 3514 |
#endif |
| 3515 |
} |
| 3516 |
#endif |
| 3517 |
|
| 3518 |
template<typename T> |
| 3519 |
void |
| 3520 |
blas_gemm(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3521 |
int m, int n, int k, |
| 3522 |
const T &alpha, |
| 3523 |
const T* A, int lda, |
| 3524 |
const T* B, int ldb, |
| 3525 |
const T &beta, |
| 3526 |
T* C, int ldc ) |
| 3527 |
{ |
| 3528 |
const T zero(0.0); |
| 3529 |
const T one(1.0); |
| 3530 |
// based on zgemm |
| 3531 |
bool nota, notb; |
| 3532 |
bool conja, conjb; |
| 3533 |
|
| 3534 |
nota = (trA == CblasNoTrans); |
| 3535 |
notb = (trB == CblasNoTrans); |
| 3536 |
conja = (trA == CblasConjTrans); |
| 3537 |
conjb = (trB == CblasConjTrans); |
| 3538 |
|
| 3539 |
// without checking parameters |
| 3540 |
|
| 3541 |
if ((m == 0) || (n == 0) || (((alpha == zero || (k == 0)) |
| 3542 |
&& (beta == one)))) { |
| 3543 |
return; |
| 3544 |
} |
| 3545 |
|
| 3546 |
if (alpha == zero) { |
| 3547 |
if (beta == zero) { |
| 3548 |
for (int j = 0; j < n; j++) { |
| 3549 |
for (int i = 0; i < m; i++) { |
| 3550 |
C[i + j * ldc] = zero; |
| 3551 |
} // loop 10 : i |
| 3552 |
} // loop 20 : j |
| 3553 |
} |
| 3554 |
else { |
| 3555 |
for (int j = 0; j < n; j++) { |
| 3556 |
for (int i = 0; i < m; i++) { |
| 3557 |
C[i + j * ldc] *= beta; |
| 3558 |
} // loop 30 : i |
| 3559 |
} // loop 40 : j |
| 3560 |
} |
| 3561 |
return; |
| 3562 |
} |
| 3563 |
if (notb) { |
| 3564 |
if (nota) { |
| 3565 |
// Form C := alpha*A*B + beta*C. |
| 3566 |
for (int j = 0; j < n; j++) { |
| 3567 |
if (beta == zero) { |
| 3568 |
for (int i = 0; i < m; i++) { |
| 3569 |
C[i + j * ldc] = zero; |
| 3570 |
} // loop 50 : i |
| 3571 |
} |
| 3572 |
else if (beta != one) { |
| 3573 |
for (int i = 0; i < m; i++) { |
| 3574 |
C[i + j * ldc] *= beta; |
| 3575 |
} // loop 60 : i |
| 3576 |
} |
| 3577 |
for (int l = 0; l < k; l++) { |
| 3578 |
if (B[l + j * ldb] != zero) { |
| 3579 |
T temp = alpha * B[l + j * ldb]; |
| 3580 |
for (int i = 0; i < m; i++) { |
| 3581 |
C[i + j * ldc] += temp * A[i + l * lda]; |
| 3582 |
} // loop 70 : i |
| 3583 |
} |
| 3584 |
} // loop 80 : l |
| 3585 |
} // loop 90 : j |
| 3586 |
} |
| 3587 |
else if (conja) { |
| 3588 |
// Form C := alpha*conjg( A' )*B + beta*C. |
| 3589 |
for (int j = 0; j < n; j++) { |
| 3590 |
for (int i = 0; i < m; i++) { |
| 3591 |
T temp = zero; |
| 3592 |
for (int l = 0; l < k; l++) { |
| 3593 |
temp += blas_conj(A[l + i * lda]) * B[l + j * ldb]; |
| 3594 |
} // loop 100 : l |
| 3595 |
if (beta == zero) { |
| 3596 |
C[i + j * ldc] = alpha * temp; |
| 3597 |
} |
| 3598 |
else { |
| 3599 |
C[i + j * ldc] = alpha * temp + beta * C[i + j * ldc]; |
| 3600 |
} |
| 3601 |
} // loop 110 : i |
| 3602 |
} // loop 120 : j |
| 3603 |
} |
| 3604 |
else { // if (nota) |
| 3605 |
// Form C := alpha*A**T*B + beta*C |
| 3606 |
for (int j = 0; j < n; j++) { |
| 3607 |
for (int i = 0; i < m; i++) { |
| 3608 |
T temp = zero; |
| 3609 |
for (int l = 0; l < k; l++) { |
| 3610 |
temp += A[l + i * lda] * B[l + j * ldb]; |
| 3611 |
} // loop 130 : l |
| 3612 |
if (beta == zero) { |
| 3613 |
C[i + j * ldc] = alpha * temp; |
| 3614 |
} |
| 3615 |
else { |
| 3616 |
C[i + j * ldc] = alpha * temp + beta * C[i + j * ldc]; |
| 3617 |
} |
| 3618 |
} // loop 140 : i |
| 3619 |
} // loop 150 : j |
| 3620 |
} // if (nota) |
| 3621 |
} // if (notb) |
| 3622 |
else { |
| 3623 |
if (nota) { |
| 3624 |
if (conjb) { |
| 3625 |
// Form C := alpha*A*conjg( B' ) + beta*C. |
| 3626 |
for (int j = 0; j < n; j++) { |
| 3627 |
if (beta == zero) { |
| 3628 |
for (int i = 0; i < m; i++) { |
| 3629 |
C[i + j * ldc] = zero; |
| 3630 |
} // loop 160 : i |
| 3631 |
} |
| 3632 |
else if (beta != one) { |
| 3633 |
for (int i = 0; i < m; i++) { |
| 3634 |
C[i + j * ldc] *= beta; |
| 3635 |
} // loop 170 : i |
| 3636 |
} |
| 3637 |
for (int l = 0; l < k; l++) { |
| 3638 |
if (B[j + l * ldb] != zero) { |
| 3639 |
T temp = alpha * blas_conj(B[j + l * ldb]); |
| 3640 |
for (int i = 0; i < m; i++) { |
| 3641 |
C[i + j * ldc] += temp * A[i + l * lda]; |
| 3642 |
} // loop 180 : i |
| 3643 |
} |
| 3644 |
} // loop 190 : i |
| 3645 |
} // loop 200 : j |
| 3646 |
} |
| 3647 |
else { |
| 3648 |
// Form C := alpha*A*B**T + beta*C |
| 3649 |
for (int j = 0; j < n; j++) { |
| 3650 |
if (beta == zero) { |
| 3651 |
for (int i = 0; i < m; i++) { |
| 3652 |
C[i + j * ldc] = zero; |
| 3653 |
} //loop 210 : i |
| 3654 |
} |
| 3655 |
else if (beta != one) { |
| 3656 |
for (int i = 0; i < m; i++) { |
| 3657 |
C[i + j * ldc] *= beta; |
| 3658 |
} // loop 220 : i |
| 3659 |
} |
| 3660 |
for (int l = 0; l < k; l++) { |
| 3661 |
if (B[j + l * ldb] != zero) { |
| 3662 |
T temp = alpha * B[j + l * ldb]; |
| 3663 |
for (int i = 0; i < m; i++) { |
| 3664 |
C[i + j * ldc] += temp * A[i + l * lda]; |
| 3665 |
} // loop 230 : i |
| 3666 |
} |
| 3667 |
} // loop 240 : i |
| 3668 |
} // loop 250 : j |
| 3669 |
} |
| 3670 |
} // if (nota) |
| 3671 |
else if (conja) { |
| 3672 |
if (conjb) { |
| 3673 |
// Form C := alpha*conjg( A' )*conjg( B' ) + beta*C. |
| 3674 |
for (int j = 0; j < n; j++) { |
| 3675 |
for (int i = 0; i < m; i++) { |
| 3676 |
T temp = zero; |
| 3677 |
for (int l = 0; l < k; l++) { |
| 3678 |
temp += blas_conj(A[l + i * lda]) * blas_conj(B[j + l * ldb]); |
| 3679 |
} // loop 260 : l |
| 3680 |
if (beta == zero) { |
| 3681 |
C[i + j * ldc] = alpha * temp; |
| 3682 |
} |
| 3683 |
else { |
| 3684 |
C[i + j * ldc] = alpha * temp + beta * C[i + j * ldc]; |
| 3685 |
} |
| 3686 |
} // loop 270 : i |
| 3687 |
} // loop 280 : i |
| 3688 |
} |
| 3689 |
else { |
| 3690 |
// Form C := alpha*conjg( A' )*B' + beta*C |
| 3691 |
for (int j = 0; j < n; j++) { |
| 3692 |
for (int i = 0; i < m; i++) { |
| 3693 |
T temp = zero; |
| 3694 |
for (int l = 0; l < k; l++) { |
| 3695 |
temp += blas_conj(A[l + i * lda]) * B[j + l * ldb]; |
| 3696 |
} // loop 290 : l |
| 3697 |
if (beta == zero) { |
| 3698 |
C[i + j * ldc] = alpha * temp; |
| 3699 |
} |
| 3700 |
else { |
| 3701 |
C[i + j * ldc] = alpha * temp + beta * C[i + j * ldc]; |
| 3702 |
} |
| 3703 |
} // loop 300 : i |
| 3704 |
} // loop 310 : i |
| 3705 |
} |
| 3706 |
} |
| 3707 |
else { |
| 3708 |
if (conjb) { |
| 3709 |
// Form C := alpha*A'*conjg( B' ) + beta*C |
| 3710 |
for (int j = 0; j < n; j++) { |
| 3711 |
for (int i = 0; i < m; i++) { |
| 3712 |
T temp = zero; |
| 3713 |
for (int l = 0; l < k; l++) { |
| 3714 |
temp += A[l + i * lda] * blas_conj(B[j + l * ldb]); |
| 3715 |
} // loop 320 : l |
| 3716 |
if (beta == zero) { |
| 3717 |
C[i + j * ldc] = alpha * temp; |
| 3718 |
} |
| 3719 |
else { |
| 3720 |
C[i + j * ldc] = alpha * temp + beta * C[i + j * ldc]; |
| 3721 |
} |
| 3722 |
} // loop 330 : i |
| 3723 |
} // loop 340 : i |
| 3724 |
} |
| 3725 |
else { |
| 3726 |
// Form C := alpha*A**T*B**T + beta*C |
| 3727 |
for (int j = 0; j < n; j++) { |
| 3728 |
for (int i = 0; i < m; i++) { |
| 3729 |
T temp = zero; |
| 3730 |
for (int l = 0; l < k; l++) { |
| 3731 |
temp += A[l + i * lda] * B[j + l * ldb]; |
| 3732 |
} // loop 350 : l |
| 3733 |
if (beta == zero) { |
| 3734 |
C[i + j * ldc] = alpha * temp; |
| 3735 |
} |
| 3736 |
else { |
| 3737 |
C[i + j * ldc] = alpha * temp + beta * C[i + j * ldc]; |
| 3738 |
} |
| 3739 |
} // loop 360 : i |
| 3740 |
} // loop 370 : i |
| 3741 |
} |
| 3742 |
} // if (nota) |
| 3743 |
} // if (notb) |
| 3744 |
} |
| 3745 |
// explicit instantiation of blas_gemm |
| 3746 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 3747 |
template |
| 3748 |
void |
| 3749 |
blas_gemm<double>(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3750 |
int m, int n, int k, |
| 3751 |
const double &alpha, |
| 3752 |
const double* A, int lda, |
| 3753 |
const double* B, int ldb, |
| 3754 |
const double &beta, |
| 3755 |
double* C, int ldc ); |
| 3756 |
|
| 3757 |
template |
| 3758 |
void |
| 3759 |
blas_gemm<complex<double> >(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3760 |
int m, int n, int k, |
| 3761 |
const complex<double> &alpha_, |
| 3762 |
const complex<double>* A, int lda, |
| 3763 |
const complex<double>* B, int ldb, |
| 3764 |
const complex<double> &beta_, |
| 3765 |
complex<double>* C, int ldc ); |
| 3766 |
|
| 3767 |
template |
| 3768 |
void |
| 3769 |
blas_gemm<float>(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3770 |
int m, int n, int k, |
| 3771 |
const float &alpha, |
| 3772 |
const float* A, int lda, |
| 3773 |
const float* B, int ldb, |
| 3774 |
const float &beta, |
| 3775 |
float* C, int ldc ); |
| 3776 |
|
| 3777 |
template |
| 3778 |
void |
| 3779 |
blas_gemm<complex<float> >(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3780 |
int m, int n, int k, |
| 3781 |
const complex<float> &alpha_, |
| 3782 |
const complex<float>* A, int lda, |
| 3783 |
const complex<float>* B, int ldb, |
| 3784 |
const complex<float> &beta_, |
| 3785 |
complex<float>* C, int ldc ); |
| 3786 |
#endif |
| 3787 |
template |
| 3788 |
void |
| 3789 |
blas_gemm<quadruple>(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3790 |
int m, int n, int k, |
| 3791 |
const quadruple &alpha, |
| 3792 |
const quadruple* A, int lda, |
| 3793 |
const quadruple* B, int ldb, |
| 3794 |
const quadruple &beta, |
| 3795 |
quadruple* C, int ldc ); |
| 3796 |
template |
| 3797 |
void |
| 3798 |
blas_gemm<complex<quadruple> >(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3799 |
int m, int n, int k, |
| 3800 |
const complex<quadruple> &alpha_, |
| 3801 |
const complex<quadruple>* A, int lda, |
| 3802 |
const complex<quadruple>* B, int ldb, |
| 3803 |
const complex<quadruple> &beta_, |
| 3804 |
complex<quadruple>* C, int ldc ); |
| 3805 |
#ifndef NO_OCTRUPLE |
| 3806 |
template |
| 3807 |
void |
| 3808 |
blas_gemm<octruple>(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3809 |
int m, int n, int k, |
| 3810 |
const octruple &alpha, |
| 3811 |
const octruple* A, int lda, |
| 3812 |
const octruple* B, int ldb, |
| 3813 |
const octruple &beta, |
| 3814 |
octruple* C, int ldc ); |
| 3815 |
template |
| 3816 |
void |
| 3817 |
blas_gemm<complex<octruple> >(CBLAS_TRANSPOSE trA, CBLAS_TRANSPOSE trB, |
| 3818 |
int m, int n, int k, |
| 3819 |
const complex<octruple> &alpha_, |
| 3820 |
const complex<octruple>* A, int lda, |
| 3821 |
const complex<octruple>* B, int ldb, |
| 3822 |
const complex<octruple> &beta_, |
| 3823 |
complex<octruple>* C, int ldc ); |
| 3824 |
#endif |
| 3825 |
|
| 3826 |
// OTHERS |
| 3827 |
template<typename T, typename U> |
| 3828 |
U blas_l2norm(const int n, T *x, const int incX) |
| 3829 |
{ |
| 3830 |
U tmp; |
| 3831 |
tmp = blas_dot<T>(n, x, incX, x, incX); |
| 3832 |
return sqrt<U>(tmp); // works for T = double, quadruple, etc. not for complex<U> |
| 3833 |
} |
| 3834 |
|
| 3835 |
template<> |
| 3836 |
double blas_l2norm<complex<double>, double>(const int n, complex<double> *x, |
| 3837 |
const int incX) |
| 3838 |
{ |
| 3839 |
complex<double> tmp; |
| 3840 |
tmp = blas_dot(n, x, incX, x, incX); |
| 3841 |
return sqrt<double>(tmp.real()); |
| 3842 |
} |
| 3843 |
|
| 3844 |
template<> |
| 3845 |
float blas_l2norm<complex<float>, float>(const int n, complex<float> *x, |
| 3846 |
const int incX) |
| 3847 |
{ |
| 3848 |
complex<float> tmp; |
| 3849 |
tmp = blas_dot(n, x, incX, x, incX); |
| 3850 |
return sqrt<float>(tmp.real()); |
| 3851 |
} |
| 3852 |
|
| 3853 |
template<> |
| 3854 |
quadruple blas_l2norm<complex<quadruple>, quadruple>(const int n, |
| 3855 |
complex<quadruple> *x, |
| 3856 |
const int incX) |
| 3857 |
{ |
| 3858 |
complex<quadruple> tmp; |
| 3859 |
tmp = blas_dot<complex<quadruple> >(n, x, incX, x, incX); |
| 3860 |
return sqrt<quadruple>(tmp.real()); // |
| 3861 |
} |
| 3862 |
#ifndef NO_OCTRUPLE |
| 3863 |
template<> |
| 3864 |
octruple blas_l2norm<complex<octruple>, octruple>(const int n, |
| 3865 |
complex<octruple> *x, |
| 3866 |
const int incX) |
| 3867 |
{ |
| 3868 |
complex<octruple> tmp; |
| 3869 |
tmp = blas_dot<complex<octruple> >(n, x, incX, x, incX); |
| 3870 |
return sqrt<octruple>(tmp.real()); // |
| 3871 |
} |
| 3872 |
#endif |
| 3873 |
|
| 3874 |
template |
| 3875 |
double blas_l2norm<double, double>(const int n, double *x, const int incX); |
| 3876 |
|
| 3877 |
template |
| 3878 |
quadruple blas_l2norm<quadruple, quadruple>(const int n, quadruple *x, |
| 3879 |
const int incX); |
| 3880 |
template |
| 3881 |
float blas_l2norm<float, float>(const int n, float *x, const int incX); |
| 3882 |
|
| 3883 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 3884 |
template |
| 3885 |
double blas_l2norm<complex<double>, double>(const int n, complex<double> *x, |
| 3886 |
const int incX); |
| 3887 |
template |
| 3888 |
quadruple blas_l2norm<complex<quadruple>, quadruple>(const int n, |
| 3889 |
complex<quadruple> *x, |
| 3890 |
const int incX); |
| 3891 |
#ifndef NO_OCTRUPLE |
| 3892 |
template |
| 3893 |
octruple blas_l2norm<complex<octruple>, octruple>(const int n, |
| 3894 |
complex<octruple> *x, |
| 3895 |
const int incX); |
| 3896 |
#endif |
| 3897 |
#endif |
| 3898 |
#ifndef NO_OCTRUPLE |
| 3899 |
template |
| 3900 |
octruple blas_l2norm<octruple, octruple>(const int n, octruple *x, |
| 3901 |
const int incX); |
| 3902 |
#endif |
| 3903 |
|
| 3904 |
double blas_l2norm_lower_prec(const int n, quadruple *x, const int incX) |
| 3905 |
{ |
| 3906 |
quadruple tmp; |
| 3907 |
tmp = blas_dot(n, x, incX, x, incX); |
| 3908 |
return sqrt<double>(quad2double(tmp)); // |
| 3909 |
} |
| 3910 |
|
| 3911 |
quadruple blas_l2norm_lower_prec(const int n, octruple *x, const int incX) |
| 3912 |
{ |
| 3913 |
octruple tmp; |
| 3914 |
tmp = blas_dot(n, x, incX, x, incX); |
| 3915 |
return sqrt<quadruple>(oct2quad(tmp)); // |
| 3916 |
} |
| 3917 |
|
| 3918 |
double blas_l2norm_lower_prec(const int n, complex<quadruple> *x, |
| 3919 |
const int incX) |
| 3920 |
{ |
| 3921 |
complex<quadruple> tmp; |
| 3922 |
tmp = blas_dot(n, x, incX, x, incX); |
| 3923 |
return sqrt<double>(quad2double(tmp.real())); // |
| 3924 |
} |
| 3925 |
|
| 3926 |
quadruple blas_l2norm_lower_prec(const int n, complex<octruple> *x, |
| 3927 |
const int incX) |
| 3928 |
{ |
| 3929 |
complex<octruple> tmp; |
| 3930 |
tmp = blas_dot(n, x, incX, x, incX); |
| 3931 |
return sqrt<quadruple>(oct2quad(tmp.real())); // |
| 3932 |
} |
| 3933 |
|
| 3934 |
template <typename T, typename U> |
| 3935 |
U blas_l2norm2(const int n, T *x, const int incX) |
| 3936 |
{ |
| 3937 |
U tmp; |
| 3938 |
tmp = blas_dot<T>(n, x, incX, x, incX); |
| 3939 |
return tmp; |
| 3940 |
} |
| 3941 |
|
| 3942 |
template<> |
| 3943 |
double blas_l2norm2<complex<double>, double>(const int n, complex<double> *x, |
| 3944 |
const int incX) |
| 3945 |
{ |
| 3946 |
complex<double> tmp; |
| 3947 |
tmp = blas_dot<complex<double> >(n, x, incX, x, incX); |
| 3948 |
return tmp.real(); |
| 3949 |
} |
| 3950 |
|
| 3951 |
template<> |
| 3952 |
float blas_l2norm2<complex<float>, float>(const int n, complex<float> *x, |
| 3953 |
const int incX) |
| 3954 |
{ |
| 3955 |
complex<float> tmp; |
| 3956 |
tmp = blas_dot<complex<float> >(n, x, incX, x, incX); |
| 3957 |
return tmp.real(); |
| 3958 |
} |
| 3959 |
|
| 3960 |
template<> |
| 3961 |
quadruple blas_l2norm2<complex<quadruple>, quadruple>(const int n, |
| 3962 |
complex<quadruple> *x, |
| 3963 |
const int incX) |
| 3964 |
{ |
| 3965 |
complex<quadruple> tmp; |
| 3966 |
tmp = blas_dot<complex<quadruple> >(n, x, incX, x, incX); |
| 3967 |
return tmp.real(); // |
| 3968 |
} |
| 3969 |
|
| 3970 |
template<> |
| 3971 |
octruple blas_l2norm2<complex<octruple>, octruple>(const int n, |
| 3972 |
complex<octruple> *x, |
| 3973 |
const int incX) |
| 3974 |
{ |
| 3975 |
complex<octruple> tmp; |
| 3976 |
tmp = blas_dot<complex<octruple> >(n, x, incX, x, incX); |
| 3977 |
return tmp.real(); // |
| 3978 |
} |
| 3979 |
|
| 3980 |
template |
| 3981 |
double blas_l2norm2<double, double>(const int n, double *x, const int incX); |
| 3982 |
|
| 3983 |
template |
| 3984 |
float blas_l2norm2<float, float>(const int n, float *x, const int incX); |
| 3985 |
|
| 3986 |
template |
| 3987 |
quadruple blas_l2norm2<quadruple, quadruple>(const int n, quadruple *x, |
| 3988 |
const int incX); |
| 3989 |
|
| 3990 |
#ifdef FORCE_EXPLICIT_INSTANTIATION |
| 3991 |
template |
| 3992 |
double blas_l2norm2<complex<double>, double>(const int n, |
| 3993 |
complex<double> *x, |
| 3994 |
const int incX); |
| 3995 |
|
| 3996 |
template |
| 3997 |
quadruple blas_l2norm2<complex<quadruple>, quadruple>(const int n, |
| 3998 |
complex<quadruple> *x, |
| 3999 |
const int incX); |
| 4000 |
|
| 4001 |
template |
| 4002 |
octruple blas_l2norm2<octruple, octruple>(const int n, |
| 4003 |
octruple *x, |
| 4004 |
const int incX); |
| 4005 |
|
| 4006 |
template |
| 4007 |
octruple blas_l2norm2<complex<octruple>, octruple>(const int n, |
| 4008 |
complex<octruple> *x, |
| 4009 |
const int incX); |
| 4010 |
|
| 4011 |
#endif |