gsl_cblas__source_tpsv_r.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* blas/source_tpsv_r.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. const int nonunit = (Diag == CblasNonUnit);
  22. const int Trans = (TransA != CblasConjTrans) ? TransA : CblasTrans;
  23. if (N == 0)
  24. return;
  25. /* form x := inv( A )*x */
  26. if ((order == CblasRowMajor && Trans == CblasNoTrans && Uplo == CblasUpper)
  27. || (order == CblasColMajor && Trans == CblasTrans && Uplo == CblasLower)) {
  28. /* backsubstitution */
  29. INDEX ix = OFFSET(N, incX) + incX * (N - 1);
  30. if (nonunit) {
  31. X[ix] = X[ix] / Ap[TPUP(N, (N - 1), (N - 1))];
  32. }
  33. ix -= incX;
  34. for (i = N - 1; i > 0 && i--;) {
  35. BASE tmp = X[ix];
  36. INDEX jx = ix + incX;
  37. for (j = i + 1; j < N; j++) {
  38. const BASE Aij = Ap[TPUP(N, i, j)];
  39. tmp -= Aij * X[jx];
  40. jx += incX;
  41. }
  42. if (nonunit) {
  43. X[ix] = tmp / Ap[TPUP(N, i, i)];
  44. } else {
  45. X[ix] = tmp;
  46. }
  47. ix -= incX;
  48. }
  49. } else if ((order == CblasRowMajor && Trans == CblasNoTrans && Uplo == CblasLower)
  50. || (order == CblasColMajor && Trans == CblasTrans && Uplo == CblasUpper)) {
  51. /* forward substitution */
  52. INDEX ix = OFFSET(N, incX);
  53. if (nonunit) {
  54. X[ix] = X[ix] / Ap[TPLO(N, 0, 0)];
  55. }
  56. ix += incX;
  57. for (i = 1; i < N; i++) {
  58. BASE tmp = X[ix];
  59. INDEX jx = OFFSET(N, incX);
  60. for (j = 0; j < i; j++) {
  61. const BASE Aij = Ap[TPLO(N, i, j)];
  62. tmp -= Aij * X[jx];
  63. jx += incX;
  64. }
  65. if (nonunit) {
  66. X[ix] = tmp / Ap[TPLO(N, i, j)];
  67. } else {
  68. X[ix] = tmp;
  69. }
  70. ix += incX;
  71. }
  72. } else if ((order == CblasRowMajor && Trans == CblasTrans && Uplo == CblasUpper)
  73. || (order == CblasColMajor && Trans == CblasNoTrans && Uplo == CblasLower)) {
  74. /* form x := inv( A' )*x */
  75. /* forward substitution */
  76. INDEX ix = OFFSET(N, incX);
  77. if (nonunit) {
  78. X[ix] = X[ix] / Ap[TPUP(N, 0, 0)];
  79. }
  80. ix += incX;
  81. for (i = 1; i < N; i++) {
  82. BASE tmp = X[ix];
  83. INDEX jx = OFFSET(N, incX);
  84. for (j = 0; j < i; j++) {
  85. const BASE Aji = Ap[TPUP(N, j, i)];
  86. tmp -= Aji * X[jx];
  87. jx += incX;
  88. }
  89. if (nonunit) {
  90. X[ix] = tmp / Ap[TPUP(N, i, i)];
  91. } else {
  92. X[ix] = tmp;
  93. }
  94. ix += incX;
  95. }
  96. } else if ((order == CblasRowMajor && Trans == CblasTrans && Uplo == CblasLower)
  97. || (order == CblasColMajor && Trans == CblasNoTrans && Uplo == CblasUpper)) {
  98. /* backsubstitution */
  99. INDEX ix = OFFSET(N, incX) + (N - 1) * incX;
  100. if (nonunit) {
  101. X[ix] = X[ix] / Ap[TPLO(N, (N - 1), (N - 1))];
  102. }
  103. ix -= incX;
  104. for (i = N - 1; i > 0 && i--;) {
  105. BASE tmp = X[ix];
  106. INDEX jx = ix + incX;
  107. for (j = i + 1; j < N; j++) {
  108. const BASE Aji = Ap[TPLO(N, j, i)];
  109. tmp -= Aji * X[jx];
  110. jx += incX;
  111. }
  112. if (nonunit) {
  113. X[ix] = tmp / Ap[TPLO(N, i, i)];
  114. } else {
  115. X[ix] = tmp;
  116. }
  117. ix -= incX;
  118. }
  119. } else {
  120. BLAS_ERROR("unrecognized operation");
  121. }
  122. }