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.

slatrs.f 26 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. *> \brief \b SLATRS solves a triangular system of equations with the scale factor set to prevent overflow.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLATRS + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slatrs.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slatrs.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slatrs.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLATRS( UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X, SCALE,
  22. * CNORM, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER DIAG, NORMIN, TRANS, UPLO
  26. * INTEGER INFO, LDA, N
  27. * REAL SCALE
  28. * ..
  29. * .. Array Arguments ..
  30. * REAL A( LDA, * ), CNORM( * ), X( * )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *>
  39. *> SLATRS solves one of the triangular systems
  40. *>
  41. *> A *x = s*b or A**T*x = s*b
  42. *>
  43. *> with scaling to prevent overflow. Here A is an upper or lower
  44. *> triangular matrix, A**T denotes the transpose of A, x and b are
  45. *> n-element vectors, and s is a scaling factor, usually less than
  46. *> or equal to 1, chosen so that the components of x will be less than
  47. *> the overflow threshold. If the unscaled problem will not cause
  48. *> overflow, the Level 2 BLAS routine STRSV is called. If the matrix A
  49. *> is singular (A(j,j) = 0 for some j), then s is set to 0 and a
  50. *> non-trivial solution to A*x = 0 is returned.
  51. *> \endverbatim
  52. *
  53. * Arguments:
  54. * ==========
  55. *
  56. *> \param[in] UPLO
  57. *> \verbatim
  58. *> UPLO is CHARACTER*1
  59. *> Specifies whether the matrix A is upper or lower triangular.
  60. *> = 'U': Upper triangular
  61. *> = 'L': Lower triangular
  62. *> \endverbatim
  63. *>
  64. *> \param[in] TRANS
  65. *> \verbatim
  66. *> TRANS is CHARACTER*1
  67. *> Specifies the operation applied to A.
  68. *> = 'N': Solve A * x = s*b (No transpose)
  69. *> = 'T': Solve A**T* x = s*b (Transpose)
  70. *> = 'C': Solve A**T* x = s*b (Conjugate transpose = Transpose)
  71. *> \endverbatim
  72. *>
  73. *> \param[in] DIAG
  74. *> \verbatim
  75. *> DIAG is CHARACTER*1
  76. *> Specifies whether or not the matrix A is unit triangular.
  77. *> = 'N': Non-unit triangular
  78. *> = 'U': Unit triangular
  79. *> \endverbatim
  80. *>
  81. *> \param[in] NORMIN
  82. *> \verbatim
  83. *> NORMIN is CHARACTER*1
  84. *> Specifies whether CNORM has been set or not.
  85. *> = 'Y': CNORM contains the column norms on entry
  86. *> = 'N': CNORM is not set on entry. On exit, the norms will
  87. *> be computed and stored in CNORM.
  88. *> \endverbatim
  89. *>
  90. *> \param[in] N
  91. *> \verbatim
  92. *> N is INTEGER
  93. *> The order of the matrix A. N >= 0.
  94. *> \endverbatim
  95. *>
  96. *> \param[in] A
  97. *> \verbatim
  98. *> A is REAL array, dimension (LDA,N)
  99. *> The triangular matrix A. If UPLO = 'U', the leading n by n
  100. *> upper triangular part of the array A contains the upper
  101. *> triangular matrix, and the strictly lower triangular part of
  102. *> A is not referenced. If UPLO = 'L', the leading n by n lower
  103. *> triangular part of the array A contains the lower triangular
  104. *> matrix, and the strictly upper triangular part of A is not
  105. *> referenced. If DIAG = 'U', the diagonal elements of A are
  106. *> also not referenced and are assumed to be 1.
  107. *> \endverbatim
  108. *>
  109. *> \param[in] LDA
  110. *> \verbatim
  111. *> LDA is INTEGER
  112. *> The leading dimension of the array A. LDA >= max (1,N).
  113. *> \endverbatim
  114. *>
  115. *> \param[in,out] X
  116. *> \verbatim
  117. *> X is REAL array, dimension (N)
  118. *> On entry, the right hand side b of the triangular system.
  119. *> On exit, X is overwritten by the solution vector x.
  120. *> \endverbatim
  121. *>
  122. *> \param[out] SCALE
  123. *> \verbatim
  124. *> SCALE is REAL
  125. *> The scaling factor s for the triangular system
  126. *> A * x = s*b or A**T* x = s*b.
  127. *> If SCALE = 0, the matrix A is singular or badly scaled, and
  128. *> the vector x is an exact or approximate solution to A*x = 0.
  129. *> \endverbatim
  130. *>
  131. *> \param[in,out] CNORM
  132. *> \verbatim
  133. *> CNORM is REAL array, dimension (N)
  134. *>
  135. *> If NORMIN = 'Y', CNORM is an input argument and CNORM(j)
  136. *> contains the norm of the off-diagonal part of the j-th column
  137. *> of A. If TRANS = 'N', CNORM(j) must be greater than or equal
  138. *> to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j)
  139. *> must be greater than or equal to the 1-norm.
  140. *>
  141. *> If NORMIN = 'N', CNORM is an output argument and CNORM(j)
  142. *> returns the 1-norm of the offdiagonal part of the j-th column
  143. *> of A.
  144. *> \endverbatim
  145. *>
  146. *> \param[out] INFO
  147. *> \verbatim
  148. *> INFO is INTEGER
  149. *> = 0: successful exit
  150. *> < 0: if INFO = -k, the k-th argument had an illegal value
  151. *> \endverbatim
  152. *
  153. * Authors:
  154. * ========
  155. *
  156. *> \author Univ. of Tennessee
  157. *> \author Univ. of California Berkeley
  158. *> \author Univ. of Colorado Denver
  159. *> \author NAG Ltd.
  160. *
  161. *> \ingroup realOTHERauxiliary
  162. *
  163. *> \par Further Details:
  164. * =====================
  165. *>
  166. *> \verbatim
  167. *>
  168. *> A rough bound on x is computed; if that is less than overflow, STRSV
  169. *> is called, otherwise, specific code is used which checks for possible
  170. *> overflow or divide-by-zero at every operation.
  171. *>
  172. *> A columnwise scheme is used for solving A*x = b. The basic algorithm
  173. *> if A is lower triangular is
  174. *>
  175. *> x[1:n] := b[1:n]
  176. *> for j = 1, ..., n
  177. *> x(j) := x(j) / A(j,j)
  178. *> x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j]
  179. *> end
  180. *>
  181. *> Define bounds on the components of x after j iterations of the loop:
  182. *> M(j) = bound on x[1:j]
  183. *> G(j) = bound on x[j+1:n]
  184. *> Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}.
  185. *>
  186. *> Then for iteration j+1 we have
  187. *> M(j+1) <= G(j) / | A(j+1,j+1) |
  188. *> G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] |
  189. *> <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | )
  190. *>
  191. *> where CNORM(j+1) is greater than or equal to the infinity-norm of
  192. *> column j+1 of A, not counting the diagonal. Hence
  193. *>
  194. *> G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | )
  195. *> 1<=i<=j
  196. *> and
  197. *>
  198. *> |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| )
  199. *> 1<=i< j
  200. *>
  201. *> Since |x(j)| <= M(j), we use the Level 2 BLAS routine STRSV if the
  202. *> reciprocal of the largest M(j), j=1,..,n, is larger than
  203. *> max(underflow, 1/overflow).
  204. *>
  205. *> The bound on x(j) is also used to determine when a step in the
  206. *> columnwise method can be performed without fear of overflow. If
  207. *> the computed bound is greater than a large constant, x is scaled to
  208. *> prevent overflow, but if the bound overflows, x is set to 0, x(j) to
  209. *> 1, and scale to 0, and a non-trivial solution to A*x = 0 is found.
  210. *>
  211. *> Similarly, a row-wise scheme is used to solve A**T*x = b. The basic
  212. *> algorithm for A upper triangular is
  213. *>
  214. *> for j = 1, ..., n
  215. *> x(j) := ( b(j) - A[1:j-1,j]**T * x[1:j-1] ) / A(j,j)
  216. *> end
  217. *>
  218. *> We simultaneously compute two bounds
  219. *> G(j) = bound on ( b(i) - A[1:i-1,i]**T * x[1:i-1] ), 1<=i<=j
  220. *> M(j) = bound on x(i), 1<=i<=j
  221. *>
  222. *> The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we
  223. *> add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1.
  224. *> Then the bound on x(j) is
  225. *>
  226. *> M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) |
  227. *>
  228. *> <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| )
  229. *> 1<=i<=j
  230. *>
  231. *> and we can safely call STRSV if 1/M(n) and 1/G(n) are both greater
  232. *> than max(underflow, 1/overflow).
  233. *> \endverbatim
  234. *>
  235. * =====================================================================
  236. SUBROUTINE SLATRS( UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X, SCALE,
  237. $ CNORM, INFO )
  238. *
  239. * -- LAPACK auxiliary routine --
  240. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  241. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  242. *
  243. * .. Scalar Arguments ..
  244. CHARACTER DIAG, NORMIN, TRANS, UPLO
  245. INTEGER INFO, LDA, N
  246. REAL SCALE
  247. * ..
  248. * .. Array Arguments ..
  249. REAL A( LDA, * ), CNORM( * ), X( * )
  250. * ..
  251. *
  252. * =====================================================================
  253. *
  254. * .. Parameters ..
  255. REAL ZERO, HALF, ONE
  256. PARAMETER ( ZERO = 0.0E+0, HALF = 0.5E+0, ONE = 1.0E+0 )
  257. * ..
  258. * .. Local Scalars ..
  259. LOGICAL NOTRAN, NOUNIT, UPPER
  260. INTEGER I, IMAX, J, JFIRST, JINC, JLAST
  261. REAL BIGNUM, GROW, REC, SMLNUM, SUMJ, TJJ, TJJS,
  262. $ TMAX, TSCAL, USCAL, XBND, XJ, XMAX
  263. * ..
  264. * .. Local Arrays ..
  265. REAL WORK (1)
  266. * ..
  267. * .. External Functions ..
  268. LOGICAL LSAME
  269. INTEGER ISAMAX
  270. REAL SASUM, SDOT, SLAMCH, SLANGE
  271. EXTERNAL LSAME, ISAMAX, SASUM, SDOT, SLAMCH, SLANGE
  272. * ..
  273. * .. External Subroutines ..
  274. EXTERNAL SAXPY, SSCAL, STRSV, XERBLA
  275. * ..
  276. * .. Intrinsic Functions ..
  277. INTRINSIC ABS, MAX, MIN
  278. * ..
  279. * .. Executable Statements ..
  280. *
  281. INFO = 0
  282. UPPER = LSAME( UPLO, 'U' )
  283. NOTRAN = LSAME( TRANS, 'N' )
  284. NOUNIT = LSAME( DIAG, 'N' )
  285. *
  286. * Test the input parameters.
  287. *
  288. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  289. INFO = -1
  290. ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
  291. $ LSAME( TRANS, 'C' ) ) THEN
  292. INFO = -2
  293. ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
  294. INFO = -3
  295. ELSE IF( .NOT.LSAME( NORMIN, 'Y' ) .AND. .NOT.
  296. $ LSAME( NORMIN, 'N' ) ) THEN
  297. INFO = -4
  298. ELSE IF( N.LT.0 ) THEN
  299. INFO = -5
  300. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  301. INFO = -7
  302. END IF
  303. IF( INFO.NE.0 ) THEN
  304. CALL XERBLA( 'SLATRS', -INFO )
  305. RETURN
  306. END IF
  307. *
  308. * Quick return if possible
  309. *
  310. SCALE = ONE
  311. IF( N.EQ.0 )
  312. $ RETURN
  313. *
  314. * Determine machine dependent parameters to control overflow.
  315. *
  316. SMLNUM = SLAMCH( 'Safe minimum' ) / SLAMCH( 'Precision' )
  317. BIGNUM = ONE / SMLNUM
  318. *
  319. IF( LSAME( NORMIN, 'N' ) ) THEN
  320. *
  321. * Compute the 1-norm of each column, not including the diagonal.
  322. *
  323. IF( UPPER ) THEN
  324. *
  325. * A is upper triangular.
  326. *
  327. DO 10 J = 1, N
  328. CNORM( J ) = SASUM( J-1, A( 1, J ), 1 )
  329. 10 CONTINUE
  330. ELSE
  331. *
  332. * A is lower triangular.
  333. *
  334. DO 20 J = 1, N - 1
  335. CNORM( J ) = SASUM( N-J, A( J+1, J ), 1 )
  336. 20 CONTINUE
  337. CNORM( N ) = ZERO
  338. END IF
  339. END IF
  340. *
  341. * Scale the column norms by TSCAL if the maximum element in CNORM is
  342. * greater than BIGNUM.
  343. *
  344. IMAX = ISAMAX( N, CNORM, 1 )
  345. TMAX = CNORM( IMAX )
  346. IF( TMAX.LE.BIGNUM ) THEN
  347. TSCAL = ONE
  348. ELSE
  349. *
  350. * Avoid NaN generation if entries in CNORM exceed the
  351. * overflow threshold
  352. *
  353. IF ( TMAX.LE.SLAMCH('Overflow') ) THEN
  354. * Case 1: All entries in CNORM are valid floating-point numbers
  355. TSCAL = ONE / ( SMLNUM*TMAX )
  356. CALL SSCAL( N, TSCAL, CNORM, 1 )
  357. ELSE
  358. * Case 2: At least one column norm of A cannot be represented
  359. * as floating-point number. Find the offdiagonal entry A( I, J )
  360. * with the largest absolute value. If this entry is not +/- Infinity,
  361. * use this value as TSCAL.
  362. TMAX = ZERO
  363. IF( UPPER ) THEN
  364. *
  365. * A is upper triangular.
  366. *
  367. DO J = 2, N
  368. TMAX = MAX( SLANGE( 'M', J-1, 1, A( 1, J ), 1, WORK ),
  369. $ TMAX )
  370. END DO
  371. ELSE
  372. *
  373. * A is lower triangular.
  374. *
  375. DO J = 1, N - 1
  376. TMAX = MAX( SLANGE( 'M', N-J, 1, A( J+1, J ), 1,
  377. $ WORK ), TMAX )
  378. END DO
  379. END IF
  380. *
  381. IF( TMAX.LE.SLAMCH('Overflow') ) THEN
  382. TSCAL = ONE / ( SMLNUM*TMAX )
  383. DO J = 1, N
  384. IF( CNORM( J ).LE.SLAMCH('Overflow') ) THEN
  385. CNORM( J ) = CNORM( J )*TSCAL
  386. ELSE
  387. * Recompute the 1-norm without introducing Infinity
  388. * in the summation
  389. CNORM( J ) = ZERO
  390. IF( UPPER ) THEN
  391. DO I = 1, J - 1
  392. CNORM( J ) = CNORM( J ) +
  393. $ TSCAL * ABS( A( I, J ) )
  394. END DO
  395. ELSE
  396. DO I = J + 1, N
  397. CNORM( J ) = CNORM( J ) +
  398. $ TSCAL * ABS( A( I, J ) )
  399. END DO
  400. END IF
  401. END IF
  402. END DO
  403. ELSE
  404. * At least one entry of A is not a valid floating-point entry.
  405. * Rely on TRSV to propagate Inf and NaN.
  406. CALL STRSV( UPLO, TRANS, DIAG, N, A, LDA, X, 1 )
  407. RETURN
  408. END IF
  409. END IF
  410. END IF
  411. *
  412. * Compute a bound on the computed solution vector to see if the
  413. * Level 2 BLAS routine STRSV can be used.
  414. *
  415. J = ISAMAX( N, X, 1 )
  416. XMAX = ABS( X( J ) )
  417. XBND = XMAX
  418. IF( NOTRAN ) THEN
  419. *
  420. * Compute the growth in A * x = b.
  421. *
  422. IF( UPPER ) THEN
  423. JFIRST = N
  424. JLAST = 1
  425. JINC = -1
  426. ELSE
  427. JFIRST = 1
  428. JLAST = N
  429. JINC = 1
  430. END IF
  431. *
  432. IF( TSCAL.NE.ONE ) THEN
  433. GROW = ZERO
  434. GO TO 50
  435. END IF
  436. *
  437. IF( NOUNIT ) THEN
  438. *
  439. * A is non-unit triangular.
  440. *
  441. * Compute GROW = 1/G(j) and XBND = 1/M(j).
  442. * Initially, G(0) = max{x(i), i=1,...,n}.
  443. *
  444. GROW = ONE / MAX( XBND, SMLNUM )
  445. XBND = GROW
  446. DO 30 J = JFIRST, JLAST, JINC
  447. *
  448. * Exit the loop if the growth factor is too small.
  449. *
  450. IF( GROW.LE.SMLNUM )
  451. $ GO TO 50
  452. *
  453. * M(j) = G(j-1) / abs(A(j,j))
  454. *
  455. TJJ = ABS( A( J, J ) )
  456. XBND = MIN( XBND, MIN( ONE, TJJ )*GROW )
  457. IF( TJJ+CNORM( J ).GE.SMLNUM ) THEN
  458. *
  459. * G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) )
  460. *
  461. GROW = GROW*( TJJ / ( TJJ+CNORM( J ) ) )
  462. ELSE
  463. *
  464. * G(j) could overflow, set GROW to 0.
  465. *
  466. GROW = ZERO
  467. END IF
  468. 30 CONTINUE
  469. GROW = XBND
  470. ELSE
  471. *
  472. * A is unit triangular.
  473. *
  474. * Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}.
  475. *
  476. GROW = MIN( ONE, ONE / MAX( XBND, SMLNUM ) )
  477. DO 40 J = JFIRST, JLAST, JINC
  478. *
  479. * Exit the loop if the growth factor is too small.
  480. *
  481. IF( GROW.LE.SMLNUM )
  482. $ GO TO 50
  483. *
  484. * G(j) = G(j-1)*( 1 + CNORM(j) )
  485. *
  486. GROW = GROW*( ONE / ( ONE+CNORM( J ) ) )
  487. 40 CONTINUE
  488. END IF
  489. 50 CONTINUE
  490. *
  491. ELSE
  492. *
  493. * Compute the growth in A**T * x = b.
  494. *
  495. IF( UPPER ) THEN
  496. JFIRST = 1
  497. JLAST = N
  498. JINC = 1
  499. ELSE
  500. JFIRST = N
  501. JLAST = 1
  502. JINC = -1
  503. END IF
  504. *
  505. IF( TSCAL.NE.ONE ) THEN
  506. GROW = ZERO
  507. GO TO 80
  508. END IF
  509. *
  510. IF( NOUNIT ) THEN
  511. *
  512. * A is non-unit triangular.
  513. *
  514. * Compute GROW = 1/G(j) and XBND = 1/M(j).
  515. * Initially, M(0) = max{x(i), i=1,...,n}.
  516. *
  517. GROW = ONE / MAX( XBND, SMLNUM )
  518. XBND = GROW
  519. DO 60 J = JFIRST, JLAST, JINC
  520. *
  521. * Exit the loop if the growth factor is too small.
  522. *
  523. IF( GROW.LE.SMLNUM )
  524. $ GO TO 80
  525. *
  526. * G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) )
  527. *
  528. XJ = ONE + CNORM( J )
  529. GROW = MIN( GROW, XBND / XJ )
  530. *
  531. * M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j))
  532. *
  533. TJJ = ABS( A( J, J ) )
  534. IF( XJ.GT.TJJ )
  535. $ XBND = XBND*( TJJ / XJ )
  536. 60 CONTINUE
  537. GROW = MIN( GROW, XBND )
  538. ELSE
  539. *
  540. * A is unit triangular.
  541. *
  542. * Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}.
  543. *
  544. GROW = MIN( ONE, ONE / MAX( XBND, SMLNUM ) )
  545. DO 70 J = JFIRST, JLAST, JINC
  546. *
  547. * Exit the loop if the growth factor is too small.
  548. *
  549. IF( GROW.LE.SMLNUM )
  550. $ GO TO 80
  551. *
  552. * G(j) = ( 1 + CNORM(j) )*G(j-1)
  553. *
  554. XJ = ONE + CNORM( J )
  555. GROW = GROW / XJ
  556. 70 CONTINUE
  557. END IF
  558. 80 CONTINUE
  559. END IF
  560. *
  561. IF( ( GROW*TSCAL ).GT.SMLNUM ) THEN
  562. *
  563. * Use the Level 2 BLAS solve if the reciprocal of the bound on
  564. * elements of X is not too small.
  565. *
  566. CALL STRSV( UPLO, TRANS, DIAG, N, A, LDA, X, 1 )
  567. ELSE
  568. *
  569. * Use a Level 1 BLAS solve, scaling intermediate results.
  570. *
  571. IF( XMAX.GT.BIGNUM ) THEN
  572. *
  573. * Scale X so that its components are less than or equal to
  574. * BIGNUM in absolute value.
  575. *
  576. SCALE = BIGNUM / XMAX
  577. CALL SSCAL( N, SCALE, X, 1 )
  578. XMAX = BIGNUM
  579. END IF
  580. *
  581. IF( NOTRAN ) THEN
  582. *
  583. * Solve A * x = b
  584. *
  585. DO 100 J = JFIRST, JLAST, JINC
  586. *
  587. * Compute x(j) = b(j) / A(j,j), scaling x if necessary.
  588. *
  589. XJ = ABS( X( J ) )
  590. IF( NOUNIT ) THEN
  591. TJJS = A( J, J )*TSCAL
  592. ELSE
  593. TJJS = TSCAL
  594. IF( TSCAL.EQ.ONE )
  595. $ GO TO 95
  596. END IF
  597. TJJ = ABS( TJJS )
  598. IF( TJJ.GT.SMLNUM ) THEN
  599. *
  600. * abs(A(j,j)) > SMLNUM:
  601. *
  602. IF( TJJ.LT.ONE ) THEN
  603. IF( XJ.GT.TJJ*BIGNUM ) THEN
  604. *
  605. * Scale x by 1/b(j).
  606. *
  607. REC = ONE / XJ
  608. CALL SSCAL( N, REC, X, 1 )
  609. SCALE = SCALE*REC
  610. XMAX = XMAX*REC
  611. END IF
  612. END IF
  613. X( J ) = X( J ) / TJJS
  614. XJ = ABS( X( J ) )
  615. ELSE IF( TJJ.GT.ZERO ) THEN
  616. *
  617. * 0 < abs(A(j,j)) <= SMLNUM:
  618. *
  619. IF( XJ.GT.TJJ*BIGNUM ) THEN
  620. *
  621. * Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM
  622. * to avoid overflow when dividing by A(j,j).
  623. *
  624. REC = ( TJJ*BIGNUM ) / XJ
  625. IF( CNORM( J ).GT.ONE ) THEN
  626. *
  627. * Scale by 1/CNORM(j) to avoid overflow when
  628. * multiplying x(j) times column j.
  629. *
  630. REC = REC / CNORM( J )
  631. END IF
  632. CALL SSCAL( N, REC, X, 1 )
  633. SCALE = SCALE*REC
  634. XMAX = XMAX*REC
  635. END IF
  636. X( J ) = X( J ) / TJJS
  637. XJ = ABS( X( J ) )
  638. ELSE
  639. *
  640. * A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and
  641. * scale = 0, and compute a solution to A*x = 0.
  642. *
  643. DO 90 I = 1, N
  644. X( I ) = ZERO
  645. 90 CONTINUE
  646. X( J ) = ONE
  647. XJ = ONE
  648. SCALE = ZERO
  649. XMAX = ZERO
  650. END IF
  651. 95 CONTINUE
  652. *
  653. * Scale x if necessary to avoid overflow when adding a
  654. * multiple of column j of A.
  655. *
  656. IF( XJ.GT.ONE ) THEN
  657. REC = ONE / XJ
  658. IF( CNORM( J ).GT.( BIGNUM-XMAX )*REC ) THEN
  659. *
  660. * Scale x by 1/(2*abs(x(j))).
  661. *
  662. REC = REC*HALF
  663. CALL SSCAL( N, REC, X, 1 )
  664. SCALE = SCALE*REC
  665. END IF
  666. ELSE IF( XJ*CNORM( J ).GT.( BIGNUM-XMAX ) ) THEN
  667. *
  668. * Scale x by 1/2.
  669. *
  670. CALL SSCAL( N, HALF, X, 1 )
  671. SCALE = SCALE*HALF
  672. END IF
  673. *
  674. IF( UPPER ) THEN
  675. IF( J.GT.1 ) THEN
  676. *
  677. * Compute the update
  678. * x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j)
  679. *
  680. CALL SAXPY( J-1, -X( J )*TSCAL, A( 1, J ), 1, X,
  681. $ 1 )
  682. I = ISAMAX( J-1, X, 1 )
  683. XMAX = ABS( X( I ) )
  684. END IF
  685. ELSE
  686. IF( J.LT.N ) THEN
  687. *
  688. * Compute the update
  689. * x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j)
  690. *
  691. CALL SAXPY( N-J, -X( J )*TSCAL, A( J+1, J ), 1,
  692. $ X( J+1 ), 1 )
  693. I = J + ISAMAX( N-J, X( J+1 ), 1 )
  694. XMAX = ABS( X( I ) )
  695. END IF
  696. END IF
  697. 100 CONTINUE
  698. *
  699. ELSE
  700. *
  701. * Solve A**T * x = b
  702. *
  703. DO 140 J = JFIRST, JLAST, JINC
  704. *
  705. * Compute x(j) = b(j) - sum A(k,j)*x(k).
  706. * k<>j
  707. *
  708. XJ = ABS( X( J ) )
  709. USCAL = TSCAL
  710. REC = ONE / MAX( XMAX, ONE )
  711. IF( CNORM( J ).GT.( BIGNUM-XJ )*REC ) THEN
  712. *
  713. * If x(j) could overflow, scale x by 1/(2*XMAX).
  714. *
  715. REC = REC*HALF
  716. IF( NOUNIT ) THEN
  717. TJJS = A( J, J )*TSCAL
  718. ELSE
  719. TJJS = TSCAL
  720. END IF
  721. TJJ = ABS( TJJS )
  722. IF( TJJ.GT.ONE ) THEN
  723. *
  724. * Divide by A(j,j) when scaling x if A(j,j) > 1.
  725. *
  726. REC = MIN( ONE, REC*TJJ )
  727. USCAL = USCAL / TJJS
  728. END IF
  729. IF( REC.LT.ONE ) THEN
  730. CALL SSCAL( N, REC, X, 1 )
  731. SCALE = SCALE*REC
  732. XMAX = XMAX*REC
  733. END IF
  734. END IF
  735. *
  736. SUMJ = ZERO
  737. IF( USCAL.EQ.ONE ) THEN
  738. *
  739. * If the scaling needed for A in the dot product is 1,
  740. * call SDOT to perform the dot product.
  741. *
  742. IF( UPPER ) THEN
  743. SUMJ = SDOT( J-1, A( 1, J ), 1, X, 1 )
  744. ELSE IF( J.LT.N ) THEN
  745. SUMJ = SDOT( N-J, A( J+1, J ), 1, X( J+1 ), 1 )
  746. END IF
  747. ELSE
  748. *
  749. * Otherwise, use in-line code for the dot product.
  750. *
  751. IF( UPPER ) THEN
  752. DO 110 I = 1, J - 1
  753. SUMJ = SUMJ + ( A( I, J )*USCAL )*X( I )
  754. 110 CONTINUE
  755. ELSE IF( J.LT.N ) THEN
  756. DO 120 I = J + 1, N
  757. SUMJ = SUMJ + ( A( I, J )*USCAL )*X( I )
  758. 120 CONTINUE
  759. END IF
  760. END IF
  761. *
  762. IF( USCAL.EQ.TSCAL ) THEN
  763. *
  764. * Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j)
  765. * was not used to scale the dotproduct.
  766. *
  767. X( J ) = X( J ) - SUMJ
  768. XJ = ABS( X( J ) )
  769. IF( NOUNIT ) THEN
  770. TJJS = A( J, J )*TSCAL
  771. ELSE
  772. TJJS = TSCAL
  773. IF( TSCAL.EQ.ONE )
  774. $ GO TO 135
  775. END IF
  776. *
  777. * Compute x(j) = x(j) / A(j,j), scaling if necessary.
  778. *
  779. TJJ = ABS( TJJS )
  780. IF( TJJ.GT.SMLNUM ) THEN
  781. *
  782. * abs(A(j,j)) > SMLNUM:
  783. *
  784. IF( TJJ.LT.ONE ) THEN
  785. IF( XJ.GT.TJJ*BIGNUM ) THEN
  786. *
  787. * Scale X by 1/abs(x(j)).
  788. *
  789. REC = ONE / XJ
  790. CALL SSCAL( N, REC, X, 1 )
  791. SCALE = SCALE*REC
  792. XMAX = XMAX*REC
  793. END IF
  794. END IF
  795. X( J ) = X( J ) / TJJS
  796. ELSE IF( TJJ.GT.ZERO ) THEN
  797. *
  798. * 0 < abs(A(j,j)) <= SMLNUM:
  799. *
  800. IF( XJ.GT.TJJ*BIGNUM ) THEN
  801. *
  802. * Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM.
  803. *
  804. REC = ( TJJ*BIGNUM ) / XJ
  805. CALL SSCAL( N, REC, X, 1 )
  806. SCALE = SCALE*REC
  807. XMAX = XMAX*REC
  808. END IF
  809. X( J ) = X( J ) / TJJS
  810. ELSE
  811. *
  812. * A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and
  813. * scale = 0, and compute a solution to A**T*x = 0.
  814. *
  815. DO 130 I = 1, N
  816. X( I ) = ZERO
  817. 130 CONTINUE
  818. X( J ) = ONE
  819. SCALE = ZERO
  820. XMAX = ZERO
  821. END IF
  822. 135 CONTINUE
  823. ELSE
  824. *
  825. * Compute x(j) := x(j) / A(j,j) - sumj if the dot
  826. * product has already been divided by 1/A(j,j).
  827. *
  828. X( J ) = X( J ) / TJJS - SUMJ
  829. END IF
  830. XMAX = MAX( XMAX, ABS( X( J ) ) )
  831. 140 CONTINUE
  832. END IF
  833. SCALE = SCALE / TSCAL
  834. END IF
  835. *
  836. * Scale the column norms by 1/TSCAL for return.
  837. *
  838. IF( TSCAL.NE.ONE ) THEN
  839. CALL SSCAL( N, ONE / TSCAL, CNORM, 1 )
  840. END IF
  841. *
  842. RETURN
  843. *
  844. * End of SLATRS
  845. *
  846. END