gsl_cblas__source_hpmv.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* blas/source_hpmv.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 = (order == CblasColMajor) ? -1 : 1;
  21. INDEX i, j;
  22. const BASE alpha_real = CONST_REAL0(alpha);
  23. const BASE alpha_imag = CONST_IMAG0(alpha);
  24. const BASE beta_real = CONST_REAL0(beta);
  25. const BASE beta_imag = CONST_IMAG0(beta);
  26. if ((alpha_real == 0.0 && alpha_imag == 0.0)
  27. && (beta_real == 1.0 && beta_imag == 0.0))
  28. return;
  29. /* form y := beta*y */
  30. if (beta_real == 0.0 && beta_imag == 0.0) {
  31. INDEX iy = OFFSET(N, incY);
  32. for (i = 0; i < N; i++) {
  33. REAL(Y, iy) = 0.0;
  34. IMAG(Y, iy) = 0.0;
  35. iy += incY;
  36. }
  37. } else if (!(beta_real == 1.0 && beta_imag == 0.0)) {
  38. INDEX iy = OFFSET(N, incY);
  39. for (i = 0; i < N; i++) {
  40. const BASE y_real = REAL(Y, iy);
  41. const BASE y_imag = IMAG(Y, iy);
  42. const BASE tmpR = y_real * beta_real - y_imag * beta_imag;
  43. const BASE tmpI = y_real * beta_imag + y_imag * beta_real;
  44. REAL(Y, iy) = tmpR;
  45. IMAG(Y, iy) = tmpI;
  46. iy += incY;
  47. }
  48. }
  49. if (alpha_real == 0.0 && alpha_imag == 0.0)
  50. return;
  51. /* form y := alpha*A*x + y */
  52. if ((order == CblasRowMajor && Uplo == CblasUpper)
  53. || (order == CblasColMajor && Uplo == CblasLower)) {
  54. INDEX ix = OFFSET(N, incX);
  55. INDEX iy = OFFSET(N, incY);
  56. for (i = 0; i < N; i++) {
  57. BASE x_real = CONST_REAL(X, ix);
  58. BASE x_imag = CONST_IMAG(X, ix);
  59. BASE temp1_real = alpha_real * x_real - alpha_imag * x_imag;
  60. BASE temp1_imag = alpha_real * x_imag + alpha_imag * x_real;
  61. BASE temp2_real = 0.0;
  62. BASE temp2_imag = 0.0;
  63. const INDEX j_min = i + 1;
  64. const INDEX j_max = N;
  65. INDEX jx = OFFSET(N, incX) + j_min * incX;
  66. INDEX jy = OFFSET(N, incY) + j_min * incY;
  67. BASE Aii_real = CONST_REAL(Ap, TPUP(N, i, i));
  68. /* Aii_imag is zero */
  69. REAL(Y, iy) += temp1_real * Aii_real;
  70. IMAG(Y, iy) += temp1_imag * Aii_real;
  71. for (j = j_min; j < j_max; j++) {
  72. BASE Aij_real = CONST_REAL(Ap, TPUP(N, i, j));
  73. BASE Aij_imag = conj * CONST_IMAG(Ap, TPUP(N, i, j));
  74. REAL(Y, jy) += temp1_real * Aij_real - temp1_imag * (-Aij_imag);
  75. IMAG(Y, jy) += temp1_real * (-Aij_imag) + temp1_imag * Aij_real;
  76. x_real = CONST_REAL(X, jx);
  77. x_imag = CONST_IMAG(X, jx);
  78. temp2_real += x_real * Aij_real - x_imag * Aij_imag;
  79. temp2_imag += x_real * Aij_imag + x_imag * Aij_real;
  80. jx += incX;
  81. jy += incY;
  82. }
  83. REAL(Y, iy) += alpha_real * temp2_real - alpha_imag * temp2_imag;
  84. IMAG(Y, iy) += alpha_real * temp2_imag + alpha_imag * temp2_real;
  85. ix += incX;
  86. iy += incY;
  87. }
  88. } else if ((order == CblasRowMajor && Uplo == CblasLower)
  89. || (order == CblasColMajor && Uplo == CblasUpper)) {
  90. INDEX ix = OFFSET(N, incX);
  91. INDEX iy = OFFSET(N, incY);
  92. for (i = 0; i < N; i++) {
  93. BASE x_real = CONST_REAL(X, ix);
  94. BASE x_imag = CONST_IMAG(X, ix);
  95. BASE temp1_real = alpha_real * x_real - alpha_imag * x_imag;
  96. BASE temp1_imag = alpha_real * x_imag + alpha_imag * x_real;
  97. BASE temp2_real = 0.0;
  98. BASE temp2_imag = 0.0;
  99. const INDEX j_min = 0;
  100. const INDEX j_max = i;
  101. INDEX jx = OFFSET(N, incX) + j_min * incX;
  102. INDEX jy = OFFSET(N, incY) + j_min * incY;
  103. BASE Aii_real = CONST_REAL(Ap, TPLO(N, i, i));
  104. /* Aii_imag is zero */
  105. REAL(Y, iy) += temp1_real * Aii_real;
  106. IMAG(Y, iy) += temp1_imag * Aii_real;
  107. for (j = j_min; j < j_max; j++) {
  108. BASE Aij_real = CONST_REAL(Ap, TPLO(N, i, j));
  109. BASE Aij_imag = conj * CONST_IMAG(Ap, TPLO(N, i, j));
  110. REAL(Y, jy) += temp1_real * Aij_real - temp1_imag * (-Aij_imag);
  111. IMAG(Y, jy) += temp1_real * (-Aij_imag) + temp1_imag * Aij_real;
  112. x_real = CONST_REAL(X, jx);
  113. x_imag = CONST_IMAG(X, jx);
  114. temp2_real += x_real * Aij_real - x_imag * Aij_imag;
  115. temp2_imag += x_real * Aij_imag + x_imag * Aij_real;
  116. jx += incX;
  117. jy += incY;
  118. }
  119. REAL(Y, iy) += alpha_real * temp2_real - alpha_imag * temp2_imag;
  120. IMAG(Y, iy) += alpha_real * temp2_imag + alpha_imag * temp2_real;
  121. ix += incX;
  122. iy += incY;
  123. }
  124. } else {
  125. BLAS_ERROR("unrecognized operation");
  126. }
  127. }