gsl_cblas__source_her2.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* blas/source_her2.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. if (alpha_real == 0.0 && alpha_imag == 0.0)
  25. return;
  26. if ((order == CblasRowMajor && Uplo == CblasUpper)
  27. || (order == CblasColMajor && Uplo == CblasLower)) {
  28. INDEX ix = OFFSET(N, incX);
  29. INDEX iy = OFFSET(N, incY);
  30. for (i = 0; i < N; i++) {
  31. const BASE Xi_real = CONST_REAL(X, ix);
  32. const BASE Xi_imag = CONST_IMAG(X, ix);
  33. /* tmp1 = alpha Xi */
  34. const BASE tmp1_real = alpha_real * Xi_real - alpha_imag * Xi_imag;
  35. const BASE tmp1_imag = alpha_imag * Xi_real + alpha_real * Xi_imag;
  36. const BASE Yi_real = CONST_REAL(Y, iy);
  37. const BASE Yi_imag = CONST_IMAG(Y, iy);
  38. /* tmp2 = conj(alpha) Yi */
  39. const BASE tmp2_real = alpha_real * Yi_real + alpha_imag * Yi_imag;
  40. const BASE tmp2_imag = -alpha_imag * Yi_real + alpha_real * Yi_imag;
  41. INDEX jx = ix + incX;
  42. INDEX jy = iy + incY;
  43. /* Aij = alpha*Xi*conj(Yj) + conj(alpha)*Yi*conj(Xj) */
  44. REAL(A, lda * i + i) += 2 * (tmp1_real * Yi_real + tmp1_imag * Yi_imag);
  45. IMAG(A, lda * i + i) = 0;
  46. for (j = i + 1; j < N; j++) {
  47. const BASE Xj_real = CONST_REAL(X, jx);
  48. const BASE Xj_imag = CONST_IMAG(X, jx);
  49. const BASE Yj_real = CONST_REAL(Y, jy);
  50. const BASE Yj_imag = CONST_IMAG(Y, jy);
  51. REAL(A, lda * i + j) += ((tmp1_real * Yj_real + tmp1_imag * Yj_imag)
  52. + (tmp2_real * Xj_real + tmp2_imag * Xj_imag));
  53. IMAG(A, lda * i + j) +=
  54. conj * ((tmp1_imag * Yj_real - tmp1_real * Yj_imag) +
  55. (tmp2_imag * Xj_real - tmp2_real * Xj_imag));
  56. jx += incX;
  57. jy += incY;
  58. }
  59. ix += incX;
  60. iy += incY;
  61. }
  62. } else if ((order == CblasRowMajor && Uplo == CblasLower)
  63. || (order == CblasColMajor && Uplo == CblasUpper)) {
  64. INDEX ix = OFFSET(N, incX);
  65. INDEX iy = OFFSET(N, incY);
  66. for (i = 0; i < N; i++) {
  67. const BASE Xi_real = CONST_REAL(X, ix);
  68. const BASE Xi_imag = CONST_IMAG(X, ix);
  69. const BASE tmp1_real = alpha_real * Xi_real - alpha_imag * Xi_imag;
  70. const BASE tmp1_imag = alpha_imag * Xi_real + alpha_real * Xi_imag;
  71. const BASE Yi_real = CONST_REAL(Y, iy);
  72. const BASE Yi_imag = CONST_IMAG(Y, iy);
  73. const BASE tmp2_real = alpha_real * Yi_real + alpha_imag * Yi_imag;
  74. const BASE tmp2_imag = -alpha_imag * Yi_real + alpha_real * Yi_imag;
  75. INDEX jx = OFFSET(N, incX);
  76. INDEX jy = OFFSET(N, incY);
  77. /* Aij = alpha*Xi*conj(Yj) + conj(alpha)*Yi*conj(Xj) */
  78. for (j = 0; j < i; j++) {
  79. const BASE Xj_real = CONST_REAL(X, jx);
  80. const BASE Xj_imag = CONST_IMAG(X, jx);
  81. const BASE Yj_real = CONST_REAL(Y, jy);
  82. const BASE Yj_imag = CONST_IMAG(Y, jy);
  83. REAL(A, lda * i + j) += ((tmp1_real * Yj_real + tmp1_imag * Yj_imag)
  84. + (tmp2_real * Xj_real + tmp2_imag * Xj_imag));
  85. IMAG(A, lda * i + j) +=
  86. conj * ((tmp1_imag * Yj_real - tmp1_real * Yj_imag) +
  87. (tmp2_imag * Xj_real - tmp2_real * Xj_imag));
  88. jx += incX;
  89. jy += incY;
  90. }
  91. REAL(A, lda * i + i) += 2 * (tmp1_real * Yi_real + tmp1_imag * Yi_imag);
  92. IMAG(A, lda * i + i) = 0;
  93. ix += incX;
  94. iy += incY;
  95. }
  96. } else {
  97. BLAS_ERROR("unrecognized operation");
  98. }
  99. }