gsl_cblas__source_spmv.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* blas/source_spmv.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. if (alpha == 0.0 && beta == 1.0)
  22. return;
  23. /* form y := beta*y */
  24. if (beta == 0.0) {
  25. INDEX iy = OFFSET(N, incY);
  26. for (i = 0; i < N; i++) {
  27. Y[iy] = 0.0;
  28. iy += incY;
  29. }
  30. } else if (beta != 1.0) {
  31. INDEX iy = OFFSET(N, incY);
  32. for (i = 0; i < N; i++) {
  33. Y[iy] *= beta;
  34. iy += incY;
  35. }
  36. }
  37. if (alpha == 0.0)
  38. return;
  39. /* form y := alpha*A*x + y */
  40. if ((order == CblasRowMajor && Uplo == CblasUpper)
  41. || (order == CblasColMajor && Uplo == CblasLower)) {
  42. INDEX ix = OFFSET(N, incX);
  43. INDEX iy = OFFSET(N, incY);
  44. for (i = 0; i < N; i++) {
  45. BASE tmp1 = alpha * X[ix];
  46. BASE tmp2 = 0.0;
  47. const INDEX j_min = i + 1;
  48. const INDEX j_max = N;
  49. INDEX jx = OFFSET(N, incX) + j_min * incX;
  50. INDEX jy = OFFSET(N, incY) + j_min * incY;
  51. Y[iy] += tmp1 * Ap[TPUP(N, i, i)];
  52. for (j = j_min; j < j_max; j++) {
  53. const BASE apk = Ap[TPUP(N, i, j)];
  54. Y[jy] += tmp1 * apk;
  55. tmp2 += apk * X[jx];
  56. jy += incY;
  57. jx += incX;
  58. }
  59. Y[iy] += alpha * tmp2;
  60. ix += incX;
  61. iy += incY;
  62. }
  63. } else if ((order == CblasRowMajor && Uplo == CblasLower)
  64. || (order == CblasColMajor && Uplo == CblasUpper)) {
  65. INDEX ix = OFFSET(N, incX);
  66. INDEX iy = OFFSET(N, incY);
  67. for (i = 0; i < N; i++) {
  68. BASE tmp1 = alpha * X[ix];
  69. BASE tmp2 = 0.0;
  70. const INDEX j_min = 0;
  71. const INDEX j_max = i;
  72. INDEX jx = OFFSET(N, incX) + j_min * incX;
  73. INDEX jy = OFFSET(N, incY) + j_min * incY;
  74. Y[iy] += tmp1 * Ap[TPLO(N, i, i)];
  75. for (j = j_min; j < j_max; j++) {
  76. const BASE apk = Ap[TPLO(N, i, j)];
  77. Y[jy] += tmp1 * apk;
  78. tmp2 += apk * X[jx];
  79. jy += incY;
  80. jx += incX;
  81. }
  82. Y[iy] += alpha * tmp2;
  83. ix += incX;
  84. iy += incY;
  85. }
  86. } else {
  87. BLAS_ERROR("unrecognized operation");
  88. }
  89. }