| 1 | /* blas/source_tpmv_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 | |
| 23 | const int conj = (TransA == CblasConjTrans) ? -1 : 1; |
| 24 | const int Trans = (TransA != CblasConjTrans) ? TransA : CblasTrans; |
| 25 | const int nonunit = (Diag == CblasNonUnit); |
| 26 | |
| 27 | if ((order == CblasRowMajor && Trans == CblasNoTrans && Uplo == CblasUpper) |
| 28 | || (order == CblasColMajor && Trans == CblasTrans && Uplo == CblasLower)) { |
| 29 | /* form x:= A*x */ |
| 30 | |
| 31 | INDEX ix = OFFSET(N, incX); |
| 32 | for (i = 0; i < N; i++) { |
| 33 | const BASE Aii_real = CONST_REAL(Ap, TPUP(N, i, i)); |
| 34 | const BASE Aii_imag = conj * CONST_IMAG(Ap, TPUP(N, i, i)); |
| 35 | BASE temp_r; |
| 36 | BASE temp_i; |
| 37 | if (nonunit) { |
| 38 | BASE x_real = REAL(X, ix); |
| 39 | BASE x_imag = IMAG(X, ix); |
| 40 | temp_r = Aii_real * x_real - Aii_imag * x_imag; |
| 41 | temp_i = Aii_real * x_imag + Aii_imag * x_real; |
| 42 | } else { |
| 43 | temp_r = REAL(X, ix); |
| 44 | temp_i = IMAG(X, ix); |
| 45 | } |
| 46 | |
| 47 | { |
| 48 | INDEX jx = OFFSET(N, incX) + (i + 1) * incX; |
| 49 | for (j = i + 1; j < N; j++) { |
| 50 | const BASE Aij_real = CONST_REAL(Ap, TPUP(N, i, j)); |
| 51 | const BASE Aij_imag = conj * CONST_IMAG(Ap, TPUP(N, i, j)); |
| 52 | BASE x_real = REAL(X, jx); |
| 53 | BASE x_imag = IMAG(X, jx); |
| 54 | temp_r += Aij_real * x_real - Aij_imag * x_imag; |
| 55 | temp_i += Aij_real * x_imag + Aij_imag * x_real; |
| 56 | jx += incX; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | REAL(X, ix) = temp_r; |
| 61 | IMAG(X, ix) = temp_i; |
| 62 | ix += incX; |
| 63 | } |
| 64 | } else if ((order == CblasRowMajor && Trans == CblasNoTrans && Uplo == CblasLower) |
| 65 | || (order == CblasColMajor && Trans == CblasTrans && Uplo == CblasUpper)) { |
| 66 | |
| 67 | INDEX ix = OFFSET(N, incX) + incX * (N - 1); |
| 68 | for (i = N; i > 0 && i--;) { |
| 69 | const BASE Aii_real = CONST_REAL(Ap, TPLO(N, i, i)); |
| 70 | const BASE Aii_imag = conj * CONST_IMAG(Ap, TPLO(N, i, i)); |
| 71 | BASE temp_r; |
| 72 | BASE temp_i; |
| 73 | if (nonunit) { |
| 74 | BASE x_real = REAL(X, ix); |
| 75 | BASE x_imag = IMAG(X, ix); |
| 76 | temp_r = Aii_real * x_real - Aii_imag * x_imag; |
| 77 | temp_i = Aii_real * x_imag + Aii_imag * x_real; |
| 78 | } else { |
| 79 | temp_r = REAL(X, ix); |
| 80 | temp_i = IMAG(X, ix); |
| 81 | } |
| 82 | |
| 83 | { |
| 84 | INDEX jx = OFFSET(N, incX); |
| 85 | for (j = 0; j < i; j++) { |
| 86 | const BASE Aij_real = CONST_REAL(Ap, TPLO(N, i, j)); |
| 87 | const BASE Aij_imag = conj * CONST_IMAG(Ap, TPLO(N, i, j)); |
| 88 | BASE x_real = REAL(X, jx); |
| 89 | BASE x_imag = IMAG(X, jx); |
| 90 | temp_r += Aij_real * x_real - Aij_imag * x_imag; |
| 91 | temp_i += Aij_real * x_imag + Aij_imag * x_real; |
| 92 | jx += incX; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | REAL(X, ix) = temp_r; |
| 97 | IMAG(X, ix) = temp_i; |
| 98 | ix -= incX; |
| 99 | } |
| 100 | } else if ((order == CblasRowMajor && Trans == CblasTrans && Uplo == CblasUpper) |
| 101 | || (order == CblasColMajor && Trans == CblasNoTrans && Uplo == CblasLower)) { |
| 102 | /* form x := A'*x */ |
| 103 | |
| 104 | INDEX ix = OFFSET(N, incX) + incX * (N - 1); |
| 105 | for (i = N; i > 0 && i--;) { |
| 106 | const BASE Aii_real = CONST_REAL(Ap, TPUP(N, i, i)); |
| 107 | const BASE Aii_imag = conj * CONST_IMAG(Ap, TPUP(N, i, i)); |
| 108 | BASE temp_r; |
| 109 | BASE temp_i; |
| 110 | if (nonunit) { |
| 111 | BASE x_real = REAL(X, ix); |
| 112 | BASE x_imag = IMAG(X, ix); |
| 113 | temp_r = Aii_real * x_real - Aii_imag * x_imag; |
| 114 | temp_i = Aii_real * x_imag + Aii_imag * x_real; |
| 115 | } else { |
| 116 | temp_r = REAL(X, ix); |
| 117 | temp_i = IMAG(X, ix); |
| 118 | } |
| 119 | { |
| 120 | INDEX jx = OFFSET(N, incX); |
| 121 | for (j = 0; j < i; j++) { |
| 122 | BASE x_real = REAL(X, jx); |
| 123 | BASE x_imag = IMAG(X, jx); |
| 124 | const BASE Aji_real = CONST_REAL(Ap, TPUP(N, j, i)); |
| 125 | const BASE Aji_imag = conj * CONST_IMAG(Ap, TPUP(N, j, i)); |
| 126 | temp_r += Aji_real * x_real - Aji_imag * x_imag; |
| 127 | temp_i += Aji_real * x_imag + Aji_imag * x_real; |
| 128 | jx += incX; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | REAL(X, ix) = temp_r; |
| 133 | IMAG(X, ix) = temp_i; |
| 134 | ix -= incX; |
| 135 | } |
| 136 | } else if ((order == CblasRowMajor && Trans == CblasTrans && Uplo == CblasLower) |
| 137 | || (order == CblasColMajor && Trans == CblasNoTrans && Uplo == CblasUpper)) { |
| 138 | |
| 139 | INDEX ix = OFFSET(N, incX); |
| 140 | for (i = 0; i < N; i++) { |
| 141 | const BASE Aii_real = CONST_REAL(Ap, TPLO(N, i, i)); |
| 142 | const BASE Aii_imag = conj * CONST_IMAG(Ap, TPLO(N, i, i)); |
| 143 | BASE temp_r; |
| 144 | BASE temp_i; |
| 145 | if (nonunit) { |
| 146 | BASE x_real = REAL(X, ix); |
| 147 | BASE x_imag = IMAG(X, ix); |
| 148 | temp_r = Aii_real * x_real - Aii_imag * x_imag; |
| 149 | temp_i = Aii_real * x_imag + Aii_imag * x_real; |
| 150 | } else { |
| 151 | temp_r = REAL(X, ix); |
| 152 | temp_i = IMAG(X, ix); |
| 153 | } |
| 154 | { |
| 155 | INDEX jx = OFFSET(N, incX) + (i + 1) * incX; |
| 156 | for (j = i + 1; j < N; j++) { |
| 157 | BASE x_real = REAL(X, jx); |
| 158 | BASE x_imag = IMAG(X, jx); |
| 159 | const BASE Aji_real = CONST_REAL(Ap, TPLO(N, j, i)); |
| 160 | const BASE Aji_imag = conj * CONST_IMAG(Ap, TPLO(N, j, i)); |
| 161 | temp_r += Aji_real * x_real - Aji_imag * x_imag; |
| 162 | temp_i += Aji_real * x_imag + Aji_imag * x_real; |
| 163 | jx += incX; |
| 164 | } |
| 165 | } |
| 166 | REAL(X, ix) = temp_r; |
| 167 | IMAG(X, ix) = temp_i; |
| 168 | ix += incX; |
| 169 | } |
| 170 | } else { |
| 171 | BLAS_ERROR("unrecognized operation"); |
| 172 | } |
| 173 | } |