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.

dgesvj.f 69 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628
  1. *> \brief \b DGESVJ
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download DGESVJ + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgesvj.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgesvj.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgesvj.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DGESVJ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V,
  22. * LDV, WORK, LWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * INTEGER INFO, LDA, LDV, LWORK, M, MV, N
  26. * CHARACTER*1 JOBA, JOBU, JOBV
  27. * ..
  28. * .. Array Arguments ..
  29. * DOUBLE PRECISION A( LDA, * ), SVA( N ), V( LDV, * ),
  30. * $ WORK( LWORK )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *>
  39. *> DGESVJ computes the singular value decomposition (SVD) of a real
  40. *> M-by-N matrix A, where M >= N. The SVD of A is written as
  41. *> [++] [xx] [x0] [xx]
  42. *> A = U * SIGMA * V^t, [++] = [xx] * [ox] * [xx]
  43. *> [++] [xx]
  44. *> where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal
  45. *> matrix, and V is an N-by-N orthogonal matrix. The diagonal elements
  46. *> of SIGMA are the singular values of A. The columns of U and V are the
  47. *> left and the right singular vectors of A, respectively.
  48. *> DGESVJ can sometimes compute tiny singular values and their singular vectors much
  49. *> more accurately than other SVD routines, see below under Further Details.
  50. *> \endverbatim
  51. *
  52. * Arguments:
  53. * ==========
  54. *
  55. *> \param[in] JOBA
  56. *> \verbatim
  57. *> JOBA is CHARACTER*1
  58. *> Specifies the structure of A.
  59. *> = 'L': The input matrix A is lower triangular;
  60. *> = 'U': The input matrix A is upper triangular;
  61. *> = 'G': The input matrix A is general M-by-N matrix, M >= N.
  62. *> \endverbatim
  63. *>
  64. *> \param[in] JOBU
  65. *> \verbatim
  66. *> JOBU is CHARACTER*1
  67. *> Specifies whether to compute the left singular vectors
  68. *> (columns of U):
  69. *> = 'U': The left singular vectors corresponding to the nonzero
  70. *> singular values are computed and returned in the leading
  71. *> columns of A. See more details in the description of A.
  72. *> The default numerical orthogonality threshold is set to
  73. *> approximately TOL=CTOL*EPS, CTOL=DSQRT(M), EPS=DLAMCH('E').
  74. *> = 'C': Analogous to JOBU='U', except that user can control the
  75. *> level of numerical orthogonality of the computed left
  76. *> singular vectors. TOL can be set to TOL = CTOL*EPS, where
  77. *> CTOL is given on input in the array WORK.
  78. *> No CTOL smaller than ONE is allowed. CTOL greater
  79. *> than 1 / EPS is meaningless. The option 'C'
  80. *> can be used if M*EPS is satisfactory orthogonality
  81. *> of the computed left singular vectors, so CTOL=M could
  82. *> save few sweeps of Jacobi rotations.
  83. *> See the descriptions of A and WORK(1).
  84. *> = 'N': The matrix U is not computed. However, see the
  85. *> description of A.
  86. *> \endverbatim
  87. *>
  88. *> \param[in] JOBV
  89. *> \verbatim
  90. *> JOBV is CHARACTER*1
  91. *> Specifies whether to compute the right singular vectors, that
  92. *> is, the matrix V:
  93. *> = 'V': the matrix V is computed and returned in the array V
  94. *> = 'A': the Jacobi rotations are applied to the MV-by-N
  95. *> array V. In other words, the right singular vector
  96. *> matrix V is not computed explicitly, instead it is
  97. *> applied to an MV-by-N matrix initially stored in the
  98. *> first MV rows of V.
  99. *> = 'N': the matrix V is not computed and the array V is not
  100. *> referenced
  101. *> \endverbatim
  102. *>
  103. *> \param[in] M
  104. *> \verbatim
  105. *> M is INTEGER
  106. *> The number of rows of the input matrix A. 1/DLAMCH('E') > M >= 0.
  107. *> \endverbatim
  108. *>
  109. *> \param[in] N
  110. *> \verbatim
  111. *> N is INTEGER
  112. *> The number of columns of the input matrix A.
  113. *> M >= N >= 0.
  114. *> \endverbatim
  115. *>
  116. *> \param[in,out] A
  117. *> \verbatim
  118. *> A is DOUBLE PRECISION array, dimension (LDA,N)
  119. *> On entry, the M-by-N matrix A.
  120. *> On exit :
  121. *> If JOBU = 'U' .OR. JOBU = 'C' :
  122. *> If INFO = 0 :
  123. *> RANKA orthonormal columns of U are returned in the
  124. *> leading RANKA columns of the array A. Here RANKA <= N
  125. *> is the number of computed singular values of A that are
  126. *> above the underflow threshold DLAMCH('S'). The singular
  127. *> vectors corresponding to underflowed or zero singular
  128. *> values are not computed. The value of RANKA is returned
  129. *> in the array WORK as RANKA=NINT(WORK(2)). Also see the
  130. *> descriptions of SVA and WORK. The computed columns of U
  131. *> are mutually numerically orthogonal up to approximately
  132. *> TOL=DSQRT(M)*EPS (default); or TOL=CTOL*EPS (JOBU = 'C'),
  133. *> see the description of JOBU.
  134. *> If INFO > 0 :
  135. *> the procedure DGESVJ did not converge in the given number
  136. *> of iterations (sweeps). In that case, the computed
  137. *> columns of U may not be orthogonal up to TOL. The output
  138. *> U (stored in A), SIGMA (given by the computed singular
  139. *> values in SVA(1:N)) and V is still a decomposition of the
  140. *> input matrix A in the sense that the residual
  141. *> ||A-SCALE*U*SIGMA*V^T||_2 / ||A||_2 is small.
  142. *>
  143. *> If JOBU = 'N' :
  144. *> If INFO = 0 :
  145. *> Note that the left singular vectors are 'for free' in the
  146. *> one-sided Jacobi SVD algorithm. However, if only the
  147. *> singular values are needed, the level of numerical
  148. *> orthogonality of U is not an issue and iterations are
  149. *> stopped when the columns of the iterated matrix are
  150. *> numerically orthogonal up to approximately M*EPS. Thus,
  151. *> on exit, A contains the columns of U scaled with the
  152. *> corresponding singular values.
  153. *> If INFO > 0 :
  154. *> the procedure DGESVJ did not converge in the given number
  155. *> of iterations (sweeps).
  156. *> \endverbatim
  157. *>
  158. *> \param[in] LDA
  159. *> \verbatim
  160. *> LDA is INTEGER
  161. *> The leading dimension of the array A. LDA >= max(1,M).
  162. *> \endverbatim
  163. *>
  164. *> \param[out] SVA
  165. *> \verbatim
  166. *> SVA is DOUBLE PRECISION array, dimension (N)
  167. *> On exit :
  168. *> If INFO = 0 :
  169. *> depending on the value SCALE = WORK(1), we have:
  170. *> If SCALE = ONE :
  171. *> SVA(1:N) contains the computed singular values of A.
  172. *> During the computation SVA contains the Euclidean column
  173. *> norms of the iterated matrices in the array A.
  174. *> If SCALE .NE. ONE :
  175. *> The singular values of A are SCALE*SVA(1:N), and this
  176. *> factored representation is due to the fact that some of the
  177. *> singular values of A might underflow or overflow.
  178. *> If INFO > 0 :
  179. *> the procedure DGESVJ did not converge in the given number of
  180. *> iterations (sweeps) and SCALE*SVA(1:N) may not be accurate.
  181. *> \endverbatim
  182. *>
  183. *> \param[in] MV
  184. *> \verbatim
  185. *> MV is INTEGER
  186. *> If JOBV = 'A', then the product of Jacobi rotations in DGESVJ
  187. *> is applied to the first MV rows of V. See the description of JOBV.
  188. *> \endverbatim
  189. *>
  190. *> \param[in,out] V
  191. *> \verbatim
  192. *> V is DOUBLE PRECISION array, dimension (LDV,N)
  193. *> If JOBV = 'V', then V contains on exit the N-by-N matrix of
  194. *> the right singular vectors;
  195. *> If JOBV = 'A', then V contains the product of the computed right
  196. *> singular vector matrix and the initial matrix in
  197. *> the array V.
  198. *> If JOBV = 'N', then V is not referenced.
  199. *> \endverbatim
  200. *>
  201. *> \param[in] LDV
  202. *> \verbatim
  203. *> LDV is INTEGER
  204. *> The leading dimension of the array V, LDV >= 1.
  205. *> If JOBV = 'V', then LDV >= max(1,N).
  206. *> If JOBV = 'A', then LDV >= max(1,MV) .
  207. *> \endverbatim
  208. *>
  209. *> \param[in,out] WORK
  210. *> \verbatim
  211. *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
  212. *> On entry :
  213. *> If JOBU = 'C' :
  214. *> WORK(1) = CTOL, where CTOL defines the threshold for convergence.
  215. *> The process stops if all columns of A are mutually
  216. *> orthogonal up to CTOL*EPS, EPS=DLAMCH('E').
  217. *> It is required that CTOL >= ONE, i.e. it is not
  218. *> allowed to force the routine to obtain orthogonality
  219. *> below EPS.
  220. *> On exit :
  221. *> WORK(1) = SCALE is the scaling factor such that SCALE*SVA(1:N)
  222. *> are the computed singular values of A.
  223. *> (See description of SVA().)
  224. *> WORK(2) = NINT(WORK(2)) is the number of the computed nonzero
  225. *> singular values.
  226. *> WORK(3) = NINT(WORK(3)) is the number of the computed singular
  227. *> values that are larger than the underflow threshold.
  228. *> WORK(4) = NINT(WORK(4)) is the number of sweeps of Jacobi
  229. *> rotations needed for numerical convergence.
  230. *> WORK(5) = max_{i.NE.j} |COS(A(:,i),A(:,j))| in the last sweep.
  231. *> This is useful information in cases when DGESVJ did
  232. *> not converge, as it can be used to estimate whether
  233. *> the output is still useful and for post festum analysis.
  234. *> WORK(6) = the largest absolute value over all sines of the
  235. *> Jacobi rotation angles in the last sweep. It can be
  236. *> useful for a post festum analysis.
  237. *> \endverbatim
  238. *>
  239. *> \param[in] LWORK
  240. *> \verbatim
  241. *> LWORK is INTEGER
  242. *> The length of the array WORK.
  243. *> LWORK >= 1, if MIN(M,N) = 0, and LWORK >= MAX(6,M+N), otherwise.
  244. *>
  245. *> If on entry LWORK = -1, then a workspace query is assumed and
  246. *> no computation is done; WORK(1) is set to the minial (and optimal)
  247. *> length of WORK.
  248. *> \endverbatim
  249. *>
  250. *> \param[out] INFO
  251. *> \verbatim
  252. *> INFO is INTEGER
  253. *> = 0: successful exit.
  254. *> < 0: if INFO = -i, then the i-th argument had an illegal value
  255. *> > 0: DGESVJ did not converge in the maximal allowed number (30)
  256. *> of sweeps. The output may still be useful. See the
  257. *> description of WORK.
  258. *> \endverbatim
  259. *
  260. * Authors:
  261. * ========
  262. *
  263. *> \author Univ. of Tennessee
  264. *> \author Univ. of California Berkeley
  265. *> \author Univ. of Colorado Denver
  266. *> \author NAG Ltd.
  267. *
  268. *> \ingroup gesvj
  269. *
  270. *> \par Further Details:
  271. * =====================
  272. *>
  273. *> \verbatim
  274. *>
  275. *> The orthogonal N-by-N matrix V is obtained as a product of Jacobi plane
  276. *> rotations. The rotations are implemented as fast scaled rotations of
  277. *> Anda and Park [1]. In the case of underflow of the Jacobi angle, a
  278. *> modified Jacobi transformation of Drmac [4] is used. Pivot strategy uses
  279. *> column interchanges of de Rijk [2]. The relative accuracy of the computed
  280. *> singular values and the accuracy of the computed singular vectors (in
  281. *> angle metric) is as guaranteed by the theory of Demmel and Veselic [3].
  282. *> The condition number that determines the accuracy in the full rank case
  283. *> is essentially min_{D=diag} kappa(A*D), where kappa(.) is the
  284. *> spectral condition number. The best performance of this Jacobi SVD
  285. *> procedure is achieved if used in an accelerated version of Drmac and
  286. *> Veselic [5,6], and it is the kernel routine in the SIGMA library [7].
  287. *> Some tuning parameters (marked with [TP]) are available for the
  288. *> implementer.
  289. *> The computational range for the nonzero singular values is the machine
  290. *> number interval ( UNDERFLOW , OVERFLOW ). In extreme cases, even
  291. *> denormalized singular values can be computed with the corresponding
  292. *> gradual loss of accurate digits.
  293. *> \endverbatim
  294. *
  295. *> \par Contributors:
  296. * ==================
  297. *>
  298. *> \verbatim
  299. *>
  300. *> ============
  301. *>
  302. *> Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
  303. *> \endverbatim
  304. *
  305. *> \par References:
  306. * ================
  307. *>
  308. *> \verbatim
  309. *>
  310. *> [1] A. A. Anda and H. Park: Fast plane rotations with dynamic scaling.
  311. *> SIAM J. matrix Anal. Appl., Vol. 15 (1994), pp. 162-174.
  312. *> [2] P. P. M. De Rijk: A one-sided Jacobi algorithm for computing the
  313. *> singular value decomposition on a vector computer.
  314. *> SIAM J. Sci. Stat. Comp., Vol. 10 (1998), pp. 359-371.
  315. *> [3] J. Demmel and K. Veselic: Jacobi method is more accurate than QR.
  316. *> [4] Z. Drmac: Implementation of Jacobi rotations for accurate singular
  317. *> value computation in floating point arithmetic.
  318. *> SIAM J. Sci. Comp., Vol. 18 (1997), pp. 1200-1222.
  319. *> [5] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I.
  320. *> SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342.
  321. *> LAPACK Working note 169.
  322. *> [6] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II.
  323. *> SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362.
  324. *> LAPACK Working note 170.
  325. *> [7] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV,
  326. *> QSVD, (H,K)-SVD computations.
  327. *> Department of Mathematics, University of Zagreb, 2008.
  328. *> \endverbatim
  329. *
  330. *> \par Bugs, examples and comments:
  331. * =================================
  332. *>
  333. *> \verbatim
  334. *> ===========================
  335. *> Please report all bugs and send interesting test examples and comments to
  336. *> drmac@math.hr. Thank you.
  337. *> \endverbatim
  338. *>
  339. * =====================================================================
  340. SUBROUTINE DGESVJ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V,
  341. $ LDV, WORK, LWORK, INFO )
  342. *
  343. * -- LAPACK computational routine --
  344. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  345. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  346. *
  347. * .. Scalar Arguments ..
  348. INTEGER INFO, LDA, LDV, LWORK, M, MV, N
  349. CHARACTER*1 JOBA, JOBU, JOBV
  350. * ..
  351. * .. Array Arguments ..
  352. DOUBLE PRECISION A( LDA, * ), SVA( N ), V( LDV, * ),
  353. $ WORK( LWORK )
  354. * ..
  355. *
  356. * =====================================================================
  357. *
  358. * .. Local Parameters ..
  359. DOUBLE PRECISION ZERO, HALF, ONE
  360. PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0)
  361. INTEGER NSWEEP
  362. PARAMETER ( NSWEEP = 30 )
  363. * ..
  364. * .. Local Scalars ..
  365. DOUBLE PRECISION AAPP, AAPP0, AAPQ, AAQQ, APOAQ, AQOAP, BIG,
  366. $ BIGTHETA, CS, CTOL, EPSLN, LARGE, MXAAPQ,
  367. $ MXSINJ, ROOTBIG, ROOTEPS, ROOTSFMIN, ROOTTOL,
  368. $ SKL, SFMIN, SMALL, SN, T, TEMP1, THETA,
  369. $ THSIGN, TOL
  370. INTEGER BLSKIP, EMPTSW, i, ibr, IERR, igl, IJBLSK, ir1,
  371. $ ISWROT, jbc, jgl, KBL, LKAHEAD, MVL, N2, N34,
  372. $ N4, NBL, NOTROT, p, PSKIPPED, q, ROWSKIP,
  373. $ SWBAND, MINMN, LWMIN
  374. LOGICAL APPLV, GOSCALE, LOWER, LQUERY, LSVEC, NOSCALE,
  375. $ ROTOK, RSVEC, UCTOL, UPPER
  376. * ..
  377. * .. Local Arrays ..
  378. DOUBLE PRECISION FASTR( 5 )
  379. * ..
  380. * .. Intrinsic Functions ..
  381. INTRINSIC DABS, MAX, MIN, DBLE, DSIGN, DSQRT
  382. * ..
  383. * .. External Functions ..
  384. * ..
  385. * from BLAS
  386. DOUBLE PRECISION DDOT, DNRM2
  387. EXTERNAL DDOT, DNRM2
  388. INTEGER IDAMAX
  389. EXTERNAL IDAMAX
  390. * from LAPACK
  391. DOUBLE PRECISION DLAMCH
  392. EXTERNAL DLAMCH
  393. LOGICAL LSAME
  394. EXTERNAL LSAME
  395. * ..
  396. * .. External Subroutines ..
  397. * ..
  398. * from BLAS
  399. EXTERNAL DAXPY, DCOPY, DROTM, DSCAL, DSWAP
  400. * from LAPACK
  401. EXTERNAL DLASCL, DLASET, DLASSQ, XERBLA
  402. *
  403. EXTERNAL DGSVJ0, DGSVJ1
  404. * ..
  405. * .. Executable Statements ..
  406. *
  407. * Test the input arguments
  408. *
  409. LSVEC = LSAME( JOBU, 'U' )
  410. UCTOL = LSAME( JOBU, 'C' )
  411. RSVEC = LSAME( JOBV, 'V' )
  412. APPLV = LSAME( JOBV, 'A' )
  413. UPPER = LSAME( JOBA, 'U' )
  414. LOWER = LSAME( JOBA, 'L' )
  415. *
  416. MINMN = MIN( M, N )
  417. IF( MINMN.EQ.0 ) THEN
  418. LWMIN = 1
  419. ELSE
  420. LWMIN = MAX( 6, M+N )
  421. END IF
  422. *
  423. LQUERY = ( LWORK.EQ.-1 )
  424. IF( .NOT.( UPPER .OR. LOWER .OR. LSAME( JOBA, 'G' ) ) ) THEN
  425. INFO = -1
  426. ELSE IF( .NOT.( LSVEC .OR. UCTOL .OR. LSAME( JOBU, 'N' ) ) ) THEN
  427. INFO = -2
  428. ELSE IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
  429. INFO = -3
  430. ELSE IF( M.LT.0 ) THEN
  431. INFO = -4
  432. ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
  433. INFO = -5
  434. ELSE IF( LDA.LT.M ) THEN
  435. INFO = -7
  436. ELSE IF( MV.LT.0 ) THEN
  437. INFO = -9
  438. ELSE IF( ( RSVEC .AND. ( LDV.LT.N ) ) .OR.
  439. $ ( APPLV .AND. ( LDV.LT.MV ) ) ) THEN
  440. INFO = -11
  441. ELSE IF( UCTOL .AND. ( WORK( 1 ).LE.ONE ) ) THEN
  442. INFO = -12
  443. ELSE IF( LWORK.LT.LWMIN .AND. ( .NOT.LQUERY ) ) THEN
  444. INFO = -13
  445. ELSE
  446. INFO = 0
  447. END IF
  448. *
  449. * #:(
  450. IF( INFO.NE.0 ) THEN
  451. CALL XERBLA( 'DGESVJ', -INFO )
  452. RETURN
  453. ELSE IF( LQUERY ) THEN
  454. WORK( 1 ) = LWMIN
  455. RETURN
  456. END IF
  457. *
  458. * #:) Quick return for void matrix
  459. *
  460. IF( MINMN.EQ.0 ) RETURN
  461. *
  462. * Set numerical parameters
  463. * The stopping criterion for Jacobi rotations is
  464. *
  465. * max_{i<>j}|A(:,i)^T * A(:,j)|/(||A(:,i)||*||A(:,j)||) < CTOL*EPS
  466. *
  467. * where EPS is the round-off and CTOL is defined as follows:
  468. *
  469. IF( UCTOL ) THEN
  470. * ... user controlled
  471. CTOL = WORK( 1 )
  472. ELSE
  473. * ... default
  474. IF( LSVEC .OR. RSVEC .OR. APPLV ) THEN
  475. CTOL = DSQRT( DBLE( M ) )
  476. ELSE
  477. CTOL = DBLE( M )
  478. END IF
  479. END IF
  480. * ... and the machine dependent parameters are
  481. *[!] (Make sure that DLAMCH() works properly on the target machine.)
  482. *
  483. EPSLN = DLAMCH( 'Epsilon' )
  484. ROOTEPS = DSQRT( EPSLN )
  485. SFMIN = DLAMCH( 'SafeMinimum' )
  486. ROOTSFMIN = DSQRT( SFMIN )
  487. SMALL = SFMIN / EPSLN
  488. BIG = DLAMCH( 'Overflow' )
  489. * BIG = ONE / SFMIN
  490. ROOTBIG = ONE / ROOTSFMIN
  491. LARGE = BIG / DSQRT( DBLE( M*N ) )
  492. BIGTHETA = ONE / ROOTEPS
  493. *
  494. TOL = CTOL*EPSLN
  495. ROOTTOL = DSQRT( TOL )
  496. *
  497. IF( DBLE( M )*EPSLN.GE.ONE ) THEN
  498. INFO = -4
  499. CALL XERBLA( 'DGESVJ', -INFO )
  500. RETURN
  501. END IF
  502. *
  503. * Initialize the right singular vector matrix.
  504. *
  505. IF( RSVEC ) THEN
  506. MVL = N
  507. CALL DLASET( 'A', MVL, N, ZERO, ONE, V, LDV )
  508. ELSE IF( APPLV ) THEN
  509. MVL = MV
  510. END IF
  511. RSVEC = RSVEC .OR. APPLV
  512. *
  513. * Initialize SVA( 1:N ) = ( ||A e_i||_2, i = 1:N )
  514. *(!) If necessary, scale A to protect the largest singular value
  515. * from overflow. It is possible that saving the largest singular
  516. * value destroys the information about the small ones.
  517. * This initial scaling is almost minimal in the sense that the
  518. * goal is to make sure that no column norm overflows, and that
  519. * DSQRT(N)*max_i SVA(i) does not overflow. If INFinite entries
  520. * in A are detected, the procedure returns with INFO=-6.
  521. *
  522. SKL= ONE / DSQRT( DBLE( M )*DBLE( N ) )
  523. NOSCALE = .TRUE.
  524. GOSCALE = .TRUE.
  525. *
  526. IF( LOWER ) THEN
  527. * the input matrix is M-by-N lower triangular (trapezoidal)
  528. DO 1874 p = 1, N
  529. AAPP = ZERO
  530. AAQQ = ONE
  531. CALL DLASSQ( M-p+1, A( p, p ), 1, AAPP, AAQQ )
  532. IF( AAPP.GT.BIG ) THEN
  533. INFO = -6
  534. CALL XERBLA( 'DGESVJ', -INFO )
  535. RETURN
  536. END IF
  537. AAQQ = DSQRT( AAQQ )
  538. IF( ( AAPP.LT.( BIG / AAQQ ) ) .AND. NOSCALE ) THEN
  539. SVA( p ) = AAPP*AAQQ
  540. ELSE
  541. NOSCALE = .FALSE.
  542. SVA( p ) = AAPP*( AAQQ*SKL)
  543. IF( GOSCALE ) THEN
  544. GOSCALE = .FALSE.
  545. DO 1873 q = 1, p - 1
  546. SVA( q ) = SVA( q )*SKL
  547. 1873 CONTINUE
  548. END IF
  549. END IF
  550. 1874 CONTINUE
  551. ELSE IF( UPPER ) THEN
  552. * the input matrix is M-by-N upper triangular (trapezoidal)
  553. DO 2874 p = 1, N
  554. AAPP = ZERO
  555. AAQQ = ONE
  556. CALL DLASSQ( p, A( 1, p ), 1, AAPP, AAQQ )
  557. IF( AAPP.GT.BIG ) THEN
  558. INFO = -6
  559. CALL XERBLA( 'DGESVJ', -INFO )
  560. RETURN
  561. END IF
  562. AAQQ = DSQRT( AAQQ )
  563. IF( ( AAPP.LT.( BIG / AAQQ ) ) .AND. NOSCALE ) THEN
  564. SVA( p ) = AAPP*AAQQ
  565. ELSE
  566. NOSCALE = .FALSE.
  567. SVA( p ) = AAPP*( AAQQ*SKL)
  568. IF( GOSCALE ) THEN
  569. GOSCALE = .FALSE.
  570. DO 2873 q = 1, p - 1
  571. SVA( q ) = SVA( q )*SKL
  572. 2873 CONTINUE
  573. END IF
  574. END IF
  575. 2874 CONTINUE
  576. ELSE
  577. * the input matrix is M-by-N general dense
  578. DO 3874 p = 1, N
  579. AAPP = ZERO
  580. AAQQ = ONE
  581. CALL DLASSQ( M, A( 1, p ), 1, AAPP, AAQQ )
  582. IF( AAPP.GT.BIG ) THEN
  583. INFO = -6
  584. CALL XERBLA( 'DGESVJ', -INFO )
  585. RETURN
  586. END IF
  587. AAQQ = DSQRT( AAQQ )
  588. IF( ( AAPP.LT.( BIG / AAQQ ) ) .AND. NOSCALE ) THEN
  589. SVA( p ) = AAPP*AAQQ
  590. ELSE
  591. NOSCALE = .FALSE.
  592. SVA( p ) = AAPP*( AAQQ*SKL)
  593. IF( GOSCALE ) THEN
  594. GOSCALE = .FALSE.
  595. DO 3873 q = 1, p - 1
  596. SVA( q ) = SVA( q )*SKL
  597. 3873 CONTINUE
  598. END IF
  599. END IF
  600. 3874 CONTINUE
  601. END IF
  602. *
  603. IF( NOSCALE )SKL= ONE
  604. *
  605. * Move the smaller part of the spectrum from the underflow threshold
  606. *(!) Start by determining the position of the nonzero entries of the
  607. * array SVA() relative to ( SFMIN, BIG ).
  608. *
  609. AAPP = ZERO
  610. AAQQ = BIG
  611. DO 4781 p = 1, N
  612. IF( SVA( p ).NE.ZERO )AAQQ = MIN( AAQQ, SVA( p ) )
  613. AAPP = MAX( AAPP, SVA( p ) )
  614. 4781 CONTINUE
  615. *
  616. * #:) Quick return for zero matrix
  617. *
  618. IF( AAPP.EQ.ZERO ) THEN
  619. IF( LSVEC )CALL DLASET( 'G', M, N, ZERO, ONE, A, LDA )
  620. WORK( 1 ) = ONE
  621. WORK( 2 ) = ZERO
  622. WORK( 3 ) = ZERO
  623. WORK( 4 ) = ZERO
  624. WORK( 5 ) = ZERO
  625. WORK( 6 ) = ZERO
  626. RETURN
  627. END IF
  628. *
  629. * #:) Quick return for one-column matrix
  630. *
  631. IF( N.EQ.1 ) THEN
  632. IF( LSVEC )CALL DLASCL( 'G', 0, 0, SVA( 1 ), SKL, M, 1,
  633. $ A( 1, 1 ), LDA, IERR )
  634. WORK( 1 ) = ONE / SKL
  635. IF( SVA( 1 ).GE.SFMIN ) THEN
  636. WORK( 2 ) = ONE
  637. ELSE
  638. WORK( 2 ) = ZERO
  639. END IF
  640. WORK( 3 ) = ZERO
  641. WORK( 4 ) = ZERO
  642. WORK( 5 ) = ZERO
  643. WORK( 6 ) = ZERO
  644. RETURN
  645. END IF
  646. *
  647. * Protect small singular values from underflow, and try to
  648. * avoid underflows/overflows in computing Jacobi rotations.
  649. *
  650. SN = DSQRT( SFMIN / EPSLN )
  651. TEMP1 = DSQRT( BIG / DBLE( N ) )
  652. IF( ( AAPP.LE.SN ) .OR. ( AAQQ.GE.TEMP1 ) .OR.
  653. $ ( ( SN.LE.AAQQ ) .AND. ( AAPP.LE.TEMP1 ) ) ) THEN
  654. TEMP1 = MIN( BIG, TEMP1 / AAPP )
  655. * AAQQ = AAQQ*TEMP1
  656. * AAPP = AAPP*TEMP1
  657. ELSE IF( ( AAQQ.LE.SN ) .AND. ( AAPP.LE.TEMP1 ) ) THEN
  658. TEMP1 = MIN( SN / AAQQ, BIG / ( AAPP*DSQRT( DBLE( N ) ) ) )
  659. * AAQQ = AAQQ*TEMP1
  660. * AAPP = AAPP*TEMP1
  661. ELSE IF( ( AAQQ.GE.SN ) .AND. ( AAPP.GE.TEMP1 ) ) THEN
  662. TEMP1 = MAX( SN / AAQQ, TEMP1 / AAPP )
  663. * AAQQ = AAQQ*TEMP1
  664. * AAPP = AAPP*TEMP1
  665. ELSE IF( ( AAQQ.LE.SN ) .AND. ( AAPP.GE.TEMP1 ) ) THEN
  666. TEMP1 = MIN( SN / AAQQ, BIG / ( DSQRT( DBLE( N ) )*AAPP ) )
  667. * AAQQ = AAQQ*TEMP1
  668. * AAPP = AAPP*TEMP1
  669. ELSE
  670. TEMP1 = ONE
  671. END IF
  672. *
  673. * Scale, if necessary
  674. *
  675. IF( TEMP1.NE.ONE ) THEN
  676. CALL DLASCL( 'G', 0, 0, ONE, TEMP1, N, 1, SVA, N, IERR )
  677. END IF
  678. SKL= TEMP1*SKL
  679. IF( SKL.NE.ONE ) THEN
  680. CALL DLASCL( JOBA, 0, 0, ONE, SKL, M, N, A, LDA, IERR )
  681. SKL= ONE / SKL
  682. END IF
  683. *
  684. * Row-cyclic Jacobi SVD algorithm with column pivoting
  685. *
  686. EMPTSW = ( N*( N-1 ) ) / 2
  687. NOTROT = 0
  688. FASTR( 1 ) = ZERO
  689. *
  690. * A is represented in factored form A = A * diag(WORK), where diag(WORK)
  691. * is initialized to identity. WORK is updated during fast scaled
  692. * rotations.
  693. *
  694. DO 1868 q = 1, N
  695. WORK( q ) = ONE
  696. 1868 CONTINUE
  697. *
  698. *
  699. SWBAND = 3
  700. *[TP] SWBAND is a tuning parameter [TP]. It is meaningful and effective
  701. * if DGESVJ is used as a computational routine in the preconditioned
  702. * Jacobi SVD algorithm DGESVJ. For sweeps i=1:SWBAND the procedure
  703. * works on pivots inside a band-like region around the diagonal.
  704. * The boundaries are determined dynamically, based on the number of
  705. * pivots above a threshold.
  706. *
  707. KBL = MIN( 8, N )
  708. *[TP] KBL is a tuning parameter that defines the tile size in the
  709. * tiling of the p-q loops of pivot pairs. In general, an optimal
  710. * value of KBL depends on the matrix dimensions and on the
  711. * parameters of the computer's memory.
  712. *
  713. NBL = N / KBL
  714. IF( ( NBL*KBL ).NE.N )NBL = NBL + 1
  715. *
  716. BLSKIP = KBL**2
  717. *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
  718. *
  719. ROWSKIP = MIN( 5, KBL )
  720. *[TP] ROWSKIP is a tuning parameter.
  721. *
  722. LKAHEAD = 1
  723. *[TP] LKAHEAD is a tuning parameter.
  724. *
  725. * Quasi block transformations, using the lower (upper) triangular
  726. * structure of the input matrix. The quasi-block-cycling usually
  727. * invokes cubic convergence. Big part of this cycle is done inside
  728. * canonical subspaces of dimensions less than M.
  729. *
  730. IF( ( LOWER .OR. UPPER ) .AND. ( N.GT.MAX( 64, 4*KBL ) ) ) THEN
  731. *[TP] The number of partition levels and the actual partition are
  732. * tuning parameters.
  733. N4 = N / 4
  734. N2 = N / 2
  735. N34 = 3*N4
  736. IF( APPLV ) THEN
  737. q = 0
  738. ELSE
  739. q = 1
  740. END IF
  741. *
  742. IF( LOWER ) THEN
  743. *
  744. * This works very well on lower triangular matrices, in particular
  745. * in the framework of the preconditioned Jacobi SVD (xGEJSV).
  746. * The idea is simple:
  747. * [+ 0 0 0] Note that Jacobi transformations of [0 0]
  748. * [+ + 0 0] [0 0]
  749. * [+ + x 0] actually work on [x 0] [x 0]
  750. * [+ + x x] [x x]. [x x]
  751. *
  752. CALL DGSVJ0( JOBV, M-N34, N-N34, A( N34+1, N34+1 ), LDA,
  753. $ WORK( N34+1 ), SVA( N34+1 ), MVL,
  754. $ V( N34*q+1, N34+1 ), LDV, EPSLN, SFMIN, TOL,
  755. $ 2, WORK( N+1 ), LWORK-N, IERR )
  756. *
  757. CALL DGSVJ0( JOBV, M-N2, N34-N2, A( N2+1, N2+1 ), LDA,
  758. $ WORK( N2+1 ), SVA( N2+1 ), MVL,
  759. $ V( N2*q+1, N2+1 ), LDV, EPSLN, SFMIN, TOL, 2,
  760. $ WORK( N+1 ), LWORK-N, IERR )
  761. *
  762. CALL DGSVJ1( JOBV, M-N2, N-N2, N4, A( N2+1, N2+1 ), LDA,
  763. $ WORK( N2+1 ), SVA( N2+1 ), MVL,
  764. $ V( N2*q+1, N2+1 ), LDV, EPSLN, SFMIN, TOL, 1,
  765. $ WORK( N+1 ), LWORK-N, IERR )
  766. *
  767. CALL DGSVJ0( JOBV, M-N4, N2-N4, A( N4+1, N4+1 ), LDA,
  768. $ WORK( N4+1 ), SVA( N4+1 ), MVL,
  769. $ V( N4*q+1, N4+1 ), LDV, EPSLN, SFMIN, TOL, 1,
  770. $ WORK( N+1 ), LWORK-N, IERR )
  771. *
  772. CALL DGSVJ0( JOBV, M, N4, A, LDA, WORK, SVA, MVL, V, LDV,
  773. $ EPSLN, SFMIN, TOL, 1, WORK( N+1 ), LWORK-N,
  774. $ IERR )
  775. *
  776. CALL DGSVJ1( JOBV, M, N2, N4, A, LDA, WORK, SVA, MVL, V,
  777. $ LDV, EPSLN, SFMIN, TOL, 1, WORK( N+1 ),
  778. $ LWORK-N, IERR )
  779. *
  780. *
  781. ELSE IF( UPPER ) THEN
  782. *
  783. *
  784. CALL DGSVJ0( JOBV, N4, N4, A, LDA, WORK, SVA, MVL, V, LDV,
  785. $ EPSLN, SFMIN, TOL, 2, WORK( N+1 ), LWORK-N,
  786. $ IERR )
  787. *
  788. CALL DGSVJ0( JOBV, N2, N4, A( 1, N4+1 ), LDA, WORK( N4+1 ),
  789. $ SVA( N4+1 ), MVL, V( N4*q+1, N4+1 ), LDV,
  790. $ EPSLN, SFMIN, TOL, 1, WORK( N+1 ), LWORK-N,
  791. $ IERR )
  792. *
  793. CALL DGSVJ1( JOBV, N2, N2, N4, A, LDA, WORK, SVA, MVL, V,
  794. $ LDV, EPSLN, SFMIN, TOL, 1, WORK( N+1 ),
  795. $ LWORK-N, IERR )
  796. *
  797. CALL DGSVJ0( JOBV, N2+N4, N4, A( 1, N2+1 ), LDA,
  798. $ WORK( N2+1 ), SVA( N2+1 ), MVL,
  799. $ V( N2*q+1, N2+1 ), LDV, EPSLN, SFMIN, TOL, 1,
  800. $ WORK( N+1 ), LWORK-N, IERR )
  801. END IF
  802. *
  803. END IF
  804. *
  805. * .. Row-cyclic pivot strategy with de Rijk's pivoting ..
  806. *
  807. DO 1993 i = 1, NSWEEP
  808. *
  809. * .. go go go ...
  810. *
  811. MXAAPQ = ZERO
  812. MXSINJ = ZERO
  813. ISWROT = 0
  814. *
  815. NOTROT = 0
  816. PSKIPPED = 0
  817. *
  818. * Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs
  819. * 1 <= p < q <= N. This is the first step toward a blocked implementation
  820. * of the rotations. New implementation, based on block transformations,
  821. * is under development.
  822. *
  823. DO 2000 ibr = 1, NBL
  824. *
  825. igl = ( ibr-1 )*KBL + 1
  826. *
  827. DO 1002 ir1 = 0, MIN( LKAHEAD, NBL-ibr )
  828. *
  829. igl = igl + ir1*KBL
  830. *
  831. DO 2001 p = igl, MIN( igl+KBL-1, N-1 )
  832. *
  833. * .. de Rijk's pivoting
  834. *
  835. q = IDAMAX( N-p+1, SVA( p ), 1 ) + p - 1
  836. IF( p.NE.q ) THEN
  837. CALL DSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
  838. IF( RSVEC )CALL DSWAP( MVL, V( 1, p ), 1,
  839. $ V( 1, q ), 1 )
  840. TEMP1 = SVA( p )
  841. SVA( p ) = SVA( q )
  842. SVA( q ) = TEMP1
  843. TEMP1 = WORK( p )
  844. WORK( p ) = WORK( q )
  845. WORK( q ) = TEMP1
  846. END IF
  847. *
  848. IF( ir1.EQ.0 ) THEN
  849. *
  850. * Column norms are periodically updated by explicit
  851. * norm computation.
  852. * Caveat:
  853. * Unfortunately, some BLAS implementations compute DNRM2(M,A(1,p),1)
  854. * as DSQRT(DDOT(M,A(1,p),1,A(1,p),1)), which may cause the result to
  855. * overflow for ||A(:,p)||_2 > DSQRT(overflow_threshold), and to
  856. * underflow for ||A(:,p)||_2 < DSQRT(underflow_threshold).
  857. * Hence, DNRM2 cannot be trusted, not even in the case when
  858. * the true norm is far from the under(over)flow boundaries.
  859. * If properly implemented DNRM2 is available, the IF-THEN-ELSE
  860. * below should read "AAPP = DNRM2( M, A(1,p), 1 ) * WORK(p)".
  861. *
  862. IF( ( SVA( p ).LT.ROOTBIG ) .AND.
  863. $ ( SVA( p ).GT.ROOTSFMIN ) ) THEN
  864. SVA( p ) = DNRM2( M, A( 1, p ), 1 )*WORK( p )
  865. ELSE
  866. TEMP1 = ZERO
  867. AAPP = ONE
  868. CALL DLASSQ( M, A( 1, p ), 1, TEMP1, AAPP )
  869. SVA( p ) = TEMP1*DSQRT( AAPP )*WORK( p )
  870. END IF
  871. AAPP = SVA( p )
  872. ELSE
  873. AAPP = SVA( p )
  874. END IF
  875. *
  876. IF( AAPP.GT.ZERO ) THEN
  877. *
  878. PSKIPPED = 0
  879. *
  880. DO 2002 q = p + 1, MIN( igl+KBL-1, N )
  881. *
  882. AAQQ = SVA( q )
  883. *
  884. IF( AAQQ.GT.ZERO ) THEN
  885. *
  886. AAPP0 = AAPP
  887. IF( AAQQ.GE.ONE ) THEN
  888. ROTOK = ( SMALL*AAPP ).LE.AAQQ
  889. IF( AAPP.LT.( BIG / AAQQ ) ) THEN
  890. AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
  891. $ q ), 1 )*WORK( p )*WORK( q ) /
  892. $ AAQQ ) / AAPP
  893. ELSE
  894. CALL DCOPY( M, A( 1, p ), 1,
  895. $ WORK( N+1 ), 1 )
  896. CALL DLASCL( 'G', 0, 0, AAPP,
  897. $ WORK( p ), M, 1,
  898. $ WORK( N+1 ), LDA, IERR )
  899. AAPQ = DDOT( M, WORK( N+1 ), 1,
  900. $ A( 1, q ), 1 )*WORK( q ) / AAQQ
  901. END IF
  902. ELSE
  903. ROTOK = AAPP.LE.( AAQQ / SMALL )
  904. IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
  905. AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
  906. $ q ), 1 )*WORK( p )*WORK( q ) /
  907. $ AAQQ ) / AAPP
  908. ELSE
  909. CALL DCOPY( M, A( 1, q ), 1,
  910. $ WORK( N+1 ), 1 )
  911. CALL DLASCL( 'G', 0, 0, AAQQ,
  912. $ WORK( q ), M, 1,
  913. $ WORK( N+1 ), LDA, IERR )
  914. AAPQ = DDOT( M, WORK( N+1 ), 1,
  915. $ A( 1, p ), 1 )*WORK( p ) / AAPP
  916. END IF
  917. END IF
  918. *
  919. MXAAPQ = MAX( MXAAPQ, DABS( AAPQ ) )
  920. *
  921. * TO rotate or NOT to rotate, THAT is the question ...
  922. *
  923. IF( DABS( AAPQ ).GT.TOL ) THEN
  924. *
  925. * .. rotate
  926. *[RTD] ROTATED = ROTATED + ONE
  927. *
  928. IF( ir1.EQ.0 ) THEN
  929. NOTROT = 0
  930. PSKIPPED = 0
  931. ISWROT = ISWROT + 1
  932. END IF
  933. *
  934. IF( ROTOK ) THEN
  935. *
  936. AQOAP = AAQQ / AAPP
  937. APOAQ = AAPP / AAQQ
  938. THETA = -HALF*DABS(AQOAP-APOAQ)/AAPQ
  939. *
  940. IF( DABS( THETA ).GT.BIGTHETA ) THEN
  941. *
  942. T = HALF / THETA
  943. FASTR( 3 ) = T*WORK( p ) / WORK( q )
  944. FASTR( 4 ) = -T*WORK( q ) /
  945. $ WORK( p )
  946. CALL DROTM( M, A( 1, p ), 1,
  947. $ A( 1, q ), 1, FASTR )
  948. IF( RSVEC )CALL DROTM( MVL,
  949. $ V( 1, p ), 1,
  950. $ V( 1, q ), 1,
  951. $ FASTR )
  952. SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
  953. $ ONE+T*APOAQ*AAPQ ) )
  954. AAPP = AAPP*DSQRT( MAX( ZERO,
  955. $ ONE-T*AQOAP*AAPQ ) )
  956. MXSINJ = MAX( MXSINJ, DABS( T ) )
  957. *
  958. ELSE
  959. *
  960. * .. choose correct signum for THETA and rotate
  961. *
  962. THSIGN = -DSIGN( ONE, AAPQ )
  963. T = ONE / ( THETA+THSIGN*
  964. $ DSQRT( ONE+THETA*THETA ) )
  965. CS = DSQRT( ONE / ( ONE+T*T ) )
  966. SN = T*CS
  967. *
  968. MXSINJ = MAX( MXSINJ, DABS( SN ) )
  969. SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
  970. $ ONE+T*APOAQ*AAPQ ) )
  971. AAPP = AAPP*DSQRT( MAX( ZERO,
  972. $ ONE-T*AQOAP*AAPQ ) )
  973. *
  974. APOAQ = WORK( p ) / WORK( q )
  975. AQOAP = WORK( q ) / WORK( p )
  976. IF( WORK( p ).GE.ONE ) THEN
  977. IF( WORK( q ).GE.ONE ) THEN
  978. FASTR( 3 ) = T*APOAQ
  979. FASTR( 4 ) = -T*AQOAP
  980. WORK( p ) = WORK( p )*CS
  981. WORK( q ) = WORK( q )*CS
  982. CALL DROTM( M, A( 1, p ), 1,
  983. $ A( 1, q ), 1,
  984. $ FASTR )
  985. IF( RSVEC )CALL DROTM( MVL,
  986. $ V( 1, p ), 1, V( 1, q ),
  987. $ 1, FASTR )
  988. ELSE
  989. CALL DAXPY( M, -T*AQOAP,
  990. $ A( 1, q ), 1,
  991. $ A( 1, p ), 1 )
  992. CALL DAXPY( M, CS*SN*APOAQ,
  993. $ A( 1, p ), 1,
  994. $ A( 1, q ), 1 )
  995. WORK( p ) = WORK( p )*CS
  996. WORK( q ) = WORK( q ) / CS
  997. IF( RSVEC ) THEN
  998. CALL DAXPY( MVL, -T*AQOAP,
  999. $ V( 1, q ), 1,
  1000. $ V( 1, p ), 1 )
  1001. CALL DAXPY( MVL,
  1002. $ CS*SN*APOAQ,
  1003. $ V( 1, p ), 1,
  1004. $ V( 1, q ), 1 )
  1005. END IF
  1006. END IF
  1007. ELSE
  1008. IF( WORK( q ).GE.ONE ) THEN
  1009. CALL DAXPY( M, T*APOAQ,
  1010. $ A( 1, p ), 1,
  1011. $ A( 1, q ), 1 )
  1012. CALL DAXPY( M, -CS*SN*AQOAP,
  1013. $ A( 1, q ), 1,
  1014. $ A( 1, p ), 1 )
  1015. WORK( p ) = WORK( p ) / CS
  1016. WORK( q ) = WORK( q )*CS
  1017. IF( RSVEC ) THEN
  1018. CALL DAXPY( MVL, T*APOAQ,
  1019. $ V( 1, p ), 1,
  1020. $ V( 1, q ), 1 )
  1021. CALL DAXPY( MVL,
  1022. $ -CS*SN*AQOAP,
  1023. $ V( 1, q ), 1,
  1024. $ V( 1, p ), 1 )
  1025. END IF
  1026. ELSE
  1027. IF( WORK( p ).GE.WORK( q ) )
  1028. $ THEN
  1029. CALL DAXPY( M, -T*AQOAP,
  1030. $ A( 1, q ), 1,
  1031. $ A( 1, p ), 1 )
  1032. CALL DAXPY( M, CS*SN*APOAQ,
  1033. $ A( 1, p ), 1,
  1034. $ A( 1, q ), 1 )
  1035. WORK( p ) = WORK( p )*CS
  1036. WORK( q ) = WORK( q ) / CS
  1037. IF( RSVEC ) THEN
  1038. CALL DAXPY( MVL,
  1039. $ -T*AQOAP,
  1040. $ V( 1, q ), 1,
  1041. $ V( 1, p ), 1 )
  1042. CALL DAXPY( MVL,
  1043. $ CS*SN*APOAQ,
  1044. $ V( 1, p ), 1,
  1045. $ V( 1, q ), 1 )
  1046. END IF
  1047. ELSE
  1048. CALL DAXPY( M, T*APOAQ,
  1049. $ A( 1, p ), 1,
  1050. $ A( 1, q ), 1 )
  1051. CALL DAXPY( M,
  1052. $ -CS*SN*AQOAP,
  1053. $ A( 1, q ), 1,
  1054. $ A( 1, p ), 1 )
  1055. WORK( p ) = WORK( p ) / CS
  1056. WORK( q ) = WORK( q )*CS
  1057. IF( RSVEC ) THEN
  1058. CALL DAXPY( MVL,
  1059. $ T*APOAQ, V( 1, p ),
  1060. $ 1, V( 1, q ), 1 )
  1061. CALL DAXPY( MVL,
  1062. $ -CS*SN*AQOAP,
  1063. $ V( 1, q ), 1,
  1064. $ V( 1, p ), 1 )
  1065. END IF
  1066. END IF
  1067. END IF
  1068. END IF
  1069. END IF
  1070. *
  1071. ELSE
  1072. * .. have to use modified Gram-Schmidt like transformation
  1073. CALL DCOPY( M, A( 1, p ), 1,
  1074. $ WORK( N+1 ), 1 )
  1075. CALL DLASCL( 'G', 0, 0, AAPP, ONE, M,
  1076. $ 1, WORK( N+1 ), LDA,
  1077. $ IERR )
  1078. CALL DLASCL( 'G', 0, 0, AAQQ, ONE, M,
  1079. $ 1, A( 1, q ), LDA, IERR )
  1080. TEMP1 = -AAPQ*WORK( p ) / WORK( q )
  1081. CALL DAXPY( M, TEMP1, WORK( N+1 ), 1,
  1082. $ A( 1, q ), 1 )
  1083. CALL DLASCL( 'G', 0, 0, ONE, AAQQ, M,
  1084. $ 1, A( 1, q ), LDA, IERR )
  1085. SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
  1086. $ ONE-AAPQ*AAPQ ) )
  1087. MXSINJ = MAX( MXSINJ, SFMIN )
  1088. END IF
  1089. * END IF ROTOK THEN ... ELSE
  1090. *
  1091. * In the case of cancellation in updating SVA(q), SVA(p)
  1092. * recompute SVA(q), SVA(p).
  1093. *
  1094. IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
  1095. $ THEN
  1096. IF( ( AAQQ.LT.ROOTBIG ) .AND.
  1097. $ ( AAQQ.GT.ROOTSFMIN ) ) THEN
  1098. SVA( q ) = DNRM2( M, A( 1, q ), 1 )*
  1099. $ WORK( q )
  1100. ELSE
  1101. T = ZERO
  1102. AAQQ = ONE
  1103. CALL DLASSQ( M, A( 1, q ), 1, T,
  1104. $ AAQQ )
  1105. SVA( q ) = T*DSQRT( AAQQ )*WORK( q )
  1106. END IF
  1107. END IF
  1108. IF( ( AAPP / AAPP0 ).LE.ROOTEPS ) THEN
  1109. IF( ( AAPP.LT.ROOTBIG ) .AND.
  1110. $ ( AAPP.GT.ROOTSFMIN ) ) THEN
  1111. AAPP = DNRM2( M, A( 1, p ), 1 )*
  1112. $ WORK( p )
  1113. ELSE
  1114. T = ZERO
  1115. AAPP = ONE
  1116. CALL DLASSQ( M, A( 1, p ), 1, T,
  1117. $ AAPP )
  1118. AAPP = T*DSQRT( AAPP )*WORK( p )
  1119. END IF
  1120. SVA( p ) = AAPP
  1121. END IF
  1122. *
  1123. ELSE
  1124. * A(:,p) and A(:,q) already numerically orthogonal
  1125. IF( ir1.EQ.0 )NOTROT = NOTROT + 1
  1126. *[RTD] SKIPPED = SKIPPED + 1
  1127. PSKIPPED = PSKIPPED + 1
  1128. END IF
  1129. ELSE
  1130. * A(:,q) is zero column
  1131. IF( ir1.EQ.0 )NOTROT = NOTROT + 1
  1132. PSKIPPED = PSKIPPED + 1
  1133. END IF
  1134. *
  1135. IF( ( i.LE.SWBAND ) .AND.
  1136. $ ( PSKIPPED.GT.ROWSKIP ) ) THEN
  1137. IF( ir1.EQ.0 )AAPP = -AAPP
  1138. NOTROT = 0
  1139. GO TO 2103
  1140. END IF
  1141. *
  1142. 2002 CONTINUE
  1143. * END q-LOOP
  1144. *
  1145. 2103 CONTINUE
  1146. * bailed out of q-loop
  1147. *
  1148. SVA( p ) = AAPP
  1149. *
  1150. ELSE
  1151. SVA( p ) = AAPP
  1152. IF( ( ir1.EQ.0 ) .AND. ( AAPP.EQ.ZERO ) )
  1153. $ NOTROT = NOTROT + MIN( igl+KBL-1, N ) - p
  1154. END IF
  1155. *
  1156. 2001 CONTINUE
  1157. * end of the p-loop
  1158. * end of doing the block ( ibr, ibr )
  1159. 1002 CONTINUE
  1160. * end of ir1-loop
  1161. *
  1162. * ... go to the off diagonal blocks
  1163. *
  1164. igl = ( ibr-1 )*KBL + 1
  1165. *
  1166. DO 2010 jbc = ibr + 1, NBL
  1167. *
  1168. jgl = ( jbc-1 )*KBL + 1
  1169. *
  1170. * doing the block at ( ibr, jbc )
  1171. *
  1172. IJBLSK = 0
  1173. DO 2100 p = igl, MIN( igl+KBL-1, N )
  1174. *
  1175. AAPP = SVA( p )
  1176. IF( AAPP.GT.ZERO ) THEN
  1177. *
  1178. PSKIPPED = 0
  1179. *
  1180. DO 2200 q = jgl, MIN( jgl+KBL-1, N )
  1181. *
  1182. AAQQ = SVA( q )
  1183. IF( AAQQ.GT.ZERO ) THEN
  1184. AAPP0 = AAPP
  1185. *
  1186. * .. M x 2 Jacobi SVD ..
  1187. *
  1188. * Safe Gram matrix computation
  1189. *
  1190. IF( AAQQ.GE.ONE ) THEN
  1191. IF( AAPP.GE.AAQQ ) THEN
  1192. ROTOK = ( SMALL*AAPP ).LE.AAQQ
  1193. ELSE
  1194. ROTOK = ( SMALL*AAQQ ).LE.AAPP
  1195. END IF
  1196. IF( AAPP.LT.( BIG / AAQQ ) ) THEN
  1197. AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
  1198. $ q ), 1 )*WORK( p )*WORK( q ) /
  1199. $ AAQQ ) / AAPP
  1200. ELSE
  1201. CALL DCOPY( M, A( 1, p ), 1,
  1202. $ WORK( N+1 ), 1 )
  1203. CALL DLASCL( 'G', 0, 0, AAPP,
  1204. $ WORK( p ), M, 1,
  1205. $ WORK( N+1 ), LDA, IERR )
  1206. AAPQ = DDOT( M, WORK( N+1 ), 1,
  1207. $ A( 1, q ), 1 )*WORK( q ) / AAQQ
  1208. END IF
  1209. ELSE
  1210. IF( AAPP.GE.AAQQ ) THEN
  1211. ROTOK = AAPP.LE.( AAQQ / SMALL )
  1212. ELSE
  1213. ROTOK = AAQQ.LE.( AAPP / SMALL )
  1214. END IF
  1215. IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
  1216. AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
  1217. $ q ), 1 )*WORK( p )*WORK( q ) /
  1218. $ AAQQ ) / AAPP
  1219. ELSE
  1220. CALL DCOPY( M, A( 1, q ), 1,
  1221. $ WORK( N+1 ), 1 )
  1222. CALL DLASCL( 'G', 0, 0, AAQQ,
  1223. $ WORK( q ), M, 1,
  1224. $ WORK( N+1 ), LDA, IERR )
  1225. AAPQ = DDOT( M, WORK( N+1 ), 1,
  1226. $ A( 1, p ), 1 )*WORK( p ) / AAPP
  1227. END IF
  1228. END IF
  1229. *
  1230. MXAAPQ = MAX( MXAAPQ, DABS( AAPQ ) )
  1231. *
  1232. * TO rotate or NOT to rotate, THAT is the question ...
  1233. *
  1234. IF( DABS( AAPQ ).GT.TOL ) THEN
  1235. NOTROT = 0
  1236. *[RTD] ROTATED = ROTATED + 1
  1237. PSKIPPED = 0
  1238. ISWROT = ISWROT + 1
  1239. *
  1240. IF( ROTOK ) THEN
  1241. *
  1242. AQOAP = AAQQ / AAPP
  1243. APOAQ = AAPP / AAQQ
  1244. THETA = -HALF*DABS(AQOAP-APOAQ)/AAPQ
  1245. IF( AAQQ.GT.AAPP0 )THETA = -THETA
  1246. *
  1247. IF( DABS( THETA ).GT.BIGTHETA ) THEN
  1248. T = HALF / THETA
  1249. FASTR( 3 ) = T*WORK( p ) / WORK( q )
  1250. FASTR( 4 ) = -T*WORK( q ) /
  1251. $ WORK( p )
  1252. CALL DROTM( M, A( 1, p ), 1,
  1253. $ A( 1, q ), 1, FASTR )
  1254. IF( RSVEC )CALL DROTM( MVL,
  1255. $ V( 1, p ), 1,
  1256. $ V( 1, q ), 1,
  1257. $ FASTR )
  1258. SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
  1259. $ ONE+T*APOAQ*AAPQ ) )
  1260. AAPP = AAPP*DSQRT( MAX( ZERO,
  1261. $ ONE-T*AQOAP*AAPQ ) )
  1262. MXSINJ = MAX( MXSINJ, DABS( T ) )
  1263. ELSE
  1264. *
  1265. * .. choose correct signum for THETA and rotate
  1266. *
  1267. THSIGN = -DSIGN( ONE, AAPQ )
  1268. IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
  1269. T = ONE / ( THETA+THSIGN*
  1270. $ DSQRT( ONE+THETA*THETA ) )
  1271. CS = DSQRT( ONE / ( ONE+T*T ) )
  1272. SN = T*CS
  1273. MXSINJ = MAX( MXSINJ, DABS( SN ) )
  1274. SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
  1275. $ ONE+T*APOAQ*AAPQ ) )
  1276. AAPP = AAPP*DSQRT( MAX( ZERO,
  1277. $ ONE-T*AQOAP*AAPQ ) )
  1278. *
  1279. APOAQ = WORK( p ) / WORK( q )
  1280. AQOAP = WORK( q ) / WORK( p )
  1281. IF( WORK( p ).GE.ONE ) THEN
  1282. *
  1283. IF( WORK( q ).GE.ONE ) THEN
  1284. FASTR( 3 ) = T*APOAQ
  1285. FASTR( 4 ) = -T*AQOAP
  1286. WORK( p ) = WORK( p )*CS
  1287. WORK( q ) = WORK( q )*CS
  1288. CALL DROTM( M, A( 1, p ), 1,
  1289. $ A( 1, q ), 1,
  1290. $ FASTR )
  1291. IF( RSVEC )CALL DROTM( MVL,
  1292. $ V( 1, p ), 1, V( 1, q ),
  1293. $ 1, FASTR )
  1294. ELSE
  1295. CALL DAXPY( M, -T*AQOAP,
  1296. $ A( 1, q ), 1,
  1297. $ A( 1, p ), 1 )
  1298. CALL DAXPY( M, CS*SN*APOAQ,
  1299. $ A( 1, p ), 1,
  1300. $ A( 1, q ), 1 )
  1301. IF( RSVEC ) THEN
  1302. CALL DAXPY( MVL, -T*AQOAP,
  1303. $ V( 1, q ), 1,
  1304. $ V( 1, p ), 1 )
  1305. CALL DAXPY( MVL,
  1306. $ CS*SN*APOAQ,
  1307. $ V( 1, p ), 1,
  1308. $ V( 1, q ), 1 )
  1309. END IF
  1310. WORK( p ) = WORK( p )*CS
  1311. WORK( q ) = WORK( q ) / CS
  1312. END IF
  1313. ELSE
  1314. IF( WORK( q ).GE.ONE ) THEN
  1315. CALL DAXPY( M, T*APOAQ,
  1316. $ A( 1, p ), 1,
  1317. $ A( 1, q ), 1 )
  1318. CALL DAXPY( M, -CS*SN*AQOAP,
  1319. $ A( 1, q ), 1,
  1320. $ A( 1, p ), 1 )
  1321. IF( RSVEC ) THEN
  1322. CALL DAXPY( MVL, T*APOAQ,
  1323. $ V( 1, p ), 1,
  1324. $ V( 1, q ), 1 )
  1325. CALL DAXPY( MVL,
  1326. $ -CS*SN*AQOAP,
  1327. $ V( 1, q ), 1,
  1328. $ V( 1, p ), 1 )
  1329. END IF
  1330. WORK( p ) = WORK( p ) / CS
  1331. WORK( q ) = WORK( q )*CS
  1332. ELSE
  1333. IF( WORK( p ).GE.WORK( q ) )
  1334. $ THEN
  1335. CALL DAXPY( M, -T*AQOAP,
  1336. $ A( 1, q ), 1,
  1337. $ A( 1, p ), 1 )
  1338. CALL DAXPY( M, CS*SN*APOAQ,
  1339. $ A( 1, p ), 1,
  1340. $ A( 1, q ), 1 )
  1341. WORK( p ) = WORK( p )*CS
  1342. WORK( q ) = WORK( q ) / CS
  1343. IF( RSVEC ) THEN
  1344. CALL DAXPY( MVL,
  1345. $ -T*AQOAP,
  1346. $ V( 1, q ), 1,
  1347. $ V( 1, p ), 1 )
  1348. CALL DAXPY( MVL,
  1349. $ CS*SN*APOAQ,
  1350. $ V( 1, p ), 1,
  1351. $ V( 1, q ), 1 )
  1352. END IF
  1353. ELSE
  1354. CALL DAXPY( M, T*APOAQ,
  1355. $ A( 1, p ), 1,
  1356. $ A( 1, q ), 1 )
  1357. CALL DAXPY( M,
  1358. $ -CS*SN*AQOAP,
  1359. $ A( 1, q ), 1,
  1360. $ A( 1, p ), 1 )
  1361. WORK( p ) = WORK( p ) / CS
  1362. WORK( q ) = WORK( q )*CS
  1363. IF( RSVEC ) THEN
  1364. CALL DAXPY( MVL,
  1365. $ T*APOAQ, V( 1, p ),
  1366. $ 1, V( 1, q ), 1 )
  1367. CALL DAXPY( MVL,
  1368. $ -CS*SN*AQOAP,
  1369. $ V( 1, q ), 1,
  1370. $ V( 1, p ), 1 )
  1371. END IF
  1372. END IF
  1373. END IF
  1374. END IF
  1375. END IF
  1376. *
  1377. ELSE
  1378. IF( AAPP.GT.AAQQ ) THEN
  1379. CALL DCOPY( M, A( 1, p ), 1,
  1380. $ WORK( N+1 ), 1 )
  1381. CALL DLASCL( 'G', 0, 0, AAPP, ONE,
  1382. $ M, 1, WORK( N+1 ), LDA,
  1383. $ IERR )
  1384. CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
  1385. $ M, 1, A( 1, q ), LDA,
  1386. $ IERR )
  1387. TEMP1 = -AAPQ*WORK( p ) / WORK( q )
  1388. CALL DAXPY( M, TEMP1, WORK( N+1 ),
  1389. $ 1, A( 1, q ), 1 )
  1390. CALL DLASCL( 'G', 0, 0, ONE, AAQQ,
  1391. $ M, 1, A( 1, q ), LDA,
  1392. $ IERR )
  1393. SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
  1394. $ ONE-AAPQ*AAPQ ) )
  1395. MXSINJ = MAX( MXSINJ, SFMIN )
  1396. ELSE
  1397. CALL DCOPY( M, A( 1, q ), 1,
  1398. $ WORK( N+1 ), 1 )
  1399. CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
  1400. $ M, 1, WORK( N+1 ), LDA,
  1401. $ IERR )
  1402. CALL DLASCL( 'G', 0, 0, AAPP, ONE,
  1403. $ M, 1, A( 1, p ), LDA,
  1404. $ IERR )
  1405. TEMP1 = -AAPQ*WORK( q ) / WORK( p )
  1406. CALL DAXPY( M, TEMP1, WORK( N+1 ),
  1407. $ 1, A( 1, p ), 1 )
  1408. CALL DLASCL( 'G', 0, 0, ONE, AAPP,
  1409. $ M, 1, A( 1, p ), LDA,
  1410. $ IERR )
  1411. SVA( p ) = AAPP*DSQRT( MAX( ZERO,
  1412. $ ONE-AAPQ*AAPQ ) )
  1413. MXSINJ = MAX( MXSINJ, SFMIN )
  1414. END IF
  1415. END IF
  1416. * END IF ROTOK THEN ... ELSE
  1417. *
  1418. * In the case of cancellation in updating SVA(q)
  1419. * .. recompute SVA(q)
  1420. IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
  1421. $ THEN
  1422. IF( ( AAQQ.LT.ROOTBIG ) .AND.
  1423. $ ( AAQQ.GT.ROOTSFMIN ) ) THEN
  1424. SVA( q ) = DNRM2( M, A( 1, q ), 1 )*
  1425. $ WORK( q )
  1426. ELSE
  1427. T = ZERO
  1428. AAQQ = ONE
  1429. CALL DLASSQ( M, A( 1, q ), 1, T,
  1430. $ AAQQ )
  1431. SVA( q ) = T*DSQRT( AAQQ )*WORK( q )
  1432. END IF
  1433. END IF
  1434. IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
  1435. IF( ( AAPP.LT.ROOTBIG ) .AND.
  1436. $ ( AAPP.GT.ROOTSFMIN ) ) THEN
  1437. AAPP = DNRM2( M, A( 1, p ), 1 )*
  1438. $ WORK( p )
  1439. ELSE
  1440. T = ZERO
  1441. AAPP = ONE
  1442. CALL DLASSQ( M, A( 1, p ), 1, T,
  1443. $ AAPP )
  1444. AAPP = T*DSQRT( AAPP )*WORK( p )
  1445. END IF
  1446. SVA( p ) = AAPP
  1447. END IF
  1448. * end of OK rotation
  1449. ELSE
  1450. NOTROT = NOTROT + 1
  1451. *[RTD] SKIPPED = SKIPPED + 1
  1452. PSKIPPED = PSKIPPED + 1
  1453. IJBLSK = IJBLSK + 1
  1454. END IF
  1455. ELSE
  1456. NOTROT = NOTROT + 1
  1457. PSKIPPED = PSKIPPED + 1
  1458. IJBLSK = IJBLSK + 1
  1459. END IF
  1460. *
  1461. IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
  1462. $ THEN
  1463. SVA( p ) = AAPP
  1464. NOTROT = 0
  1465. GO TO 2011
  1466. END IF
  1467. IF( ( i.LE.SWBAND ) .AND.
  1468. $ ( PSKIPPED.GT.ROWSKIP ) ) THEN
  1469. AAPP = -AAPP
  1470. NOTROT = 0
  1471. GO TO 2203
  1472. END IF
  1473. *
  1474. 2200 CONTINUE
  1475. * end of the q-loop
  1476. 2203 CONTINUE
  1477. *
  1478. SVA( p ) = AAPP
  1479. *
  1480. ELSE
  1481. *
  1482. IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
  1483. $ MIN( jgl+KBL-1, N ) - jgl + 1
  1484. IF( AAPP.LT.ZERO )NOTROT = 0
  1485. *
  1486. END IF
  1487. *
  1488. 2100 CONTINUE
  1489. * end of the p-loop
  1490. 2010 CONTINUE
  1491. * end of the jbc-loop
  1492. 2011 CONTINUE
  1493. *2011 bailed out of the jbc-loop
  1494. DO 2012 p = igl, MIN( igl+KBL-1, N )
  1495. SVA( p ) = DABS( SVA( p ) )
  1496. 2012 CONTINUE
  1497. ***
  1498. 2000 CONTINUE
  1499. *2000 :: end of the ibr-loop
  1500. *
  1501. * .. update SVA(N)
  1502. IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
  1503. $ THEN
  1504. SVA( N ) = DNRM2( M, A( 1, N ), 1 )*WORK( N )
  1505. ELSE
  1506. T = ZERO
  1507. AAPP = ONE
  1508. CALL DLASSQ( M, A( 1, N ), 1, T, AAPP )
  1509. SVA( N ) = T*DSQRT( AAPP )*WORK( N )
  1510. END IF
  1511. *
  1512. * Additional steering devices
  1513. *
  1514. IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
  1515. $ ( ISWROT.LE.N ) ) )SWBAND = i
  1516. *
  1517. IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.DSQRT( DBLE( N ) )*
  1518. $ TOL ) .AND. ( DBLE( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
  1519. GO TO 1994
  1520. END IF
  1521. *
  1522. IF( NOTROT.GE.EMPTSW )GO TO 1994
  1523. *
  1524. 1993 CONTINUE
  1525. * end i=1:NSWEEP loop
  1526. *
  1527. * #:( Reaching this point means that the procedure has not converged.
  1528. INFO = NSWEEP - 1
  1529. GO TO 1995
  1530. *
  1531. 1994 CONTINUE
  1532. * #:) Reaching this point means numerical convergence after the i-th
  1533. * sweep.
  1534. *
  1535. INFO = 0
  1536. * #:) INFO = 0 confirms successful iterations.
  1537. 1995 CONTINUE
  1538. *
  1539. * Sort the singular values and find how many are above
  1540. * the underflow threshold.
  1541. *
  1542. N2 = 0
  1543. N4 = 0
  1544. DO 5991 p = 1, N - 1
  1545. q = IDAMAX( N-p+1, SVA( p ), 1 ) + p - 1
  1546. IF( p.NE.q ) THEN
  1547. TEMP1 = SVA( p )
  1548. SVA( p ) = SVA( q )
  1549. SVA( q ) = TEMP1
  1550. TEMP1 = WORK( p )
  1551. WORK( p ) = WORK( q )
  1552. WORK( q ) = TEMP1
  1553. CALL DSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
  1554. IF( RSVEC )CALL DSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
  1555. END IF
  1556. IF( SVA( p ).NE.ZERO ) THEN
  1557. N4 = N4 + 1
  1558. IF( SVA( p )*SKL.GT.SFMIN )N2 = N2 + 1
  1559. END IF
  1560. 5991 CONTINUE
  1561. IF( SVA( N ).NE.ZERO ) THEN
  1562. N4 = N4 + 1
  1563. IF( SVA( N )*SKL.GT.SFMIN )N2 = N2 + 1
  1564. END IF
  1565. *
  1566. * Normalize the left singular vectors.
  1567. *
  1568. IF( LSVEC .OR. UCTOL ) THEN
  1569. DO 1998 p = 1, N2
  1570. CALL DSCAL( M, WORK( p ) / SVA( p ), A( 1, p ), 1 )
  1571. 1998 CONTINUE
  1572. END IF
  1573. *
  1574. * Scale the product of Jacobi rotations (assemble the fast rotations).
  1575. *
  1576. IF( RSVEC ) THEN
  1577. IF( APPLV ) THEN
  1578. DO 2398 p = 1, N
  1579. CALL DSCAL( MVL, WORK( p ), V( 1, p ), 1 )
  1580. 2398 CONTINUE
  1581. ELSE
  1582. DO 2399 p = 1, N
  1583. TEMP1 = ONE / DNRM2( MVL, V( 1, p ), 1 )
  1584. CALL DSCAL( MVL, TEMP1, V( 1, p ), 1 )
  1585. 2399 CONTINUE
  1586. END IF
  1587. END IF
  1588. *
  1589. * Undo scaling, if necessary (and possible).
  1590. IF( ( ( SKL.GT.ONE ) .AND. ( SVA( 1 ).LT.( BIG / SKL) ) )
  1591. $ .OR. ( ( SKL.LT.ONE ) .AND. ( SVA( MAX( N2, 1 ) ) .GT.
  1592. $ ( SFMIN / SKL) ) ) ) THEN
  1593. DO 2400 p = 1, N
  1594. SVA( P ) = SKL*SVA( P )
  1595. 2400 CONTINUE
  1596. SKL= ONE
  1597. END IF
  1598. *
  1599. WORK( 1 ) = SKL
  1600. * The singular values of A are SKL*SVA(1:N). If SKL.NE.ONE
  1601. * then some of the singular values may overflow or underflow and
  1602. * the spectrum is given in this factored representation.
  1603. *
  1604. WORK( 2 ) = DBLE( N4 )
  1605. * N4 is the number of computed nonzero singular values of A.
  1606. *
  1607. WORK( 3 ) = DBLE( N2 )
  1608. * N2 is the number of singular values of A greater than SFMIN.
  1609. * If N2<N, SVA(N2:N) contains ZEROS and/or denormalized numbers
  1610. * that may carry some information.
  1611. *
  1612. WORK( 4 ) = DBLE( i )
  1613. * i is the index of the last sweep before declaring convergence.
  1614. *
  1615. WORK( 5 ) = MXAAPQ
  1616. * MXAAPQ is the largest absolute value of scaled pivots in the
  1617. * last sweep
  1618. *
  1619. WORK( 6 ) = MXSINJ
  1620. * MXSINJ is the largest absolute value of the sines of Jacobi angles
  1621. * in the last sweep
  1622. *
  1623. RETURN
  1624. * ..
  1625. * .. END OF DGESVJ
  1626. * ..
  1627. END