| 1 | /* blas/source_tbsv_r.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 | const int nonunit = (Diag == CblasNonUnit); |
| 22 | INDEX i, j; |
| 23 | const int Trans = (TransA != CblasConjTrans) ? TransA : CblasTrans; |
| 24 | |
| 25 | if (N == 0) |
| 26 | return; |
| 27 | |
| 28 | /* form x := inv( A )*x */ |
| 29 | |
| 30 | if ((order == CblasRowMajor && Trans == CblasNoTrans && Uplo == CblasUpper) |
| 31 | || (order == CblasColMajor && Trans == CblasTrans && Uplo == CblasLower)) { |
| 32 | /* backsubstitution */ |
| 33 | INDEX ix = OFFSET(N, incX) + incX * (N - 1); |
| 34 | for (i = N; i > 0 && i--;) { |
| 35 | BASE tmp = X[ix]; |
| 36 | const INDEX j_min = i + 1; |
| 37 | const INDEX j_max = GSL_MIN(N, i + K + 1); |
| 38 | INDEX jx = OFFSET(N, incX) + j_min * incX; |
| 39 | for (j = j_min; j < j_max; j++) { |
| 40 | const BASE Aij = A[lda * i + (j - i)]; |
| 41 | tmp -= Aij * X[jx]; |
| 42 | jx += incX; |
| 43 | } |
| 44 | if (nonunit) { |
| 45 | X[ix] = tmp / A[lda * i + 0]; |
| 46 | } else { |
| 47 | X[ix] = tmp; |
| 48 | } |
| 49 | ix -= incX; |
| 50 | } |
| 51 | } else if ((order == CblasRowMajor && Trans == CblasNoTrans && Uplo == CblasLower) |
| 52 | || (order == CblasColMajor && Trans == CblasTrans && Uplo == CblasUpper)) { |
| 53 | |
| 54 | /* forward substitution */ |
| 55 | INDEX ix = OFFSET(N, incX); |
| 56 | |
| 57 | for (i = 0; i < N; i++) { |
| 58 | BASE tmp = X[ix]; |
| 59 | const INDEX j_min = (i > K ? i - K : 0); |
| 60 | const INDEX j_max = i; |
| 61 | INDEX jx = OFFSET(N, incX) + j_min * incX; |
| 62 | for (j = j_min; j < j_max; j++) { |
| 63 | const BASE Aij = A[lda * i + (K + j - i)]; |
| 64 | tmp -= Aij * X[jx]; |
| 65 | jx += incX; |
| 66 | } |
| 67 | if (nonunit) { |
| 68 | X[ix] = tmp / A[lda * i + K]; |
| 69 | } else { |
| 70 | X[ix] = tmp; |
| 71 | } |
| 72 | ix += incX; |
| 73 | } |
| 74 | } else if ((order == CblasRowMajor && Trans == CblasTrans && Uplo == CblasUpper) |
| 75 | || (order == CblasColMajor && Trans == CblasNoTrans && Uplo == CblasLower)) { |
| 76 | |
| 77 | /* form x := inv( A' )*x */ |
| 78 | |
| 79 | /* forward substitution */ |
| 80 | INDEX ix = OFFSET(N, incX); |
| 81 | for (i = 0; i < N; i++) { |
| 82 | BASE tmp = X[ix]; |
| 83 | const INDEX j_min = (K > i ? 0 : i - K); |
| 84 | const INDEX j_max = i; |
| 85 | INDEX jx = OFFSET(N, incX) + j_min * incX; |
| 86 | for (j = j_min; j < j_max; j++) { |
| 87 | const BASE Aji = A[(i - j) + lda * j]; |
| 88 | tmp -= Aji * X[jx]; |
| 89 | jx += incX; |
| 90 | } |
| 91 | if (nonunit) { |
| 92 | X[ix] = tmp / A[0 + lda * i]; |
| 93 | } else { |
| 94 | X[ix] = tmp; |
| 95 | } |
| 96 | ix += incX; |
| 97 | } |
| 98 | } else if ((order == CblasRowMajor && Trans == CblasTrans && Uplo == CblasLower) |
| 99 | || (order == CblasColMajor && Trans == CblasNoTrans && Uplo == CblasUpper)) { |
| 100 | |
| 101 | /* backsubstitution */ |
| 102 | INDEX ix = OFFSET(N, incX) + (N - 1) * incX; |
| 103 | for (i = N; i > 0 && i--;) { |
| 104 | BASE tmp = X[ix]; |
| 105 | const INDEX j_min = i + 1; |
| 106 | const INDEX j_max = GSL_MIN(N, i + K + 1); |
| 107 | INDEX jx = OFFSET(N, incX) + j_min * incX; |
| 108 | for (j = j_min; j < j_max; j++) { |
| 109 | const BASE Aji = A[(K + i - j) + lda * j]; |
| 110 | tmp -= Aji * X[jx]; |
| 111 | jx += incX; |
| 112 | } |
| 113 | if (nonunit) { |
| 114 | X[ix] = tmp / A[K + lda * i]; |
| 115 | } else { |
| 116 | X[ix] = tmp; |
| 117 | } |
| 118 | ix -= incX; |
| 119 | } |
| 120 | } else { |
| 121 | BLAS_ERROR("unrecognized operation"); |
| 122 | } |
| 123 | } |