gsl_cblas__source_tbsv_c.h 6.5 KB

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