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.

slavsy.f 16 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. *> \brief \b SLAVSY
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * SUBROUTINE SLAVSY( UPLO, TRANS, DIAG, N, NRHS, A, LDA, IPIV, B,
  12. * LDB, INFO )
  13. *
  14. * .. Scalar Arguments ..
  15. * CHARACTER DIAG, TRANS, UPLO
  16. * INTEGER INFO, LDA, LDB, N, NRHS
  17. * ..
  18. * .. Array Arguments ..
  19. * INTEGER IPIV( * )
  20. * REAL A( LDA, * ), B( LDB, * )
  21. * ..
  22. *
  23. *
  24. *> \par Purpose:
  25. * =============
  26. *>
  27. *> \verbatim
  28. *>
  29. *> SLAVSY performs one of the matrix-vector operations
  30. *> x := A*x or x := A'*x,
  31. *> where x is an N element vector and A is one of the factors
  32. *> from the block U*D*U' or L*D*L' factorization computed by SSYTRF.
  33. *>
  34. *> If TRANS = 'N', multiplies by U or U * D (or L or L * D)
  35. *> If TRANS = 'T', multiplies by U' or D * U' (or L' or D * L')
  36. *> If TRANS = 'C', multiplies by U' or D * U' (or L' or D * L')
  37. *> \endverbatim
  38. *
  39. * Arguments:
  40. * ==========
  41. *
  42. *> \param[in] UPLO
  43. *> \verbatim
  44. *> UPLO is CHARACTER*1
  45. *> Specifies whether the factor stored in A is upper or lower
  46. *> triangular.
  47. *> = 'U': Upper triangular
  48. *> = 'L': Lower triangular
  49. *> \endverbatim
  50. *>
  51. *> \param[in] TRANS
  52. *> \verbatim
  53. *> TRANS is CHARACTER*1
  54. *> Specifies the operation to be performed:
  55. *> = 'N': x := A*x
  56. *> = 'T': x := A'*x
  57. *> = 'C': x := A'*x
  58. *> \endverbatim
  59. *>
  60. *> \param[in] DIAG
  61. *> \verbatim
  62. *> DIAG is CHARACTER*1
  63. *> Specifies whether or not the diagonal blocks are unit
  64. *> matrices. If the diagonal blocks are assumed to be unit,
  65. *> then A = U or A = L, otherwise A = U*D or A = L*D.
  66. *> = 'U': Diagonal blocks are assumed to be unit matrices.
  67. *> = 'N': Diagonal blocks are assumed to be non-unit matrices.
  68. *> \endverbatim
  69. *>
  70. *> \param[in] N
  71. *> \verbatim
  72. *> N is INTEGER
  73. *> The number of rows and columns of the matrix A. N >= 0.
  74. *> \endverbatim
  75. *>
  76. *> \param[in] NRHS
  77. *> \verbatim
  78. *> NRHS is INTEGER
  79. *> The number of right hand sides, i.e., the number of vectors
  80. *> x to be multiplied by A. NRHS >= 0.
  81. *> \endverbatim
  82. *>
  83. *> \param[in] A
  84. *> \verbatim
  85. *> A is REAL array, dimension (LDA,N)
  86. *> The block diagonal matrix D and the multipliers used to
  87. *> obtain the factor U or L as computed by SSYTRF.
  88. *> Stored as a 2-D triangular matrix.
  89. *> \endverbatim
  90. *>
  91. *> \param[in] LDA
  92. *> \verbatim
  93. *> LDA is INTEGER
  94. *> The leading dimension of the array A. LDA >= max(1,N).
  95. *> \endverbatim
  96. *>
  97. *> \param[in] IPIV
  98. *> \verbatim
  99. *> IPIV is INTEGER array, dimension (N)
  100. *> Details of the interchanges and the block structure of D,
  101. *> as determined by SSYTRF.
  102. *>
  103. *> If UPLO = 'U':
  104. *> If IPIV(k) > 0, then rows and columns k and IPIV(k)
  105. *> were interchanged and D(k,k) is a 1-by-1 diagonal block.
  106. *> (If IPIV( k ) = k, no interchange was done).
  107. *>
  108. *> If IPIV(k) = IPIV(k-1) < 0, then rows and
  109. *> columns k-1 and -IPIV(k) were interchanged,
  110. *> D(k-1:k,k-1:k) is a 2-by-2 diagonal block.
  111. *>
  112. *> If UPLO = 'L':
  113. *> If IPIV(k) > 0, then rows and columns k and IPIV(k)
  114. *> were interchanged and D(k,k) is a 1-by-1 diagonal block.
  115. *> (If IPIV( k ) = k, no interchange was done).
  116. *>
  117. *> If IPIV(k) = IPIV(k+1) < 0, then rows and
  118. *> columns k+1 and -IPIV(k) were interchanged,
  119. *> D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
  120. *> \endverbatim
  121. *>
  122. *> \param[in,out] B
  123. *> \verbatim
  124. *> B is REAL array, dimension (LDB,NRHS)
  125. *> On entry, B contains NRHS vectors of length N.
  126. *> On exit, B is overwritten with the product A * B.
  127. *> \endverbatim
  128. *>
  129. *> \param[in] LDB
  130. *> \verbatim
  131. *> LDB is INTEGER
  132. *> The leading dimension of the array B. LDB >= max(1,N).
  133. *> \endverbatim
  134. *>
  135. *> \param[out] INFO
  136. *> \verbatim
  137. *> INFO is INTEGER
  138. *> = 0: successful exit
  139. *> < 0: if INFO = -k, the k-th argument had an illegal value
  140. *> \endverbatim
  141. *
  142. * Authors:
  143. * ========
  144. *
  145. *> \author Univ. of Tennessee
  146. *> \author Univ. of California Berkeley
  147. *> \author Univ. of Colorado Denver
  148. *> \author NAG Ltd.
  149. *
  150. *> \date November 2013
  151. *
  152. *> \ingroup single_lin
  153. *
  154. * =====================================================================
  155. SUBROUTINE SLAVSY( UPLO, TRANS, DIAG, N, NRHS, A, LDA, IPIV, B,
  156. $ LDB, INFO )
  157. *
  158. * -- LAPACK test routine (version 3.5.0) --
  159. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  160. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  161. * November 2013
  162. *
  163. * .. Scalar Arguments ..
  164. CHARACTER DIAG, TRANS, UPLO
  165. INTEGER INFO, LDA, LDB, N, NRHS
  166. * ..
  167. * .. Array Arguments ..
  168. INTEGER IPIV( * )
  169. REAL A( LDA, * ), B( LDB, * )
  170. * ..
  171. *
  172. * =====================================================================
  173. *
  174. * .. Parameters ..
  175. REAL ONE
  176. PARAMETER ( ONE = 1.0E+0 )
  177. * ..
  178. * .. Local Scalars ..
  179. LOGICAL NOUNIT
  180. INTEGER J, K, KP
  181. REAL D11, D12, D21, D22, T1, T2
  182. * ..
  183. * .. External Functions ..
  184. LOGICAL LSAME
  185. EXTERNAL LSAME
  186. * ..
  187. * .. External Subroutines ..
  188. EXTERNAL SGEMV, SGER, SSCAL, SSWAP, XERBLA
  189. * ..
  190. * .. Intrinsic Functions ..
  191. INTRINSIC ABS, MAX
  192. * ..
  193. * .. Executable Statements ..
  194. *
  195. * Test the input parameters.
  196. *
  197. INFO = 0
  198. IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  199. INFO = -1
  200. ELSE IF( .NOT.LSAME( TRANS, 'N' ) .AND. .NOT.
  201. $ LSAME( TRANS, 'T' ) .AND. .NOT.LSAME( TRANS, 'C' ) ) THEN
  202. INFO = -2
  203. ELSE IF( .NOT.LSAME( DIAG, 'U' ) .AND. .NOT.LSAME( DIAG, 'N' ) )
  204. $ THEN
  205. INFO = -3
  206. ELSE IF( N.LT.0 ) THEN
  207. INFO = -4
  208. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  209. INFO = -6
  210. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  211. INFO = -9
  212. END IF
  213. IF( INFO.NE.0 ) THEN
  214. CALL XERBLA( 'SLAVSY ', -INFO )
  215. RETURN
  216. END IF
  217. *
  218. * Quick return if possible.
  219. *
  220. IF( N.EQ.0 )
  221. $ RETURN
  222. *
  223. NOUNIT = LSAME( DIAG, 'N' )
  224. *------------------------------------------
  225. *
  226. * Compute B := A * B (No transpose)
  227. *
  228. *------------------------------------------
  229. IF( LSAME( TRANS, 'N' ) ) THEN
  230. *
  231. * Compute B := U*B
  232. * where U = P(m)*inv(U(m))* ... *P(1)*inv(U(1))
  233. *
  234. IF( LSAME( UPLO, 'U' ) ) THEN
  235. *
  236. * Loop forward applying the transformations.
  237. *
  238. K = 1
  239. 10 CONTINUE
  240. IF( K.GT.N )
  241. $ GO TO 30
  242. IF( IPIV( K ).GT.0 ) THEN
  243. *
  244. * 1 x 1 pivot block
  245. *
  246. * Multiply by the diagonal element if forming U * D.
  247. *
  248. IF( NOUNIT )
  249. $ CALL SSCAL( NRHS, A( K, K ), B( K, 1 ), LDB )
  250. *
  251. * Multiply by P(K) * inv(U(K)) if K > 1.
  252. *
  253. IF( K.GT.1 ) THEN
  254. *
  255. * Apply the transformation.
  256. *
  257. CALL SGER( K-1, NRHS, ONE, A( 1, K ), 1, B( K, 1 ),
  258. $ LDB, B( 1, 1 ), LDB )
  259. *
  260. * Interchange if P(K) .ne. I.
  261. *
  262. KP = IPIV( K )
  263. IF( KP.NE.K )
  264. $ CALL SSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  265. END IF
  266. K = K + 1
  267. ELSE
  268. *
  269. * 2 x 2 pivot block
  270. *
  271. * Multiply by the diagonal block if forming U * D.
  272. *
  273. IF( NOUNIT ) THEN
  274. D11 = A( K, K )
  275. D22 = A( K+1, K+1 )
  276. D12 = A( K, K+1 )
  277. D21 = D12
  278. DO 20 J = 1, NRHS
  279. T1 = B( K, J )
  280. T2 = B( K+1, J )
  281. B( K, J ) = D11*T1 + D12*T2
  282. B( K+1, J ) = D21*T1 + D22*T2
  283. 20 CONTINUE
  284. END IF
  285. *
  286. * Multiply by P(K) * inv(U(K)) if K > 1.
  287. *
  288. IF( K.GT.1 ) THEN
  289. *
  290. * Apply the transformations.
  291. *
  292. CALL SGER( K-1, NRHS, ONE, A( 1, K ), 1, B( K, 1 ),
  293. $ LDB, B( 1, 1 ), LDB )
  294. CALL SGER( K-1, NRHS, ONE, A( 1, K+1 ), 1,
  295. $ B( K+1, 1 ), LDB, B( 1, 1 ), LDB )
  296. *
  297. * Interchange if P(K) .ne. I.
  298. *
  299. KP = ABS( IPIV( K ) )
  300. IF( KP.NE.K )
  301. $ CALL SSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  302. END IF
  303. K = K + 2
  304. END IF
  305. GO TO 10
  306. 30 CONTINUE
  307. *
  308. * Compute B := L*B
  309. * where L = P(1)*inv(L(1))* ... *P(m)*inv(L(m)) .
  310. *
  311. ELSE
  312. *
  313. * Loop backward applying the transformations to B.
  314. *
  315. K = N
  316. 40 CONTINUE
  317. IF( K.LT.1 )
  318. $ GO TO 60
  319. *
  320. * Test the pivot index. If greater than zero, a 1 x 1
  321. * pivot was used, otherwise a 2 x 2 pivot was used.
  322. *
  323. IF( IPIV( K ).GT.0 ) THEN
  324. *
  325. * 1 x 1 pivot block:
  326. *
  327. * Multiply by the diagonal element if forming L * D.
  328. *
  329. IF( NOUNIT )
  330. $ CALL SSCAL( NRHS, A( K, K ), B( K, 1 ), LDB )
  331. *
  332. * Multiply by P(K) * inv(L(K)) if K < N.
  333. *
  334. IF( K.NE.N ) THEN
  335. KP = IPIV( K )
  336. *
  337. * Apply the transformation.
  338. *
  339. CALL SGER( N-K, NRHS, ONE, A( K+1, K ), 1, B( K, 1 ),
  340. $ LDB, B( K+1, 1 ), LDB )
  341. *
  342. * Interchange if a permutation was applied at the
  343. * K-th step of the factorization.
  344. *
  345. IF( KP.NE.K )
  346. $ CALL SSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  347. END IF
  348. K = K - 1
  349. *
  350. ELSE
  351. *
  352. * 2 x 2 pivot block:
  353. *
  354. * Multiply by the diagonal block if forming L * D.
  355. *
  356. IF( NOUNIT ) THEN
  357. D11 = A( K-1, K-1 )
  358. D22 = A( K, K )
  359. D21 = A( K, K-1 )
  360. D12 = D21
  361. DO 50 J = 1, NRHS
  362. T1 = B( K-1, J )
  363. T2 = B( K, J )
  364. B( K-1, J ) = D11*T1 + D12*T2
  365. B( K, J ) = D21*T1 + D22*T2
  366. 50 CONTINUE
  367. END IF
  368. *
  369. * Multiply by P(K) * inv(L(K)) if K < N.
  370. *
  371. IF( K.NE.N ) THEN
  372. *
  373. * Apply the transformation.
  374. *
  375. CALL SGER( N-K, NRHS, ONE, A( K+1, K ), 1, B( K, 1 ),
  376. $ LDB, B( K+1, 1 ), LDB )
  377. CALL SGER( N-K, NRHS, ONE, A( K+1, K-1 ), 1,
  378. $ B( K-1, 1 ), LDB, B( K+1, 1 ), LDB )
  379. *
  380. * Interchange if a permutation was applied at the
  381. * K-th step of the factorization.
  382. *
  383. KP = ABS( IPIV( K ) )
  384. IF( KP.NE.K )
  385. $ CALL SSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  386. END IF
  387. K = K - 2
  388. END IF
  389. GO TO 40
  390. 60 CONTINUE
  391. END IF
  392. *----------------------------------------
  393. *
  394. * Compute B := A' * B (transpose)
  395. *
  396. *----------------------------------------
  397. ELSE
  398. *
  399. * Form B := U'*B
  400. * where U = P(m)*inv(U(m))* ... *P(1)*inv(U(1))
  401. * and U' = inv(U'(1))*P(1)* ... *inv(U'(m))*P(m)
  402. *
  403. IF( LSAME( UPLO, 'U' ) ) THEN
  404. *
  405. * Loop backward applying the transformations.
  406. *
  407. K = N
  408. 70 CONTINUE
  409. IF( K.LT.1 )
  410. $ GO TO 90
  411. *
  412. * 1 x 1 pivot block.
  413. *
  414. IF( IPIV( K ).GT.0 ) THEN
  415. IF( K.GT.1 ) THEN
  416. *
  417. * Interchange if P(K) .ne. I.
  418. *
  419. KP = IPIV( K )
  420. IF( KP.NE.K )
  421. $ CALL SSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  422. *
  423. * Apply the transformation
  424. *
  425. CALL SGEMV( 'Transpose', K-1, NRHS, ONE, B, LDB,
  426. $ A( 1, K ), 1, ONE, B( K, 1 ), LDB )
  427. END IF
  428. IF( NOUNIT )
  429. $ CALL SSCAL( NRHS, A( K, K ), B( K, 1 ), LDB )
  430. K = K - 1
  431. *
  432. * 2 x 2 pivot block.
  433. *
  434. ELSE
  435. IF( K.GT.2 ) THEN
  436. *
  437. * Interchange if P(K) .ne. I.
  438. *
  439. KP = ABS( IPIV( K ) )
  440. IF( KP.NE.K-1 )
  441. $ CALL SSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ),
  442. $ LDB )
  443. *
  444. * Apply the transformations
  445. *
  446. CALL SGEMV( 'Transpose', K-2, NRHS, ONE, B, LDB,
  447. $ A( 1, K ), 1, ONE, B( K, 1 ), LDB )
  448. CALL SGEMV( 'Transpose', K-2, NRHS, ONE, B, LDB,
  449. $ A( 1, K-1 ), 1, ONE, B( K-1, 1 ), LDB )
  450. END IF
  451. *
  452. * Multiply by the diagonal block if non-unit.
  453. *
  454. IF( NOUNIT ) THEN
  455. D11 = A( K-1, K-1 )
  456. D22 = A( K, K )
  457. D12 = A( K-1, K )
  458. D21 = D12
  459. DO 80 J = 1, NRHS
  460. T1 = B( K-1, J )
  461. T2 = B( K, J )
  462. B( K-1, J ) = D11*T1 + D12*T2
  463. B( K, J ) = D21*T1 + D22*T2
  464. 80 CONTINUE
  465. END IF
  466. K = K - 2
  467. END IF
  468. GO TO 70
  469. 90 CONTINUE
  470. *
  471. * Form B := L'*B
  472. * where L = P(1)*inv(L(1))* ... *P(m)*inv(L(m))
  473. * and L' = inv(L'(m))*P(m)* ... *inv(L'(1))*P(1)
  474. *
  475. ELSE
  476. *
  477. * Loop forward applying the L-transformations.
  478. *
  479. K = 1
  480. 100 CONTINUE
  481. IF( K.GT.N )
  482. $ GO TO 120
  483. *
  484. * 1 x 1 pivot block
  485. *
  486. IF( IPIV( K ).GT.0 ) THEN
  487. IF( K.LT.N ) THEN
  488. *
  489. * Interchange if P(K) .ne. I.
  490. *
  491. KP = IPIV( K )
  492. IF( KP.NE.K )
  493. $ CALL SSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  494. *
  495. * Apply the transformation
  496. *
  497. CALL SGEMV( 'Transpose', N-K, NRHS, ONE, B( K+1, 1 ),
  498. $ LDB, A( K+1, K ), 1, ONE, B( K, 1 ), LDB )
  499. END IF
  500. IF( NOUNIT )
  501. $ CALL SSCAL( NRHS, A( K, K ), B( K, 1 ), LDB )
  502. K = K + 1
  503. *
  504. * 2 x 2 pivot block.
  505. *
  506. ELSE
  507. IF( K.LT.N-1 ) THEN
  508. *
  509. * Interchange if P(K) .ne. I.
  510. *
  511. KP = ABS( IPIV( K ) )
  512. IF( KP.NE.K+1 )
  513. $ CALL SSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ),
  514. $ LDB )
  515. *
  516. * Apply the transformation
  517. *
  518. CALL SGEMV( 'Transpose', N-K-1, NRHS, ONE,
  519. $ B( K+2, 1 ), LDB, A( K+2, K+1 ), 1, ONE,
  520. $ B( K+1, 1 ), LDB )
  521. CALL SGEMV( 'Transpose', N-K-1, NRHS, ONE,
  522. $ B( K+2, 1 ), LDB, A( K+2, K ), 1, ONE,
  523. $ B( K, 1 ), LDB )
  524. END IF
  525. *
  526. * Multiply by the diagonal block if non-unit.
  527. *
  528. IF( NOUNIT ) THEN
  529. D11 = A( K, K )
  530. D22 = A( K+1, K+1 )
  531. D21 = A( K+1, K )
  532. D12 = D21
  533. DO 110 J = 1, NRHS
  534. T1 = B( K, J )
  535. T2 = B( K+1, J )
  536. B( K, J ) = D11*T1 + D12*T2
  537. B( K+1, J ) = D21*T1 + D22*T2
  538. 110 CONTINUE
  539. END IF
  540. K = K + 2
  541. END IF
  542. GO TO 100
  543. 120 CONTINUE
  544. END IF
  545. *
  546. END IF
  547. RETURN
  548. *
  549. * End of SLAVSY
  550. *
  551. END