| 1 |
/* blas/source_gbmv_c.h |
| 2 |
* |
| 3 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman |
| 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 |
INDEX i, j; |
| 22 |
INDEX lenX, lenY, L, U; |
| 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 (M == 0 || N == 0) |
| 31 |
return; |
| 32 |
|
| 33 |
if ((alpha_real == 0.0 && alpha_imag == 0.0) |
| 34 |
&& (beta_real == 1.0 && beta_imag == 0.0)) |
| 35 |
return; |
| 36 |
|
| 37 |
if (TransA == CblasNoTrans) { |
| 38 |
lenX = N; |
| 39 |
lenY = M; |
| 40 |
L = KL; |
| 41 |
U = KU; |
| 42 |
} else { |
| 43 |
lenX = M; |
| 44 |
lenY = N; |
| 45 |
L = KU; |
| 46 |
U = KL; |
| 47 |
} |
| 48 |
|
| 49 |
/* form y := beta*y */ |
| 50 |
if (beta_real == 0.0 && beta_imag == 0.0) { |
| 51 |
INDEX iy = OFFSET(lenY, incY); |
| 52 |
for (i = 0; i < lenY; i++) { |
| 53 |
REAL(Y, iy) = 0.0; |
| 54 |
IMAG(Y, iy) = 0.0; |
| 55 |
iy += incY; |
| 56 |
} |
| 57 |
} else if (!(beta_real == 1.0 && beta_imag == 0.0)) { |
| 58 |
INDEX iy = OFFSET(lenY, incY); |
| 59 |
for (i = 0; i < lenY; i++) { |
| 60 |
const BASE y_real = REAL(Y, iy); |
| 61 |
const BASE y_imag = IMAG(Y, iy); |
| 62 |
const BASE tmpR = y_real * beta_real - y_imag * beta_imag; |
| 63 |
const BASE tmpI = y_real * beta_imag + y_imag * beta_real; |
| 64 |
REAL(Y, iy) = tmpR; |
| 65 |
IMAG(Y, iy) = tmpI; |
| 66 |
iy += incY; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
if (alpha_real == 0.0 && alpha_imag == 0.0) |
| 71 |
return; |
| 72 |
|
| 73 |
if ((order == CblasRowMajor && TransA == CblasNoTrans) |
| 74 |
|| (order == CblasColMajor && TransA == CblasTrans)) { |
| 75 |
/* form y := alpha*A*x + y */ |
| 76 |
INDEX iy = OFFSET(lenY, incY); |
| 77 |
for (i = 0; i < lenY; i++) { |
| 78 |
BASE dotR = 0.0; |
| 79 |
BASE dotI = 0.0; |
| 80 |
const INDEX j_min = (i > L ? i - L : 0); |
| 81 |
const INDEX j_max = GSL_MIN(lenX, i + U + 1); |
| 82 |
INDEX ix = OFFSET(lenX, incX) + j_min * incX; |
| 83 |
for (j = j_min; j < j_max; j++) { |
| 84 |
const BASE x_real = CONST_REAL(X, ix); |
| 85 |
const BASE x_imag = CONST_IMAG(X, ix); |
| 86 |
const BASE A_real = CONST_REAL(A, lda * i + (L + j - i)); |
| 87 |
const BASE A_imag = CONST_IMAG(A, lda * i + (L + j - i)); |
| 88 |
|
| 89 |
dotR += A_real * x_real - A_imag * x_imag; |
| 90 |
dotI += A_real * x_imag + A_imag * x_real; |
| 91 |
ix += incX; |
| 92 |
} |
| 93 |
|
| 94 |
REAL(Y, iy) += alpha_real * dotR - alpha_imag * dotI; |
| 95 |
IMAG(Y, iy) += alpha_real * dotI + alpha_imag * dotR; |
| 96 |
iy += incY; |
| 97 |
} |
| 98 |
} else if ((order == CblasRowMajor && TransA == CblasTrans) |
| 99 |
|| (order == CblasColMajor && TransA == CblasNoTrans)) { |
| 100 |
/* form y := alpha*A'*x + y */ |
| 101 |
INDEX ix = OFFSET(lenX, incX); |
| 102 |
for (j = 0; j < lenX; j++) { |
| 103 |
const BASE x_real = CONST_REAL(X, ix); |
| 104 |
const BASE x_imag = CONST_IMAG(X, ix); |
| 105 |
BASE tmpR = alpha_real * x_real - alpha_imag * x_imag; |
| 106 |
BASE tmpI = alpha_real * x_imag + alpha_imag * x_real; |
| 107 |
if (!(tmpR == 0.0 && tmpI == 0.0)) { |
| 108 |
const INDEX i_min = (j > U ? j - U : 0); |
| 109 |
const INDEX i_max = GSL_MIN(lenY, j + L + 1); |
| 110 |
INDEX iy = OFFSET(lenY, incY) + i_min * incY; |
| 111 |
for (i = i_min; i < i_max; i++) { |
| 112 |
const BASE A_real = CONST_REAL(A, lda * j + (U + i - j)); |
| 113 |
const BASE A_imag = CONST_IMAG(A, lda * j + (U + i - j)); |
| 114 |
REAL(Y, iy) += A_real * tmpR - A_imag * tmpI; |
| 115 |
IMAG(Y, iy) += A_real * tmpI + A_imag * tmpR; |
| 116 |
iy += incY; |
| 117 |
} |
| 118 |
} |
| 119 |
ix += incX; |
| 120 |
} |
| 121 |
} else if (order == CblasRowMajor && TransA == CblasConjTrans) { |
| 122 |
/* form y := alpha*A^H*x + y */ |
| 123 |
INDEX ix = OFFSET(lenX, incX); |
| 124 |
for (j = 0; j < lenX; j++) { |
| 125 |
const BASE x_real = CONST_REAL(X, ix); |
| 126 |
const BASE x_imag = CONST_IMAG(X, ix); |
| 127 |
BASE tmpR = alpha_real * x_real - alpha_imag * x_imag; |
| 128 |
BASE tmpI = alpha_real * x_imag + alpha_imag * x_real; |
| 129 |
if (!(tmpR == 0.0 && tmpI == 0.0)) { |
| 130 |
const INDEX i_min = (j > U ? j - U : 0); |
| 131 |
const INDEX i_max = GSL_MIN(lenY, j + L + 1); |
| 132 |
INDEX iy = OFFSET(lenY, incY) + i_min * incY; |
| 133 |
for (i = i_min; i < i_max; i++) { |
| 134 |
const BASE A_real = CONST_REAL(A, lda * j + (U + i - j)); |
| 135 |
const BASE A_imag = CONST_IMAG(A, lda * j + (U + i - j)); |
| 136 |
REAL(Y, iy) += A_real * tmpR - (-A_imag) * tmpI; |
| 137 |
IMAG(Y, iy) += A_real * tmpI + (-A_imag) * tmpR; |
| 138 |
iy += incY; |
| 139 |
} |
| 140 |
} |
| 141 |
ix += incX; |
| 142 |
} |
| 143 |
} else if (order == CblasColMajor && TransA == CblasConjTrans) { |
| 144 |
/* form y := alpha*A^H*x + y */ |
| 145 |
INDEX iy = OFFSET(lenY, incY); |
| 146 |
for (i = 0; i < lenY; i++) { |
| 147 |
BASE dotR = 0.0; |
| 148 |
BASE dotI = 0.0; |
| 149 |
const INDEX j_min = (i > L ? i - L : 0); |
| 150 |
const INDEX j_max = GSL_MIN(lenX, i + U + 1); |
| 151 |
INDEX ix = OFFSET(lenX, incX) + j_min * incX; |
| 152 |
for (j = j_min; j < j_max; j++) { |
| 153 |
const BASE x_real = CONST_REAL(X, ix); |
| 154 |
const BASE x_imag = CONST_IMAG(X, ix); |
| 155 |
const BASE A_real = CONST_REAL(A, lda * i + (L + j - i)); |
| 156 |
const BASE A_imag = CONST_IMAG(A, lda * i + (L + j - i)); |
| 157 |
|
| 158 |
dotR += A_real * x_real - (-A_imag) * x_imag; |
| 159 |
dotI += A_real * x_imag + (-A_imag) * x_real; |
| 160 |
ix += incX; |
| 161 |
} |
| 162 |
|
| 163 |
REAL(Y, iy) += alpha_real * dotR - alpha_imag * dotI; |
| 164 |
IMAG(Y, iy) += alpha_real * dotI + alpha_imag * dotR; |
| 165 |
iy += incY; |
| 166 |
} |
| 167 |
} else { |
| 168 |
BLAS_ERROR("unrecognized operation"); |
| 169 |
} |
| 170 |
} |