/*! \file blas.cpp
\brief BLAS function interface
\author Xavier Juvigny, ONERA
\date Jan. 12th 2005
\modification function from NETLIB source with BLAS and CBLAS wrapper
\author Atsushi Suzuki, Laboratoire Jacques-Louis Lions
\date Mar. 16th 2015
\date Jul. 17th 2015
\date Nov. 30th 2016
*/
// This file is part of Dissection
//
// Dissection is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Linking Dissection statically or dynamically with other modules is making
// a combined work based on Disssection. Thus, the terms and conditions of
// the GNU General Public License cover the whole combination.
//
// As a special exception, the copyright holders of Dissection give you
// permission to combine Dissection program with free software programs or
// libraries that are released under the GNU LGPL and with independent modules
// that communicate with Dissection solely through the Dissection-fortran
// interface. You may copy and distribute such a system following the terms of
// the GNU GPL for Dissection and the licenses of the other code concerned,
// provided that you include the source code of that other code when and as
// the GNU GPL requires distribution of source code and provided that you do
// not modify the Dissection-fortran interface.
//
// Note that people who make modified versions of Dissection are not obligated
// to grant this special exception for their modified versions; it is their
// choice whether to do so. The GNU General Public License gives permission to
// release a modified version without this exception; this exception also makes
// it possible to release a modified version which carries forward this
// exception. If you modify the Dissection-fortran interface, this exception
// does not apply to your modified version of Dissection, and you must remove
// this exception when you distribute your modified version.
//
// This exception is an additional permission under section 7 of the GNU
// General Public License, version 3 ("GPLv3")
//
// Dissection is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Dissection. If not, see .
//
#include "Compiler/blas.hpp"
#include
#include
#define FORCE_EXPLICIT_INSTANTIATION
#if __clang_major__ == 4
#undef FORCE_EXPLICIT_INSTANTIATION
#endif
#ifdef BLAS_FORTRAN
extern "C" {
// double precision
extern int FORTRAN_DECL(idamax)(const int &n, // return Fortran index
const double *x,
const int &incx);
extern int FORTRAN_DECL(izamax)(const int &n, // retrun Fortran index
const double *x,
const int &incx);
extern void FORTRAN_DECL(dcopy)(const int &n,
const double *x, const int &incx,
double *y, const int &incy);
extern void FORTRAN_DECL(zcopy)(const int &n,
const double *x, const int &incx,
double *y, const int &incy);
extern void FORTRAN_DECL(daxpy)(const int &n, const double &alpha,
const double *x, const int &incx,
double *y, const int &incy);
extern void FORTRAN_DECL(zaxpy)(const int &n, const double *alpha,
const double *x, const int &incx,
double *y, const int &incy);
extern double FORTRAN_DECL(ddot)(const int &n,
const double *x, const int &incx,
const double *y, const int &incy);
extern void FORTRAN_DECL(zdotc)(double *z,
const int &n,
const double *x, const int &incx,
const double *y, const int &incy);
extern void FORTRAN_DECL(dscal)(const int &N, const double &alpha,
double *X, const int &incX);
extern void FORTRAN_DECL(zscal)(const int &N, const double *alpha,
double *X, const int &incX);
extern void FORTRAN_DECL(dgemv)(unsigned char &tra_,
const int &m,
const int &n,
const double &alpha,
const double *A,
const int &lda,
const double *x,
const int &incx,
const double &beta,
double *y,
const int &incy);
extern void FORTRAN_DECL(zgemv)(unsigned char &tra_,
const int &m,
const int &n,
const double *alpha,
const double *A,
const int &lda,
const double *x,
const int &incx,
const double *beta,
double *y,
const int &incy);
extern void FORTRAN_DECL(dtrsv)(unsigned char &uplo_,
unsigned char &transa_,
unsigned char &diag_,
const int &N,
const double *A,
const int &lda,
double *X,
const int &incX);
extern void FORTRAN_DECL(ztrsv)(unsigned char &uplo_,
unsigned char &transa_,
unsigned char &diag_,
const int &N,
const double *A,
const int &lda,
double *X,
const int &incX);
extern void FORTRAN_DECL(dsyr)(unsigned char &uplo_,
const int &N,
const double &alpha,
const double *X,
const int &incX,
double *A,
const int &lda);
extern void FORTRAN_DECL(dsyr2)(unsigned char &uplo_,
const int &N,
const double &alpha,
const double *X,
const int &incX,
const double *Y,
const int &incY,
double *A,
const int &lda);
extern void FORTRAN_DECL(dger)(const int &M, const int &N,
const double &alpha,
const double *X, const int &incX,
const double *Y, const int &incY,
double *A, const int &lda);
extern void FORTRAN_DECL(zgeru)(const int &M, const int &N,
const double *alpha,
double *X, const int &incX,
double *Y, const int &incY,
double *A, const int &lda);
extern void FORTRAN_DECL(zgerc)(const int &M, const int &N,
const double *alpha,
const double *X, const int &incX,
const double *Y, const int &incY,
double *A, const int &lda);
extern void FORTRAN_DECL(dtrsm)(unsigned char &side_, unsigned char &uplo_,
unsigned char &transa_, unsigned char &diag_,
const int &M, const int &N,
const double &alpha,
const double *A, const int &lda,
double *B, const int &ldb);
extern void FORTRAN_DECL(ztrsm)(unsigned char &side_, unsigned char &uplo_,
unsigned char &transa_, unsigned char &diag_,
const int &M, const int &N,
const double *alpha,
const double *A, const int &lda,
double *B, const int &ldb);
extern void FORTRAN_DECL(dgemm)(unsigned char &tra_, unsigned char &trb_,
const int &m, const int &n, const int &k,
const double &alpha,
const double *A, const int &lda,
const double *B, const int &ldb,
const double &beta,
double *C, const int &ldc);
extern void FORTRAN_DECL(zgemm)(unsigned char &tra_, unsigned char &trb_,
const int &m, const int &n, const int &k,
const double *alpha,
const double *A, const int &lda,
const double *B, const int &ldb,
const double *beta,
double *C, const int &ldc);
// single precision
extern int FORTRAN_DECL(isamax)(const int &n, // return Fortran index
const float *x,
const int &incx);
extern int FORTRAN_DECL(icamax)(const int &n, // retrun Fortran index
const float *x,
const int &incx);
extern void FORTRAN_DECL(scopy)(const int &n,
const float *x, const int &incx,
float *y, const int &incy);
extern void FORTRAN_DECL(ccopy)(const int &n,
const float *x, const int &incx,
float *y, const int &incy);
extern void FORTRAN_DECL(saxpy)(const int &n, const float &alpha,
const float *x, const int &incx,
float *y, const int &incy);
extern void FORTRAN_DECL(caxpy)(const int &n, const float *alpha,
const float *x, const int &incx,
float *y, const int &incy);
extern float FORTRAN_DECL(sdot)(const int &n,
const float *x, const int &incx,
const float *y, const int &incy);
extern void FORTRAN_DECL(cdotc)(float *z,
const int &n,
const float *x, const int &incx,
const float *y, const int &incy);
extern void FORTRAN_DECL(sscal)(const int &N, const float &alpha,
float *X, const int &incX);
extern void FORTRAN_DECL(cscal)(const int &N, const float *alpha,
float *X, const int &incX);
extern void FORTRAN_DECL(sgemv)(unsigned char &tra_,
const int &m,
const int &n,
const float &alpha,
const float *A,
const int &lda,
const float *x,
const int &incx,
const float &beta,
float *y,
const int &incy);
extern void FORTRAN_DECL(cgemv)(unsigned char &tra_,
const int &m,
const int &n,
const float *alpha,
const float *A,
const int &lda,
const float *x,
const int &incx,
const float *beta,
float *y,
const int &incy);
extern void FORTRAN_DECL(strsv)(unsigned char &uplo_,
unsigned char &transa_,
unsigned char &diag_,
const int &N,
const float *A,
const int &lda,
float *X,
const int &incX);
extern void FORTRAN_DECL(ctrsv)(unsigned char &uplo_,
unsigned char &transa_,
unsigned char &diag_,
const int &N,
const float *A,
const int &lda,
float *X,
const int &incX);
extern void FORTRAN_DECL(ssyr)(unsigned char &uplo_,
const int &N,
const float &alpha,
const float *X,
const int &incX,
float *A,
const int &lda);
extern void FORTRAN_DECL(ssyr2)(unsigned char &uplo_,
const int &N,
const float &alpha,
const float *X,
const int &incX,
const float *Y,
const int &incY,
float *A,
const int &lda);
extern void FORTRAN_DECL(sger)(const int &M, const int &N,
const float &alpha,
const float *X, const int &incX,
const float *Y, const int &incY,
float *A, const int &lda);
extern void FORTRAN_DECL(cgeru)(const int &M, const int &N,
const float *alpha,
float *X, const int &incX,
float *Y, const int &incY,
float *A, const int &lda);
extern void FORTRAN_DECL(cgerc)(const int &M, const int &N,
const float *alpha,
const float *X, const int &incX,
const float *Y, const int &incY,
float *A, const int &lda);
extern void FORTRAN_DECL(strsm)(unsigned char &side_, unsigned char &uplo_,
unsigned char &transa_, unsigned char &diag_,
const int &M, const int &N,
const float &alpha,
const float *A, const int &lda,
float *B, const int &ldb);
extern void FORTRAN_DECL(ctrsm)(unsigned char &side_, unsigned char &uplo_,
unsigned char &transa_, unsigned char &diag_,
const int &M, const int &N,
const float *alpha,
const float *A, const int &lda,
float *B, const int &ldb);
extern void FORTRAN_DECL(sgemm)(unsigned char &tra_, unsigned char &trb_,
const int &m, const int &n, const int &k,
const float &alpha,
const float *A, const int &lda,
const float *B, const int &ldb,
const float &beta,
float *C, const int &ldc);
extern void FORTRAN_DECL(cgemm)(unsigned char &tra_, unsigned char &trb_,
const int &m, const int &n, const int &k,
const float *alpha,
const float *A, const int &lda,
const float *B, const int &ldb,
const float *beta,
float *C, const int &ldc);
}
#endif
// BLAS 1
// dz copy
#ifndef BLAS_GENERIC
template<>
void
blas_copy(const int n, const double* x, const int incx, double* y,
const int incy)
{
if ((incx == 1) && (incy == 1)) {
memcpy((void *)y, (void *)x, n * sizeof(double));
}
else {
#ifdef BLAS_FORTRAN
FORTRAN_DECL(dcopy)(n, x, incx, y, incy);
#else
cblas_dcopy((BLAS_INT)n, x, (BLAS_INT)incx, y, (BLAS_INT)incy);
#endif
}
}
template<>
void
blas_copy >(const int n,
const complex* x, const int incx,
complex* y, const int incy)
{
if ((incx == 1) && (incy == 1)) {
memcpy((void *)y, (void *)x, n * sizeof(complex));
}
else {
#ifdef BLAS_FORTRAN
FORTRAN_DECL(zcopy)(n, (double *)x, incx, (double *)y, incy);
#else
cblas_zcopy((BLAS_INT)n, (void *)x, (BLAS_INT)incx,
(BLAS_VOID *)y, (BLAS_INT)incy);
#endif
}
}
template<>
void
blas_copy(const int n, const float* x, const int incx, float* y,
const int incy)
{
if ((incx == 1) && (incy == 1)) {
memcpy((void *)y, (void *)x, n * sizeof(float));
}
else {
#ifdef BLAS_FORTRAN
FORTRAN_DECL(scopy)(n, x, incx, y, incy);
#else
cblas_scopy((BLAS_INT)n, x, (BLAS_INT)incx, y, (BLAS_INT)incy);
#endif
}
}
template<>
void
blas_copy >(const int n,
const complex* x, const int incx,
complex* y, const int incy)
{
if ((incx == 1) && (incy == 1)) {
memcpy((void *)y, (void *)x, n * sizeof(complex));
}
else {
#ifdef BLAS_FORTRAN
FORTRAN_DECL(ccopy)(n, (float *)x, incx, (float *)y, incy);
#else
cblas_ccopy((BLAS_INT)n, (void *)x, (BLAS_INT)incx,
(BLAS_VOID *)y, (BLAS_INT)incy);
#endif
}
}
#endif
template
void
blas_copy(const int n, const T* x, const int incx, T *y, const int incy)
{
if ((incx == 1) && (incy == 1)) {
memcpy((void *)y, (void *)x, n * sizeof(T));
}
else {
int ix = 0;
int iy = 0;
for (int i = 0; i < n; i++, ix += incx, iy += incy) {
y[iy] = x[ix];
}
}
}
#ifdef FORCE_EXPLICIT_INSTANTIATION
template
void
blas_copy(const int n, const double* x, const int incx,
double *y, const int incy);
template
void
blas_copy > (const int n,
const complex* x, const int incx,
complex *y, const int incy);
template
void
blas_copy(const int n, const float* x, const int incx,
float *y, const int incy);
template
void
blas_copy > (const int n,
const complex* x, const int incx,
complex *y, const int incy);
#endif
template
void
blas_copy(const int n, const quadruple* x, const int incx,
quadruple *y, const int incy);
template
void
blas_copy > (const int n,
const complex* x, const int incx,
complex *y, const int incy);
template
void
blas_copy(const int n, const octruple* x, const int incx,
octruple *y, const int incy);
template
void
blas_copy > (const int n,
const complex* x, const int incx,
complex *y, const int incy);
// dz axpy
#ifndef BLAS_GENERIC
template<>
void
blas_axpy(const int n, const double &alpha,
const double* x, const int incx,
double* y, const int incy)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(daxpy)(n, alpha, x, incx, y, incy);
#else
cblas_daxpy((BLAS_INT)n, alpha, x, (BLAS_INT)incx, y, (BLAS_INT)incy);
#endif
}
template<>
void
blas_axpy >(const int n, const complex &alpha,
const complex* x, const int incx,
complex* y, int incy)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(zaxpy)(n, (double *)&alpha, (double *)x, incx, (double *)y, incy);
#else
cblas_zaxpy((BLAS_INT)n, (BLAS_VOID *)&alpha, (BLAS_VOID *)x, (BLAS_INT)incx,
(BLAS_VOID *)y, (BLAS_INT)incy);
#endif
}
template<>
void
blas_axpy(const int n, const float &alpha,
const float* x, const int incx,
float* y, const int incy)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(saxpy)(n, alpha, x, incx, y, incy);
#else
cblas_saxpy((BLAS_INT)n, alpha, x, (BLAS_INT)incx, y, (BLAS_INT)incy);
#endif
}
template<>
void
blas_axpy >(const int n, const complex &alpha,
const complex* x, const int incx,
complex* y, int incy)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(caxpy)(n, (float *)&alpha, (float *)x, incx, (float *)y, incy);
#else
cblas_caxpy((BLAS_INT)n, (BLAS_VOID *)&alpha, (BLAS_VOID *)x, (BLAS_INT)incx,
(BLAS_VOID *)y, (BLAS_INT)incy);
#endif
}
#endif
template
void
blas_axpy(const int n, const T &alpha,
const T* x, const int incx,
T* y, int incy)
{
int ix = 0;
int iy = 0;
for (int i = 0; i < n; i++, ix += incx, iy += incy) {
y[iy] += alpha * x[ix];
}
}
#ifdef FORCE_EXPLICIT_INSTANTIATION
template
void
blas_axpy(const int n, const double &alpha,
const double* x, const int incx,
double* y, int incy);
template
void
blas_axpy >(const int n, const complex &alpha,
const complex* x, const int incx,
complex* y, int incy);
template
void
blas_axpy(const int n, const float &alpha,
const float* x, const int incx,
float* y, int incy);
template
void
blas_axpy >(const int n, const complex &alpha,
const complex* x, const int incx,
complex* y, int incy);
#endif
template
void
blas_axpy(const int n, const quadruple &alpha,
const quadruple* x, const int incx,
quadruple* y, int incy);
template
void
blas_axpy >(const int n, const complex &alpha,
const complex* x, const int incx,
complex* y, int incy);
// dz dot
#ifndef BLAS_GENERIC
template<>
double
blas_dot(const int n, const double* x, const int incx,
const double* y, const int incy)
{
#ifdef BLAS_FORTRAN
return FORTRAN_DECL(ddot)(n, x, incx, y, incy); // ?
#else
return cblas_ddot((BLAS_INT)n, x, (BLAS_INT)incx, y, (BLAS_INT)incy);
#endif
}
template<>
complex
blas_dot >(const int n,
const complex* x, const int incx,
const complex* y, const int incy)
{
complex val;
#ifdef BLAS_FORTRAN
// fortran function that returns complex is called as C void function
FORTRAN_DECL(zdotc)((double*) &val, n, (double *)x, incx, (double *)y, incy);
#else
cblas_zdotc_sub((BLAS_INT)n, (BLAS_VOID *)x, (BLAS_INT)incx,
(BLAS_VOID *)y, (BLAS_INT)incy, (BLAS_VOID *)&val);
#endif
return val;
}
template<>
float
blas_dot(const int n, const float* x, const int incx,
const float* y, const int incy)
{
#ifdef BLAS_FORTRAN
return FORTRAN_DECL(sdot)(n, x, incx, y, incy); // ?
#else
return cblas_sdot((BLAS_INT)n, x, (BLAS_INT)incx, y, (BLAS_INT)incy);
#endif
}
template<>
complex
blas_dot >(const int n,
const complex* x, const int incx,
const complex* y, const int incy)
{
complex val;
#ifdef BLAS_FORTRAN
// fortran function that returns complex is called as C void function
FORTRAN_DECL(cdotc)((float*) &val, n, (float *)x, incx, (float *)y, incy);
#else
cblas_cdotc_sub((BLAS_INT)n, (BLAS_VOID *)x, (BLAS_INT)incx,
(BLAS_VOID *)y, (BLAS_INT)incy, (BLAS_VOID *)&val);
#endif
return val;
}
#endif
template
T
blas_dot(const int n, const T* x, const int incx,
const T* y, const int incy)
{
int ix, iy;
T temp;
temp = T(0.0);
if (n <= 0) {
return temp;
}
if ((incx == 1) && (incy == 1)) {
for (int i = 0; i < n; i++) {
temp += blas_conj(x[i]) * y[i];
}
}
else {
ix = 0;
iy = 0;
if (incx < 0) {
ix = (n - 1)* (-incx); // decrement form the last index
}
if (incy < 0) {
iy = (n - 1)* (-incy); // decrement form the last index
}
for (int i = 0; i < n; i++) {
temp += blas_conj(x[i]) * y[i];
ix += incx;
iy += incy;
}
}
return temp;
}
// explicit instantiation of blas_dot
#ifdef FORCE_EXPLICIT_INSTANTIATION
template
double
blas_dot(const int n, const double* x, const int incx,
const double* y, const int incy);
template
complex
blas_dot >(const int n,
const complex* x, const int incx,
const complex* y, const int incy);
template
float
blas_dot(const int n, const float* x, const int incx,
const float* y, const int incy);
template
complex
blas_dot >(const int n,
const complex* x, const int incx,
const complex* y, const int incy);
#endif
template
quadruple
blas_dot(const int n, const quadruple* x, const int incx,
const quadruple* y, const int incy);
template
complex
blas_dot >(const int n,
const complex* x, const int incx,
const complex* y, const int incy);
#ifndef NO_OCTRUPLE
template
octruple
blas_dot(const int n, const octruple* x, const int incx,
const octruple* y, const int incy);
template
complex
blas_dot >(const int n,
const complex* x, const int incx,
const complex* y, const int incy);
#endif
// dz scal
#ifndef BLAS_GENERIC
template<>
void
blas_scal(const int N, const double &alpha, double *X, const int incX)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(dscal)(N, alpha, X, incX);
#else
cblas_dscal((BLAS_INT)N, alpha, X, (BLAS_INT)incX);
#endif
}
template<>
void
blas_scal >(const int N, const complex &alpha,
complex *X, const int incX)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(zscal)(N, (double *)&alpha, (double *)X, incX);
#else
cblas_zscal((BLAS_INT)N, (BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX);
#endif
}
template<>
void
blas_scal(const int N, const float &alpha, float *X, const int incX)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(sscal)(N, alpha, X, incX);
#else
cblas_sscal((BLAS_INT)N, alpha, X, (BLAS_INT)incX);
#endif
}
template<>
void
blas_scal >(const int N, const complex &alpha,
complex *X, const int incX)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(cscal)(N, (float *)&alpha, (float *)X, incX);
#else
cblas_cscal((BLAS_INT)N, (BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX);
#endif
}
#endif // #ifdef BLAS_GENERIC
template
void
blas_scal(const int N, const T &alpha,
T *X, const int incX)
{
if ((N <= 0) || (incX <= 0)) {
return;
}
if (incX == 1) {
for (int i = 0; i < N; i++) {
X[i] *= alpha;
}
}
else {
int nincx = N * incX;
for (int i = 0; i < nincx; i += incX) {
X[i] *= alpha;
}
}
}
// explicit instantiation of blas_scal
#ifdef FORCE_EXPLICIT_INSTANTIATION
template
void
blas_scal(const int N, const double &alpha,
double *X, const int incX);
template
void
blas_scal >(const int N, const complex &alpha,
complex *X, const int incX);
template
void
blas_scal(const int N, const float &alpha,
float *X, const int incX);
template
void
blas_scal >(const int N, const complex &alpha,
complex *X, const int incX);
#endif
template
void
blas_scal(const int N, const quadruple &alpha,
quadruple *X, const int incX);
template
void
blas_scal >(const int N, const complex &alpha,
complex *X, const int incX);
#ifndef NO_OCTRUPLE
template
void
blas_scal(const int N, const octruple &alpha,
octruple *X, const int incX);
template
void
blas_scal >(const int N, const complex &alpha,
complex *X, const int incX);
#endif
// scaling with magnitude represented by real valued
#ifndef BLAS_GENERIC
template<>
void
blas_scal2(const int N, const double &alpha,
double *X, const int incX)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(dscal)(N, alpha, X, incX);
#else
cblas_dscal((BLAS_INT)N, alpha, X, (BLAS_INT)incX);
#endif
}
template<>
void
blas_scal2, double>(const int N, const double &alpha_,
complex *X, const int incX)
{
const complex alpha = complex(alpha_, 0.0);
#ifdef BLAS_FORTRAN
FORTRAN_DECL(zscal)(N, (double *)&alpha, (double *)X, incX);
#else
cblas_zscal((BLAS_INT)N, (BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX);
#endif
}
template<>
void
blas_scal2(const int N, const float &alpha,
float *X, const int incX)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(sscal)(N, alpha, X, incX);
#else
cblas_sscal((BLAS_INT)N, alpha, X, (BLAS_INT)incX);
#endif
}
template<>
void
blas_scal2, float>(const int N, const float &alpha_,
complex *X, const int incX)
{
const complex alpha = complex(alpha_, 0.0);
#ifdef BLAS_FORTRAN
FORTRAN_DECL(cscal)(N, (float *)&alpha, (float *)X, incX);
#else
cblas_cscal((BLAS_INT)N, (BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX);
#endif
}
template<>
void
blas_scal2(const int N, const quadruple &alpha,
quadruple *X, const int incX)
{
blas_scal(N, alpha, X, incX);
}
template<>
void
blas_scal2, quadruple>(const int N, const quadruple &alpha_,
complex *X, const int incX)
{
complex alpha = complex(alpha_, quadruple(0.0));
blas_scal >(N, alpha, X, incX);
}
#ifndef NO_OCTRUPLE
template<>
void
blas_scal2(const int N, const octruple &alpha,
octruple *X, const int incX)
{
blas_scal(N, alpha, X, incX);
}
template<>
void
blas_scal2, octruple>(const int N, const octruple &alpha_,
complex *X, const int incX)
{
complex alpha = complex(alpha_, octruple(0.0));
blas_scal >(N, alpha, X, incX);
}
#endif
#endif // ifndef BLAS_GENERIC
template
void
blas_scal2(const int N, const U &alpha_,
T *X, const int incX)
{
T alpha = tocomplex(alpha_);
if ((N <= 0) || (incX <= 0)) {
return;
}
if (incX == 1) {
for (int i = 0; i < N; i++) {
X[i] *= alpha;
}
}
else {
int nincx = N * incX;
for (int i = 0; i < nincx; i += incX) {
X[i] *= alpha;
}
}
}
// explicit instantiation blas_scal with real number saling
#ifdef FORCE_EXPLICIT_INSTANTIATION
template void
blas_scal2(const int N, const double &alpha,
double *X, const int incX);
template void
blas_scal2, double>(const int N, const double &alpha_,
complex *X, const int incX);
template void
blas_scal2(const int N, const float &alpha,
float *X, const int incX);
template void
blas_scal2, float>(const int N, const float &alpha_,
complex *X, const int incX);
template void
blas_scal2(const int N, const quadruple &alpha,
quadruple *X, const int incX);
template void
blas_scal2, quadruple>(const int N, const quadruple &alpha_,
complex *X, const int incX);
#ifndef NO_OCTRUPLE
template void
blas_scal2(const int N, const octruple &alpha,
octruple *X, const int incX);
template void
blas_scal2, octruple>(const int N, const octruple &alpha,
complex *X, const int incX);
#endif
#endif
template
int blas_iamax(const int n, const T *x, const int incx)
{
U umax;
int ix, iamax;
iamax = (-1);
if ((n < 1) || incx <= 0) {
return iamax;
}
iamax = 0;
if (n == 1) {
return iamax;
}
if (incx == 1) {
umax = blas_abs(x[0]);
for (int i = 1; i < n; i++) {
U tmax = blas_abs(x[0]);
if (tmax > umax) {
iamax = i;
umax = tmax;
}
}
}
else {
ix = 0;
umax = blas_abs(x[0]);
for (int i = 1; i < n; i++) {
ix += incx;
U tmax = blas_abs(x[ix]);
if (tmax > umax) {
iamax = i;
umax = tmax;
}
}
}
return iamax;
}
#ifndef BLAS_GENERIC
template<>
int blas_iamax(const int n, const double *x, const int incx)
{
#ifdef BLAS_FORTRAN
return (FORTRAN_DECL(idamax)(n, x, incx) - 1); // Fortran to C index
#else
return cblas_idamax((BLAS_INT)n, x, (BLAS_INT)incx);
#endif
}
template<>
int blas_iamax, double>(const int n,
const complex *x,
const int incx)
{
#ifdef BLAS_FORTRAN // Fortran to C index
return (FORTRAN_DECL(izamax)(n, (double *)x, incx) - 1);
#else
return cblas_izamax((BLAS_INT)n, (double *)x, (BLAS_INT)incx);
#endif
}
template<>
int blas_iamax(const int n, const float *x, const int incx)
{
#ifdef BLAS_FORTRAN
return (FORTRAN_DECL(isamax)(n, x, incx) - 1); // Fortran to C index
#else
return cblas_isamax((BLAS_INT)n, x, (BLAS_INT)incx);
#endif
}
template<>
int blas_iamax, float>(const int n,
const complex *x,
const int incx)
{
#ifdef BLAS_FORTRAN // Fortran to C index
return (FORTRAN_DECL(icamax)(n, (float *)x, incx) - 1);
#else
return cblas_icamax((BLAS_INT)n, (float *)x, (BLAS_INT)incx);
#endif
}
#endif
#ifdef FORCE_EXPLICIT_INSTANTIATION
template
int blas_iamax(const int n, const double *x, const int incx);
template
int blas_iamax, double>(const int n, const complex *x,
const int incx);
template
int blas_iamax(const int n, const float *x, const int incx);
template
int blas_iamax, float>(const int n, const complex *x,
const int incx);
#endif
template
int blas_iamax(const int n, const quadruple *x, const int incx);
template
int blas_iamax, quadruple>(const int n,
const complex *x,
const int incx);
template
int blas_iamax(const int n, const octruple *x, const int incx);
template
int blas_iamax, octruple>(const int n,
const complex *x,
const int incx);
//
// BLAS 2
// dz gemv
#ifndef BLAS_GENERIC
template<>
void
blas_gemv(const CBLAS_TRANSPOSE trA,
const int m, const int n, const double &alpha,
const double* A, const int lda, const double* x,
const int incx,
const double &beta, double* y, const int incy)
{
#ifdef BLAS_FORTRAN
unsigned char tra_ = 0;
switch(trA) {
case CblasNoTrans :
tra_ = 'n';
break;
case CblasTrans :
tra_ = 't';
break;
case CblasConjTrans:
tra_ = 'c';
break;
}
FORTRAN_DECL(dgemv)(tra_, m, n, alpha, A, lda, x, incx, beta, y, incy); //
#else
cblas_dgemv(CblasColMajor, trA, (BLAS_INT)m, (BLAS_INT)n, alpha,
A, (BLAS_INT)lda, x, (BLAS_INT)incx, beta, y, (BLAS_INT)incy);
#endif
}
template<>
void
blas_gemv >(const CBLAS_TRANSPOSE trA,
const int m, const int n,
const complex &alpha,
const complex* A, const int lda,
const complex* x, const int incx,
const complex &beta,
complex* y, const int incy)
{
#ifdef BLAS_FORTRAN
unsigned char tra_ = 0;
switch(trA) {
case CblasNoTrans:
tra_ = 'n';
break;
case CblasTrans:
tra_ = 't';
break;
case CblasConjTrans:
tra_ = 'c';
break;
}
FORTRAN_DECL(zgemv)(tra_, m, n, (double *)&alpha, (double *)A, lda,
(double *)x, incx, (double *)&beta, (double *)y, incy);
#else
cblas_zgemv(CblasColMajor, trA, (BLAS_INT)m, (BLAS_INT)n, (BLAS_VOID *)&alpha,
(BLAS_VOID *)A, (BLAS_INT)lda, (BLAS_VOID *)x, (BLAS_INT)incx,
(BLAS_VOID *)&beta, (void *)y, (BLAS_INT)incy);
#endif
}
template<>
void
blas_gemv(const CBLAS_TRANSPOSE trA,
const int m, const int n, const float &alpha,
const float* A, const int lda, const float* x,
const int incx,
const float &beta, float* y, const int incy)
{
#ifdef BLAS_FORTRAN
unsigned char tra_ = 0;
switch(trA) {
case CblasNoTrans :
tra_ = 'n';
break;
case CblasTrans :
tra_ = 't';
break;
case CblasConjTrans:
tra_ = 'c';
break;
}
FORTRAN_DECL(sgemv)(tra_, m, n, alpha, A, lda, x, incx, beta, y, incy); //
#else
cblas_sgemv(CblasColMajor, trA, (BLAS_INT)m, (BLAS_INT)n, alpha,
A, (BLAS_INT)lda, x, (BLAS_INT)incx, beta, y, (BLAS_INT)incy);
#endif
}
template<>
void
blas_gemv >(const CBLAS_TRANSPOSE trA,
const int m, const int n,
const complex &alpha,
const complex* A, const int lda,
const complex* x, const int incx,
const complex &beta,
complex* y, const int incy)
{
#ifdef BLAS_FORTRAN
unsigned char tra_ = 0;
switch(trA) {
case CblasNoTrans:
tra_ = 'n';
break;
case CblasTrans:
tra_ = 't';
break;
case CblasConjTrans:
tra_ = 'c';
break;
}
FORTRAN_DECL(cgemv)(tra_, m, n, (float *)&alpha, (float *)A, lda,
(float *)x, incx, (float *)&beta, (float *)y, incy);
#else
cblas_cgemv(CblasColMajor, trA, (BLAS_INT)m, (BLAS_INT)n, (BLAS_VOID *)&alpha,
(BLAS_VOID *)A, (BLAS_INT)lda, (BLAS_VOID *)x, (BLAS_INT)incx,
(BLAS_VOID *)&beta, (void *)y, (BLAS_INT)incy);
#endif
}
#endif
template
void
blas_gemv(const CBLAS_TRANSPOSE trA,
const int m, const int n, const T &alpha,
const T* A, const int lda,
const T* x, const int incx,
const T &beta, T* y, const int incy)
{
const T zero(0.0);
const T one(1.0);
int lenx, leny, ix, iy, jx, jy, kx, ky;
bool noconj;
if ((m == 0) || (n == 0) ||
((alpha == zero) && (beta == one))) {
return;
}
noconj = (trA == CblasTrans);
if (trA == CblasNoTrans) {
lenx = n;
leny = m;
}
else {
lenx = m;
leny = n;
}
if (incx > 0) {
kx = 0;
}
else {
kx = (lenx - 1) * (-incx); //
}
if (incy > 0) {
ky = 0;
}
else {
ky = (leny - 1) * (-incy); //
}
if (beta != one) {
if (incy == 1) {
if (beta == zero) {
for (int i = 0; i < leny; i++) {
y[i] = zero;
} // loop 10 : i
}
else {
for (int i = 0; i < leny; i++) {
y[i] *= beta;
} // loop 20 : i
}
}
else {
iy = ky;
if (beta == zero) {
for (int i = 0; i < leny; i++) {
y[iy] = zero;
iy += incy;
} // loop 30 : i
}
else {
for (int i = 0; i < leny; i++) {
y[iy] *= beta;
iy += incy;
} // loop 40 : i
}
}
} // if (beta != one)
if (alpha == zero) {
return;
}
if (trA == CblasNoTrans) {
// Form y := alpha*A*x + y.
jx = kx;
if (incy == 1) {
for (int j = 0; j < n; j++) {
if (x[jx] != zero) {
T temp = alpha * x[jx];
for (int i = 0; i < m; i++) {
y[i] += temp * A[i + j * lda];
} // loop 50 : i
} // end if
jx += incx;
} // loop 60 : j
}
else {
for (int j = 0; j < n; j++) {
if (x[jx] != zero) {
T temp = alpha * x[jx];
iy = ky;
for (int i = 0; i < m; i++) {
y[iy] += temp * A[i + j * lda];
iy += incy;
} // loop 70 : i
}
jx += incx;
} // loop 80 : j
}
}
else {
// Form y := alpha*A**T*x + y or y := alpha*conjg( A' )*x + y.
jy = ky;
if (incx == 1) {
for (int j = 0; j < n; j++) {
T temp = zero;
if (noconj) {
for (int i = 0; i < m; i++) {
temp += A[i + j * lda] * x[i];
} // loop 90 : i
}
else {
for (int i = 0; i < m; i++) {
temp += blas_conj(A[i + j * lda]) * x[i];
} // loop 100 : j
}
y[jy] += alpha * temp;
jy += incy;
} // loop 110 : j
}
else {
for (int j = 0; j < n; j++) {
T temp = zero;
ix = kx;
if (noconj) {
for (int i = 0; i < m; i++) {
temp += A[i + j * lda] * x[ix];
ix += incx;
} // loop 120 : i
}
else {
for (int i = 0; i < m; i++) {
temp += blas_conj(A[i + j * lda]) * x[ix];
ix += incx;
} // loop 130 : i
}
y[jy] += alpha * temp;
jy += incy;
} // loop 140 : j
} // if (incx != 1)
}
}
// explicit instantiation of blas_gemv
#ifdef FORCE_EXPLICIT_INSTANTIATION
template
void
blas_gemv(const CBLAS_TRANSPOSE trA,
const int m, const int n, const double &alpha,
const double* A, const int lda,
const double* x, const int incx,
const double &beta, double* y, const int incy);
template
void
blas_gemv >(const CBLAS_TRANSPOSE trA,
const int m, const int n,
const complex &alpha,
const complex* A, const int lda,
const complex* x, const int incx,
const complex &beta,
complex* y, const int incy);
template
void
blas_gemv(const CBLAS_TRANSPOSE trA,
const int m, const int n, const float &alpha,
const float* A, const int lda,
const float* x, const int incx,
const float &beta, float* y, const int incy);
template
void
blas_gemv >(const CBLAS_TRANSPOSE trA,
const int m, const int n,
const complex &alpha,
const complex* A, const int lda,
const complex* x, const int incx,
const complex &beta,
complex* y, const int incy);
#endif
template
void
blas_gemv(const CBLAS_TRANSPOSE trA,
const int m, const int n, const quadruple &alpha,
const quadruple* A, const int lda,
const quadruple* x, const int incx,
const quadruple &beta, quadruple* y, const int incy);
#ifndef NO_OCTRUPLE
template
void
blas_gemv(const CBLAS_TRANSPOSE trA,
const int m, const int n, const octruple &alpha,
const octruple* A, const int lda,
const octruple* x, const int incx,
const octruple &beta, octruple* y, const int incy);
#endif
template
void
blas_gemv >(const CBLAS_TRANSPOSE trA,
const int m, const int n,
const complex &alpha,
const complex* A, const int lda,
const complex* x, const int incx,
const complex &beta,
complex* y, const int incy);
#ifndef NO_OCTRUPLE
template
void
blas_gemv >(const CBLAS_TRANSPOSE trA,
const int m, const int n,
const complex &alpha,
const complex* A, const int lda,
const complex* x, const int incx,
const complex &beta,
complex* y, const int incy);
#endif
// dz trsv
#ifndef BLAS_GENERIC
template<>
void
blas_trsv(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N, const double *A, const int lda, double *X,
const int incX)
{
#ifdef BLAS_FORTRAN
unsigned char uplo_ = 0;
unsigned char transa_ = 0;
unsigned char diag_ = 0;
switch(Uplo) {
case CblasUpper:
uplo_ = 'u';
break;
case CblasLower:
uplo_ = 'l';
break;
}
switch(TransA) {
case CblasNoTrans:
transa_ = 'n';
break;
case CblasTrans:
transa_ = 't';
break;
case CblasConjTrans:
transa_ = 'c';
break;
}
switch(Diag) {
case CblasNonUnit:
diag_ = 'n';
break;
case CblasUnit:
diag_ = 'u';
break;
}
FORTRAN_DECL(dtrsv)(uplo_, transa_, diag_, N, A, lda, X, incX);
#else
cblas_dtrsv(CblasColMajor, Uplo, TransA, Diag, (BLAS_INT)N,
A, (BLAS_INT)lda, X, (BLAS_INT)incX);
#endif
}
template<>
void
blas_trsv >(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N, const complex* A,
const int lda,
complex *X, const int incX)
{
#ifdef BLAS_FORTRAN
unsigned char uplo_ = 0;
unsigned char transa_ = 0;
unsigned char diag_ = 0;
switch(Uplo) {
case CblasUpper:
uplo_ = 'u';
break;
case CblasLower:
uplo_ = 'l';
break;
}
switch(TransA) {
case CblasNoTrans:
transa_ = 'n';
break;
case CblasTrans:
transa_ = 't';
break;
case CblasConjTrans:
transa_ = 'c';
break;
}
switch(Diag) {
case CblasNonUnit:
diag_ = 'n';
break;
case CblasUnit:
diag_ = 'u';
break;
}
FORTRAN_DECL(ztrsv)(uplo_, transa_, diag_, N, (double *)A, lda,
(double *)X, incX);
#else
cblas_ztrsv(CblasColMajor, Uplo, TransA, Diag, (BLAS_INT)N,
(BLAS_VOID *)A, (BLAS_INT)lda, (BLAS_VOID *)X, (BLAS_INT)incX);
#endif
}
template<>
void
blas_trsv(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N, const float *A, const int lda, float *X,
const int incX)
{
#ifdef BLAS_FORTRAN
unsigned char uplo_ = 0;
unsigned char transa_ = 0;
unsigned char diag_ = 0;
switch(Uplo) {
case CblasUpper:
uplo_ = 'u';
break;
case CblasLower:
uplo_ = 'l';
break;
}
switch(TransA) {
case CblasNoTrans:
transa_ = 'n';
break;
case CblasTrans:
transa_ = 't';
break;
case CblasConjTrans:
transa_ = 'c';
break;
}
switch(Diag) {
case CblasNonUnit:
diag_ = 'n';
break;
case CblasUnit:
diag_ = 'u';
break;
}
FORTRAN_DECL(strsv)(uplo_, transa_, diag_, N, A, lda, X, incX);
#else
cblas_strsv(CblasColMajor, Uplo, TransA, Diag, (BLAS_INT)N,
A, (BLAS_INT)lda, X, (BLAS_INT)incX);
#endif
}
template<>
void
blas_trsv >(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N, const complex* A,
const int lda,
complex *X, const int incX)
{
#ifdef BLAS_FORTRAN
unsigned char uplo_ = 0;
unsigned char transa_ = 0;
unsigned char diag_ = 0;
switch(Uplo) {
case CblasUpper:
uplo_ = 'u';
break;
case CblasLower:
uplo_ = 'l';
break;
}
switch(TransA) {
case CblasNoTrans:
transa_ = 'n';
break;
case CblasTrans:
transa_ = 't';
break;
case CblasConjTrans:
transa_ = 'c';
break;
}
switch(Diag) {
case CblasNonUnit:
diag_ = 'n';
break;
case CblasUnit:
diag_ = 'u';
break;
}
FORTRAN_DECL(ctrsv)(uplo_, transa_, diag_, N, (float *)A, lda,
(float *)X, incX);
#else
cblas_ctrsv(CblasColMajor, Uplo, TransA, Diag, (BLAS_INT)N,
(BLAS_VOID *)A, (BLAS_INT)lda, (BLAS_VOID *)X, (BLAS_INT)incX);
#endif
}
#endif
template
void
blas_trsv(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N, const T *A, const int lda, T *X,
const int incX)
{
const T zero(0.0);
bool noconj, nounit;
int ix, jx, kx;
if (N == 0) {
return;
}
noconj = (TransA == CblasTrans);
nounit = (Diag == CblasNonUnit);
if (incX < 0) {
kx = (N - 1) * (-incX); // decrement form the last index
}
else {
kx = 0;
}
if (TransA == CblasNoTrans) {
// Form x := inv( A )*x.
if (Uplo == CblasUpper) {
if (incX == 1) {
for (int j = (N - 1); j >= 0; j--) {
if (X[j] != zero) {
if (nounit) {
X[j] /= A[j + j * lda];
}
T temp = X[j];
for (int i = (j - 1); i >= 0; i--) {
X[i] -= temp * A[i + j * lda];
} // loop 10 : i
}
} // loop 20 : j
}
else {
jx = kx + (N - 1) * incX;
for (int j = (N - 1); j >= 0; j--) {
if (X[jx] != zero) {
if (nounit) {
X[jx] /= A[j + j * lda];
}
T temp = X[jx];
ix = jx;
for (int i = (j - 1); j >= 0; j--) {
ix -= incX;
X[ix] -= temp * A[i + j * lda];
} // loop 30 : i
}
jx -= incX;
} // loop 40 : j
} // if (incX == 1)
}
else {
if (incX == 1) {
for (int j = 0; j < N; j++) {
if (X[j] != zero) {
if (nounit) {
X[j] /= A[j + j * lda];
}
T temp = X[j];
for (int i = j + 1; i < N; i++) {
X[i] -= temp * A[i + j * lda];
} // loop 50 : i
}
} // loop 60 : j
}
else {
jx = kx;
for (int j = 0; j < N; j++) {
if (X[jx] != zero) {
if (nounit) {
X[jx] /= A[j + j * lda];
}
T temp = X[jx];
ix = jx;
for (int i = j + 1; i < N; i++) {
ix += incX;
X[ix] -= temp * A[i + j * lda];
} // loop 70 : i
}
jx += incX;
} // loop 80 : j
} // if (incX == 1)
} // if (Uplo == CblasUpper)
}
else {
// Form x := inv( A **T )*x or x := inv( A **H ) *x.
if (Uplo == CblasUpper) {
if (incX == 1) {
for (int j = 0; j < N; j++) {
T temp = X[j];
if (noconj) {
for (int i = 0; i < j; i++) {
temp -= A[i + j * lda] * X[i];
} // loop 90 : i
if (nounit) {
temp /= A[j + j * lda];
}
}
else {
for (int i = 0; i < j; i++) {
temp -= blas_conj(A[i + j * lda]) * X[i];
} // loop 100 : i
if (nounit) {
temp /= blas_conj(A[j + j * lda]);
}
}
X[j] = temp;
} // loop 110 : j
}
else {
jx = kx;
for (int j = 0; j < N; j++) {
ix = kx;
T temp = X[jx];
if (noconj) {
for (int i = 0; i < j; i++) {
temp -= A[i + j * lda] * X[ix];
ix += incX;
} // loop 120 : i
if (nounit) {
temp /= A[j + j * lda];
}
}
else {
for (int i = 0; i < j; i++) {
temp -= blas_conj(A[i + j * lda]) * X[ix];
ix += incX;
} // loop 120 : i
if (nounit) {
temp /= blas_conj(A[j + j * lda]);
}
}
X[jx] = temp;
jx += incX;
}
}
}
else {
if (incX == 1) {
for (int j = (N - 1); j >= 0; j--) {
T temp = X[j];
if (noconj) {
for (int i = (N - 1); i > j; i--) {
temp -= A[i + j * lda] * X[i];
} // loop 150 : i
if (nounit) {
temp /= A[j + j * lda];
}
}
else {
for (int i = 0; i < j; i++) {
temp -= blas_conj(A[i + j * lda]) * X[i];
} // loop 160 : i
if (nounit) {
temp /= blas_conj(A[j + j * lda]);
}
}
X[j] = temp;
} // loop 170 : j
}
else {
kx = kx + N * incX;
jx = kx;
for (int j = (N - 1); j >= 0; j--) {
ix = kx;
T temp = X[jx];
if (noconj) {
for (int i = (N - 1); i > j; i--) {
temp -= A[i + j * lda] * X[ix];
ix -= incX;
} // loop 180 : i
if (nounit) {
temp /= A[j + j * lda];
}
}
else {
for (int i = (N - 1); i > j; i--) {
temp -= blas_conj(A[i + j * lda]) * X[ix];
ix -= incX;
} // loop 190 : i
if (nounit) {
temp /= blas_conj(A[j + j * lda]);
}
}
X[jx] = temp;
jx -= incX;
} // loop 200 : j
}
} // if (Uplo == CblasUpper)
}
}
// explicit instantiation of blas_trsv
#ifdef FORCE_EXPLICIT_INSTANTIATION
template
void
blas_trsv(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N, const double *A, const int lda,
double *X, const int incX);
template
void
blas_trsv >(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N,
const complex *A, const int lda,
complex *X, const int incX);
template
void
blas_trsv(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N, const float *A, const int lda,
float *X, const int incX);
template
void
blas_trsv >(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N,
const complex *A, const int lda,
complex *X, const int incX);
#endif
template
void
blas_trsv(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N, const quadruple *A, const int lda,
quadruple *X, const int incX);
#ifndef NO_OCTRUPLE
template
void
blas_trsv(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N, const octruple *A, const int lda,
octruple *X, const int incX);
#endif
template
void
blas_trsv >(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N,
const complex *A, const int lda,
complex *X, const int incX);
#ifndef NO_OCTRUPLE
template
void
blas_trsv >(const CBLAS_UPLO Uplo,
const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
const int N,
const complex *A, const int lda,
complex *X, const int incX);
#endif
// dz syr : symmetric rank-1 update
template
void
blas_syr(const CBLAS_UPLO Uplo,
const int N, const T &alpha,
const T *X, const int incX,
T *A, const int lda)
{
const T zero(0.0);
int ix, jx, kx;
if ((N == 0) || (alpha == zero)) {
return;
}
if (incX > 0) {
kx = 0;
}
else {
kx = (N - 1) * (-incX); // decrement form the last index
}
if (Uplo == CblasUpper) {
// Form A when A is stored in upper triangle.
if (incX == 1) {
for (int j = 0; j < N; j++) {
if (X[j] != zero) {
T temp = alpha * X[j];
for (int i = 0; i <= j; i++) {
A[i + j * lda] += X[i] * temp;
} // loop 10 : i
}
} // loop 20 : j
}
else {
jx = kx;
for (int j = 0; j < N; j++) {
if (X[jx] != zero) {
T temp = alpha * X[jx];
ix = kx;
for (int i = 0; i <= j; i++) {
A[i + j * lda] += X[ix] * temp;
ix += incX;
} // loop 30 : i
}
jx += incX;
} // loop 40 : j
}
}
else {
// Form A when A is stored in lower triangle.
if (incX == 1) {
for (int j = 0; j < N; j++) {
if (X[j] != zero) {
T temp = alpha * X[j];
for (int i = j; i < N; i++) {
A[i + j * lda] += X[i] * temp;
} // loop 50 : i
}
} // loop 60 : j
}
else {
jx = kx;
for (int j = 0; j < N; j++) {
if (X[jx] != zero) {
T temp = alpha * X[jx];
ix = jx;
for (int i = j; i < N; i++) {
A[i + j * lda] += X[ix] * temp;
ix += incX;
} // loop 70 : i
}
jx += incX;
} // loop 80 : j
}
}
}
#ifndef BLAS_GENERIC
template<>
void
blas_syr(const CBLAS_UPLO Uplo,
const int N, const double &alpha,
const double *X, const int incX,
double *A, const int lda)
{
#ifdef BLAS_FORTRAN
unsigned char uplo_ = 0;
switch(Uplo) {
case CblasUpper:
uplo_ = 'u';
break;
case CblasLower:
uplo_ = 'l';
break;
}
FORTRAN_DECL(dsyr)(uplo_, N, alpha, X, incX, A, lda);
#else
cblas_dsyr(CblasColMajor, Uplo, (BLAS_INT)N, alpha,
X, (BLAS_INT)incX, A, (BLAS_INT)lda);
#endif
}
template<>
void
blas_syr >(const CBLAS_UPLO Uplo,
const int N, const complex &alpha,
const complex *X, const int incX,
complex *A, const int lda)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(zgeru)(N, N,
(double *)&alpha, (double *)X, incX, (double *)X, incX,
(double *)A, lda); // no zsyr in BLAS! : Uplo is ignored
#else
cblas_zgeru(CblasColMajor, N, N,
(BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX,
(BLAS_VOID *)X, (BLAS_INT)incX,
(BLAS_VOID *)A, (BLAS_INT)lda); // no zsyr in BLAS! : Uplo is ignored
#endif
}
template<>
void
blas_syr(const CBLAS_UPLO Uplo,
const int N, const float &alpha,
const float *X, const int incX,
float *A, const int lda)
{
#ifdef BLAS_FORTRAN
unsigned char uplo_ = 0;
switch(Uplo) {
case CblasUpper:
uplo_ = 'u';
break;
case CblasLower:
uplo_ = 'l';
break;
}
FORTRAN_DECL(ssyr)(uplo_, N, alpha, X, incX, A, lda);
#else
cblas_ssyr(CblasColMajor, Uplo, (BLAS_INT)N, alpha,
X, (BLAS_INT)incX, A, (BLAS_INT)lda);
#endif
}
template<>
void
blas_syr >(const CBLAS_UPLO Uplo,
const int N, const complex &alpha,
const complex *X, const int incX,
complex *A, const int lda)
{
#ifdef BLAS_FORTRAN
FORTRAN_DECL(cgeru)(N, N,
(float *)&alpha, (float *)X, incX, (float *)X, incX,
(float *)A, lda); // no zsyr in BLAS! : Uplo is ignored
#else
cblas_cgeru(CblasColMajor, N, N,
(BLAS_VOID *)&alpha, (BLAS_VOID *)X, (BLAS_INT)incX,
(BLAS_VOID *)X, (BLAS_INT)incX,
(BLAS_VOID *)A, (BLAS_INT)lda); // no zsyr in BLAS! : Uplo is ignored
#endif
}
#endif
// explicit instantiation of blas_syr
#ifdef FORCE_EXPLICIT_INSTANTIATION
template
void
blas_syr(const CBLAS_UPLO Uplo, const int N,
const double &alpha,
const double *X, const int incX,
double *A, const int lda);
template
void
blas_syr