gsl_cblas__source_gemv_c.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* blas/source_gemv_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. INDEX lenX, lenY;
  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 (M == 0 || N == 0)
  27. return;
  28. if ((alpha_real == 0.0 && alpha_imag == 0.0)
  29. && (beta_real == 1.0 && beta_imag == 0.0))
  30. return;
  31. if (TransA == CblasNoTrans) {
  32. lenX = N;
  33. lenY = M;
  34. } else {
  35. lenX = M;
  36. lenY = N;
  37. }
  38. /* form y := beta*y */
  39. if (beta_real == 0.0 && beta_imag == 0.0) {
  40. INDEX iy = OFFSET(lenY, incY);
  41. for (i = 0; i < lenY; i++) {
  42. REAL(Y, iy) = 0.0;
  43. IMAG(Y, iy) = 0.0;
  44. iy += incY;
  45. }
  46. } else if (!(beta_real == 1.0 && beta_imag == 0.0)) {
  47. INDEX iy = OFFSET(lenY, incY);
  48. for (i = 0; i < lenY; i++) {
  49. const BASE y_real = REAL(Y, iy);
  50. const BASE y_imag = IMAG(Y, iy);
  51. const BASE tmpR = y_real * beta_real - y_imag * beta_imag;
  52. const BASE tmpI = y_real * beta_imag + y_imag * beta_real;
  53. REAL(Y, iy) = tmpR;
  54. IMAG(Y, iy) = tmpI;
  55. iy += incY;
  56. }
  57. }
  58. if (alpha_real == 0.0 && alpha_imag == 0.0)
  59. return;
  60. if ((order == CblasRowMajor && TransA == CblasNoTrans)
  61. || (order == CblasColMajor && TransA == CblasTrans)) {
  62. /* form y := alpha*A*x + y */
  63. INDEX iy = OFFSET(lenY, incY);
  64. for (i = 0; i < lenY; i++) {
  65. BASE dotR = 0.0;
  66. BASE dotI = 0.0;
  67. INDEX ix = OFFSET(lenX, incX);
  68. for (j = 0; j < lenX; j++) {
  69. const BASE x_real = CONST_REAL(X, ix);
  70. const BASE x_imag = CONST_IMAG(X, ix);
  71. const BASE A_real = CONST_REAL(A, lda * i + j);
  72. const BASE A_imag = CONST_IMAG(A, lda * i + j);
  73. dotR += A_real * x_real - A_imag * x_imag;
  74. dotI += A_real * x_imag + A_imag * x_real;
  75. ix += incX;
  76. }
  77. REAL(Y, iy) += alpha_real * dotR - alpha_imag * dotI;
  78. IMAG(Y, iy) += alpha_real * dotI + alpha_imag * dotR;
  79. iy += incY;
  80. }
  81. } else if ((order == CblasRowMajor && TransA == CblasTrans)
  82. || (order == CblasColMajor && TransA == CblasNoTrans)) {
  83. /* form y := alpha*A'*x + y */
  84. INDEX ix = OFFSET(lenX, incX);
  85. for (j = 0; j < lenX; j++) {
  86. BASE x_real = CONST_REAL(X, ix);
  87. BASE x_imag = CONST_IMAG(X, ix);
  88. BASE tmpR = alpha_real * x_real - alpha_imag * x_imag;
  89. BASE tmpI = alpha_real * x_imag + alpha_imag * x_real;
  90. INDEX iy = OFFSET(lenY, incY);
  91. for (i = 0; i < lenY; i++) {
  92. const BASE A_real = CONST_REAL(A, lda * j + i);
  93. const BASE A_imag = CONST_IMAG(A, lda * j + i);
  94. REAL(Y, iy) += A_real * tmpR - A_imag * tmpI;
  95. IMAG(Y, iy) += A_real * tmpI + A_imag * tmpR;
  96. iy += incY;
  97. }
  98. ix += incX;
  99. }
  100. } else if (order == CblasRowMajor && TransA == CblasConjTrans) {
  101. /* form y := alpha*A^H*x + y */
  102. INDEX ix = OFFSET(lenX, incX);
  103. for (j = 0; j < lenX; j++) {
  104. BASE x_real = CONST_REAL(X, ix);
  105. BASE x_imag = CONST_IMAG(X, ix);
  106. BASE tmpR = alpha_real * x_real - alpha_imag * x_imag;
  107. BASE tmpI = alpha_real * x_imag + alpha_imag * x_real;
  108. INDEX iy = OFFSET(lenY, incY);
  109. for (i = 0; i < lenY; i++) {
  110. const BASE A_real = CONST_REAL(A, lda * j + i);
  111. const BASE A_imag = CONST_IMAG(A, lda * j + i);
  112. REAL(Y, iy) += A_real * tmpR - (-A_imag) * tmpI;
  113. IMAG(Y, iy) += A_real * tmpI + (-A_imag) * tmpR;
  114. iy += incY;
  115. }
  116. ix += incX;
  117. }
  118. } else if (order == CblasColMajor && TransA == CblasConjTrans) {
  119. /* form y := alpha*A^H*x + y */
  120. INDEX iy = OFFSET(lenY, incY);
  121. for (i = 0; i < lenY; i++) {
  122. BASE dotR = 0.0;
  123. BASE dotI = 0.0;
  124. INDEX ix = OFFSET(lenX, incX);
  125. for (j = 0; j < lenX; j++) {
  126. const BASE x_real = CONST_REAL(X, ix);
  127. const BASE x_imag = CONST_IMAG(X, ix);
  128. const BASE A_real = CONST_REAL(A, lda * i + j);
  129. const BASE A_imag = CONST_IMAG(A, lda * i + j);
  130. dotR += A_real * x_real - (-A_imag) * x_imag;
  131. dotI += A_real * x_imag + (-A_imag) * x_real;
  132. ix += incX;
  133. }
  134. REAL(Y, iy) += alpha_real * dotR - alpha_imag * dotI;
  135. IMAG(Y, iy) += alpha_real * dotI + alpha_imag * dotR;
  136. iy += incY;
  137. }
  138. } else {
  139. BLAS_ERROR("unrecognized operation");
  140. }
  141. }