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.

dlasd3.f 13 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. *> \brief \b DLASD3 finds all square roots of the roots of the secular equation, as defined by the values in D and Z, and then updates the singular vectors by matrix multiplication. Used by sbdsdc.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download DLASD3 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasd3.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasd3.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasd3.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DLASD3( NL, NR, SQRE, K, D, Q, LDQ, DSIGMA, U, LDU, U2,
  22. * LDU2, VT, LDVT, VT2, LDVT2, IDXC, CTOT, Z,
  23. * INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * INTEGER INFO, K, LDQ, LDU, LDU2, LDVT, LDVT2, NL, NR,
  27. * $ SQRE
  28. * ..
  29. * .. Array Arguments ..
  30. * INTEGER CTOT( * ), IDXC( * )
  31. * DOUBLE PRECISION D( * ), DSIGMA( * ), Q( LDQ, * ), U( LDU, * ),
  32. * $ U2( LDU2, * ), VT( LDVT, * ), VT2( LDVT2, * ),
  33. * $ Z( * )
  34. * ..
  35. *
  36. *
  37. *> \par Purpose:
  38. * =============
  39. *>
  40. *> \verbatim
  41. *>
  42. *> DLASD3 finds all the square roots of the roots of the secular
  43. *> equation, as defined by the values in D and Z. It makes the
  44. *> appropriate calls to DLASD4 and then updates the singular
  45. *> vectors by matrix multiplication.
  46. *>
  47. *> DLASD3 is called from DLASD1.
  48. *> \endverbatim
  49. *
  50. * Arguments:
  51. * ==========
  52. *
  53. *> \param[in] NL
  54. *> \verbatim
  55. *> NL is INTEGER
  56. *> The row dimension of the upper block. NL >= 1.
  57. *> \endverbatim
  58. *>
  59. *> \param[in] NR
  60. *> \verbatim
  61. *> NR is INTEGER
  62. *> The row dimension of the lower block. NR >= 1.
  63. *> \endverbatim
  64. *>
  65. *> \param[in] SQRE
  66. *> \verbatim
  67. *> SQRE is INTEGER
  68. *> = 0: the lower block is an NR-by-NR square matrix.
  69. *> = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
  70. *>
  71. *> The bidiagonal matrix has N = NL + NR + 1 rows and
  72. *> M = N + SQRE >= N columns.
  73. *> \endverbatim
  74. *>
  75. *> \param[in] K
  76. *> \verbatim
  77. *> K is INTEGER
  78. *> The size of the secular equation, 1 =< K = < N.
  79. *> \endverbatim
  80. *>
  81. *> \param[out] D
  82. *> \verbatim
  83. *> D is DOUBLE PRECISION array, dimension(K)
  84. *> On exit the square roots of the roots of the secular equation,
  85. *> in ascending order.
  86. *> \endverbatim
  87. *>
  88. *> \param[out] Q
  89. *> \verbatim
  90. *> Q is DOUBLE PRECISION array, dimension (LDQ,K)
  91. *> \endverbatim
  92. *>
  93. *> \param[in] LDQ
  94. *> \verbatim
  95. *> LDQ is INTEGER
  96. *> The leading dimension of the array Q. LDQ >= K.
  97. *> \endverbatim
  98. *>
  99. *> \param[in] DSIGMA
  100. *> \verbatim
  101. *> DSIGMA is DOUBLE PRECISION array, dimension(K)
  102. *> The first K elements of this array contain the old roots
  103. *> of the deflated updating problem. These are the poles
  104. *> of the secular equation.
  105. *> \endverbatim
  106. *>
  107. *> \param[out] U
  108. *> \verbatim
  109. *> U is DOUBLE PRECISION array, dimension (LDU, N)
  110. *> The last N - K columns of this matrix contain the deflated
  111. *> left singular vectors.
  112. *> \endverbatim
  113. *>
  114. *> \param[in] LDU
  115. *> \verbatim
  116. *> LDU is INTEGER
  117. *> The leading dimension of the array U. LDU >= N.
  118. *> \endverbatim
  119. *>
  120. *> \param[in] U2
  121. *> \verbatim
  122. *> U2 is DOUBLE PRECISION array, dimension (LDU2, N)
  123. *> The first K columns of this matrix contain the non-deflated
  124. *> left singular vectors for the split problem.
  125. *> \endverbatim
  126. *>
  127. *> \param[in] LDU2
  128. *> \verbatim
  129. *> LDU2 is INTEGER
  130. *> The leading dimension of the array U2. LDU2 >= N.
  131. *> \endverbatim
  132. *>
  133. *> \param[out] VT
  134. *> \verbatim
  135. *> VT is DOUBLE PRECISION array, dimension (LDVT, M)
  136. *> The last M - K columns of VT**T contain the deflated
  137. *> right singular vectors.
  138. *> \endverbatim
  139. *>
  140. *> \param[in] LDVT
  141. *> \verbatim
  142. *> LDVT is INTEGER
  143. *> The leading dimension of the array VT. LDVT >= N.
  144. *> \endverbatim
  145. *>
  146. *> \param[in,out] VT2
  147. *> \verbatim
  148. *> VT2 is DOUBLE PRECISION array, dimension (LDVT2, N)
  149. *> The first K columns of VT2**T contain the non-deflated
  150. *> right singular vectors for the split problem.
  151. *> \endverbatim
  152. *>
  153. *> \param[in] LDVT2
  154. *> \verbatim
  155. *> LDVT2 is INTEGER
  156. *> The leading dimension of the array VT2. LDVT2 >= N.
  157. *> \endverbatim
  158. *>
  159. *> \param[in] IDXC
  160. *> \verbatim
  161. *> IDXC is INTEGER array, dimension ( N )
  162. *> The permutation used to arrange the columns of U (and rows of
  163. *> VT) into three groups: the first group contains non-zero
  164. *> entries only at and above (or before) NL +1; the second
  165. *> contains non-zero entries only at and below (or after) NL+2;
  166. *> and the third is dense. The first column of U and the row of
  167. *> VT are treated separately, however.
  168. *>
  169. *> The rows of the singular vectors found by DLASD4
  170. *> must be likewise permuted before the matrix multiplies can
  171. *> take place.
  172. *> \endverbatim
  173. *>
  174. *> \param[in] CTOT
  175. *> \verbatim
  176. *> CTOT is INTEGER array, dimension ( 4 )
  177. *> A count of the total number of the various types of columns
  178. *> in U (or rows in VT), as described in IDXC. The fourth column
  179. *> type is any column which has been deflated.
  180. *> \endverbatim
  181. *>
  182. *> \param[in,out] Z
  183. *> \verbatim
  184. *> Z is DOUBLE PRECISION array, dimension (K)
  185. *> The first K elements of this array contain the components
  186. *> of the deflation-adjusted updating row vector.
  187. *> \endverbatim
  188. *>
  189. *> \param[out] INFO
  190. *> \verbatim
  191. *> INFO is INTEGER
  192. *> = 0: successful exit.
  193. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  194. *> > 0: if INFO = 1, a singular value did not converge
  195. *> \endverbatim
  196. *
  197. * Authors:
  198. * ========
  199. *
  200. *> \author Univ. of Tennessee
  201. *> \author Univ. of California Berkeley
  202. *> \author Univ. of Colorado Denver
  203. *> \author NAG Ltd.
  204. *
  205. *> \ingroup OTHERauxiliary
  206. *
  207. *> \par Contributors:
  208. * ==================
  209. *>
  210. *> Ming Gu and Huan Ren, Computer Science Division, University of
  211. *> California at Berkeley, USA
  212. *>
  213. * =====================================================================
  214. SUBROUTINE DLASD3( NL, NR, SQRE, K, D, Q, LDQ, DSIGMA, U, LDU, U2,
  215. $ LDU2, VT, LDVT, VT2, LDVT2, IDXC, CTOT, Z,
  216. $ INFO )
  217. *
  218. * -- LAPACK auxiliary routine --
  219. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  220. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  221. *
  222. * .. Scalar Arguments ..
  223. INTEGER INFO, K, LDQ, LDU, LDU2, LDVT, LDVT2, NL, NR,
  224. $ SQRE
  225. * ..
  226. * .. Array Arguments ..
  227. INTEGER CTOT( * ), IDXC( * )
  228. DOUBLE PRECISION D( * ), DSIGMA( * ), Q( LDQ, * ), U( LDU, * ),
  229. $ U2( LDU2, * ), VT( LDVT, * ), VT2( LDVT2, * ),
  230. $ Z( * )
  231. * ..
  232. *
  233. * =====================================================================
  234. *
  235. * .. Parameters ..
  236. DOUBLE PRECISION ONE, ZERO, NEGONE
  237. PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0,
  238. $ NEGONE = -1.0D+0 )
  239. * ..
  240. * .. Local Scalars ..
  241. INTEGER CTEMP, I, J, JC, KTEMP, M, N, NLP1, NLP2, NRP1
  242. DOUBLE PRECISION RHO, TEMP
  243. * ..
  244. * .. External Functions ..
  245. DOUBLE PRECISION DNRM2
  246. EXTERNAL DNRM2
  247. * ..
  248. * .. External Subroutines ..
  249. EXTERNAL DCOPY, DGEMM, DLACPY, DLASCL, DLASD4, XERBLA
  250. * ..
  251. * .. Intrinsic Functions ..
  252. INTRINSIC ABS, SIGN, SQRT
  253. * ..
  254. * .. Executable Statements ..
  255. *
  256. * Test the input parameters.
  257. *
  258. INFO = 0
  259. *
  260. IF( NL.LT.1 ) THEN
  261. INFO = -1
  262. ELSE IF( NR.LT.1 ) THEN
  263. INFO = -2
  264. ELSE IF( ( SQRE.NE.1 ) .AND. ( SQRE.NE.0 ) ) THEN
  265. INFO = -3
  266. END IF
  267. *
  268. N = NL + NR + 1
  269. M = N + SQRE
  270. NLP1 = NL + 1
  271. NLP2 = NL + 2
  272. *
  273. IF( ( K.LT.1 ) .OR. ( K.GT.N ) ) THEN
  274. INFO = -4
  275. ELSE IF( LDQ.LT.K ) THEN
  276. INFO = -7
  277. ELSE IF( LDU.LT.N ) THEN
  278. INFO = -10
  279. ELSE IF( LDU2.LT.N ) THEN
  280. INFO = -12
  281. ELSE IF( LDVT.LT.M ) THEN
  282. INFO = -14
  283. ELSE IF( LDVT2.LT.M ) THEN
  284. INFO = -16
  285. END IF
  286. IF( INFO.NE.0 ) THEN
  287. CALL XERBLA( 'DLASD3', -INFO )
  288. RETURN
  289. END IF
  290. *
  291. * Quick return if possible
  292. *
  293. IF( K.EQ.1 ) THEN
  294. D( 1 ) = ABS( Z( 1 ) )
  295. CALL DCOPY( M, VT2( 1, 1 ), LDVT2, VT( 1, 1 ), LDVT )
  296. IF( Z( 1 ).GT.ZERO ) THEN
  297. CALL DCOPY( N, U2( 1, 1 ), 1, U( 1, 1 ), 1 )
  298. ELSE
  299. DO 10 I = 1, N
  300. U( I, 1 ) = -U2( I, 1 )
  301. 10 CONTINUE
  302. END IF
  303. RETURN
  304. END IF
  305. *
  306. * Keep a copy of Z.
  307. *
  308. CALL DCOPY( K, Z, 1, Q, 1 )
  309. *
  310. * Normalize Z.
  311. *
  312. RHO = DNRM2( K, Z, 1 )
  313. CALL DLASCL( 'G', 0, 0, RHO, ONE, K, 1, Z, K, INFO )
  314. RHO = RHO*RHO
  315. *
  316. * Find the new singular values.
  317. *
  318. DO 30 J = 1, K
  319. CALL DLASD4( K, J, DSIGMA, Z, U( 1, J ), RHO, D( J ),
  320. $ VT( 1, J ), INFO )
  321. *
  322. * If the zero finder fails, report the convergence failure.
  323. *
  324. IF( INFO.NE.0 ) THEN
  325. RETURN
  326. END IF
  327. 30 CONTINUE
  328. *
  329. * Compute updated Z.
  330. *
  331. DO 60 I = 1, K
  332. Z( I ) = U( I, K )*VT( I, K )
  333. DO 40 J = 1, I - 1
  334. Z( I ) = Z( I )*( U( I, J )*VT( I, J ) /
  335. $ ( DSIGMA( I )-DSIGMA( J ) ) /
  336. $ ( DSIGMA( I )+DSIGMA( J ) ) )
  337. 40 CONTINUE
  338. DO 50 J = I, K - 1
  339. Z( I ) = Z( I )*( U( I, J )*VT( I, J ) /
  340. $ ( DSIGMA( I )-DSIGMA( J+1 ) ) /
  341. $ ( DSIGMA( I )+DSIGMA( J+1 ) ) )
  342. 50 CONTINUE
  343. Z( I ) = SIGN( SQRT( ABS( Z( I ) ) ), Q( I, 1 ) )
  344. 60 CONTINUE
  345. *
  346. * Compute left singular vectors of the modified diagonal matrix,
  347. * and store related information for the right singular vectors.
  348. *
  349. DO 90 I = 1, K
  350. VT( 1, I ) = Z( 1 ) / U( 1, I ) / VT( 1, I )
  351. U( 1, I ) = NEGONE
  352. DO 70 J = 2, K
  353. VT( J, I ) = Z( J ) / U( J, I ) / VT( J, I )
  354. U( J, I ) = DSIGMA( J )*VT( J, I )
  355. 70 CONTINUE
  356. TEMP = DNRM2( K, U( 1, I ), 1 )
  357. Q( 1, I ) = U( 1, I ) / TEMP
  358. DO 80 J = 2, K
  359. JC = IDXC( J )
  360. Q( J, I ) = U( JC, I ) / TEMP
  361. 80 CONTINUE
  362. 90 CONTINUE
  363. *
  364. * Update the left singular vector matrix.
  365. *
  366. IF( K.EQ.2 ) THEN
  367. CALL DGEMM( 'N', 'N', N, K, K, ONE, U2, LDU2, Q, LDQ, ZERO, U,
  368. $ LDU )
  369. GO TO 100
  370. END IF
  371. IF( CTOT( 1 ).GT.0 ) THEN
  372. CALL DGEMM( 'N', 'N', NL, K, CTOT( 1 ), ONE, U2( 1, 2 ), LDU2,
  373. $ Q( 2, 1 ), LDQ, ZERO, U( 1, 1 ), LDU )
  374. IF( CTOT( 3 ).GT.0 ) THEN
  375. KTEMP = 2 + CTOT( 1 ) + CTOT( 2 )
  376. CALL DGEMM( 'N', 'N', NL, K, CTOT( 3 ), ONE, U2( 1, KTEMP ),
  377. $ LDU2, Q( KTEMP, 1 ), LDQ, ONE, U( 1, 1 ), LDU )
  378. END IF
  379. ELSE IF( CTOT( 3 ).GT.0 ) THEN
  380. KTEMP = 2 + CTOT( 1 ) + CTOT( 2 )
  381. CALL DGEMM( 'N', 'N', NL, K, CTOT( 3 ), ONE, U2( 1, KTEMP ),
  382. $ LDU2, Q( KTEMP, 1 ), LDQ, ZERO, U( 1, 1 ), LDU )
  383. ELSE
  384. CALL DLACPY( 'F', NL, K, U2, LDU2, U, LDU )
  385. END IF
  386. CALL DCOPY( K, Q( 1, 1 ), LDQ, U( NLP1, 1 ), LDU )
  387. KTEMP = 2 + CTOT( 1 )
  388. CTEMP = CTOT( 2 ) + CTOT( 3 )
  389. CALL DGEMM( 'N', 'N', NR, K, CTEMP, ONE, U2( NLP2, KTEMP ), LDU2,
  390. $ Q( KTEMP, 1 ), LDQ, ZERO, U( NLP2, 1 ), LDU )
  391. *
  392. * Generate the right singular vectors.
  393. *
  394. 100 CONTINUE
  395. DO 120 I = 1, K
  396. TEMP = DNRM2( K, VT( 1, I ), 1 )
  397. Q( I, 1 ) = VT( 1, I ) / TEMP
  398. DO 110 J = 2, K
  399. JC = IDXC( J )
  400. Q( I, J ) = VT( JC, I ) / TEMP
  401. 110 CONTINUE
  402. 120 CONTINUE
  403. *
  404. * Update the right singular vector matrix.
  405. *
  406. IF( K.EQ.2 ) THEN
  407. CALL DGEMM( 'N', 'N', K, M, K, ONE, Q, LDQ, VT2, LDVT2, ZERO,
  408. $ VT, LDVT )
  409. RETURN
  410. END IF
  411. KTEMP = 1 + CTOT( 1 )
  412. CALL DGEMM( 'N', 'N', K, NLP1, KTEMP, ONE, Q( 1, 1 ), LDQ,
  413. $ VT2( 1, 1 ), LDVT2, ZERO, VT( 1, 1 ), LDVT )
  414. KTEMP = 2 + CTOT( 1 ) + CTOT( 2 )
  415. IF( KTEMP.LE.LDVT2 )
  416. $ CALL DGEMM( 'N', 'N', K, NLP1, CTOT( 3 ), ONE, Q( 1, KTEMP ),
  417. $ LDQ, VT2( KTEMP, 1 ), LDVT2, ONE, VT( 1, 1 ),
  418. $ LDVT )
  419. *
  420. KTEMP = CTOT( 1 ) + 1
  421. NRP1 = NR + SQRE
  422. IF( KTEMP.GT.1 ) THEN
  423. DO 130 I = 1, K
  424. Q( I, KTEMP ) = Q( I, 1 )
  425. 130 CONTINUE
  426. DO 140 I = NLP2, M
  427. VT2( KTEMP, I ) = VT2( 1, I )
  428. 140 CONTINUE
  429. END IF
  430. CTEMP = 1 + CTOT( 2 ) + CTOT( 3 )
  431. CALL DGEMM( 'N', 'N', K, NRP1, CTEMP, ONE, Q( 1, KTEMP ), LDQ,
  432. $ VT2( KTEMP, NLP2 ), LDVT2, ZERO, VT( 1, NLP2 ), LDVT )
  433. *
  434. RETURN
  435. *
  436. * End of DLASD3
  437. *
  438. END