gsl_cblas__source_trsv_r.h 3.7 KB

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