gsl_cblas__source_tbsv_r.h 3.8 KB

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