gsl_cblas__source_gbmv_c.h 5.8 KB

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