schex.f 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. *DECK SCHEX
  2. SUBROUTINE SCHEX (R, LDR, P, K, L, Z, LDZ, NZ, C, S, JOB)
  3. C***BEGIN PROLOGUE SCHEX
  4. C***PURPOSE Update the Cholesky factorization A=TRANS(R)*R of A
  5. C positive definite matrix A of order P under diagonal
  6. C permutations of the form TRANS(E)*A*E, where E is a
  7. C permutation matrix.
  8. C***LIBRARY SLATEC (LINPACK)
  9. C***CATEGORY D7B
  10. C***TYPE SINGLE PRECISION (SCHEX-S, DCHEX-D, CCHEX-C)
  11. C***KEYWORDS CHOLESKY DECOMPOSITION, EXCHANGE, LINEAR ALGEBRA, LINPACK,
  12. C MATRIX, POSITIVE DEFINITE
  13. C***AUTHOR Stewart, G. W., (U. of Maryland)
  14. C***DESCRIPTION
  15. C
  16. C SCHEX updates the Cholesky factorization
  17. C
  18. C A = TRANS(R)*R
  19. C
  20. C of a positive definite matrix A of order P under diagonal
  21. C permutations of the form
  22. C
  23. C TRANS(E)*A*E
  24. C
  25. C where E is a permutation matrix. Specifically, given
  26. C an upper triangular matrix R and a permutation matrix
  27. C E (which is specified by K, L, and JOB), SCHEX determines
  28. C an orthogonal matrix U such that
  29. C
  30. C U*R*E = RR,
  31. C
  32. C where RR is upper triangular. At the users option, the
  33. C transformation U will be multiplied into the array Z.
  34. C If A = TRANS(X)*X, so that R is the triangular part of the
  35. C QR factorization of X, then RR is the triangular part of the
  36. C QR factorization of X*E, i.e., X with its columns permuted.
  37. C For a less terse description of what SCHEX does and how
  38. C it may be applied, see the LINPACK guide.
  39. C
  40. C The matrix Q is determined as the product U(L-K)*...*U(1)
  41. C of plane rotations of the form
  42. C
  43. C ( C(I) S(I) )
  44. C ( ) ,
  45. C ( -S(I) C(I) )
  46. C
  47. C where C(I) is real. The rows these rotations operate on
  48. C are described below.
  49. C
  50. C There are two types of permutations, which are determined
  51. C by the value of JOB.
  52. C
  53. C 1. Right circular shift (JOB = 1).
  54. C
  55. C The columns are rearranged in the following order.
  56. C
  57. C 1,...,K-1,L,K,K+1,...,L-1,L+1,...,P.
  58. C
  59. C U is the product of L-K rotations U(I), where U(I)
  60. C acts in the (L-I,L-I+1)-plane.
  61. C
  62. C 2. Left circular shift (JOB = 2).
  63. C The columns are rearranged in the following order
  64. C
  65. C 1,...,K-1,K+1,K+2,...,L,K,L+1,...,P.
  66. C
  67. C U is the product of L-K rotations U(I), where U(I)
  68. C acts in the (K+I-1,K+I)-plane.
  69. C
  70. C On Entry
  71. C
  72. C R REAL(LDR,P), where LDR .GE. P.
  73. C R contains the upper triangular factor
  74. C that is to be updated. Elements of R
  75. C below the diagonal are not referenced.
  76. C
  77. C LDR INTEGER.
  78. C LDR is the leading dimension of the array R.
  79. C
  80. C P INTEGER.
  81. C P is the order of the matrix R.
  82. C
  83. C K INTEGER.
  84. C K is the first column to be permuted.
  85. C
  86. C L INTEGER.
  87. C L is the last column to be permuted.
  88. C L must be strictly greater than K.
  89. C
  90. C Z REAL(LDZ,NZ), where LDZ.GE.P.
  91. C Z is an array of NZ P-vectors into which the
  92. C transformation U is multiplied. Z is
  93. C not referenced if NZ = 0.
  94. C
  95. C LDZ INTEGER.
  96. C LDZ is the leading dimension of the array Z.
  97. C
  98. C NZ INTEGER.
  99. C NZ is the number of columns of the matrix Z.
  100. C
  101. C JOB INTEGER.
  102. C JOB determines the type of permutation.
  103. C JOB = 1 right circular shift.
  104. C JOB = 2 left circular shift.
  105. C
  106. C On Return
  107. C
  108. C R contains the updated factor.
  109. C
  110. C Z contains the updated matrix Z.
  111. C
  112. C C REAL(P).
  113. C C contains the cosines of the transforming rotations.
  114. C
  115. C S REAL(P).
  116. C S contains the sines of the transforming rotations.
  117. C
  118. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  119. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  120. C***ROUTINES CALLED SROTG
  121. C***REVISION HISTORY (YYMMDD)
  122. C 780814 DATE WRITTEN
  123. C 890531 Changed all specific intrinsics to generic. (WRB)
  124. C 890531 REVISION DATE from Version 3.2
  125. C 891214 Prologue converted to Version 4.0 format. (BAB)
  126. C 900326 Removed duplicate information from DESCRIPTION section.
  127. C (WRB)
  128. C 920501 Reformatted the REFERENCES section. (WRB)
  129. C***END PROLOGUE SCHEX
  130. INTEGER LDR,P,K,L,LDZ,NZ,JOB
  131. REAL R(LDR,*),Z(LDZ,*),S(*)
  132. REAL C(*)
  133. C
  134. INTEGER I,II,IL,IU,J,JJ,KM1,KP1,LMK,LM1
  135. REAL T
  136. C
  137. C INITIALIZE
  138. C
  139. C***FIRST EXECUTABLE STATEMENT SCHEX
  140. KM1 = K - 1
  141. KP1 = K + 1
  142. LMK = L - K
  143. LM1 = L - 1
  144. C
  145. C PERFORM THE APPROPRIATE TASK.
  146. C
  147. GO TO (10,130), JOB
  148. C
  149. C RIGHT CIRCULAR SHIFT.
  150. C
  151. 10 CONTINUE
  152. C
  153. C REORDER THE COLUMNS.
  154. C
  155. DO 20 I = 1, L
  156. II = L - I + 1
  157. S(I) = R(II,L)
  158. 20 CONTINUE
  159. DO 40 JJ = K, LM1
  160. J = LM1 - JJ + K
  161. DO 30 I = 1, J
  162. R(I,J+1) = R(I,J)
  163. 30 CONTINUE
  164. R(J+1,J+1) = 0.0E0
  165. 40 CONTINUE
  166. IF (K .EQ. 1) GO TO 60
  167. DO 50 I = 1, KM1
  168. II = L - I + 1
  169. R(I,K) = S(II)
  170. 50 CONTINUE
  171. 60 CONTINUE
  172. C
  173. C CALCULATE THE ROTATIONS.
  174. C
  175. T = S(1)
  176. DO 70 I = 1, LMK
  177. CALL SROTG(S(I+1),T,C(I),S(I))
  178. T = S(I+1)
  179. 70 CONTINUE
  180. R(K,K) = T
  181. DO 90 J = KP1, P
  182. IL = MAX(1,L-J+1)
  183. DO 80 II = IL, LMK
  184. I = L - II
  185. T = C(II)*R(I,J) + S(II)*R(I+1,J)
  186. R(I+1,J) = C(II)*R(I+1,J) - S(II)*R(I,J)
  187. R(I,J) = T
  188. 80 CONTINUE
  189. 90 CONTINUE
  190. C
  191. C IF REQUIRED, APPLY THE TRANSFORMATIONS TO Z.
  192. C
  193. IF (NZ .LT. 1) GO TO 120
  194. DO 110 J = 1, NZ
  195. DO 100 II = 1, LMK
  196. I = L - II
  197. T = C(II)*Z(I,J) + S(II)*Z(I+1,J)
  198. Z(I+1,J) = C(II)*Z(I+1,J) - S(II)*Z(I,J)
  199. Z(I,J) = T
  200. 100 CONTINUE
  201. 110 CONTINUE
  202. 120 CONTINUE
  203. GO TO 260
  204. C
  205. C LEFT CIRCULAR SHIFT
  206. C
  207. 130 CONTINUE
  208. C
  209. C REORDER THE COLUMNS
  210. C
  211. DO 140 I = 1, K
  212. II = LMK + I
  213. S(II) = R(I,K)
  214. 140 CONTINUE
  215. DO 160 J = K, LM1
  216. DO 150 I = 1, J
  217. R(I,J) = R(I,J+1)
  218. 150 CONTINUE
  219. JJ = J - KM1
  220. S(JJ) = R(J+1,J+1)
  221. 160 CONTINUE
  222. DO 170 I = 1, K
  223. II = LMK + I
  224. R(I,L) = S(II)
  225. 170 CONTINUE
  226. DO 180 I = KP1, L
  227. R(I,L) = 0.0E0
  228. 180 CONTINUE
  229. C
  230. C REDUCTION LOOP.
  231. C
  232. DO 220 J = K, P
  233. IF (J .EQ. K) GO TO 200
  234. C
  235. C APPLY THE ROTATIONS.
  236. C
  237. IU = MIN(J-1,L-1)
  238. DO 190 I = K, IU
  239. II = I - K + 1
  240. T = C(II)*R(I,J) + S(II)*R(I+1,J)
  241. R(I+1,J) = C(II)*R(I+1,J) - S(II)*R(I,J)
  242. R(I,J) = T
  243. 190 CONTINUE
  244. 200 CONTINUE
  245. IF (J .GE. L) GO TO 210
  246. JJ = J - K + 1
  247. T = S(JJ)
  248. CALL SROTG(R(J,J),T,C(JJ),S(JJ))
  249. 210 CONTINUE
  250. 220 CONTINUE
  251. C
  252. C APPLY THE ROTATIONS TO Z.
  253. C
  254. IF (NZ .LT. 1) GO TO 250
  255. DO 240 J = 1, NZ
  256. DO 230 I = K, LM1
  257. II = I - KM1
  258. T = C(II)*Z(I,J) + S(II)*Z(I+1,J)
  259. Z(I+1,J) = C(II)*Z(I+1,J) - S(II)*Z(I,J)
  260. Z(I,J) = T
  261. 230 CONTINUE
  262. 240 CONTINUE
  263. 250 CONTINUE
  264. 260 CONTINUE
  265. RETURN
  266. END