gsl_cblas__source_tpmv_c.h 5.9 KB

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