| 1 |
/* blas/source_hemv.h |
| 2 |
* |
| 3 |
* Copyright (C) 2001, 2007 Brian Gough |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
{ |
| 21 |
const int conj = (order == CblasColMajor) ? -1 : 1; |
| 22 |
INDEX i, j; |
| 23 |
|
| 24 |
const BASE alpha_real = CONST_REAL0(alpha); |
| 25 |
const BASE alpha_imag = CONST_IMAG0(alpha); |
| 26 |
|
| 27 |
const BASE beta_real = CONST_REAL0(beta); |
| 28 |
const BASE beta_imag = CONST_IMAG0(beta); |
| 29 |
|
| 30 |
if ((alpha_real == 0.0 && alpha_imag == 0.0) |
| 31 |
&& (beta_real == 1.0 && beta_imag == 0.0)) |
| 32 |
return; |
| 33 |
|
| 34 |
/* form y := beta*y */ |
| 35 |
if (beta_real == 0.0 && beta_imag == 0.0) { |
| 36 |
INDEX iy = OFFSET(N, incY); |
| 37 |
for (i = 0; i < N; i++) { |
| 38 |
REAL(Y, iy) = 0.0; |
| 39 |
IMAG(Y, iy) = 0.0; |
| 40 |
iy += incY; |
| 41 |
} |
| 42 |
} else if (!(beta_real == 1.0 && beta_imag == 0.0)) { |
| 43 |
INDEX iy = OFFSET(N, incY); |
| 44 |
for (i = 0; i < N; i++) { |
| 45 |
const BASE y_real = REAL(Y, iy); |
| 46 |
const BASE y_imag = IMAG(Y, iy); |
| 47 |
const BASE tmpR = y_real * beta_real - y_imag * beta_imag; |
| 48 |
const BASE tmpI = y_real * beta_imag + y_imag * beta_real; |
| 49 |
REAL(Y, iy) = tmpR; |
| 50 |
IMAG(Y, iy) = tmpI; |
| 51 |
iy += incY; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if (alpha_real == 0.0 && alpha_imag == 0.0) |
| 56 |
return; |
| 57 |
|
| 58 |
/* form y := alpha*A*x + y */ |
| 59 |
|
| 60 |
if ((order == CblasRowMajor && Uplo == CblasUpper) |
| 61 |
|| (order == CblasColMajor && Uplo == CblasLower)) { |
| 62 |
INDEX ix = OFFSET(N, incX); |
| 63 |
INDEX iy = OFFSET(N, incY); |
| 64 |
for (i = 0; i < N; i++) { |
| 65 |
BASE x_real = CONST_REAL(X, ix); |
| 66 |
BASE x_imag = CONST_IMAG(X, ix); |
| 67 |
BASE temp1_real = alpha_real * x_real - alpha_imag * x_imag; |
| 68 |
BASE temp1_imag = alpha_real * x_imag + alpha_imag * x_real; |
| 69 |
BASE temp2_real = 0.0; |
| 70 |
BASE temp2_imag = 0.0; |
| 71 |
const INDEX j_min = i + 1; |
| 72 |
const INDEX j_max = N; |
| 73 |
INDEX jx = OFFSET(N, incX) + j_min * incX; |
| 74 |
INDEX jy = OFFSET(N, incY) + j_min * incY; |
| 75 |
BASE Aii_real = CONST_REAL(A, lda * i + i); |
| 76 |
/* Aii_imag is zero */ |
| 77 |
REAL(Y, iy) += temp1_real * Aii_real; |
| 78 |
IMAG(Y, iy) += temp1_imag * Aii_real; |
| 79 |
for (j = j_min; j < j_max; j++) { |
| 80 |
BASE Aij_real = CONST_REAL(A, lda * i + j); |
| 81 |
BASE Aij_imag = conj * CONST_IMAG(A, lda * i + j); |
| 82 |
REAL(Y, jy) += temp1_real * Aij_real - temp1_imag * (-Aij_imag); |
| 83 |
IMAG(Y, jy) += temp1_real * (-Aij_imag) + temp1_imag * Aij_real; |
| 84 |
x_real = CONST_REAL(X, jx); |
| 85 |
x_imag = CONST_IMAG(X, jx); |
| 86 |
temp2_real += x_real * Aij_real - x_imag * Aij_imag; |
| 87 |
temp2_imag += x_real * Aij_imag + x_imag * Aij_real; |
| 88 |
jx += incX; |
| 89 |
jy += incY; |
| 90 |
} |
| 91 |
REAL(Y, iy) += alpha_real * temp2_real - alpha_imag * temp2_imag; |
| 92 |
IMAG(Y, iy) += alpha_real * temp2_imag + alpha_imag * temp2_real; |
| 93 |
ix += incX; |
| 94 |
iy += incY; |
| 95 |
} |
| 96 |
} else if ((order == CblasRowMajor && Uplo == CblasLower) |
| 97 |
|| (order == CblasColMajor && Uplo == CblasUpper)) { |
| 98 |
INDEX ix = OFFSET(N, incX) + (N - 1) * incX; |
| 99 |
INDEX iy = OFFSET(N, incY) + (N - 1) * incY; |
| 100 |
for (i = N; i > 0 && i--;) { |
| 101 |
BASE x_real = CONST_REAL(X, ix); |
| 102 |
BASE x_imag = CONST_IMAG(X, ix); |
| 103 |
BASE temp1_real = alpha_real * x_real - alpha_imag * x_imag; |
| 104 |
BASE temp1_imag = alpha_real * x_imag + alpha_imag * x_real; |
| 105 |
BASE temp2_real = 0.0; |
| 106 |
BASE temp2_imag = 0.0; |
| 107 |
const INDEX j_min = 0; |
| 108 |
const INDEX j_max = i; |
| 109 |
INDEX jx = OFFSET(N, incX) + j_min * incX; |
| 110 |
INDEX jy = OFFSET(N, incY) + j_min * incY; |
| 111 |
BASE Aii_real = CONST_REAL(A, lda * i + i); |
| 112 |
/* Aii_imag is zero */ |
| 113 |
REAL(Y, iy) += temp1_real * Aii_real; |
| 114 |
IMAG(Y, iy) += temp1_imag * Aii_real; |
| 115 |
|
| 116 |
for (j = j_min; j < j_max; j++) { |
| 117 |
BASE Aij_real = CONST_REAL(A, lda * i + j); |
| 118 |
BASE Aij_imag = conj * CONST_IMAG(A, lda * i + j); |
| 119 |
REAL(Y, jy) += temp1_real * Aij_real - temp1_imag * (-Aij_imag); |
| 120 |
IMAG(Y, jy) += temp1_real * (-Aij_imag) + temp1_imag * Aij_real; |
| 121 |
x_real = CONST_REAL(X, jx); |
| 122 |
x_imag = CONST_IMAG(X, jx); |
| 123 |
temp2_real += x_real * Aij_real - x_imag * Aij_imag; |
| 124 |
temp2_imag += x_real * Aij_imag + x_imag * Aij_real; |
| 125 |
jx += incX; |
| 126 |
jy += incY; |
| 127 |
} |
| 128 |
REAL(Y, iy) += alpha_real * temp2_real - alpha_imag * temp2_imag; |
| 129 |
IMAG(Y, iy) += alpha_real * temp2_imag + alpha_imag * temp2_real; |
| 130 |
ix -= incX; |
| 131 |
iy -= incY; |
| 132 |
} |
| 133 |
} else { |
| 134 |
BLAS_ERROR("unrecognized operation"); |
| 135 |
} |
| 136 |
} |