gsl_cblas__source_tpsv_c.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* blas/source_tpsv_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. if (nonunit) {
  31. const BASE a_real = CONST_REAL(Ap, TPUP(N, (N - 1), (N - 1)));
  32. const BASE a_imag = conj * CONST_IMAG(Ap, TPUP(N, (N - 1), (N - 1)));
  33. const BASE x_real = REAL(X, ix);
  34. const BASE x_imag = IMAG(X, ix);
  35. const BASE s = xhypot(a_real, a_imag);
  36. const BASE b_real = a_real / s;
  37. const BASE b_imag = a_imag / s;
  38. REAL(X, ix) = (x_real * b_real + x_imag * b_imag) / s;
  39. IMAG(X, ix) = (x_imag * b_real - b_imag * x_real) / s;
  40. }
  41. ix -= incX;
  42. for (i = N - 1; i > 0 && i--;) {
  43. BASE tmp_real = REAL(X, ix);
  44. BASE tmp_imag = IMAG(X, ix);
  45. INDEX jx = ix + incX;
  46. for (j = i + 1; j < N; j++) {
  47. const BASE Aij_real = CONST_REAL(Ap, TPUP(N, i, j));
  48. const BASE Aij_imag = conj * CONST_IMAG(Ap, TPUP(N, i, j));
  49. const BASE x_real = REAL(X, jx);
  50. const BASE x_imag = IMAG(X, jx);
  51. tmp_real -= Aij_real * x_real - Aij_imag * x_imag;
  52. tmp_imag -= Aij_real * x_imag + Aij_imag * x_real;
  53. jx += incX;
  54. }
  55. if (nonunit) {
  56. const BASE a_real = CONST_REAL(Ap, TPUP(N, i, i));
  57. const BASE a_imag = conj * CONST_IMAG(Ap, TPUP(N, i, i));
  58. const BASE s = xhypot(a_real, a_imag);
  59. const BASE b_real = a_real / s;
  60. const BASE b_imag = a_imag / s;
  61. REAL(X, ix) = (tmp_real * b_real + tmp_imag * b_imag) / s;
  62. IMAG(X, ix) = (tmp_imag * b_real - tmp_real * b_imag) / s;
  63. } else {
  64. REAL(X, ix) = tmp_real;
  65. IMAG(X, ix) = tmp_imag;
  66. }
  67. ix -= incX;
  68. }
  69. } else if ((order == CblasRowMajor && Trans == CblasNoTrans && Uplo == CblasLower)
  70. || (order == CblasColMajor && Trans == CblasTrans && Uplo == CblasUpper)) {
  71. /* forward substitution */
  72. INDEX ix = OFFSET(N, incX);
  73. if (nonunit) {
  74. const BASE a_real = CONST_REAL(Ap, TPLO(N, 0, 0));
  75. const BASE a_imag = conj * CONST_IMAG(Ap, TPLO(N, 0, 0));
  76. const BASE x_real = REAL(X, ix);
  77. const BASE x_imag = IMAG(X, ix);
  78. const BASE s = xhypot(a_real, a_imag);
  79. const BASE b_real = a_real / s;
  80. const BASE b_imag = a_imag / s;
  81. REAL(X, ix) = (x_real * b_real + x_imag * b_imag) / s;
  82. IMAG(X, ix) = (x_imag * b_real - b_imag * x_real) / s;
  83. }
  84. ix += incX;
  85. for (i = 1; i < N; i++) {
  86. BASE tmp_real = REAL(X, ix);
  87. BASE tmp_imag = IMAG(X, ix);
  88. INDEX jx = OFFSET(N, incX);
  89. for (j = 0; j < i; j++) {
  90. const BASE Aij_real = CONST_REAL(Ap, TPLO(N, i, j));
  91. const BASE Aij_imag = conj * CONST_IMAG(Ap, TPLO(N, i, j));
  92. const BASE x_real = REAL(X, jx);
  93. const BASE x_imag = IMAG(X, jx);
  94. tmp_real -= Aij_real * x_real - Aij_imag * x_imag;
  95. tmp_imag -= Aij_real * x_imag + Aij_imag * x_real;
  96. jx += incX;
  97. }
  98. if (nonunit) {
  99. const BASE a_real = CONST_REAL(Ap, TPLO(N, i, i));
  100. const BASE a_imag = conj * CONST_IMAG(Ap, TPLO(N, i, i));
  101. const BASE s = xhypot(a_real, a_imag);
  102. const BASE b_real = a_real / s;
  103. const BASE b_imag = a_imag / s;
  104. REAL(X, ix) = (tmp_real * b_real + tmp_imag * b_imag) / s;
  105. IMAG(X, ix) = (tmp_imag * b_real - tmp_real * b_imag) / s;
  106. } else {
  107. REAL(X, ix) = tmp_real;
  108. IMAG(X, ix) = tmp_imag;
  109. }
  110. ix += incX;
  111. }
  112. } else if ((order == CblasRowMajor && Trans == CblasTrans && Uplo == CblasUpper)
  113. || (order == CblasColMajor && Trans == CblasNoTrans && Uplo == CblasLower)) {
  114. /* form x := inv( A' )*x */
  115. /* forward substitution */
  116. INDEX ix = OFFSET(N, incX);
  117. if (nonunit) {
  118. const BASE a_real = CONST_REAL(Ap, TPUP(N, 0, 0));
  119. const BASE a_imag = conj * CONST_IMAG(Ap, TPUP(N, 0, 0));
  120. const BASE x_real = REAL(X, ix);
  121. const BASE x_imag = IMAG(X, ix);
  122. const BASE s = xhypot(a_real, a_imag);
  123. const BASE b_real = a_real / s;
  124. const BASE b_imag = a_imag / s;
  125. REAL(X, ix) = (x_real * b_real + x_imag * b_imag) / s;
  126. IMAG(X, ix) = (x_imag * b_real - b_imag * x_real) / s;
  127. }
  128. ix += incX;
  129. for (i = 1; i < N; i++) {
  130. BASE tmp_real = REAL(X, ix);
  131. BASE tmp_imag = IMAG(X, ix);
  132. INDEX jx = OFFSET(N, incX);
  133. for (j = 0; j < i; j++) {
  134. const BASE Aij_real = CONST_REAL(Ap, TPUP(N, j, i));
  135. const BASE Aij_imag = conj * CONST_IMAG(Ap, TPUP(N, j, i));
  136. const BASE x_real = REAL(X, jx);
  137. const BASE x_imag = IMAG(X, jx);
  138. tmp_real -= Aij_real * x_real - Aij_imag * x_imag;
  139. tmp_imag -= Aij_real * x_imag + Aij_imag * x_real;
  140. jx += incX;
  141. }
  142. if (nonunit) {
  143. const BASE a_real = CONST_REAL(Ap, TPUP(N, i, i));
  144. const BASE a_imag = conj * CONST_IMAG(Ap, TPUP(N, i, i));
  145. const BASE s = xhypot(a_real, a_imag);
  146. const BASE b_real = a_real / s;
  147. const BASE b_imag = a_imag / s;
  148. REAL(X, ix) = (tmp_real * b_real + tmp_imag * b_imag) / s;
  149. IMAG(X, ix) = (tmp_imag * b_real - tmp_real * b_imag) / s;
  150. } else {
  151. REAL(X, ix) = tmp_real;
  152. IMAG(X, ix) = tmp_imag;
  153. }
  154. ix += incX;
  155. }
  156. } else if ((order == CblasRowMajor && Trans == CblasTrans && Uplo == CblasLower)
  157. || (order == CblasColMajor && Trans == CblasNoTrans && Uplo == CblasUpper)) {
  158. /* backsubstitution */
  159. INDEX ix = OFFSET(N, incX) + incX * (N - 1);
  160. if (nonunit) {
  161. const BASE a_real = CONST_REAL(Ap, TPLO(N, (N - 1), (N - 1)));
  162. const BASE a_imag = conj * CONST_IMAG(Ap, TPLO(N, (N - 1), (N - 1)));
  163. const BASE x_real = REAL(X, ix);
  164. const BASE x_imag = IMAG(X, ix);
  165. const BASE s = xhypot(a_real, a_imag);
  166. const BASE b_real = a_real / s;
  167. const BASE b_imag = a_imag / s;
  168. REAL(X, ix) = (x_real * b_real + x_imag * b_imag) / s;
  169. IMAG(X, ix) = (x_imag * b_real - b_imag * x_real) / s;
  170. }
  171. ix -= incX;
  172. for (i = N - 1; i > 0 && i--;) {
  173. BASE tmp_real = REAL(X, ix);
  174. BASE tmp_imag = IMAG(X, ix);
  175. INDEX jx = ix + incX;
  176. for (j = i + 1; j < N; j++) {
  177. const BASE Aij_real = CONST_REAL(Ap, TPLO(N, j, i));
  178. const BASE Aij_imag = conj * CONST_IMAG(Ap, TPLO(N, j, i));
  179. const BASE x_real = REAL(X, jx);
  180. const BASE x_imag = IMAG(X, jx);
  181. tmp_real -= Aij_real * x_real - Aij_imag * x_imag;
  182. tmp_imag -= Aij_real * x_imag + Aij_imag * x_real;
  183. jx += incX;
  184. }
  185. if (nonunit) {
  186. const BASE a_real = CONST_REAL(Ap, TPLO(N, i, i));
  187. const BASE a_imag = conj * CONST_IMAG(Ap, TPLO(N, i, i));
  188. const BASE s = xhypot(a_real, a_imag);
  189. const BASE b_real = a_real / s;
  190. const BASE b_imag = a_imag / s;
  191. REAL(X, ix) = (tmp_real * b_real + tmp_imag * b_imag) / s;
  192. IMAG(X, ix) = (tmp_imag * b_real - tmp_real * b_imag) / s;
  193. } else {
  194. REAL(X, ix) = tmp_real;
  195. IMAG(X, ix) = tmp_imag;
  196. }
  197. ix -= incX;
  198. }
  199. } else {
  200. BLAS_ERROR("unrecognized operation");
  201. }
  202. }