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_gercond.f 8.9 kB

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