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.

clavsy_rook.f 18 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. *> \brief \b CLAVSY_ROOK
  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 CLAVSY_ROOK( 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. * COMPLEX A( LDA, * ), B( LDB, * )
  21. * ..
  22. *
  23. *
  24. *> \par Purpose:
  25. * =============
  26. *>
  27. *> \verbatim
  28. *>
  29. *> CLAVSY_ROOK 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 CSYTRF_ROOK.
  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. *> \endverbatim
  37. *
  38. * Arguments:
  39. * ==========
  40. *
  41. *> \param[in] UPLO
  42. *> \verbatim
  43. *> UPLO is CHARACTER*1
  44. *> Specifies whether the factor stored in A is upper or lower
  45. *> triangular.
  46. *> = 'U': Upper triangular
  47. *> = 'L': Lower triangular
  48. *> \endverbatim
  49. *>
  50. *> \param[in] TRANS
  51. *> \verbatim
  52. *> TRANS is CHARACTER*1
  53. *> Specifies the operation to be performed:
  54. *> = 'N': x := A*x
  55. *> = 'T': x := A'*x
  56. *> \endverbatim
  57. *>
  58. *> \param[in] DIAG
  59. *> \verbatim
  60. *> DIAG is CHARACTER*1
  61. *> Specifies whether or not the diagonal blocks are unit
  62. *> matrices. If the diagonal blocks are assumed to be unit,
  63. *> then A = U or A = L, otherwise A = U*D or A = L*D.
  64. *> = 'U': Diagonal blocks are assumed to be unit matrices.
  65. *> = 'N': Diagonal blocks are assumed to be non-unit matrices.
  66. *> \endverbatim
  67. *>
  68. *> \param[in] N
  69. *> \verbatim
  70. *> N is INTEGER
  71. *> The number of rows and columns of the matrix A. N >= 0.
  72. *> \endverbatim
  73. *>
  74. *> \param[in] NRHS
  75. *> \verbatim
  76. *> NRHS is INTEGER
  77. *> The number of right hand sides, i.e., the number of vectors
  78. *> x to be multiplied by A. NRHS >= 0.
  79. *> \endverbatim
  80. *>
  81. *> \param[in] A
  82. *> \verbatim
  83. *> A is COMPLEX array, dimension (LDA,N)
  84. *> The block diagonal matrix D and the multipliers used to
  85. *> obtain the factor U or L as computed by CSYTRF_ROOK.
  86. *> Stored as a 2-D triangular matrix.
  87. *> \endverbatim
  88. *>
  89. *> \param[in] LDA
  90. *> \verbatim
  91. *> LDA is INTEGER
  92. *> The leading dimension of the array A. LDA >= max(1,N).
  93. *> \endverbatim
  94. *>
  95. *> \param[in] IPIV
  96. *> \verbatim
  97. *> IPIV is INTEGER array, dimension (N)
  98. *> Details of the interchanges and the block structure of D,
  99. *> as determined by CSYTRF_ROOK.
  100. *>
  101. *> If UPLO = 'U':
  102. *> If IPIV(k) > 0, then rows and columns k and IPIV(k)
  103. *> were interchanged and D(k,k) is a 1-by-1 diagonal block.
  104. *> (If IPIV( k ) = k, no interchange was done).
  105. *>
  106. *> If IPIV(k) < 0 and IPIV(k-1) < 0, then rows and
  107. *> columns k and -IPIV(k) were interchanged and rows and
  108. *> columns k-1 and -IPIV(k-1) were inerchaged,
  109. *> D(k-1:k,k-1:k) is a 2-by-2 diagonal block.
  110. *>
  111. *> If UPLO = 'L':
  112. *> If IPIV(k) > 0, then rows and columns k and IPIV(k)
  113. *> were interchanged and D(k,k) is a 1-by-1 diagonal block.
  114. *> (If IPIV( k ) = k, no interchange was done).
  115. *>
  116. *> If IPIV(k) < 0 and IPIV(k+1) < 0, then rows and
  117. *> columns k and -IPIV(k) were interchanged and rows and
  118. *> columns k+1 and -IPIV(k+1) were inerchaged,
  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 COMPLEX 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 complex_lin
  153. *
  154. * =====================================================================
  155. SUBROUTINE CLAVSY_ROOK( UPLO, TRANS, DIAG, N, NRHS, A, LDA, IPIV,
  156. $ B, 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. COMPLEX A( LDA, * ), B( LDB, * )
  170. * ..
  171. *
  172. * =====================================================================
  173. *
  174. * .. Parameters ..
  175. COMPLEX CONE
  176. PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
  177. * ..
  178. * .. Local Scalars ..
  179. LOGICAL NOUNIT
  180. INTEGER J, K, KP
  181. COMPLEX D11, D12, D21, D22, T1, T2
  182. * ..
  183. * .. External Functions ..
  184. LOGICAL LSAME
  185. EXTERNAL LSAME
  186. * ..
  187. * .. External Subroutines ..
  188. EXTERNAL CGEMV, CGERU, CSCAL, CSWAP, 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.LSAME( TRANS, 'T' ) )
  201. $ 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( 'CLAVSY_ROOK ', -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 CSCAL( 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 CGERU( K-1, NRHS, CONE, A( 1, K ), 1, B( K, 1 ),
  258. $ LDB, B( 1, 1 ), LDB )
  259. *
  260. * Interchange if P(K) != I.
  261. *
  262. KP = IPIV( K )
  263. IF( KP.NE.K )
  264. $ CALL CSWAP( 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 CGERU( K-1, NRHS, CONE, A( 1, K ), 1, B( K, 1 ),
  293. $ LDB, B( 1, 1 ), LDB )
  294. CALL CGERU( K-1, NRHS, CONE, A( 1, K+1 ), 1,
  295. $ B( K+1, 1 ), LDB, B( 1, 1 ), LDB )
  296. *
  297. * Interchange if a permutation was applied at the
  298. * K-th step of the factorization.
  299. *
  300. * Swap the first of pair with IMAXth
  301. *
  302. KP = ABS( IPIV( K ) )
  303. IF( KP.NE.K )
  304. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  305. *
  306. * NOW swap the first of pair with Pth
  307. *
  308. KP = ABS( IPIV( K+1 ) )
  309. IF( KP.NE.K+1 )
  310. $ CALL CSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ),
  311. $ LDB )
  312. END IF
  313. K = K + 2
  314. END IF
  315. GO TO 10
  316. 30 CONTINUE
  317. *
  318. * Compute B := L*B
  319. * where L = P(1)*inv(L(1))* ... *P(m)*inv(L(m)) .
  320. *
  321. ELSE
  322. *
  323. * Loop backward applying the transformations to B.
  324. *
  325. K = N
  326. 40 CONTINUE
  327. IF( K.LT.1 )
  328. $ GO TO 60
  329. *
  330. * Test the pivot index. If greater than zero, a 1 x 1
  331. * pivot was used, otherwise a 2 x 2 pivot was used.
  332. *
  333. IF( IPIV( K ).GT.0 ) THEN
  334. *
  335. * 1 x 1 pivot block:
  336. *
  337. * Multiply by the diagonal element if forming L * D.
  338. *
  339. IF( NOUNIT )
  340. $ CALL CSCAL( NRHS, A( K, K ), B( K, 1 ), LDB )
  341. *
  342. * Multiply by P(K) * inv(L(K)) if K < N.
  343. *
  344. IF( K.NE.N ) THEN
  345. KP = IPIV( K )
  346. *
  347. * Apply the transformation.
  348. *
  349. CALL CGERU( N-K, NRHS, CONE, A( K+1, K ), 1,
  350. $ B( K, 1 ), LDB, B( K+1, 1 ), LDB )
  351. *
  352. * Interchange if a permutation was applied at the
  353. * K-th step of the factorization.
  354. *
  355. IF( KP.NE.K )
  356. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  357. END IF
  358. K = K - 1
  359. *
  360. ELSE
  361. *
  362. * 2 x 2 pivot block:
  363. *
  364. * Multiply by the diagonal block if forming L * D.
  365. *
  366. IF( NOUNIT ) THEN
  367. D11 = A( K-1, K-1 )
  368. D22 = A( K, K )
  369. D21 = A( K, K-1 )
  370. D12 = D21
  371. DO 50 J = 1, NRHS
  372. T1 = B( K-1, J )
  373. T2 = B( K, J )
  374. B( K-1, J ) = D11*T1 + D12*T2
  375. B( K, J ) = D21*T1 + D22*T2
  376. 50 CONTINUE
  377. END IF
  378. *
  379. * Multiply by P(K) * inv(L(K)) if K < N.
  380. *
  381. IF( K.NE.N ) THEN
  382. *
  383. * Apply the transformation.
  384. *
  385. CALL CGERU( N-K, NRHS, CONE, A( K+1, K ), 1,
  386. $ B( K, 1 ), LDB, B( K+1, 1 ), LDB )
  387. CALL CGERU( N-K, NRHS, CONE, A( K+1, K-1 ), 1,
  388. $ B( K-1, 1 ), LDB, B( K+1, 1 ), LDB )
  389. *
  390. * Interchange if a permutation was applied at the
  391. * K-th step of the factorization.
  392. *
  393. * Swap the second of pair with IMAXth
  394. *
  395. KP = ABS( IPIV( K ) )
  396. IF( KP.NE.K )
  397. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  398. *
  399. * NOW swap the first of pair with Pth
  400. *
  401. KP = ABS( IPIV( K-1 ) )
  402. IF( KP.NE.K-1 )
  403. $ CALL CSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ),
  404. $ LDB )
  405. END IF
  406. K = K - 2
  407. END IF
  408. GO TO 40
  409. 60 CONTINUE
  410. END IF
  411. *----------------------------------------
  412. *
  413. * Compute B := A' * B (transpose)
  414. *
  415. *----------------------------------------
  416. ELSE IF( LSAME( TRANS, 'T' ) ) THEN
  417. *
  418. * Form B := U'*B
  419. * where U = P(m)*inv(U(m))* ... *P(1)*inv(U(1))
  420. * and U' = inv(U'(1))*P(1)* ... *inv(U'(m))*P(m)
  421. *
  422. IF( LSAME( UPLO, 'U' ) ) THEN
  423. *
  424. * Loop backward applying the transformations.
  425. *
  426. K = N
  427. 70 IF( K.LT.1 )
  428. $ GO TO 90
  429. *
  430. * 1 x 1 pivot block.
  431. *
  432. IF( IPIV( K ).GT.0 ) THEN
  433. IF( K.GT.1 ) THEN
  434. *
  435. * Interchange if P(K) != I.
  436. *
  437. KP = IPIV( K )
  438. IF( KP.NE.K )
  439. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  440. *
  441. * Apply the transformation
  442. *
  443. CALL CGEMV( 'Transpose', K-1, NRHS, CONE, B, LDB,
  444. $ A( 1, K ), 1, CONE, B( K, 1 ), LDB )
  445. END IF
  446. IF( NOUNIT )
  447. $ CALL CSCAL( NRHS, A( K, K ), B( K, 1 ), LDB )
  448. K = K - 1
  449. *
  450. * 2 x 2 pivot block.
  451. *
  452. ELSE
  453. IF( K.GT.2 ) THEN
  454. *
  455. * Swap the second of pair with Pth
  456. *
  457. KP = ABS( IPIV( K ) )
  458. IF( KP.NE.K )
  459. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  460. *
  461. * Now swap the first of pair with IMAX(r)th
  462. *
  463. KP = ABS( IPIV( K-1 ) )
  464. IF( KP.NE.K-1 )
  465. $ CALL CSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ),
  466. $ LDB )
  467. *
  468. * Apply the transformations
  469. *
  470. CALL CGEMV( 'Transpose', K-2, NRHS, CONE, B, LDB,
  471. $ A( 1, K ), 1, CONE, B( K, 1 ), LDB )
  472. CALL CGEMV( 'Transpose', K-2, NRHS, CONE, B, LDB,
  473. $ A( 1, K-1 ), 1, CONE, B( K-1, 1 ), LDB )
  474. END IF
  475. *
  476. * Multiply by the diagonal block if non-unit.
  477. *
  478. IF( NOUNIT ) THEN
  479. D11 = A( K-1, K-1 )
  480. D22 = A( K, K )
  481. D12 = A( K-1, K )
  482. D21 = D12
  483. DO 80 J = 1, NRHS
  484. T1 = B( K-1, J )
  485. T2 = B( K, J )
  486. B( K-1, J ) = D11*T1 + D12*T2
  487. B( K, J ) = D21*T1 + D22*T2
  488. 80 CONTINUE
  489. END IF
  490. K = K - 2
  491. END IF
  492. GO TO 70
  493. 90 CONTINUE
  494. *
  495. * Form B := L'*B
  496. * where L = P(1)*inv(L(1))* ... *P(m)*inv(L(m))
  497. * and L' = inv(L'(m))*P(m)* ... *inv(L'(1))*P(1)
  498. *
  499. ELSE
  500. *
  501. * Loop forward applying the L-transformations.
  502. *
  503. K = 1
  504. 100 CONTINUE
  505. IF( K.GT.N )
  506. $ GO TO 120
  507. *
  508. * 1 x 1 pivot block
  509. *
  510. IF( IPIV( K ).GT.0 ) THEN
  511. IF( K.LT.N ) THEN
  512. *
  513. * Interchange if P(K) != I.
  514. *
  515. KP = IPIV( K )
  516. IF( KP.NE.K )
  517. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  518. *
  519. * Apply the transformation
  520. *
  521. CALL CGEMV( 'Transpose', N-K, NRHS, CONE, B( K+1, 1 ),
  522. $ LDB, A( K+1, K ), 1, CONE, B( K, 1 ), LDB )
  523. END IF
  524. IF( NOUNIT )
  525. $ CALL CSCAL( NRHS, A( K, K ), B( K, 1 ), LDB )
  526. K = K + 1
  527. *
  528. * 2 x 2 pivot block.
  529. *
  530. ELSE
  531. IF( K.LT.N-1 ) THEN
  532. *
  533. * Swap the first of pair with Pth
  534. *
  535. KP = ABS( IPIV( K ) )
  536. IF( KP.NE.K )
  537. $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  538. *
  539. * Now swap the second of pair with IMAX(r)th
  540. *
  541. KP = ABS( IPIV( K+1 ) )
  542. IF( KP.NE.K+1 )
  543. $ CALL CSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ),
  544. $ LDB )
  545. *
  546. * Apply the transformation
  547. *
  548. CALL CGEMV( 'Transpose', N-K-1, NRHS, CONE,
  549. $ B( K+2, 1 ), LDB, A( K+2, K+1 ), 1, CONE,
  550. $ B( K+1, 1 ), LDB )
  551. CALL CGEMV( 'Transpose', N-K-1, NRHS, CONE,
  552. $ B( K+2, 1 ), LDB, A( K+2, K ), 1, CONE,
  553. $ B( K, 1 ), LDB )
  554. END IF
  555. *
  556. * Multiply by the diagonal block if non-unit.
  557. *
  558. IF( NOUNIT ) THEN
  559. D11 = A( K, K )
  560. D22 = A( K+1, K+1 )
  561. D21 = A( K+1, K )
  562. D12 = D21
  563. DO 110 J = 1, NRHS
  564. T1 = B( K, J )
  565. T2 = B( K+1, J )
  566. B( K, J ) = D11*T1 + D12*T2
  567. B( K+1, J ) = D21*T1 + D22*T2
  568. 110 CONTINUE
  569. END IF
  570. K = K + 2
  571. END IF
  572. GO TO 100
  573. 120 CONTINUE
  574. END IF
  575. END IF
  576. RETURN
  577. *
  578. * End of CLAVSY_ROOK
  579. *
  580. END