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.

cggsvp.f 15 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. *> \brief \b CGGSVP
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CGGSVP + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cggsvp.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cggsvp.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cggsvp.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CGGSVP( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB,
  22. * TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ,
  23. * IWORK, RWORK, TAU, WORK, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * CHARACTER JOBQ, JOBU, JOBV
  27. * INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P
  28. * REAL TOLA, TOLB
  29. * ..
  30. * .. Array Arguments ..
  31. * INTEGER IWORK( * )
  32. * REAL RWORK( * )
  33. * COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
  34. * $ TAU( * ), U( LDU, * ), V( LDV, * ), WORK( * )
  35. * ..
  36. *
  37. *
  38. *> \par Purpose:
  39. * =============
  40. *>
  41. *> \verbatim
  42. *>
  43. *> CGGSVP computes unitary matrices U, V and Q such that
  44. *>
  45. *> N-K-L K L
  46. *> U**H*A*Q = K ( 0 A12 A13 ) if M-K-L >= 0;
  47. *> L ( 0 0 A23 )
  48. *> M-K-L ( 0 0 0 )
  49. *>
  50. *> N-K-L K L
  51. *> = K ( 0 A12 A13 ) if M-K-L < 0;
  52. *> M-K ( 0 0 A23 )
  53. *>
  54. *> N-K-L K L
  55. *> V**H*B*Q = L ( 0 0 B13 )
  56. *> P-L ( 0 0 0 )
  57. *>
  58. *> where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular
  59. *> upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0,
  60. *> otherwise A23 is (M-K)-by-L upper trapezoidal. K+L = the effective
  61. *> numerical rank of the (M+P)-by-N matrix (A**H,B**H)**H.
  62. *>
  63. *> This decomposition is the preprocessing step for computing the
  64. *> Generalized Singular Value Decomposition (GSVD), see subroutine
  65. *> CGGSVD.
  66. *> \endverbatim
  67. *
  68. * Arguments:
  69. * ==========
  70. *
  71. *> \param[in] JOBU
  72. *> \verbatim
  73. *> JOBU is CHARACTER*1
  74. *> = 'U': Unitary matrix U is computed;
  75. *> = 'N': U is not computed.
  76. *> \endverbatim
  77. *>
  78. *> \param[in] JOBV
  79. *> \verbatim
  80. *> JOBV is CHARACTER*1
  81. *> = 'V': Unitary matrix V is computed;
  82. *> = 'N': V is not computed.
  83. *> \endverbatim
  84. *>
  85. *> \param[in] JOBQ
  86. *> \verbatim
  87. *> JOBQ is CHARACTER*1
  88. *> = 'Q': Unitary matrix Q is computed;
  89. *> = 'N': Q is not computed.
  90. *> \endverbatim
  91. *>
  92. *> \param[in] M
  93. *> \verbatim
  94. *> M is INTEGER
  95. *> The number of rows of the matrix A. M >= 0.
  96. *> \endverbatim
  97. *>
  98. *> \param[in] P
  99. *> \verbatim
  100. *> P is INTEGER
  101. *> The number of rows of the matrix B. P >= 0.
  102. *> \endverbatim
  103. *>
  104. *> \param[in] N
  105. *> \verbatim
  106. *> N is INTEGER
  107. *> The number of columns of the matrices A and B. N >= 0.
  108. *> \endverbatim
  109. *>
  110. *> \param[in,out] A
  111. *> \verbatim
  112. *> A is COMPLEX array, dimension (LDA,N)
  113. *> On entry, the M-by-N matrix A.
  114. *> On exit, A contains the triangular (or trapezoidal) matrix
  115. *> described in the Purpose section.
  116. *> \endverbatim
  117. *>
  118. *> \param[in] LDA
  119. *> \verbatim
  120. *> LDA is INTEGER
  121. *> The leading dimension of the array A. LDA >= max(1,M).
  122. *> \endverbatim
  123. *>
  124. *> \param[in,out] B
  125. *> \verbatim
  126. *> B is COMPLEX array, dimension (LDB,N)
  127. *> On entry, the P-by-N matrix B.
  128. *> On exit, B contains the triangular matrix described in
  129. *> the Purpose section.
  130. *> \endverbatim
  131. *>
  132. *> \param[in] LDB
  133. *> \verbatim
  134. *> LDB is INTEGER
  135. *> The leading dimension of the array B. LDB >= max(1,P).
  136. *> \endverbatim
  137. *>
  138. *> \param[in] TOLA
  139. *> \verbatim
  140. *> TOLA is REAL
  141. *> \endverbatim
  142. *>
  143. *> \param[in] TOLB
  144. *> \verbatim
  145. *> TOLB is REAL
  146. *>
  147. *> TOLA and TOLB are the thresholds to determine the effective
  148. *> numerical rank of matrix B and a subblock of A. Generally,
  149. *> they are set to
  150. *> TOLA = MAX(M,N)*norm(A)*MACHEPS,
  151. *> TOLB = MAX(P,N)*norm(B)*MACHEPS.
  152. *> The size of TOLA and TOLB may affect the size of backward
  153. *> errors of the decomposition.
  154. *> \endverbatim
  155. *>
  156. *> \param[out] K
  157. *> \verbatim
  158. *> K is INTEGER
  159. *> \endverbatim
  160. *>
  161. *> \param[out] L
  162. *> \verbatim
  163. *> L is INTEGER
  164. *>
  165. *> On exit, K and L specify the dimension of the subblocks
  166. *> described in Purpose section.
  167. *> K + L = effective numerical rank of (A**H,B**H)**H.
  168. *> \endverbatim
  169. *>
  170. *> \param[out] U
  171. *> \verbatim
  172. *> U is COMPLEX array, dimension (LDU,M)
  173. *> If JOBU = 'U', U contains the unitary matrix U.
  174. *> If JOBU = 'N', U is not referenced.
  175. *> \endverbatim
  176. *>
  177. *> \param[in] LDU
  178. *> \verbatim
  179. *> LDU is INTEGER
  180. *> The leading dimension of the array U. LDU >= max(1,M) if
  181. *> JOBU = 'U'; LDU >= 1 otherwise.
  182. *> \endverbatim
  183. *>
  184. *> \param[out] V
  185. *> \verbatim
  186. *> V is COMPLEX array, dimension (LDV,P)
  187. *> If JOBV = 'V', V contains the unitary matrix V.
  188. *> If JOBV = 'N', V is not referenced.
  189. *> \endverbatim
  190. *>
  191. *> \param[in] LDV
  192. *> \verbatim
  193. *> LDV is INTEGER
  194. *> The leading dimension of the array V. LDV >= max(1,P) if
  195. *> JOBV = 'V'; LDV >= 1 otherwise.
  196. *> \endverbatim
  197. *>
  198. *> \param[out] Q
  199. *> \verbatim
  200. *> Q is COMPLEX array, dimension (LDQ,N)
  201. *> If JOBQ = 'Q', Q contains the unitary matrix Q.
  202. *> If JOBQ = 'N', Q is not referenced.
  203. *> \endverbatim
  204. *>
  205. *> \param[in] LDQ
  206. *> \verbatim
  207. *> LDQ is INTEGER
  208. *> The leading dimension of the array Q. LDQ >= max(1,N) if
  209. *> JOBQ = 'Q'; LDQ >= 1 otherwise.
  210. *> \endverbatim
  211. *>
  212. *> \param[out] IWORK
  213. *> \verbatim
  214. *> IWORK is INTEGER array, dimension (N)
  215. *> \endverbatim
  216. *>
  217. *> \param[out] RWORK
  218. *> \verbatim
  219. *> RWORK is REAL array, dimension (2*N)
  220. *> \endverbatim
  221. *>
  222. *> \param[out] TAU
  223. *> \verbatim
  224. *> TAU is COMPLEX array, dimension (N)
  225. *> \endverbatim
  226. *>
  227. *> \param[out] WORK
  228. *> \verbatim
  229. *> WORK is COMPLEX array, dimension (max(3*N,M,P))
  230. *> \endverbatim
  231. *>
  232. *> \param[out] INFO
  233. *> \verbatim
  234. *> INFO is INTEGER
  235. *> = 0: successful exit
  236. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  237. *> \endverbatim
  238. *
  239. * Authors:
  240. * ========
  241. *
  242. *> \author Univ. of Tennessee
  243. *> \author Univ. of California Berkeley
  244. *> \author Univ. of Colorado Denver
  245. *> \author NAG Ltd.
  246. *
  247. *> \date November 2011
  248. *
  249. *> \ingroup complexOTHERcomputational
  250. *
  251. *> \par Further Details:
  252. * =====================
  253. *>
  254. *> The subroutine uses LAPACK subroutine CGEQPF for the QR factorization
  255. *> with column pivoting to detect the effective numerical rank of the
  256. *> a matrix. It may be replaced by a better rank determination strategy.
  257. *>
  258. * =====================================================================
  259. SUBROUTINE CGGSVP( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB,
  260. $ TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ,
  261. $ IWORK, RWORK, TAU, WORK, INFO )
  262. *
  263. * -- LAPACK computational routine (version 3.4.0) --
  264. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  265. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  266. * November 2011
  267. *
  268. * .. Scalar Arguments ..
  269. CHARACTER JOBQ, JOBU, JOBV
  270. INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P
  271. REAL TOLA, TOLB
  272. * ..
  273. * .. Array Arguments ..
  274. INTEGER IWORK( * )
  275. REAL RWORK( * )
  276. COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
  277. $ TAU( * ), U( LDU, * ), V( LDV, * ), WORK( * )
  278. * ..
  279. *
  280. * =====================================================================
  281. *
  282. * .. Parameters ..
  283. COMPLEX CZERO, CONE
  284. PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ),
  285. $ CONE = ( 1.0E+0, 0.0E+0 ) )
  286. * ..
  287. * .. Local Scalars ..
  288. LOGICAL FORWRD, WANTQ, WANTU, WANTV
  289. INTEGER I, J
  290. COMPLEX T
  291. * ..
  292. * .. External Functions ..
  293. LOGICAL LSAME
  294. EXTERNAL LSAME
  295. * ..
  296. * .. External Subroutines ..
  297. EXTERNAL CGEQPF, CGEQR2, CGERQ2, CLACPY, CLAPMT, CLASET,
  298. $ CUNG2R, CUNM2R, CUNMR2, XERBLA
  299. * ..
  300. * .. Intrinsic Functions ..
  301. INTRINSIC ABS, AIMAG, MAX, MIN, REAL
  302. * ..
  303. * .. Statement Functions ..
  304. REAL CABS1
  305. * ..
  306. * .. Statement Function definitions ..
  307. CABS1( T ) = ABS( REAL( T ) ) + ABS( AIMAG( T ) )
  308. * ..
  309. * .. Executable Statements ..
  310. *
  311. * Test the input parameters
  312. *
  313. WANTU = LSAME( JOBU, 'U' )
  314. WANTV = LSAME( JOBV, 'V' )
  315. WANTQ = LSAME( JOBQ, 'Q' )
  316. FORWRD = .TRUE.
  317. *
  318. INFO = 0
  319. IF( .NOT.( WANTU .OR. LSAME( JOBU, 'N' ) ) ) THEN
  320. INFO = -1
  321. ELSE IF( .NOT.( WANTV .OR. LSAME( JOBV, 'N' ) ) ) THEN
  322. INFO = -2
  323. ELSE IF( .NOT.( WANTQ .OR. LSAME( JOBQ, 'N' ) ) ) THEN
  324. INFO = -3
  325. ELSE IF( M.LT.0 ) THEN
  326. INFO = -4
  327. ELSE IF( P.LT.0 ) THEN
  328. INFO = -5
  329. ELSE IF( N.LT.0 ) THEN
  330. INFO = -6
  331. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  332. INFO = -8
  333. ELSE IF( LDB.LT.MAX( 1, P ) ) THEN
  334. INFO = -10
  335. ELSE IF( LDU.LT.1 .OR. ( WANTU .AND. LDU.LT.M ) ) THEN
  336. INFO = -16
  337. ELSE IF( LDV.LT.1 .OR. ( WANTV .AND. LDV.LT.P ) ) THEN
  338. INFO = -18
  339. ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN
  340. INFO = -20
  341. END IF
  342. IF( INFO.NE.0 ) THEN
  343. CALL XERBLA( 'CGGSVP', -INFO )
  344. RETURN
  345. END IF
  346. *
  347. * QR with column pivoting of B: B*P = V*( S11 S12 )
  348. * ( 0 0 )
  349. *
  350. DO 10 I = 1, N
  351. IWORK( I ) = 0
  352. 10 CONTINUE
  353. CALL CGEQPF( P, N, B, LDB, IWORK, TAU, WORK, RWORK, INFO )
  354. *
  355. * Update A := A*P
  356. *
  357. CALL CLAPMT( FORWRD, M, N, A, LDA, IWORK )
  358. *
  359. * Determine the effective rank of matrix B.
  360. *
  361. L = 0
  362. DO 20 I = 1, MIN( P, N )
  363. IF( CABS1( B( I, I ) ).GT.TOLB )
  364. $ L = L + 1
  365. 20 CONTINUE
  366. *
  367. IF( WANTV ) THEN
  368. *
  369. * Copy the details of V, and form V.
  370. *
  371. CALL CLASET( 'Full', P, P, CZERO, CZERO, V, LDV )
  372. IF( P.GT.1 )
  373. $ CALL CLACPY( 'Lower', P-1, N, B( 2, 1 ), LDB, V( 2, 1 ),
  374. $ LDV )
  375. CALL CUNG2R( P, P, MIN( P, N ), V, LDV, TAU, WORK, INFO )
  376. END IF
  377. *
  378. * Clean up B
  379. *
  380. DO 40 J = 1, L - 1
  381. DO 30 I = J + 1, L
  382. B( I, J ) = CZERO
  383. 30 CONTINUE
  384. 40 CONTINUE
  385. IF( P.GT.L )
  386. $ CALL CLASET( 'Full', P-L, N, CZERO, CZERO, B( L+1, 1 ), LDB )
  387. *
  388. IF( WANTQ ) THEN
  389. *
  390. * Set Q = I and Update Q := Q*P
  391. *
  392. CALL CLASET( 'Full', N, N, CZERO, CONE, Q, LDQ )
  393. CALL CLAPMT( FORWRD, N, N, Q, LDQ, IWORK )
  394. END IF
  395. *
  396. IF( P.GE.L .AND. N.NE.L ) THEN
  397. *
  398. * RQ factorization of ( S11 S12 ) = ( 0 S12 )*Z
  399. *
  400. CALL CGERQ2( L, N, B, LDB, TAU, WORK, INFO )
  401. *
  402. * Update A := A*Z**H
  403. *
  404. CALL CUNMR2( 'Right', 'Conjugate transpose', M, N, L, B, LDB,
  405. $ TAU, A, LDA, WORK, INFO )
  406. IF( WANTQ ) THEN
  407. *
  408. * Update Q := Q*Z**H
  409. *
  410. CALL CUNMR2( 'Right', 'Conjugate transpose', N, N, L, B,
  411. $ LDB, TAU, Q, LDQ, WORK, INFO )
  412. END IF
  413. *
  414. * Clean up B
  415. *
  416. CALL CLASET( 'Full', L, N-L, CZERO, CZERO, B, LDB )
  417. DO 60 J = N - L + 1, N
  418. DO 50 I = J - N + L + 1, L
  419. B( I, J ) = CZERO
  420. 50 CONTINUE
  421. 60 CONTINUE
  422. *
  423. END IF
  424. *
  425. * Let N-L L
  426. * A = ( A11 A12 ) M,
  427. *
  428. * then the following does the complete QR decomposition of A11:
  429. *
  430. * A11 = U*( 0 T12 )*P1**H
  431. * ( 0 0 )
  432. *
  433. DO 70 I = 1, N - L
  434. IWORK( I ) = 0
  435. 70 CONTINUE
  436. CALL CGEQPF( M, N-L, A, LDA, IWORK, TAU, WORK, RWORK, INFO )
  437. *
  438. * Determine the effective rank of A11
  439. *
  440. K = 0
  441. DO 80 I = 1, MIN( M, N-L )
  442. IF( CABS1( A( I, I ) ).GT.TOLA )
  443. $ K = K + 1
  444. 80 CONTINUE
  445. *
  446. * Update A12 := U**H*A12, where A12 = A( 1:M, N-L+1:N )
  447. *
  448. CALL CUNM2R( 'Left', 'Conjugate transpose', M, L, MIN( M, N-L ),
  449. $ A, LDA, TAU, A( 1, N-L+1 ), LDA, WORK, INFO )
  450. *
  451. IF( WANTU ) THEN
  452. *
  453. * Copy the details of U, and form U
  454. *
  455. CALL CLASET( 'Full', M, M, CZERO, CZERO, U, LDU )
  456. IF( M.GT.1 )
  457. $ CALL CLACPY( 'Lower', M-1, N-L, A( 2, 1 ), LDA, U( 2, 1 ),
  458. $ LDU )
  459. CALL CUNG2R( M, M, MIN( M, N-L ), U, LDU, TAU, WORK, INFO )
  460. END IF
  461. *
  462. IF( WANTQ ) THEN
  463. *
  464. * Update Q( 1:N, 1:N-L ) = Q( 1:N, 1:N-L )*P1
  465. *
  466. CALL CLAPMT( FORWRD, N, N-L, Q, LDQ, IWORK )
  467. END IF
  468. *
  469. * Clean up A: set the strictly lower triangular part of
  470. * A(1:K, 1:K) = 0, and A( K+1:M, 1:N-L ) = 0.
  471. *
  472. DO 100 J = 1, K - 1
  473. DO 90 I = J + 1, K
  474. A( I, J ) = CZERO
  475. 90 CONTINUE
  476. 100 CONTINUE
  477. IF( M.GT.K )
  478. $ CALL CLASET( 'Full', M-K, N-L, CZERO, CZERO, A( K+1, 1 ), LDA )
  479. *
  480. IF( N-L.GT.K ) THEN
  481. *
  482. * RQ factorization of ( T11 T12 ) = ( 0 T12 )*Z1
  483. *
  484. CALL CGERQ2( K, N-L, A, LDA, TAU, WORK, INFO )
  485. *
  486. IF( WANTQ ) THEN
  487. *
  488. * Update Q( 1:N,1:N-L ) = Q( 1:N,1:N-L )*Z1**H
  489. *
  490. CALL CUNMR2( 'Right', 'Conjugate transpose', N, N-L, K, A,
  491. $ LDA, TAU, Q, LDQ, WORK, INFO )
  492. END IF
  493. *
  494. * Clean up A
  495. *
  496. CALL CLASET( 'Full', K, N-L-K, CZERO, CZERO, A, LDA )
  497. DO 120 J = N - L - K + 1, N - L
  498. DO 110 I = J - N + L + K + 1, K
  499. A( I, J ) = CZERO
  500. 110 CONTINUE
  501. 120 CONTINUE
  502. *
  503. END IF
  504. *
  505. IF( M.GT.K ) THEN
  506. *
  507. * QR factorization of A( K+1:M,N-L+1:N )
  508. *
  509. CALL CGEQR2( M-K, L, A( K+1, N-L+1 ), LDA, TAU, WORK, INFO )
  510. *
  511. IF( WANTU ) THEN
  512. *
  513. * Update U(:,K+1:M) := U(:,K+1:M)*U1
  514. *
  515. CALL CUNM2R( 'Right', 'No transpose', M, M-K, MIN( M-K, L ),
  516. $ A( K+1, N-L+1 ), LDA, TAU, U( 1, K+1 ), LDU,
  517. $ WORK, INFO )
  518. END IF
  519. *
  520. * Clean up
  521. *
  522. DO 140 J = N - L + 1, N
  523. DO 130 I = J - N + K + L + 1, M
  524. A( I, J ) = CZERO
  525. 130 CONTINUE
  526. 140 CONTINUE
  527. *
  528. END IF
  529. *
  530. RETURN
  531. *
  532. * End of CGGSVP
  533. *
  534. END