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.

zgesvdx.f 29 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. *> \brief <b> ZGESVDX computes the singular value decomposition (SVD) for GE matrices</b>
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download ZGESVDX + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgesvdx.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgesvdx.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgesvdx.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZGESVDX( JOBU, JOBVT, RANGE, M, N, A, LDA, VL, VU,
  22. * $ IL, IU, NS, S, U, LDU, VT, LDVT, WORK,
  23. * $ LWORK, RWORK, IWORK, INFO )
  24. *
  25. *
  26. * .. Scalar Arguments ..
  27. * CHARACTER JOBU, JOBVT, RANGE
  28. * INTEGER IL, INFO, IU, LDA, LDU, LDVT, LWORK, M, N, NS
  29. * DOUBLE PRECISION VL, VU
  30. * ..
  31. * .. Array Arguments ..
  32. * INTEGER IWORK( * )
  33. * DOUBLE PRECISION S( * ), RWORK( * )
  34. * COMPLEX*16 A( LDA, * ), U( LDU, * ), VT( LDVT, * ),
  35. * $ WORK( * )
  36. * ..
  37. *
  38. *
  39. *> \par Purpose:
  40. * =============
  41. *>
  42. *> \verbatim
  43. *>
  44. *> ZGESVDX computes the singular value decomposition (SVD) of a complex
  45. *> M-by-N matrix A, optionally computing the left and/or right singular
  46. *> vectors. The SVD is written
  47. *>
  48. *> A = U * SIGMA * transpose(V)
  49. *>
  50. *> where SIGMA is an M-by-N matrix which is zero except for its
  51. *> min(m,n) diagonal elements, U is an M-by-M unitary matrix, and
  52. *> V is an N-by-N unitary matrix. The diagonal elements of SIGMA
  53. *> are the singular values of A; they are real and non-negative, and
  54. *> are returned in descending order. The first min(m,n) columns of
  55. *> U and V are the left and right singular vectors of A.
  56. *>
  57. *> ZGESVDX uses an eigenvalue problem for obtaining the SVD, which
  58. *> allows for the computation of a subset of singular values and
  59. *> vectors. See DBDSVDX for details.
  60. *>
  61. *> Note that the routine returns V**T, not V.
  62. *> \endverbatim
  63. *
  64. * Arguments:
  65. * ==========
  66. *
  67. *> \param[in] JOBU
  68. *> \verbatim
  69. *> JOBU is CHARACTER*1
  70. *> Specifies options for computing all or part of the matrix U:
  71. *> = 'V': the first min(m,n) columns of U (the left singular
  72. *> vectors) or as specified by RANGE are returned in
  73. *> the array U;
  74. *> = 'N': no columns of U (no left singular vectors) are
  75. *> computed.
  76. *> \endverbatim
  77. *>
  78. *> \param[in] JOBVT
  79. *> \verbatim
  80. *> JOBVT is CHARACTER*1
  81. *> Specifies options for computing all or part of the matrix
  82. *> V**T:
  83. *> = 'V': the first min(m,n) rows of V**T (the right singular
  84. *> vectors) or as specified by RANGE are returned in
  85. *> the array VT;
  86. *> = 'N': no rows of V**T (no right singular vectors) are
  87. *> computed.
  88. *> \endverbatim
  89. *>
  90. *> \param[in] RANGE
  91. *> \verbatim
  92. *> RANGE is CHARACTER*1
  93. *> = 'A': all singular values will be found.
  94. *> = 'V': all singular values in the half-open interval (VL,VU]
  95. *> will be found.
  96. *> = 'I': the IL-th through IU-th singular values will be found.
  97. *> \endverbatim
  98. *>
  99. *> \param[in] M
  100. *> \verbatim
  101. *> M is INTEGER
  102. *> The number of rows of the input matrix A. M >= 0.
  103. *> \endverbatim
  104. *>
  105. *> \param[in] N
  106. *> \verbatim
  107. *> N is INTEGER
  108. *> The number of columns of the input matrix A. N >= 0.
  109. *> \endverbatim
  110. *>
  111. *> \param[in,out] A
  112. *> \verbatim
  113. *> A is COMPLEX*16 array, dimension (LDA,N)
  114. *> On entry, the M-by-N matrix A.
  115. *> On exit, the contents of A are destroyed.
  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] VL
  125. *> \verbatim
  126. *> VL is DOUBLE PRECISION
  127. *> If RANGE='V', the lower bound of the interval to
  128. *> be searched for singular values. VU > VL.
  129. *> Not referenced if RANGE = 'A' or 'I'.
  130. *> \endverbatim
  131. *>
  132. *> \param[in] VU
  133. *> \verbatim
  134. *> VU is DOUBLE PRECISION
  135. *> If RANGE='V', the upper bound of the interval to
  136. *> be searched for singular values. VU > VL.
  137. *> Not referenced if RANGE = 'A' or 'I'.
  138. *> \endverbatim
  139. *>
  140. *> \param[in] IL
  141. *> \verbatim
  142. *> IL is INTEGER
  143. *> If RANGE='I', the index of the
  144. *> smallest singular value to be returned.
  145. *> 1 <= IL <= IU <= min(M,N), if min(M,N) > 0.
  146. *> Not referenced if RANGE = 'A' or 'V'.
  147. *> \endverbatim
  148. *>
  149. *> \param[in] IU
  150. *> \verbatim
  151. *> IU is INTEGER
  152. *> If RANGE='I', the index of the
  153. *> largest singular value to be returned.
  154. *> 1 <= IL <= IU <= min(M,N), if min(M,N) > 0.
  155. *> Not referenced if RANGE = 'A' or 'V'.
  156. *> \endverbatim
  157. *>
  158. *> \param[out] NS
  159. *> \verbatim
  160. *> NS is INTEGER
  161. *> The total number of singular values found,
  162. *> 0 <= NS <= min(M,N).
  163. *> If RANGE = 'A', NS = min(M,N); if RANGE = 'I', NS = IU-IL+1.
  164. *> \endverbatim
  165. *>
  166. *> \param[out] S
  167. *> \verbatim
  168. *> S is DOUBLE PRECISION array, dimension (min(M,N))
  169. *> The singular values of A, sorted so that S(i) >= S(i+1).
  170. *> \endverbatim
  171. *>
  172. *> \param[out] U
  173. *> \verbatim
  174. *> U is COMPLEX*16 array, dimension (LDU,UCOL)
  175. *> If JOBU = 'V', U contains columns of U (the left singular
  176. *> vectors, stored columnwise) as specified by RANGE; if
  177. *> JOBU = 'N', U is not referenced.
  178. *> Note: The user must ensure that UCOL >= NS; if RANGE = 'V',
  179. *> the exact value of NS is not known in advance and an upper
  180. *> bound must be used.
  181. *> \endverbatim
  182. *>
  183. *> \param[in] LDU
  184. *> \verbatim
  185. *> LDU is INTEGER
  186. *> The leading dimension of the array U. LDU >= 1; if
  187. *> JOBU = 'V', LDU >= M.
  188. *> \endverbatim
  189. *>
  190. *> \param[out] VT
  191. *> \verbatim
  192. *> VT is COMPLEX*16 array, dimension (LDVT,N)
  193. *> If JOBVT = 'V', VT contains the rows of V**T (the right singular
  194. *> vectors, stored rowwise) as specified by RANGE; if JOBVT = 'N',
  195. *> VT is not referenced.
  196. *> Note: The user must ensure that LDVT >= NS; if RANGE = 'V',
  197. *> the exact value of NS is not known in advance and an upper
  198. *> bound must be used.
  199. *> \endverbatim
  200. *>
  201. *> \param[in] LDVT
  202. *> \verbatim
  203. *> LDVT is INTEGER
  204. *> The leading dimension of the array VT. LDVT >= 1; if
  205. *> JOBVT = 'V', LDVT >= NS (see above).
  206. *> \endverbatim
  207. *>
  208. *> \param[out] WORK
  209. *> \verbatim
  210. *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
  211. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK;
  212. *> \endverbatim
  213. *>
  214. *> \param[in] LWORK
  215. *> \verbatim
  216. *> LWORK is INTEGER
  217. *> The dimension of the array WORK.
  218. *> LWORK >= MAX(1,MIN(M,N)*(MIN(M,N)+4)) for the paths (see
  219. *> comments inside the code):
  220. *> - PATH 1 (M much larger than N)
  221. *> - PATH 1t (N much larger than M)
  222. *> LWORK >= MAX(1,MIN(M,N)*2+MAX(M,N)) for the other paths.
  223. *> For good performance, LWORK should generally be larger.
  224. *>
  225. *> If LWORK = -1, then a workspace query is assumed; the routine
  226. *> only calculates the optimal size of the WORK array, returns
  227. *> this value as the first entry of the WORK array, and no error
  228. *> message related to LWORK is issued by XERBLA.
  229. *> \endverbatim
  230. *>
  231. *> \param[out] RWORK
  232. *> \verbatim
  233. *> RWORK is DOUBLE PRECISION array, dimension (MAX(1,LRWORK))
  234. *> LRWORK >= MIN(M,N)*(MIN(M,N)*2+15*MIN(M,N)).
  235. *> \endverbatim
  236. *>
  237. *> \param[out] IWORK
  238. *> \verbatim
  239. *> IWORK is INTEGER array, dimension (12*MIN(M,N))
  240. *> If INFO = 0, the first NS elements of IWORK are zero. If INFO > 0,
  241. *> then IWORK contains the indices of the eigenvectors that failed
  242. *> to converge in DBDSVDX/DSTEVX.
  243. *> \endverbatim
  244. *>
  245. *> \param[out] INFO
  246. *> \verbatim
  247. *> INFO is INTEGER
  248. *> = 0: successful exit
  249. *> < 0: if INFO = -i, the i-th argument had an illegal value
  250. *> > 0: if INFO = i, then i eigenvectors failed to converge
  251. *> in DBDSVDX/DSTEVX.
  252. *> if INFO = N*2 + 1, an internal error occurred in
  253. *> DBDSVDX
  254. *> \endverbatim
  255. *
  256. * Authors:
  257. * ========
  258. *
  259. *> \author Univ. of Tennessee
  260. *> \author Univ. of California Berkeley
  261. *> \author Univ. of Colorado Denver
  262. *> \author NAG Ltd.
  263. *
  264. *> \ingroup complex16GEsing
  265. *
  266. * =====================================================================
  267. SUBROUTINE ZGESVDX( JOBU, JOBVT, RANGE, M, N, A, LDA, VL, VU,
  268. $ IL, IU, NS, S, U, LDU, VT, LDVT, WORK,
  269. $ LWORK, RWORK, IWORK, INFO )
  270. *
  271. * -- LAPACK driver routine --
  272. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  273. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  274. *
  275. * .. Scalar Arguments ..
  276. CHARACTER JOBU, JOBVT, RANGE
  277. INTEGER IL, INFO, IU, LDA, LDU, LDVT, LWORK, M, N, NS
  278. DOUBLE PRECISION VL, VU
  279. * ..
  280. * .. Array Arguments ..
  281. INTEGER IWORK( * )
  282. DOUBLE PRECISION S( * ), RWORK( * )
  283. COMPLEX*16 A( LDA, * ), U( LDU, * ), VT( LDVT, * ),
  284. $ WORK( * )
  285. * ..
  286. *
  287. * =====================================================================
  288. *
  289. * .. Parameters ..
  290. COMPLEX*16 CZERO, CONE
  291. PARAMETER ( CZERO = ( 0.0D0, 0.0D0 ),
  292. $ CONE = ( 1.0D0, 0.0D0 ) )
  293. DOUBLE PRECISION ZERO, ONE
  294. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
  295. * ..
  296. * .. Local Scalars ..
  297. CHARACTER JOBZ, RNGTGK
  298. LOGICAL ALLS, INDS, LQUERY, VALS, WANTU, WANTVT
  299. INTEGER I, ID, IE, IERR, ILQF, ILTGK, IQRF, ISCL,
  300. $ ITAU, ITAUP, ITAUQ, ITEMP, ITEMPR, ITGKZ,
  301. $ IUTGK, J, K, MAXWRK, MINMN, MINWRK, MNTHR
  302. DOUBLE PRECISION ABSTOL, ANRM, BIGNUM, EPS, SMLNUM
  303. * ..
  304. * .. Local Arrays ..
  305. DOUBLE PRECISION DUM( 1 )
  306. * ..
  307. * .. External Subroutines ..
  308. EXTERNAL ZGEBRD, ZGELQF, ZGEQRF, ZLASCL, ZLASET, ZLACPY,
  309. $ ZUNMLQ, ZUNMBR, ZUNMQR, DBDSVDX, DLASCL, XERBLA
  310. * ..
  311. * .. External Functions ..
  312. LOGICAL LSAME
  313. INTEGER ILAENV
  314. DOUBLE PRECISION DLAMCH, ZLANGE
  315. EXTERNAL LSAME, ILAENV, DLAMCH, ZLANGE
  316. * ..
  317. * .. Intrinsic Functions ..
  318. INTRINSIC MAX, MIN, SQRT
  319. * ..
  320. * .. Executable Statements ..
  321. *
  322. * Test the input arguments.
  323. *
  324. NS = 0
  325. INFO = 0
  326. ABSTOL = 2*DLAMCH('S')
  327. LQUERY = ( LWORK.EQ.-1 )
  328. MINMN = MIN( M, N )
  329. WANTU = LSAME( JOBU, 'V' )
  330. WANTVT = LSAME( JOBVT, 'V' )
  331. IF( WANTU .OR. WANTVT ) THEN
  332. JOBZ = 'V'
  333. ELSE
  334. JOBZ = 'N'
  335. END IF
  336. ALLS = LSAME( RANGE, 'A' )
  337. VALS = LSAME( RANGE, 'V' )
  338. INDS = LSAME( RANGE, 'I' )
  339. *
  340. INFO = 0
  341. IF( .NOT.LSAME( JOBU, 'V' ) .AND.
  342. $ .NOT.LSAME( JOBU, 'N' ) ) THEN
  343. INFO = -1
  344. ELSE IF( .NOT.LSAME( JOBVT, 'V' ) .AND.
  345. $ .NOT.LSAME( JOBVT, 'N' ) ) THEN
  346. INFO = -2
  347. ELSE IF( .NOT.( ALLS .OR. VALS .OR. INDS ) ) THEN
  348. INFO = -3
  349. ELSE IF( M.LT.0 ) THEN
  350. INFO = -4
  351. ELSE IF( N.LT.0 ) THEN
  352. INFO = -5
  353. ELSE IF( M.GT.LDA ) THEN
  354. INFO = -7
  355. ELSE IF( MINMN.GT.0 ) THEN
  356. IF( VALS ) THEN
  357. IF( VL.LT.ZERO ) THEN
  358. INFO = -8
  359. ELSE IF( VU.LE.VL ) THEN
  360. INFO = -9
  361. END IF
  362. ELSE IF( INDS ) THEN
  363. IF( IL.LT.1 .OR. IL.GT.MAX( 1, MINMN ) ) THEN
  364. INFO = -10
  365. ELSE IF( IU.LT.MIN( MINMN, IL ) .OR. IU.GT.MINMN ) THEN
  366. INFO = -11
  367. END IF
  368. END IF
  369. IF( INFO.EQ.0 ) THEN
  370. IF( WANTU .AND. LDU.LT.M ) THEN
  371. INFO = -15
  372. ELSE IF( WANTVT ) THEN
  373. IF( INDS ) THEN
  374. IF( LDVT.LT.IU-IL+1 ) THEN
  375. INFO = -17
  376. END IF
  377. ELSE IF( LDVT.LT.MINMN ) THEN
  378. INFO = -17
  379. END IF
  380. END IF
  381. END IF
  382. END IF
  383. *
  384. * Compute workspace
  385. * (Note: Comments in the code beginning "Workspace:" describe the
  386. * minimal amount of workspace needed at that point in the code,
  387. * as well as the preferred amount for good performance.
  388. * NB refers to the optimal block size for the immediately
  389. * following subroutine, as returned by ILAENV.)
  390. *
  391. IF( INFO.EQ.0 ) THEN
  392. MINWRK = 1
  393. MAXWRK = 1
  394. IF( MINMN.GT.0 ) THEN
  395. IF( M.GE.N ) THEN
  396. MNTHR = ILAENV( 6, 'ZGESVD', JOBU // JOBVT, M, N, 0, 0 )
  397. IF( M.GE.MNTHR ) THEN
  398. *
  399. * Path 1 (M much larger than N)
  400. *
  401. MINWRK = N*(N+5)
  402. MAXWRK = N + N*ILAENV(1,'ZGEQRF',' ',M,N,-1,-1)
  403. MAXWRK = MAX(MAXWRK,
  404. $ N*N+2*N+2*N*ILAENV(1,'ZGEBRD',' ',N,N,-1,-1))
  405. IF (WANTU .OR. WANTVT) THEN
  406. MAXWRK = MAX(MAXWRK,
  407. $ N*N+2*N+N*ILAENV(1,'ZUNMQR','LN',N,N,N,-1))
  408. END IF
  409. ELSE
  410. *
  411. * Path 2 (M at least N, but not much larger)
  412. *
  413. MINWRK = 3*N + M
  414. MAXWRK = 2*N + (M+N)*ILAENV(1,'ZGEBRD',' ',M,N,-1,-1)
  415. IF (WANTU .OR. WANTVT) THEN
  416. MAXWRK = MAX(MAXWRK,
  417. $ 2*N+N*ILAENV(1,'ZUNMQR','LN',N,N,N,-1))
  418. END IF
  419. END IF
  420. ELSE
  421. MNTHR = ILAENV( 6, 'ZGESVD', JOBU // JOBVT, M, N, 0, 0 )
  422. IF( N.GE.MNTHR ) THEN
  423. *
  424. * Path 1t (N much larger than M)
  425. *
  426. MINWRK = M*(M+5)
  427. MAXWRK = M + M*ILAENV(1,'ZGELQF',' ',M,N,-1,-1)
  428. MAXWRK = MAX(MAXWRK,
  429. $ M*M+2*M+2*M*ILAENV(1,'ZGEBRD',' ',M,M,-1,-1))
  430. IF (WANTU .OR. WANTVT) THEN
  431. MAXWRK = MAX(MAXWRK,
  432. $ M*M+2*M+M*ILAENV(1,'ZUNMQR','LN',M,M,M,-1))
  433. END IF
  434. ELSE
  435. *
  436. * Path 2t (N greater than M, but not much larger)
  437. *
  438. *
  439. MINWRK = 3*M + N
  440. MAXWRK = 2*M + (M+N)*ILAENV(1,'ZGEBRD',' ',M,N,-1,-1)
  441. IF (WANTU .OR. WANTVT) THEN
  442. MAXWRK = MAX(MAXWRK,
  443. $ 2*M+M*ILAENV(1,'ZUNMQR','LN',M,M,M,-1))
  444. END IF
  445. END IF
  446. END IF
  447. END IF
  448. MAXWRK = MAX( MAXWRK, MINWRK )
  449. WORK( 1 ) = DCMPLX( DBLE( MAXWRK ), ZERO )
  450. *
  451. IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
  452. INFO = -19
  453. END IF
  454. END IF
  455. *
  456. IF( INFO.NE.0 ) THEN
  457. CALL XERBLA( 'ZGESVDX', -INFO )
  458. RETURN
  459. ELSE IF( LQUERY ) THEN
  460. RETURN
  461. END IF
  462. *
  463. * Quick return if possible
  464. *
  465. IF( M.EQ.0 .OR. N.EQ.0 ) THEN
  466. RETURN
  467. END IF
  468. *
  469. * Set singular values indices accord to RANGE='A'.
  470. *
  471. IF( ALLS ) THEN
  472. RNGTGK = 'I'
  473. ILTGK = 1
  474. IUTGK = MIN( M, N )
  475. ELSE IF( INDS ) THEN
  476. RNGTGK = 'I'
  477. ILTGK = IL
  478. IUTGK = IU
  479. ELSE
  480. RNGTGK = 'V'
  481. ILTGK = 0
  482. IUTGK = 0
  483. END IF
  484. *
  485. * Get machine constants
  486. *
  487. EPS = DLAMCH( 'P' )
  488. SMLNUM = SQRT( DLAMCH( 'S' ) ) / EPS
  489. BIGNUM = ONE / SMLNUM
  490. *
  491. * Scale A if max element outside range [SMLNUM,BIGNUM]
  492. *
  493. ANRM = ZLANGE( 'M', M, N, A, LDA, DUM )
  494. ISCL = 0
  495. IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
  496. ISCL = 1
  497. CALL ZLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, A, LDA, INFO )
  498. ELSE IF( ANRM.GT.BIGNUM ) THEN
  499. ISCL = 1
  500. CALL ZLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, A, LDA, INFO )
  501. END IF
  502. *
  503. IF( M.GE.N ) THEN
  504. *
  505. * A has at least as many rows as columns. If A has sufficiently
  506. * more rows than columns, first reduce A using the QR
  507. * decomposition.
  508. *
  509. IF( M.GE.MNTHR ) THEN
  510. *
  511. * Path 1 (M much larger than N):
  512. * A = Q * R = Q * ( QB * B * PB**T )
  513. * = Q * ( QB * ( UB * S * VB**T ) * PB**T )
  514. * U = Q * QB * UB; V**T = VB**T * PB**T
  515. *
  516. * Compute A=Q*R
  517. * (Workspace: need 2*N, prefer N+N*NB)
  518. *
  519. ITAU = 1
  520. ITEMP = ITAU + N
  521. CALL ZGEQRF( M, N, A, LDA, WORK( ITAU ), WORK( ITEMP ),
  522. $ LWORK-ITEMP+1, INFO )
  523. *
  524. * Copy R into WORK and bidiagonalize it:
  525. * (Workspace: need N*N+3*N, prefer N*N+N+2*N*NB)
  526. *
  527. IQRF = ITEMP
  528. ITAUQ = ITEMP + N*N
  529. ITAUP = ITAUQ + N
  530. ITEMP = ITAUP + N
  531. ID = 1
  532. IE = ID + N
  533. ITGKZ = IE + N
  534. CALL ZLACPY( 'U', N, N, A, LDA, WORK( IQRF ), N )
  535. CALL ZLASET( 'L', N-1, N-1, CZERO, CZERO,
  536. $ WORK( IQRF+1 ), N )
  537. CALL ZGEBRD( N, N, WORK( IQRF ), N, RWORK( ID ),
  538. $ RWORK( IE ), WORK( ITAUQ ), WORK( ITAUP ),
  539. $ WORK( ITEMP ), LWORK-ITEMP+1, INFO )
  540. ITEMPR = ITGKZ + N*(N*2+1)
  541. *
  542. * Solve eigenvalue problem TGK*Z=Z*S.
  543. * (Workspace: need 2*N*N+14*N)
  544. *
  545. CALL DBDSVDX( 'U', JOBZ, RNGTGK, N, RWORK( ID ),
  546. $ RWORK( IE ), VL, VU, ILTGK, IUTGK, NS, S,
  547. $ RWORK( ITGKZ ), N*2, RWORK( ITEMPR ),
  548. $ IWORK, INFO)
  549. *
  550. * If needed, compute left singular vectors.
  551. *
  552. IF( WANTU ) THEN
  553. K = ITGKZ
  554. DO I = 1, NS
  555. DO J = 1, N
  556. U( J, I ) = DCMPLX( RWORK( K ), ZERO )
  557. K = K + 1
  558. END DO
  559. K = K + N
  560. END DO
  561. CALL ZLASET( 'A', M-N, NS, CZERO, CZERO, U( N+1,1 ), LDU)
  562. *
  563. * Call ZUNMBR to compute QB*UB.
  564. * (Workspace in WORK( ITEMP ): need N, prefer N*NB)
  565. *
  566. CALL ZUNMBR( 'Q', 'L', 'N', N, NS, N, WORK( IQRF ), N,
  567. $ WORK( ITAUQ ), U, LDU, WORK( ITEMP ),
  568. $ LWORK-ITEMP+1, INFO )
  569. *
  570. * Call ZUNMQR to compute Q*(QB*UB).
  571. * (Workspace in WORK( ITEMP ): need N, prefer N*NB)
  572. *
  573. CALL ZUNMQR( 'L', 'N', M, NS, N, A, LDA,
  574. $ WORK( ITAU ), U, LDU, WORK( ITEMP ),
  575. $ LWORK-ITEMP+1, INFO )
  576. END IF
  577. *
  578. * If needed, compute right singular vectors.
  579. *
  580. IF( WANTVT) THEN
  581. K = ITGKZ + N
  582. DO I = 1, NS
  583. DO J = 1, N
  584. VT( I, J ) = DCMPLX( RWORK( K ), ZERO )
  585. K = K + 1
  586. END DO
  587. K = K + N
  588. END DO
  589. *
  590. * Call ZUNMBR to compute VB**T * PB**T
  591. * (Workspace in WORK( ITEMP ): need N, prefer N*NB)
  592. *
  593. CALL ZUNMBR( 'P', 'R', 'C', NS, N, N, WORK( IQRF ), N,
  594. $ WORK( ITAUP ), VT, LDVT, WORK( ITEMP ),
  595. $ LWORK-ITEMP+1, INFO )
  596. END IF
  597. ELSE
  598. *
  599. * Path 2 (M at least N, but not much larger)
  600. * Reduce A to bidiagonal form without QR decomposition
  601. * A = QB * B * PB**T = QB * ( UB * S * VB**T ) * PB**T
  602. * U = QB * UB; V**T = VB**T * PB**T
  603. *
  604. * Bidiagonalize A
  605. * (Workspace: need 2*N+M, prefer 2*N+(M+N)*NB)
  606. *
  607. ITAUQ = 1
  608. ITAUP = ITAUQ + N
  609. ITEMP = ITAUP + N
  610. ID = 1
  611. IE = ID + N
  612. ITGKZ = IE + N
  613. CALL ZGEBRD( M, N, A, LDA, RWORK( ID ), RWORK( IE ),
  614. $ WORK( ITAUQ ), WORK( ITAUP ), WORK( ITEMP ),
  615. $ LWORK-ITEMP+1, INFO )
  616. ITEMPR = ITGKZ + N*(N*2+1)
  617. *
  618. * Solve eigenvalue problem TGK*Z=Z*S.
  619. * (Workspace: need 2*N*N+14*N)
  620. *
  621. CALL DBDSVDX( 'U', JOBZ, RNGTGK, N, RWORK( ID ),
  622. $ RWORK( IE ), VL, VU, ILTGK, IUTGK, NS, S,
  623. $ RWORK( ITGKZ ), N*2, RWORK( ITEMPR ),
  624. $ IWORK, INFO)
  625. *
  626. * If needed, compute left singular vectors.
  627. *
  628. IF( WANTU ) THEN
  629. K = ITGKZ
  630. DO I = 1, NS
  631. DO J = 1, N
  632. U( J, I ) = DCMPLX( RWORK( K ), ZERO )
  633. K = K + 1
  634. END DO
  635. K = K + N
  636. END DO
  637. CALL ZLASET( 'A', M-N, NS, CZERO, CZERO, U( N+1,1 ), LDU)
  638. *
  639. * Call ZUNMBR to compute QB*UB.
  640. * (Workspace in WORK( ITEMP ): need N, prefer N*NB)
  641. *
  642. CALL ZUNMBR( 'Q', 'L', 'N', M, NS, N, A, LDA,
  643. $ WORK( ITAUQ ), U, LDU, WORK( ITEMP ),
  644. $ LWORK-ITEMP+1, IERR )
  645. END IF
  646. *
  647. * If needed, compute right singular vectors.
  648. *
  649. IF( WANTVT) THEN
  650. K = ITGKZ + N
  651. DO I = 1, NS
  652. DO J = 1, N
  653. VT( I, J ) = DCMPLX( RWORK( K ), ZERO )
  654. K = K + 1
  655. END DO
  656. K = K + N
  657. END DO
  658. *
  659. * Call ZUNMBR to compute VB**T * PB**T
  660. * (Workspace in WORK( ITEMP ): need N, prefer N*NB)
  661. *
  662. CALL ZUNMBR( 'P', 'R', 'C', NS, N, N, A, LDA,
  663. $ WORK( ITAUP ), VT, LDVT, WORK( ITEMP ),
  664. $ LWORK-ITEMP+1, IERR )
  665. END IF
  666. END IF
  667. ELSE
  668. *
  669. * A has more columns than rows. If A has sufficiently more
  670. * columns than rows, first reduce A using the LQ decomposition.
  671. *
  672. IF( N.GE.MNTHR ) THEN
  673. *
  674. * Path 1t (N much larger than M):
  675. * A = L * Q = ( QB * B * PB**T ) * Q
  676. * = ( QB * ( UB * S * VB**T ) * PB**T ) * Q
  677. * U = QB * UB ; V**T = VB**T * PB**T * Q
  678. *
  679. * Compute A=L*Q
  680. * (Workspace: need 2*M, prefer M+M*NB)
  681. *
  682. ITAU = 1
  683. ITEMP = ITAU + M
  684. CALL ZGELQF( M, N, A, LDA, WORK( ITAU ), WORK( ITEMP ),
  685. $ LWORK-ITEMP+1, INFO )
  686. * Copy L into WORK and bidiagonalize it:
  687. * (Workspace in WORK( ITEMP ): need M*M+3*M, prefer M*M+M+2*M*NB)
  688. *
  689. ILQF = ITEMP
  690. ITAUQ = ILQF + M*M
  691. ITAUP = ITAUQ + M
  692. ITEMP = ITAUP + M
  693. ID = 1
  694. IE = ID + M
  695. ITGKZ = IE + M
  696. CALL ZLACPY( 'L', M, M, A, LDA, WORK( ILQF ), M )
  697. CALL ZLASET( 'U', M-1, M-1, CZERO, CZERO,
  698. $ WORK( ILQF+M ), M )
  699. CALL ZGEBRD( M, M, WORK( ILQF ), M, RWORK( ID ),
  700. $ RWORK( IE ), WORK( ITAUQ ), WORK( ITAUP ),
  701. $ WORK( ITEMP ), LWORK-ITEMP+1, INFO )
  702. ITEMPR = ITGKZ + M*(M*2+1)
  703. *
  704. * Solve eigenvalue problem TGK*Z=Z*S.
  705. * (Workspace: need 2*M*M+14*M)
  706. *
  707. CALL DBDSVDX( 'U', JOBZ, RNGTGK, M, RWORK( ID ),
  708. $ RWORK( IE ), VL, VU, ILTGK, IUTGK, NS, S,
  709. $ RWORK( ITGKZ ), M*2, RWORK( ITEMPR ),
  710. $ IWORK, INFO)
  711. *
  712. * If needed, compute left singular vectors.
  713. *
  714. IF( WANTU ) THEN
  715. K = ITGKZ
  716. DO I = 1, NS
  717. DO J = 1, M
  718. U( J, I ) = DCMPLX( RWORK( K ), ZERO )
  719. K = K + 1
  720. END DO
  721. K = K + M
  722. END DO
  723. *
  724. * Call ZUNMBR to compute QB*UB.
  725. * (Workspace in WORK( ITEMP ): need M, prefer M*NB)
  726. *
  727. CALL ZUNMBR( 'Q', 'L', 'N', M, NS, M, WORK( ILQF ), M,
  728. $ WORK( ITAUQ ), U, LDU, WORK( ITEMP ),
  729. $ LWORK-ITEMP+1, INFO )
  730. END IF
  731. *
  732. * If needed, compute right singular vectors.
  733. *
  734. IF( WANTVT) THEN
  735. K = ITGKZ + M
  736. DO I = 1, NS
  737. DO J = 1, M
  738. VT( I, J ) = DCMPLX( RWORK( K ), ZERO )
  739. K = K + 1
  740. END DO
  741. K = K + M
  742. END DO
  743. CALL ZLASET( 'A', NS, N-M, CZERO, CZERO,
  744. $ VT( 1,M+1 ), LDVT )
  745. *
  746. * Call ZUNMBR to compute (VB**T)*(PB**T)
  747. * (Workspace in WORK( ITEMP ): need M, prefer M*NB)
  748. *
  749. CALL ZUNMBR( 'P', 'R', 'C', NS, M, M, WORK( ILQF ), M,
  750. $ WORK( ITAUP ), VT, LDVT, WORK( ITEMP ),
  751. $ LWORK-ITEMP+1, INFO )
  752. *
  753. * Call ZUNMLQ to compute ((VB**T)*(PB**T))*Q.
  754. * (Workspace in WORK( ITEMP ): need M, prefer M*NB)
  755. *
  756. CALL ZUNMLQ( 'R', 'N', NS, N, M, A, LDA,
  757. $ WORK( ITAU ), VT, LDVT, WORK( ITEMP ),
  758. $ LWORK-ITEMP+1, INFO )
  759. END IF
  760. ELSE
  761. *
  762. * Path 2t (N greater than M, but not much larger)
  763. * Reduce to bidiagonal form without LQ decomposition
  764. * A = QB * B * PB**T = QB * ( UB * S * VB**T ) * PB**T
  765. * U = QB * UB; V**T = VB**T * PB**T
  766. *
  767. * Bidiagonalize A
  768. * (Workspace: need 2*M+N, prefer 2*M+(M+N)*NB)
  769. *
  770. ITAUQ = 1
  771. ITAUP = ITAUQ + M
  772. ITEMP = ITAUP + M
  773. ID = 1
  774. IE = ID + M
  775. ITGKZ = IE + M
  776. CALL ZGEBRD( M, N, A, LDA, RWORK( ID ), RWORK( IE ),
  777. $ WORK( ITAUQ ), WORK( ITAUP ), WORK( ITEMP ),
  778. $ LWORK-ITEMP+1, INFO )
  779. ITEMPR = ITGKZ + M*(M*2+1)
  780. *
  781. * Solve eigenvalue problem TGK*Z=Z*S.
  782. * (Workspace: need 2*M*M+14*M)
  783. *
  784. CALL DBDSVDX( 'L', JOBZ, RNGTGK, M, RWORK( ID ),
  785. $ RWORK( IE ), VL, VU, ILTGK, IUTGK, NS, S,
  786. $ RWORK( ITGKZ ), M*2, RWORK( ITEMPR ),
  787. $ IWORK, INFO)
  788. *
  789. * If needed, compute left singular vectors.
  790. *
  791. IF( WANTU ) THEN
  792. K = ITGKZ
  793. DO I = 1, NS
  794. DO J = 1, M
  795. U( J, I ) = DCMPLX( RWORK( K ), ZERO )
  796. K = K + 1
  797. END DO
  798. K = K + M
  799. END DO
  800. *
  801. * Call ZUNMBR to compute QB*UB.
  802. * (Workspace in WORK( ITEMP ): need M, prefer M*NB)
  803. *
  804. CALL ZUNMBR( 'Q', 'L', 'N', M, NS, N, A, LDA,
  805. $ WORK( ITAUQ ), U, LDU, WORK( ITEMP ),
  806. $ LWORK-ITEMP+1, INFO )
  807. END IF
  808. *
  809. * If needed, compute right singular vectors.
  810. *
  811. IF( WANTVT) THEN
  812. K = ITGKZ + M
  813. DO I = 1, NS
  814. DO J = 1, M
  815. VT( I, J ) = DCMPLX( RWORK( K ), ZERO )
  816. K = K + 1
  817. END DO
  818. K = K + M
  819. END DO
  820. CALL ZLASET( 'A', NS, N-M, CZERO, CZERO,
  821. $ VT( 1,M+1 ), LDVT )
  822. *
  823. * Call ZUNMBR to compute VB**T * PB**T
  824. * (Workspace in WORK( ITEMP ): need M, prefer M*NB)
  825. *
  826. CALL ZUNMBR( 'P', 'R', 'C', NS, N, M, A, LDA,
  827. $ WORK( ITAUP ), VT, LDVT, WORK( ITEMP ),
  828. $ LWORK-ITEMP+1, INFO )
  829. END IF
  830. END IF
  831. END IF
  832. *
  833. * Undo scaling if necessary
  834. *
  835. IF( ISCL.EQ.1 ) THEN
  836. IF( ANRM.GT.BIGNUM )
  837. $ CALL DLASCL( 'G', 0, 0, BIGNUM, ANRM, MINMN, 1,
  838. $ S, MINMN, INFO )
  839. IF( ANRM.LT.SMLNUM )
  840. $ CALL DLASCL( 'G', 0, 0, SMLNUM, ANRM, MINMN, 1,
  841. $ S, MINMN, INFO )
  842. END IF
  843. *
  844. * Return optimal workspace in WORK(1)
  845. *
  846. WORK( 1 ) = DCMPLX( DBLE( MAXWRK ), ZERO )
  847. *
  848. RETURN
  849. *
  850. * End of ZGESVDX
  851. *
  852. END