You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

296 lines
9.2 KiB

  1. SUBROUTINE DTPSV(UPLO,TRANS,DIAG,N,AP,X,INCX)
  2. * .. Scalar Arguments ..
  3. INTEGER INCX,N
  4. CHARACTER DIAG,TRANS,UPLO
  5. * ..
  6. * .. Array Arguments ..
  7. DOUBLE PRECISION AP(*),X(*)
  8. * ..
  9. *
  10. * Purpose
  11. * =======
  12. *
  13. * DTPSV solves one of the systems of equations
  14. *
  15. * A*x = b, or A'*x = b,
  16. *
  17. * where b and x are n element vectors and A is an n by n unit, or
  18. * non-unit, upper or lower triangular matrix, supplied in packed form.
  19. *
  20. * No test for singularity or near-singularity is included in this
  21. * routine. Such tests must be performed before calling this routine.
  22. *
  23. * Arguments
  24. * ==========
  25. *
  26. * UPLO - CHARACTER*1.
  27. * On entry, UPLO specifies whether the matrix is an upper or
  28. * lower triangular matrix as follows:
  29. *
  30. * UPLO = 'U' or 'u' A is an upper triangular matrix.
  31. *
  32. * UPLO = 'L' or 'l' A is a lower triangular matrix.
  33. *
  34. * Unchanged on exit.
  35. *
  36. * TRANS - CHARACTER*1.
  37. * On entry, TRANS specifies the equations to be solved as
  38. * follows:
  39. *
  40. * TRANS = 'N' or 'n' A*x = b.
  41. *
  42. * TRANS = 'T' or 't' A'*x = b.
  43. *
  44. * TRANS = 'C' or 'c' A'*x = b.
  45. *
  46. * Unchanged on exit.
  47. *
  48. * DIAG - CHARACTER*1.
  49. * On entry, DIAG specifies whether or not A is unit
  50. * triangular as follows:
  51. *
  52. * DIAG = 'U' or 'u' A is assumed to be unit triangular.
  53. *
  54. * DIAG = 'N' or 'n' A is not assumed to be unit
  55. * triangular.
  56. *
  57. * Unchanged on exit.
  58. *
  59. * N - INTEGER.
  60. * On entry, N specifies the order of the matrix A.
  61. * N must be at least zero.
  62. * Unchanged on exit.
  63. *
  64. * AP - DOUBLE PRECISION array of DIMENSION at least
  65. * ( ( n*( n + 1 ) )/2 ).
  66. * Before entry with UPLO = 'U' or 'u', the array AP must
  67. * contain the upper triangular matrix packed sequentially,
  68. * column by column, so that AP( 1 ) contains a( 1, 1 ),
  69. * AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 )
  70. * respectively, and so on.
  71. * Before entry with UPLO = 'L' or 'l', the array AP must
  72. * contain the lower triangular matrix packed sequentially,
  73. * column by column, so that AP( 1 ) contains a( 1, 1 ),
  74. * AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 )
  75. * respectively, and so on.
  76. * Note that when DIAG = 'U' or 'u', the diagonal elements of
  77. * A are not referenced, but are assumed to be unity.
  78. * Unchanged on exit.
  79. *
  80. * X - DOUBLE PRECISION array of dimension at least
  81. * ( 1 + ( n - 1 )*abs( INCX ) ).
  82. * Before entry, the incremented array X must contain the n
  83. * element right-hand side vector b. On exit, X is overwritten
  84. * with the solution vector x.
  85. *
  86. * INCX - INTEGER.
  87. * On entry, INCX specifies the increment for the elements of
  88. * X. INCX must not be zero.
  89. * Unchanged on exit.
  90. *
  91. * Further Details
  92. * ===============
  93. *
  94. * Level 2 Blas routine.
  95. *
  96. * -- Written on 22-October-1986.
  97. * Jack Dongarra, Argonne National Lab.
  98. * Jeremy Du Croz, Nag Central Office.
  99. * Sven Hammarling, Nag Central Office.
  100. * Richard Hanson, Sandia National Labs.
  101. *
  102. * =====================================================================
  103. *
  104. * .. Parameters ..
  105. DOUBLE PRECISION ZERO
  106. PARAMETER (ZERO=0.0D+0)
  107. * ..
  108. * .. Local Scalars ..
  109. DOUBLE PRECISION TEMP
  110. INTEGER I,INFO,IX,J,JX,K,KK,KX
  111. LOGICAL NOUNIT
  112. * ..
  113. * .. External Functions ..
  114. LOGICAL LSAME
  115. EXTERNAL LSAME
  116. * ..
  117. * .. External Subroutines ..
  118. EXTERNAL XERBLA
  119. * ..
  120. *
  121. * Test the input parameters.
  122. *
  123. INFO = 0
  124. IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
  125. INFO = 1
  126. ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND.
  127. + .NOT.LSAME(TRANS,'C')) THEN
  128. INFO = 2
  129. ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN
  130. INFO = 3
  131. ELSE IF (N.LT.0) THEN
  132. INFO = 4
  133. ELSE IF (INCX.EQ.0) THEN
  134. INFO = 7
  135. END IF
  136. IF (INFO.NE.0) THEN
  137. CALL XERBLA('DTPSV ',INFO)
  138. RETURN
  139. END IF
  140. *
  141. * Quick return if possible.
  142. *
  143. IF (N.EQ.0) RETURN
  144. *
  145. NOUNIT = LSAME(DIAG,'N')
  146. *
  147. * Set up the start point in X if the increment is not unity. This
  148. * will be ( N - 1 )*INCX too small for descending loops.
  149. *
  150. IF (INCX.LE.0) THEN
  151. KX = 1 - (N-1)*INCX
  152. ELSE IF (INCX.NE.1) THEN
  153. KX = 1
  154. END IF
  155. *
  156. * Start the operations. In this version the elements of AP are
  157. * accessed sequentially with one pass through AP.
  158. *
  159. IF (LSAME(TRANS,'N')) THEN
  160. *
  161. * Form x := inv( A )*x.
  162. *
  163. IF (LSAME(UPLO,'U')) THEN
  164. KK = (N* (N+1))/2
  165. IF (INCX.EQ.1) THEN
  166. DO 20 J = N,1,-1
  167. IF (X(J).NE.ZERO) THEN
  168. IF (NOUNIT) X(J) = X(J)/AP(KK)
  169. TEMP = X(J)
  170. K = KK - 1
  171. DO 10 I = J - 1,1,-1
  172. X(I) = X(I) - TEMP*AP(K)
  173. K = K - 1
  174. 10 CONTINUE
  175. END IF
  176. KK = KK - J
  177. 20 CONTINUE
  178. ELSE
  179. JX = KX + (N-1)*INCX
  180. DO 40 J = N,1,-1
  181. IF (X(JX).NE.ZERO) THEN
  182. IF (NOUNIT) X(JX) = X(JX)/AP(KK)
  183. TEMP = X(JX)
  184. IX = JX
  185. DO 30 K = KK - 1,KK - J + 1,-1
  186. IX = IX - INCX
  187. X(IX) = X(IX) - TEMP*AP(K)
  188. 30 CONTINUE
  189. END IF
  190. JX = JX - INCX
  191. KK = KK - J
  192. 40 CONTINUE
  193. END IF
  194. ELSE
  195. KK = 1
  196. IF (INCX.EQ.1) THEN
  197. DO 60 J = 1,N
  198. IF (X(J).NE.ZERO) THEN
  199. IF (NOUNIT) X(J) = X(J)/AP(KK)
  200. TEMP = X(J)
  201. K = KK + 1
  202. DO 50 I = J + 1,N
  203. X(I) = X(I) - TEMP*AP(K)
  204. K = K + 1
  205. 50 CONTINUE
  206. END IF
  207. KK = KK + (N-J+1)
  208. 60 CONTINUE
  209. ELSE
  210. JX = KX
  211. DO 80 J = 1,N
  212. IF (X(JX).NE.ZERO) THEN
  213. IF (NOUNIT) X(JX) = X(JX)/AP(KK)
  214. TEMP = X(JX)
  215. IX = JX
  216. DO 70 K = KK + 1,KK + N - J
  217. IX = IX + INCX
  218. X(IX) = X(IX) - TEMP*AP(K)
  219. 70 CONTINUE
  220. END IF
  221. JX = JX + INCX
  222. KK = KK + (N-J+1)
  223. 80 CONTINUE
  224. END IF
  225. END IF
  226. ELSE
  227. *
  228. * Form x := inv( A' )*x.
  229. *
  230. IF (LSAME(UPLO,'U')) THEN
  231. KK = 1
  232. IF (INCX.EQ.1) THEN
  233. DO 100 J = 1,N
  234. TEMP = X(J)
  235. K = KK
  236. DO 90 I = 1,J - 1
  237. TEMP = TEMP - AP(K)*X(I)
  238. K = K + 1
  239. 90 CONTINUE
  240. IF (NOUNIT) TEMP = TEMP/AP(KK+J-1)
  241. X(J) = TEMP
  242. KK = KK + J
  243. 100 CONTINUE
  244. ELSE
  245. JX = KX
  246. DO 120 J = 1,N
  247. TEMP = X(JX)
  248. IX = KX
  249. DO 110 K = KK,KK + J - 2
  250. TEMP = TEMP - AP(K)*X(IX)
  251. IX = IX + INCX
  252. 110 CONTINUE
  253. IF (NOUNIT) TEMP = TEMP/AP(KK+J-1)
  254. X(JX) = TEMP
  255. JX = JX + INCX
  256. KK = KK + J
  257. 120 CONTINUE
  258. END IF
  259. ELSE
  260. KK = (N* (N+1))/2
  261. IF (INCX.EQ.1) THEN
  262. DO 140 J = N,1,-1
  263. TEMP = X(J)
  264. K = KK
  265. DO 130 I = N,J + 1,-1
  266. TEMP = TEMP - AP(K)*X(I)
  267. K = K - 1
  268. 130 CONTINUE
  269. IF (NOUNIT) TEMP = TEMP/AP(KK-N+J)
  270. X(J) = TEMP
  271. KK = KK - (N-J+1)
  272. 140 CONTINUE
  273. ELSE
  274. KX = KX + (N-1)*INCX
  275. JX = KX
  276. DO 160 J = N,1,-1
  277. TEMP = X(JX)
  278. IX = KX
  279. DO 150 K = KK,KK - (N- (J+1)),-1
  280. TEMP = TEMP - AP(K)*X(IX)
  281. IX = IX - INCX
  282. 150 CONTINUE
  283. IF (NOUNIT) TEMP = TEMP/AP(KK-N+J)
  284. X(JX) = TEMP
  285. JX = JX - INCX
  286. KK = KK - (N-J+1)
  287. 160 CONTINUE
  288. END IF
  289. END IF
  290. END IF
  291. *
  292. RETURN
  293. *
  294. * End of DTPSV .
  295. *
  296. END