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