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_gbrcond.f 10 kB

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