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.

sgsvj1.f 31 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. *> \brief \b SGSVJ1 pre-processor for the routine sgesvj, applies Jacobi rotations targeting only particular pivots.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SGSVJ1 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgsvj1.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgsvj1.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgsvj1.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV,
  22. * EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * REAL EPS, SFMIN, TOL
  26. * INTEGER INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP
  27. * CHARACTER*1 JOBV
  28. * ..
  29. * .. Array Arguments ..
  30. * REAL A( LDA, * ), D( N ), SVA( N ), V( LDV, * ),
  31. * $ WORK( LWORK )
  32. * ..
  33. *
  34. *
  35. *> \par Purpose:
  36. * =============
  37. *>
  38. *> \verbatim
  39. *>
  40. *> SGSVJ1 is called from SGESVJ as a pre-processor and that is its main
  41. *> purpose. It applies Jacobi rotations in the same way as SGESVJ does, but
  42. *> it targets only particular pivots and it does not check convergence
  43. *> (stopping criterion). Few tuning parameters (marked by [TP]) are
  44. *> available for the implementer.
  45. *>
  46. *> Further Details
  47. *> ~~~~~~~~~~~~~~~
  48. *> SGSVJ1 applies few sweeps of Jacobi rotations in the column space of
  49. *> the input M-by-N matrix A. The pivot pairs are taken from the (1,2)
  50. *> off-diagonal block in the corresponding N-by-N Gram matrix A^T * A. The
  51. *> block-entries (tiles) of the (1,2) off-diagonal block are marked by the
  52. *> [x]'s in the following scheme:
  53. *>
  54. *> | * * * [x] [x] [x]|
  55. *> | * * * [x] [x] [x]| Row-cycling in the nblr-by-nblc [x] blocks.
  56. *> | * * * [x] [x] [x]| Row-cyclic pivoting inside each [x] block.
  57. *> |[x] [x] [x] * * * |
  58. *> |[x] [x] [x] * * * |
  59. *> |[x] [x] [x] * * * |
  60. *>
  61. *> In terms of the columns of A, the first N1 columns are rotated 'against'
  62. *> the remaining N-N1 columns, trying to increase the angle between the
  63. *> corresponding subspaces. The off-diagonal block is N1-by(N-N1) and it is
  64. *> tiled using quadratic tiles of side KBL. Here, KBL is a tuning parameter.
  65. *> The number of sweeps is given in NSWEEP and the orthogonality threshold
  66. *> is given in TOL.
  67. *> \endverbatim
  68. *
  69. * Arguments:
  70. * ==========
  71. *
  72. *> \param[in] JOBV
  73. *> \verbatim
  74. *> JOBV is CHARACTER*1
  75. *> Specifies whether the output from this procedure is used
  76. *> to compute the matrix V:
  77. *> = 'V': the product of the Jacobi rotations is accumulated
  78. *> by postmulyiplying the N-by-N array V.
  79. *> (See the description of V.)
  80. *> = 'A': the product of the Jacobi rotations is accumulated
  81. *> by postmulyiplying the MV-by-N array V.
  82. *> (See the descriptions of MV and V.)
  83. *> = 'N': the Jacobi rotations are not accumulated.
  84. *> \endverbatim
  85. *>
  86. *> \param[in] M
  87. *> \verbatim
  88. *> M is INTEGER
  89. *> The number of rows of the input matrix A. M >= 0.
  90. *> \endverbatim
  91. *>
  92. *> \param[in] N
  93. *> \verbatim
  94. *> N is INTEGER
  95. *> The number of columns of the input matrix A.
  96. *> M >= N >= 0.
  97. *> \endverbatim
  98. *>
  99. *> \param[in] N1
  100. *> \verbatim
  101. *> N1 is INTEGER
  102. *> N1 specifies the 2 x 2 block partition, the first N1 columns are
  103. *> rotated 'against' the remaining N-N1 columns of A.
  104. *> \endverbatim
  105. *>
  106. *> \param[in,out] A
  107. *> \verbatim
  108. *> A is REAL array, dimension (LDA,N)
  109. *> On entry, M-by-N matrix A, such that A*diag(D) represents
  110. *> the input matrix.
  111. *> On exit,
  112. *> A_onexit * D_onexit represents the input matrix A*diag(D)
  113. *> post-multiplied by a sequence of Jacobi rotations, where the
  114. *> rotation threshold and the total number of sweeps are given in
  115. *> TOL and NSWEEP, respectively.
  116. *> (See the descriptions of N1, D, TOL and NSWEEP.)
  117. *> \endverbatim
  118. *>
  119. *> \param[in] LDA
  120. *> \verbatim
  121. *> LDA is INTEGER
  122. *> The leading dimension of the array A. LDA >= max(1,M).
  123. *> \endverbatim
  124. *>
  125. *> \param[in,out] D
  126. *> \verbatim
  127. *> D is REAL array, dimension (N)
  128. *> The array D accumulates the scaling factors from the fast scaled
  129. *> Jacobi rotations.
  130. *> On entry, A*diag(D) represents the input matrix.
  131. *> On exit, A_onexit*diag(D_onexit) represents the input matrix
  132. *> post-multiplied by a sequence of Jacobi rotations, where the
  133. *> rotation threshold and the total number of sweeps are given in
  134. *> TOL and NSWEEP, respectively.
  135. *> (See the descriptions of N1, A, TOL and NSWEEP.)
  136. *> \endverbatim
  137. *>
  138. *> \param[in,out] SVA
  139. *> \verbatim
  140. *> SVA is REAL array, dimension (N)
  141. *> On entry, SVA contains the Euclidean norms of the columns of
  142. *> the matrix A*diag(D).
  143. *> On exit, SVA contains the Euclidean norms of the columns of
  144. *> the matrix onexit*diag(D_onexit).
  145. *> \endverbatim
  146. *>
  147. *> \param[in] MV
  148. *> \verbatim
  149. *> MV is INTEGER
  150. *> If JOBV = 'A', then MV rows of V are post-multipled by a
  151. *> sequence of Jacobi rotations.
  152. *> If JOBV = 'N', then MV is not referenced.
  153. *> \endverbatim
  154. *>
  155. *> \param[in,out] V
  156. *> \verbatim
  157. *> V is REAL array, dimension (LDV,N)
  158. *> If JOBV = 'V' then N rows of V are post-multipled by a
  159. *> sequence of Jacobi rotations.
  160. *> If JOBV = 'A' then MV rows of V are post-multipled by a
  161. *> sequence of Jacobi rotations.
  162. *> If JOBV = 'N', then V is not referenced.
  163. *> \endverbatim
  164. *>
  165. *> \param[in] LDV
  166. *> \verbatim
  167. *> LDV is INTEGER
  168. *> The leading dimension of the array V, LDV >= 1.
  169. *> If JOBV = 'V', LDV >= N.
  170. *> If JOBV = 'A', LDV >= MV.
  171. *> \endverbatim
  172. *>
  173. *> \param[in] EPS
  174. *> \verbatim
  175. *> EPS is REAL
  176. *> EPS = SLAMCH('Epsilon')
  177. *> \endverbatim
  178. *>
  179. *> \param[in] SFMIN
  180. *> \verbatim
  181. *> SFMIN is REAL
  182. *> SFMIN = SLAMCH('Safe Minimum')
  183. *> \endverbatim
  184. *>
  185. *> \param[in] TOL
  186. *> \verbatim
  187. *> TOL is REAL
  188. *> TOL is the threshold for Jacobi rotations. For a pair
  189. *> A(:,p), A(:,q) of pivot columns, the Jacobi rotation is
  190. *> applied only if ABS(COS(angle(A(:,p),A(:,q)))) > TOL.
  191. *> \endverbatim
  192. *>
  193. *> \param[in] NSWEEP
  194. *> \verbatim
  195. *> NSWEEP is INTEGER
  196. *> NSWEEP is the number of sweeps of Jacobi rotations to be
  197. *> performed.
  198. *> \endverbatim
  199. *>
  200. *> \param[out] WORK
  201. *> \verbatim
  202. *> WORK is REAL array, dimension (LWORK)
  203. *> \endverbatim
  204. *>
  205. *> \param[in] LWORK
  206. *> \verbatim
  207. *> LWORK is INTEGER
  208. *> LWORK is the dimension of WORK. LWORK >= M.
  209. *> \endverbatim
  210. *>
  211. *> \param[out] INFO
  212. *> \verbatim
  213. *> INFO is INTEGER
  214. *> = 0: successful exit.
  215. *> < 0: if INFO = -i, then the i-th argument had an illegal value
  216. *> \endverbatim
  217. *
  218. * Authors:
  219. * ========
  220. *
  221. *> \author Univ. of Tennessee
  222. *> \author Univ. of California Berkeley
  223. *> \author Univ. of Colorado Denver
  224. *> \author NAG Ltd.
  225. *
  226. *> \ingroup realOTHERcomputational
  227. *
  228. *> \par Contributors:
  229. * ==================
  230. *>
  231. *> Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
  232. *
  233. * =====================================================================
  234. SUBROUTINE SGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV,
  235. $ EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
  236. *
  237. * -- LAPACK computational routine --
  238. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  239. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  240. *
  241. * .. Scalar Arguments ..
  242. REAL EPS, SFMIN, TOL
  243. INTEGER INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP
  244. CHARACTER*1 JOBV
  245. * ..
  246. * .. Array Arguments ..
  247. REAL A( LDA, * ), D( N ), SVA( N ), V( LDV, * ),
  248. $ WORK( LWORK )
  249. * ..
  250. *
  251. * =====================================================================
  252. *
  253. * .. Local Parameters ..
  254. REAL ZERO, HALF, ONE
  255. PARAMETER ( ZERO = 0.0E0, HALF = 0.5E0, ONE = 1.0E0)
  256. * ..
  257. * .. Local Scalars ..
  258. REAL AAPP, AAPP0, AAPQ, AAQQ, APOAQ, AQOAP, BIG,
  259. $ BIGTHETA, CS, LARGE, MXAAPQ, MXSINJ, ROOTBIG,
  260. $ ROOTEPS, ROOTSFMIN, ROOTTOL, SMALL, SN, T,
  261. $ TEMP1, THETA, THSIGN
  262. INTEGER BLSKIP, EMPTSW, i, ibr, igl, IERR, IJBLSK,
  263. $ ISWROT, jbc, jgl, KBL, MVL, NOTROT, nblc, nblr,
  264. $ p, PSKIPPED, q, ROWSKIP, SWBAND
  265. LOGICAL APPLV, ROTOK, RSVEC
  266. * ..
  267. * .. Local Arrays ..
  268. REAL FASTR( 5 )
  269. * ..
  270. * .. Intrinsic Functions ..
  271. INTRINSIC ABS, MAX, FLOAT, MIN, SIGN, SQRT
  272. * ..
  273. * .. External Functions ..
  274. REAL SDOT, SNRM2
  275. INTEGER ISAMAX
  276. LOGICAL LSAME
  277. EXTERNAL ISAMAX, LSAME, SDOT, SNRM2
  278. * ..
  279. * .. External Subroutines ..
  280. EXTERNAL SAXPY, SCOPY, SLASCL, SLASSQ, SROTM, SSWAP,
  281. $ XERBLA
  282. * ..
  283. * .. Executable Statements ..
  284. *
  285. * Test the input parameters.
  286. *
  287. APPLV = LSAME( JOBV, 'A' )
  288. RSVEC = LSAME( JOBV, 'V' )
  289. IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
  290. INFO = -1
  291. ELSE IF( M.LT.0 ) THEN
  292. INFO = -2
  293. ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
  294. INFO = -3
  295. ELSE IF( N1.LT.0 ) THEN
  296. INFO = -4
  297. ELSE IF( LDA.LT.M ) THEN
  298. INFO = -6
  299. ELSE IF( ( RSVEC.OR.APPLV ) .AND. ( MV.LT.0 ) ) THEN
  300. INFO = -9
  301. ELSE IF( ( RSVEC.AND.( LDV.LT.N ) ).OR.
  302. $ ( APPLV.AND.( LDV.LT.MV ) ) ) THEN
  303. INFO = -11
  304. ELSE IF( TOL.LE.EPS ) THEN
  305. INFO = -14
  306. ELSE IF( NSWEEP.LT.0 ) THEN
  307. INFO = -15
  308. ELSE IF( LWORK.LT.M ) THEN
  309. INFO = -17
  310. ELSE
  311. INFO = 0
  312. END IF
  313. *
  314. * #:(
  315. IF( INFO.NE.0 ) THEN
  316. CALL XERBLA( 'SGSVJ1', -INFO )
  317. RETURN
  318. END IF
  319. *
  320. IF( RSVEC ) THEN
  321. MVL = N
  322. ELSE IF( APPLV ) THEN
  323. MVL = MV
  324. END IF
  325. RSVEC = RSVEC .OR. APPLV
  326. ROOTEPS = SQRT( EPS )
  327. ROOTSFMIN = SQRT( SFMIN )
  328. SMALL = SFMIN / EPS
  329. BIG = ONE / SFMIN
  330. ROOTBIG = ONE / ROOTSFMIN
  331. LARGE = BIG / SQRT( FLOAT( M*N ) )
  332. BIGTHETA = ONE / ROOTEPS
  333. ROOTTOL = SQRT( TOL )
  334. *
  335. * .. Initialize the right singular vector matrix ..
  336. *
  337. * RSVEC = LSAME( JOBV, 'Y' )
  338. *
  339. EMPTSW = N1*( N-N1 )
  340. NOTROT = 0
  341. FASTR( 1 ) = ZERO
  342. *
  343. * .. Row-cyclic pivot strategy with de Rijk's pivoting ..
  344. *
  345. KBL = MIN( 8, N )
  346. NBLR = N1 / KBL
  347. IF( ( NBLR*KBL ).NE.N1 )NBLR = NBLR + 1
  348. * .. the tiling is nblr-by-nblc [tiles]
  349. NBLC = ( N-N1 ) / KBL
  350. IF( ( NBLC*KBL ).NE.( N-N1 ) )NBLC = NBLC + 1
  351. BLSKIP = ( KBL**2 ) + 1
  352. *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
  353. ROWSKIP = MIN( 5, KBL )
  354. *[TP] ROWSKIP is a tuning parameter.
  355. SWBAND = 0
  356. *[TP] SWBAND is a tuning parameter. It is meaningful and effective
  357. * if SGESVJ is used as a computational routine in the preconditioned
  358. * Jacobi SVD algorithm SGESVJ.
  359. *
  360. *
  361. * | * * * [x] [x] [x]|
  362. * | * * * [x] [x] [x]| Row-cycling in the nblr-by-nblc [x] blocks.
  363. * | * * * [x] [x] [x]| Row-cyclic pivoting inside each [x] block.
  364. * |[x] [x] [x] * * * |
  365. * |[x] [x] [x] * * * |
  366. * |[x] [x] [x] * * * |
  367. *
  368. *
  369. DO 1993 i = 1, NSWEEP
  370. * .. go go go ...
  371. *
  372. MXAAPQ = ZERO
  373. MXSINJ = ZERO
  374. ISWROT = 0
  375. *
  376. NOTROT = 0
  377. PSKIPPED = 0
  378. *
  379. DO 2000 ibr = 1, NBLR
  380. igl = ( ibr-1 )*KBL + 1
  381. *
  382. *
  383. *........................................................
  384. * ... go to the off diagonal blocks
  385. igl = ( ibr-1 )*KBL + 1
  386. DO 2010 jbc = 1, NBLC
  387. jgl = N1 + ( jbc-1 )*KBL + 1
  388. * doing the block at ( ibr, jbc )
  389. IJBLSK = 0
  390. DO 2100 p = igl, MIN( igl+KBL-1, N1 )
  391. AAPP = SVA( p )
  392. IF( AAPP.GT.ZERO ) THEN
  393. PSKIPPED = 0
  394. DO 2200 q = jgl, MIN( jgl+KBL-1, N )
  395. *
  396. AAQQ = SVA( q )
  397. IF( AAQQ.GT.ZERO ) THEN
  398. AAPP0 = AAPP
  399. *
  400. * .. M x 2 Jacobi SVD ..
  401. *
  402. * .. Safe Gram matrix computation ..
  403. *
  404. IF( AAQQ.GE.ONE ) THEN
  405. IF( AAPP.GE.AAQQ ) THEN
  406. ROTOK = ( SMALL*AAPP ).LE.AAQQ
  407. ELSE
  408. ROTOK = ( SMALL*AAQQ ).LE.AAPP
  409. END IF
  410. IF( AAPP.LT.( BIG / AAQQ ) ) THEN
  411. AAPQ = ( SDOT( M, A( 1, p ), 1, A( 1,
  412. $ q ), 1 )*D( p )*D( q ) / AAQQ )
  413. $ / AAPP
  414. ELSE
  415. CALL SCOPY( M, A( 1, p ), 1, WORK, 1 )
  416. CALL SLASCL( 'G', 0, 0, AAPP, D( p ),
  417. $ M, 1, WORK, LDA, IERR )
  418. AAPQ = SDOT( M, WORK, 1, A( 1, q ),
  419. $ 1 )*D( q ) / AAQQ
  420. END IF
  421. ELSE
  422. IF( AAPP.GE.AAQQ ) THEN
  423. ROTOK = AAPP.LE.( AAQQ / SMALL )
  424. ELSE
  425. ROTOK = AAQQ.LE.( AAPP / SMALL )
  426. END IF
  427. IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
  428. AAPQ = ( SDOT( M, A( 1, p ), 1, A( 1,
  429. $ q ), 1 )*D( p )*D( q ) / AAQQ )
  430. $ / AAPP
  431. ELSE
  432. CALL SCOPY( M, A( 1, q ), 1, WORK, 1 )
  433. CALL SLASCL( 'G', 0, 0, AAQQ, D( q ),
  434. $ M, 1, WORK, LDA, IERR )
  435. AAPQ = SDOT( M, WORK, 1, A( 1, p ),
  436. $ 1 )*D( p ) / AAPP
  437. END IF
  438. END IF
  439. MXAAPQ = MAX( MXAAPQ, ABS( AAPQ ) )
  440. * TO rotate or NOT to rotate, THAT is the question ...
  441. *
  442. IF( ABS( AAPQ ).GT.TOL ) THEN
  443. NOTROT = 0
  444. * ROTATED = ROTATED + 1
  445. PSKIPPED = 0
  446. ISWROT = ISWROT + 1
  447. *
  448. IF( ROTOK ) THEN
  449. *
  450. AQOAP = AAQQ / AAPP
  451. APOAQ = AAPP / AAQQ
  452. THETA = -HALF*ABS( AQOAP-APOAQ ) / AAPQ
  453. IF( AAQQ.GT.AAPP0 )THETA = -THETA
  454. IF( ABS( THETA ).GT.BIGTHETA ) THEN
  455. T = HALF / THETA
  456. FASTR( 3 ) = T*D( p ) / D( q )
  457. FASTR( 4 ) = -T*D( q ) / D( p )
  458. CALL SROTM( M, A( 1, p ), 1,
  459. $ A( 1, q ), 1, FASTR )
  460. IF( RSVEC )CALL SROTM( MVL,
  461. $ V( 1, p ), 1,
  462. $ V( 1, q ), 1,
  463. $ FASTR )
  464. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  465. $ ONE+T*APOAQ*AAPQ ) )
  466. AAPP = AAPP*SQRT( MAX( ZERO,
  467. $ ONE-T*AQOAP*AAPQ ) )
  468. MXSINJ = MAX( MXSINJ, ABS( T ) )
  469. ELSE
  470. *
  471. * .. choose correct signum for THETA and rotate
  472. *
  473. THSIGN = -SIGN( ONE, AAPQ )
  474. IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
  475. T = ONE / ( THETA+THSIGN*
  476. $ SQRT( ONE+THETA*THETA ) )
  477. CS = SQRT( ONE / ( ONE+T*T ) )
  478. SN = T*CS
  479. MXSINJ = MAX( MXSINJ, ABS( SN ) )
  480. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  481. $ ONE+T*APOAQ*AAPQ ) )
  482. AAPP = AAPP*SQRT( MAX( ZERO,
  483. $ ONE-T*AQOAP*AAPQ ) )
  484. APOAQ = D( p ) / D( q )
  485. AQOAP = D( q ) / D( p )
  486. IF( D( p ).GE.ONE ) THEN
  487. *
  488. IF( D( q ).GE.ONE ) THEN
  489. FASTR( 3 ) = T*APOAQ
  490. FASTR( 4 ) = -T*AQOAP
  491. D( p ) = D( p )*CS
  492. D( q ) = D( q )*CS
  493. CALL SROTM( M, A( 1, p ), 1,
  494. $ A( 1, q ), 1,
  495. $ FASTR )
  496. IF( RSVEC )CALL SROTM( MVL,
  497. $ V( 1, p ), 1, V( 1, q ),
  498. $ 1, FASTR )
  499. ELSE
  500. CALL SAXPY( M, -T*AQOAP,
  501. $ A( 1, q ), 1,
  502. $ A( 1, p ), 1 )
  503. CALL SAXPY( M, CS*SN*APOAQ,
  504. $ A( 1, p ), 1,
  505. $ A( 1, q ), 1 )
  506. IF( RSVEC ) THEN
  507. CALL SAXPY( MVL, -T*AQOAP,
  508. $ V( 1, q ), 1,
  509. $ V( 1, p ), 1 )
  510. CALL SAXPY( MVL,
  511. $ CS*SN*APOAQ,
  512. $ V( 1, p ), 1,
  513. $ V( 1, q ), 1 )
  514. END IF
  515. D( p ) = D( p )*CS
  516. D( q ) = D( q ) / CS
  517. END IF
  518. ELSE
  519. IF( D( q ).GE.ONE ) THEN
  520. CALL SAXPY( M, T*APOAQ,
  521. $ A( 1, p ), 1,
  522. $ A( 1, q ), 1 )
  523. CALL SAXPY( M, -CS*SN*AQOAP,
  524. $ A( 1, q ), 1,
  525. $ A( 1, p ), 1 )
  526. IF( RSVEC ) THEN
  527. CALL SAXPY( MVL, T*APOAQ,
  528. $ V( 1, p ), 1,
  529. $ V( 1, q ), 1 )
  530. CALL SAXPY( MVL,
  531. $ -CS*SN*AQOAP,
  532. $ V( 1, q ), 1,
  533. $ V( 1, p ), 1 )
  534. END IF
  535. D( p ) = D( p ) / CS
  536. D( q ) = D( q )*CS
  537. ELSE
  538. IF( D( p ).GE.D( q ) ) THEN
  539. CALL SAXPY( M, -T*AQOAP,
  540. $ A( 1, q ), 1,
  541. $ A( 1, p ), 1 )
  542. CALL SAXPY( M, CS*SN*APOAQ,
  543. $ A( 1, p ), 1,
  544. $ A( 1, q ), 1 )
  545. D( p ) = D( p )*CS
  546. D( q ) = D( q ) / CS
  547. IF( RSVEC ) THEN
  548. CALL SAXPY( MVL,
  549. $ -T*AQOAP,
  550. $ V( 1, q ), 1,
  551. $ V( 1, p ), 1 )
  552. CALL SAXPY( MVL,
  553. $ CS*SN*APOAQ,
  554. $ V( 1, p ), 1,
  555. $ V( 1, q ), 1 )
  556. END IF
  557. ELSE
  558. CALL SAXPY( M, T*APOAQ,
  559. $ A( 1, p ), 1,
  560. $ A( 1, q ), 1 )
  561. CALL SAXPY( M,
  562. $ -CS*SN*AQOAP,
  563. $ A( 1, q ), 1,
  564. $ A( 1, p ), 1 )
  565. D( p ) = D( p ) / CS
  566. D( q ) = D( q )*CS
  567. IF( RSVEC ) THEN
  568. CALL SAXPY( MVL,
  569. $ T*APOAQ, V( 1, p ),
  570. $ 1, V( 1, q ), 1 )
  571. CALL SAXPY( MVL,
  572. $ -CS*SN*AQOAP,
  573. $ V( 1, q ), 1,
  574. $ V( 1, p ), 1 )
  575. END IF
  576. END IF
  577. END IF
  578. END IF
  579. END IF
  580. ELSE
  581. IF( AAPP.GT.AAQQ ) THEN
  582. CALL SCOPY( M, A( 1, p ), 1, WORK,
  583. $ 1 )
  584. CALL SLASCL( 'G', 0, 0, AAPP, ONE,
  585. $ M, 1, WORK, LDA, IERR )
  586. CALL SLASCL( 'G', 0, 0, AAQQ, ONE,
  587. $ M, 1, A( 1, q ), LDA,
  588. $ IERR )
  589. TEMP1 = -AAPQ*D( p ) / D( q )
  590. CALL SAXPY( M, TEMP1, WORK, 1,
  591. $ A( 1, q ), 1 )
  592. CALL SLASCL( 'G', 0, 0, ONE, AAQQ,
  593. $ M, 1, A( 1, q ), LDA,
  594. $ IERR )
  595. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  596. $ ONE-AAPQ*AAPQ ) )
  597. MXSINJ = MAX( MXSINJ, SFMIN )
  598. ELSE
  599. CALL SCOPY( M, A( 1, q ), 1, WORK,
  600. $ 1 )
  601. CALL SLASCL( 'G', 0, 0, AAQQ, ONE,
  602. $ M, 1, WORK, LDA, IERR )
  603. CALL SLASCL( 'G', 0, 0, AAPP, ONE,
  604. $ M, 1, A( 1, p ), LDA,
  605. $ IERR )
  606. TEMP1 = -AAPQ*D( q ) / D( p )
  607. CALL SAXPY( M, TEMP1, WORK, 1,
  608. $ A( 1, p ), 1 )
  609. CALL SLASCL( 'G', 0, 0, ONE, AAPP,
  610. $ M, 1, A( 1, p ), LDA,
  611. $ IERR )
  612. SVA( p ) = AAPP*SQRT( MAX( ZERO,
  613. $ ONE-AAPQ*AAPQ ) )
  614. MXSINJ = MAX( MXSINJ, SFMIN )
  615. END IF
  616. END IF
  617. * END IF ROTOK THEN ... ELSE
  618. *
  619. * In the case of cancellation in updating SVA(q)
  620. * .. recompute SVA(q)
  621. IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
  622. $ THEN
  623. IF( ( AAQQ.LT.ROOTBIG ) .AND.
  624. $ ( AAQQ.GT.ROOTSFMIN ) ) THEN
  625. SVA( q ) = SNRM2( M, A( 1, q ), 1 )*
  626. $ D( q )
  627. ELSE
  628. T = ZERO
  629. AAQQ = ONE
  630. CALL SLASSQ( M, A( 1, q ), 1, T,
  631. $ AAQQ )
  632. SVA( q ) = T*SQRT( AAQQ )*D( q )
  633. END IF
  634. END IF
  635. IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
  636. IF( ( AAPP.LT.ROOTBIG ) .AND.
  637. $ ( AAPP.GT.ROOTSFMIN ) ) THEN
  638. AAPP = SNRM2( M, A( 1, p ), 1 )*
  639. $ D( p )
  640. ELSE
  641. T = ZERO
  642. AAPP = ONE
  643. CALL SLASSQ( M, A( 1, p ), 1, T,
  644. $ AAPP )
  645. AAPP = T*SQRT( AAPP )*D( p )
  646. END IF
  647. SVA( p ) = AAPP
  648. END IF
  649. * end of OK rotation
  650. ELSE
  651. NOTROT = NOTROT + 1
  652. * SKIPPED = SKIPPED + 1
  653. PSKIPPED = PSKIPPED + 1
  654. IJBLSK = IJBLSK + 1
  655. END IF
  656. ELSE
  657. NOTROT = NOTROT + 1
  658. PSKIPPED = PSKIPPED + 1
  659. IJBLSK = IJBLSK + 1
  660. END IF
  661. * IF ( NOTROT .GE. EMPTSW ) GO TO 2011
  662. IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
  663. $ THEN
  664. SVA( p ) = AAPP
  665. NOTROT = 0
  666. GO TO 2011
  667. END IF
  668. IF( ( i.LE.SWBAND ) .AND.
  669. $ ( PSKIPPED.GT.ROWSKIP ) ) THEN
  670. AAPP = -AAPP
  671. NOTROT = 0
  672. GO TO 2203
  673. END IF
  674. *
  675. 2200 CONTINUE
  676. * end of the q-loop
  677. 2203 CONTINUE
  678. SVA( p ) = AAPP
  679. *
  680. ELSE
  681. IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
  682. $ MIN( jgl+KBL-1, N ) - jgl + 1
  683. IF( AAPP.LT.ZERO )NOTROT = 0
  684. *** IF ( NOTROT .GE. EMPTSW ) GO TO 2011
  685. END IF
  686. 2100 CONTINUE
  687. * end of the p-loop
  688. 2010 CONTINUE
  689. * end of the jbc-loop
  690. 2011 CONTINUE
  691. *2011 bailed out of the jbc-loop
  692. DO 2012 p = igl, MIN( igl+KBL-1, N )
  693. SVA( p ) = ABS( SVA( p ) )
  694. 2012 CONTINUE
  695. *** IF ( NOTROT .GE. EMPTSW ) GO TO 1994
  696. 2000 CONTINUE
  697. *2000 :: end of the ibr-loop
  698. *
  699. * .. update SVA(N)
  700. IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
  701. $ THEN
  702. SVA( N ) = SNRM2( M, A( 1, N ), 1 )*D( N )
  703. ELSE
  704. T = ZERO
  705. AAPP = ONE
  706. CALL SLASSQ( M, A( 1, N ), 1, T, AAPP )
  707. SVA( N ) = T*SQRT( AAPP )*D( N )
  708. END IF
  709. *
  710. * Additional steering devices
  711. *
  712. IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
  713. $ ( ISWROT.LE.N ) ) )SWBAND = i
  714. IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.FLOAT( N )*TOL ) .AND.
  715. $ ( FLOAT( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
  716. GO TO 1994
  717. END IF
  718. *
  719. IF( NOTROT.GE.EMPTSW )GO TO 1994
  720. 1993 CONTINUE
  721. * end i=1:NSWEEP loop
  722. * #:) Reaching this point means that the procedure has completed the given
  723. * number of sweeps.
  724. INFO = NSWEEP - 1
  725. GO TO 1995
  726. 1994 CONTINUE
  727. * #:) Reaching this point means that during the i-th sweep all pivots were
  728. * below the given threshold, causing early exit.
  729. INFO = 0
  730. * #:) INFO = 0 confirms successful iterations.
  731. 1995 CONTINUE
  732. *
  733. * Sort the vector D
  734. *
  735. DO 5991 p = 1, N - 1
  736. q = ISAMAX( N-p+1, SVA( p ), 1 ) + p - 1
  737. IF( p.NE.q ) THEN
  738. TEMP1 = SVA( p )
  739. SVA( p ) = SVA( q )
  740. SVA( q ) = TEMP1
  741. TEMP1 = D( p )
  742. D( p ) = D( q )
  743. D( q ) = TEMP1
  744. CALL SSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
  745. IF( RSVEC )CALL SSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
  746. END IF
  747. 5991 CONTINUE
  748. *
  749. RETURN
  750. * ..
  751. * .. END OF SGSVJ1
  752. * ..
  753. END