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

sla_porcond.f 8.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. *> \brief \b SLA_PORCOND estimates the Skeel condition number for a symmetric positive-definite matrix.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLA_PORCOND + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sla_porcond.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sla_porcond.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sla_porcond.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * REAL FUNCTION SLA_PORCOND( UPLO, N, A, LDA, AF, LDAF, CMODE, C,
  22. * INFO, WORK, IWORK )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER UPLO
  26. * INTEGER N, LDA, LDAF, INFO, CMODE
  27. * REAL A( LDA, * ), AF( LDAF, * ), WORK( * ),
  28. * $ C( * )
  29. * ..
  30. * .. Array Arguments ..
  31. * INTEGER IWORK( * )
  32. * ..
  33. *
  34. *
  35. *> \par Purpose:
  36. * =============
  37. *>
  38. *> \verbatim
  39. *>
  40. *> SLA_PORCOND Estimates the Skeel condition number of op(A) * op2(C)
  41. *> where op2 is determined by CMODE as follows
  42. *> CMODE = 1 op2(C) = C
  43. *> CMODE = 0 op2(C) = I
  44. *> CMODE = -1 op2(C) = inv(C)
  45. *> The Skeel condition number cond(A) = norminf( |inv(A)||A| )
  46. *> is computed by computing scaling factors R such that
  47. *> diag(R)*A*op2(C) is row equilibrated and computing the standard
  48. *> infinity-norm condition number.
  49. *> \endverbatim
  50. *
  51. * Arguments:
  52. * ==========
  53. *
  54. *> \param[in] UPLO
  55. *> \verbatim
  56. *> UPLO is CHARACTER*1
  57. *> = 'U': Upper triangle of A is stored;
  58. *> = 'L': Lower triangle of A is stored.
  59. *> \endverbatim
  60. *>
  61. *> \param[in] N
  62. *> \verbatim
  63. *> N is INTEGER
  64. *> The number of linear equations, i.e., the order of the
  65. *> matrix A. N >= 0.
  66. *> \endverbatim
  67. *>
  68. *> \param[in] A
  69. *> \verbatim
  70. *> A is REAL array, dimension (LDA,N)
  71. *> On entry, the N-by-N matrix A.
  72. *> \endverbatim
  73. *>
  74. *> \param[in] LDA
  75. *> \verbatim
  76. *> LDA is INTEGER
  77. *> The leading dimension of the array A. LDA >= max(1,N).
  78. *> \endverbatim
  79. *>
  80. *> \param[in] AF
  81. *> \verbatim
  82. *> AF is REAL array, dimension (LDAF,N)
  83. *> The triangular factor U or L from the Cholesky factorization
  84. *> A = U**T*U or A = L*L**T, as computed by SPOTRF.
  85. *> \endverbatim
  86. *>
  87. *> \param[in] LDAF
  88. *> \verbatim
  89. *> LDAF is INTEGER
  90. *> The leading dimension of the array AF. LDAF >= max(1,N).
  91. *> \endverbatim
  92. *>
  93. *> \param[in] CMODE
  94. *> \verbatim
  95. *> CMODE is INTEGER
  96. *> Determines op2(C) in the formula op(A) * op2(C) as follows:
  97. *> CMODE = 1 op2(C) = C
  98. *> CMODE = 0 op2(C) = I
  99. *> CMODE = -1 op2(C) = inv(C)
  100. *> \endverbatim
  101. *>
  102. *> \param[in] C
  103. *> \verbatim
  104. *> C is REAL array, dimension (N)
  105. *> The vector C in the formula op(A) * op2(C).
  106. *> \endverbatim
  107. *>
  108. *> \param[out] INFO
  109. *> \verbatim
  110. *> INFO is INTEGER
  111. *> = 0: Successful exit.
  112. *> i > 0: The ith argument is invalid.
  113. *> \endverbatim
  114. *>
  115. *> \param[in] WORK
  116. *> \verbatim
  117. *> WORK is REAL array, dimension (3*N).
  118. *> Workspace.
  119. *> \endverbatim
  120. *>
  121. *> \param[in] IWORK
  122. *> \verbatim
  123. *> IWORK is INTEGER array, dimension (N).
  124. *> Workspace.
  125. *> \endverbatim
  126. *
  127. * Authors:
  128. * ========
  129. *
  130. *> \author Univ. of Tennessee
  131. *> \author Univ. of California Berkeley
  132. *> \author Univ. of Colorado Denver
  133. *> \author NAG Ltd.
  134. *
  135. *> \date December 2016
  136. *
  137. *> \ingroup realPOcomputational
  138. *
  139. * =====================================================================
  140. REAL FUNCTION SLA_PORCOND( UPLO, N, A, LDA, AF, LDAF, CMODE, C,
  141. $ INFO, WORK, IWORK )
  142. *
  143. * -- LAPACK computational routine (version 3.7.0) --
  144. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  145. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  146. * December 2016
  147. *
  148. * .. Scalar Arguments ..
  149. CHARACTER UPLO
  150. INTEGER N, LDA, LDAF, INFO, CMODE
  151. REAL A( LDA, * ), AF( LDAF, * ), WORK( * ),
  152. $ C( * )
  153. * ..
  154. * .. Array Arguments ..
  155. INTEGER IWORK( * )
  156. * ..
  157. *
  158. * =====================================================================
  159. *
  160. * .. Local Scalars ..
  161. INTEGER KASE, I, J
  162. REAL AINVNM, TMP
  163. LOGICAL UP
  164. * ..
  165. * .. Array Arguments ..
  166. INTEGER ISAVE( 3 )
  167. * ..
  168. * .. External Functions ..
  169. LOGICAL LSAME
  170. EXTERNAL LSAME
  171. * ..
  172. * .. External Subroutines ..
  173. EXTERNAL SLACN2, SPOTRS, XERBLA
  174. * ..
  175. * .. Intrinsic Functions ..
  176. INTRINSIC ABS, MAX
  177. * ..
  178. * .. Executable Statements ..
  179. *
  180. SLA_PORCOND = 0.0
  181. *
  182. INFO = 0
  183. IF( N.LT.0 ) THEN
  184. INFO = -2
  185. END IF
  186. IF( INFO.NE.0 ) THEN
  187. CALL XERBLA( 'SLA_PORCOND', -INFO )
  188. RETURN
  189. END IF
  190. IF( N.EQ.0 ) THEN
  191. SLA_PORCOND = 1.0
  192. RETURN
  193. END IF
  194. UP = .FALSE.
  195. IF ( LSAME( UPLO, 'U' ) ) UP = .TRUE.
  196. *
  197. * Compute the equilibration matrix R such that
  198. * inv(R)*A*C has unit 1-norm.
  199. *
  200. IF ( UP ) THEN
  201. DO I = 1, N
  202. TMP = 0.0
  203. IF ( CMODE .EQ. 1 ) THEN
  204. DO J = 1, I
  205. TMP = TMP + ABS( A( J, I ) * C( J ) )
  206. END DO
  207. DO J = I+1, N
  208. TMP = TMP + ABS( A( I, J ) * C( J ) )
  209. END DO
  210. ELSE IF ( CMODE .EQ. 0 ) THEN
  211. DO J = 1, I
  212. TMP = TMP + ABS( A( J, I ) )
  213. END DO
  214. DO J = I+1, N
  215. TMP = TMP + ABS( A( I, J ) )
  216. END DO
  217. ELSE
  218. DO J = 1, I
  219. TMP = TMP + ABS( A( J ,I ) / C( J ) )
  220. END DO
  221. DO J = I+1, N
  222. TMP = TMP + ABS( A( I, J ) / C( J ) )
  223. END DO
  224. END IF
  225. WORK( 2*N+I ) = TMP
  226. END DO
  227. ELSE
  228. DO I = 1, N
  229. TMP = 0.0
  230. IF ( CMODE .EQ. 1 ) THEN
  231. DO J = 1, I
  232. TMP = TMP + ABS( A( I, J ) * C( J ) )
  233. END DO
  234. DO J = I+1, N
  235. TMP = TMP + ABS( A( J, I ) * C( J ) )
  236. END DO
  237. ELSE IF ( CMODE .EQ. 0 ) THEN
  238. DO J = 1, I
  239. TMP = TMP + ABS( A( I, J ) )
  240. END DO
  241. DO J = I+1, N
  242. TMP = TMP + ABS( A( J, I ) )
  243. END DO
  244. ELSE
  245. DO J = 1, I
  246. TMP = TMP + ABS( A( I, J ) / C( J ) )
  247. END DO
  248. DO J = I+1, N
  249. TMP = TMP + ABS( A( J, I ) / C( J ) )
  250. END DO
  251. END IF
  252. WORK( 2*N+I ) = TMP
  253. END DO
  254. ENDIF
  255. *
  256. * Estimate the norm of inv(op(A)).
  257. *
  258. AINVNM = 0.0
  259. KASE = 0
  260. 10 CONTINUE
  261. CALL SLACN2( N, WORK( N+1 ), WORK, IWORK, AINVNM, KASE, ISAVE )
  262. IF( KASE.NE.0 ) THEN
  263. IF( KASE.EQ.2 ) THEN
  264. *
  265. * Multiply by R.
  266. *
  267. DO I = 1, N
  268. WORK( I ) = WORK( I ) * WORK( 2*N+I )
  269. END DO
  270. IF (UP) THEN
  271. CALL SPOTRS( 'Upper', N, 1, AF, LDAF, WORK, N, INFO )
  272. ELSE
  273. CALL SPOTRS( 'Lower', N, 1, AF, LDAF, WORK, N, INFO )
  274. ENDIF
  275. *
  276. * Multiply by inv(C).
  277. *
  278. IF ( CMODE .EQ. 1 ) THEN
  279. DO I = 1, N
  280. WORK( I ) = WORK( I ) / C( I )
  281. END DO
  282. ELSE IF ( CMODE .EQ. -1 ) THEN
  283. DO I = 1, N
  284. WORK( I ) = WORK( I ) * C( I )
  285. END DO
  286. END IF
  287. ELSE
  288. *
  289. * Multiply by inv(C**T).
  290. *
  291. IF ( CMODE .EQ. 1 ) THEN
  292. DO I = 1, N
  293. WORK( I ) = WORK( I ) / C( I )
  294. END DO
  295. ELSE IF ( CMODE .EQ. -1 ) THEN
  296. DO I = 1, N
  297. WORK( I ) = WORK( I ) * C( I )
  298. END DO
  299. END IF
  300. IF ( UP ) THEN
  301. CALL SPOTRS( 'Upper', N, 1, AF, LDAF, WORK, N, INFO )
  302. ELSE
  303. CALL SPOTRS( 'Lower', N, 1, AF, LDAF, WORK, N, INFO )
  304. ENDIF
  305. *
  306. * Multiply by R.
  307. *
  308. DO I = 1, N
  309. WORK( I ) = WORK( I ) * WORK( 2*N+I )
  310. END DO
  311. END IF
  312. GO TO 10
  313. END IF
  314. *
  315. * Compute the estimate of the reciprocal condition number.
  316. *
  317. IF( AINVNM .NE. 0.0 )
  318. $ SLA_PORCOND = ( 1.0 / AINVNM )
  319. *
  320. RETURN
  321. *
  322. END