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.

sgejsv.f 72 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777
  1. *> \brief \b SGEJSV
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SGEJSV + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgejsv.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgejsv.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgejsv.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SGEJSV( JOBA, JOBU, JOBV, JOBR, JOBT, JOBP,
  22. * M, N, A, LDA, SVA, U, LDU, V, LDV,
  23. * WORK, LWORK, IWORK, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * IMPLICIT NONE
  27. * INTEGER INFO, LDA, LDU, LDV, LWORK, M, N
  28. * ..
  29. * .. Array Arguments ..
  30. * REAL A( LDA, * ), SVA( N ), U( LDU, * ), V( LDV, * ),
  31. * $ WORK( LWORK )
  32. * INTEGER IWORK( * )
  33. * CHARACTER*1 JOBA, JOBP, JOBR, JOBT, JOBU, JOBV
  34. * ..
  35. *
  36. *
  37. *> \par Purpose:
  38. * =============
  39. *>
  40. *> \verbatim
  41. *>
  42. *> SGEJSV computes the singular value decomposition (SVD) of a real M-by-N
  43. *> matrix [A], where M >= N. The SVD of [A] is written as
  44. *>
  45. *> [A] = [U] * [SIGMA] * [V]^t,
  46. *>
  47. *> where [SIGMA] is an N-by-N (M-by-N) matrix which is zero except for its N
  48. *> diagonal elements, [U] is an M-by-N (or M-by-M) orthonormal matrix, and
  49. *> [V] is an N-by-N orthogonal matrix. The diagonal elements of [SIGMA] are
  50. *> the singular values of [A]. The columns of [U] and [V] are the left and
  51. *> the right singular vectors of [A], respectively. The matrices [U] and [V]
  52. *> are computed and stored in the arrays U and V, respectively. The diagonal
  53. *> of [SIGMA] is computed and stored in the array SVA.
  54. *> \endverbatim
  55. *
  56. * Arguments:
  57. * ==========
  58. *
  59. *> \param[in] JOBA
  60. *> \verbatim
  61. *> JOBA is CHARACTER*1
  62. *> Specifies the level of accuracy:
  63. *> = 'C': This option works well (high relative accuracy) if A = B * D,
  64. *> with well-conditioned B and arbitrary diagonal matrix D.
  65. *> The accuracy cannot be spoiled by COLUMN scaling. The
  66. *> accuracy of the computed output depends on the condition of
  67. *> B, and the procedure aims at the best theoretical accuracy.
  68. *> The relative error max_{i=1:N}|d sigma_i| / sigma_i is
  69. *> bounded by f(M,N)*epsilon* cond(B), independent of D.
  70. *> The input matrix is preprocessed with the QRF with column
  71. *> pivoting. This initial preprocessing and preconditioning by
  72. *> a rank revealing QR factorization is common for all values of
  73. *> JOBA. Additional actions are specified as follows:
  74. *> = 'E': Computation as with 'C' with an additional estimate of the
  75. *> condition number of B. It provides a realistic error bound.
  76. *> = 'F': If A = D1 * C * D2 with ill-conditioned diagonal scalings
  77. *> D1, D2, and well-conditioned matrix C, this option gives
  78. *> higher accuracy than the 'C' option. If the structure of the
  79. *> input matrix is not known, and relative accuracy is
  80. *> desirable, then this option is advisable. The input matrix A
  81. *> is preprocessed with QR factorization with FULL (row and
  82. *> column) pivoting.
  83. *> = 'G' Computation as with 'F' with an additional estimate of the
  84. *> condition number of B, where A=D*B. If A has heavily weighted
  85. *> rows, then using this condition number gives too pessimistic
  86. *> error bound.
  87. *> = 'A': Small singular values are the noise and the matrix is treated
  88. *> as numerically rank defficient. The error in the computed
  89. *> singular values is bounded by f(m,n)*epsilon*||A||.
  90. *> The computed SVD A = U * S * V^t restores A up to
  91. *> f(m,n)*epsilon*||A||.
  92. *> This gives the procedure the licence to discard (set to zero)
  93. *> all singular values below N*epsilon*||A||.
  94. *> = 'R': Similar as in 'A'. Rank revealing property of the initial
  95. *> QR factorization is used do reveal (using triangular factor)
  96. *> a gap sigma_{r+1} < epsilon * sigma_r in which case the
  97. *> numerical RANK is declared to be r. The SVD is computed with
  98. *> absolute error bounds, but more accurately than with 'A'.
  99. *> \endverbatim
  100. *>
  101. *> \param[in] JOBU
  102. *> \verbatim
  103. *> JOBU is CHARACTER*1
  104. *> Specifies whether to compute the columns of U:
  105. *> = 'U': N columns of U are returned in the array U.
  106. *> = 'F': full set of M left sing. vectors is returned in the array U.
  107. *> = 'W': U may be used as workspace of length M*N. See the description
  108. *> of U.
  109. *> = 'N': U is not computed.
  110. *> \endverbatim
  111. *>
  112. *> \param[in] JOBV
  113. *> \verbatim
  114. *> JOBV is CHARACTER*1
  115. *> Specifies whether to compute the matrix V:
  116. *> = 'V': N columns of V are returned in the array V; Jacobi rotations
  117. *> are not explicitly accumulated.
  118. *> = 'J': N columns of V are returned in the array V, but they are
  119. *> computed as the product of Jacobi rotations. This option is
  120. *> allowed only if JOBU .NE. 'N', i.e. in computing the full SVD.
  121. *> = 'W': V may be used as workspace of length N*N. See the description
  122. *> of V.
  123. *> = 'N': V is not computed.
  124. *> \endverbatim
  125. *>
  126. *> \param[in] JOBR
  127. *> \verbatim
  128. *> JOBR is CHARACTER*1
  129. *> Specifies the RANGE for the singular values. Issues the licence to
  130. *> set to zero small positive singular values if they are outside
  131. *> specified range. If A .NE. 0 is scaled so that the largest singular
  132. *> value of c*A is around SQRT(BIG), BIG=SLAMCH('O'), then JOBR issues
  133. *> the licence to kill columns of A whose norm in c*A is less than
  134. *> SQRT(SFMIN) (for JOBR.EQ.'R'), or less than SMALL=SFMIN/EPSLN,
  135. *> where SFMIN=SLAMCH('S'), EPSLN=SLAMCH('E').
  136. *> = 'N': Do not kill small columns of c*A. This option assumes that
  137. *> BLAS and QR factorizations and triangular solvers are
  138. *> implemented to work in that range. If the condition of A
  139. *> is greater than BIG, use SGESVJ.
  140. *> = 'R': RESTRICTED range for sigma(c*A) is [SQRT(SFMIN), SQRT(BIG)]
  141. *> (roughly, as described above). This option is recommended.
  142. *> ===========================
  143. *> For computing the singular values in the FULL range [SFMIN,BIG]
  144. *> use SGESVJ.
  145. *> \endverbatim
  146. *>
  147. *> \param[in] JOBT
  148. *> \verbatim
  149. *> JOBT is CHARACTER*1
  150. *> If the matrix is square then the procedure may determine to use
  151. *> transposed A if A^t seems to be better with respect to convergence.
  152. *> If the matrix is not square, JOBT is ignored. This is subject to
  153. *> changes in the future.
  154. *> The decision is based on two values of entropy over the adjoint
  155. *> orbit of A^t * A. See the descriptions of WORK(6) and WORK(7).
  156. *> = 'T': transpose if entropy test indicates possibly faster
  157. *> convergence of Jacobi process if A^t is taken as input. If A is
  158. *> replaced with A^t, then the row pivoting is included automatically.
  159. *> = 'N': do not speculate.
  160. *> This option can be used to compute only the singular values, or the
  161. *> full SVD (U, SIGMA and V). For only one set of singular vectors
  162. *> (U or V), the caller should provide both U and V, as one of the
  163. *> matrices is used as workspace if the matrix A is transposed.
  164. *> The implementer can easily remove this constraint and make the
  165. *> code more complicated. See the descriptions of U and V.
  166. *> \endverbatim
  167. *>
  168. *> \param[in] JOBP
  169. *> \verbatim
  170. *> JOBP is CHARACTER*1
  171. *> Issues the licence to introduce structured perturbations to drown
  172. *> denormalized numbers. This licence should be active if the
  173. *> denormals are poorly implemented, causing slow computation,
  174. *> especially in cases of fast convergence (!). For details see [1,2].
  175. *> For the sake of simplicity, this perturbations are included only
  176. *> when the full SVD or only the singular values are requested. The
  177. *> implementer/user can easily add the perturbation for the cases of
  178. *> computing one set of singular vectors.
  179. *> = 'P': introduce perturbation
  180. *> = 'N': do not perturb
  181. *> \endverbatim
  182. *>
  183. *> \param[in] M
  184. *> \verbatim
  185. *> M is INTEGER
  186. *> The number of rows of the input matrix A. M >= 0.
  187. *> \endverbatim
  188. *>
  189. *> \param[in] N
  190. *> \verbatim
  191. *> N is INTEGER
  192. *> The number of columns of the input matrix A. M >= N >= 0.
  193. *> \endverbatim
  194. *>
  195. *> \param[in,out] A
  196. *> \verbatim
  197. *> A is REAL array, dimension (LDA,N)
  198. *> On entry, the M-by-N matrix A.
  199. *> \endverbatim
  200. *>
  201. *> \param[in] LDA
  202. *> \verbatim
  203. *> LDA is INTEGER
  204. *> The leading dimension of the array A. LDA >= max(1,M).
  205. *> \endverbatim
  206. *>
  207. *> \param[out] SVA
  208. *> \verbatim
  209. *> SVA is REAL array, dimension (N)
  210. *> On exit,
  211. *> - For WORK(1)/WORK(2) = ONE: The singular values of A. During the
  212. *> computation SVA contains Euclidean column norms of the
  213. *> iterated matrices in the array A.
  214. *> - For WORK(1) .NE. WORK(2): The singular values of A are
  215. *> (WORK(1)/WORK(2)) * SVA(1:N). This factored form is used if
  216. *> sigma_max(A) overflows or if small singular values have been
  217. *> saved from underflow by scaling the input matrix A.
  218. *> - If JOBR='R' then some of the singular values may be returned
  219. *> as exact zeros obtained by "set to zero" because they are
  220. *> below the numerical rank threshold or are denormalized numbers.
  221. *> \endverbatim
  222. *>
  223. *> \param[out] U
  224. *> \verbatim
  225. *> U is REAL array, dimension ( LDU, N )
  226. *> If JOBU = 'U', then U contains on exit the M-by-N matrix of
  227. *> the left singular vectors.
  228. *> If JOBU = 'F', then U contains on exit the M-by-M matrix of
  229. *> the left singular vectors, including an ONB
  230. *> of the orthogonal complement of the Range(A).
  231. *> If JOBU = 'W' .AND. (JOBV.EQ.'V' .AND. JOBT.EQ.'T' .AND. M.EQ.N),
  232. *> then U is used as workspace if the procedure
  233. *> replaces A with A^t. In that case, [V] is computed
  234. *> in U as left singular vectors of A^t and then
  235. *> copied back to the V array. This 'W' option is just
  236. *> a reminder to the caller that in this case U is
  237. *> reserved as workspace of length N*N.
  238. *> If JOBU = 'N' U is not referenced.
  239. *> \endverbatim
  240. *>
  241. *> \param[in] LDU
  242. *> \verbatim
  243. *> LDU is INTEGER
  244. *> The leading dimension of the array U, LDU >= 1.
  245. *> IF JOBU = 'U' or 'F' or 'W', then LDU >= M.
  246. *> \endverbatim
  247. *>
  248. *> \param[out] V
  249. *> \verbatim
  250. *> V is REAL array, dimension ( LDV, N )
  251. *> If JOBV = 'V', 'J' then V contains on exit the N-by-N matrix of
  252. *> the right singular vectors;
  253. *> If JOBV = 'W', AND (JOBU.EQ.'U' AND JOBT.EQ.'T' AND M.EQ.N),
  254. *> then V is used as workspace if the pprocedure
  255. *> replaces A with A^t. In that case, [U] is computed
  256. *> in V as right singular vectors of A^t and then
  257. *> copied back to the U array. This 'W' option is just
  258. *> a reminder to the caller that in this case V is
  259. *> reserved as workspace of length N*N.
  260. *> If JOBV = 'N' V is not referenced.
  261. *> \endverbatim
  262. *>
  263. *> \param[in] LDV
  264. *> \verbatim
  265. *> LDV is INTEGER
  266. *> The leading dimension of the array V, LDV >= 1.
  267. *> If JOBV = 'V' or 'J' or 'W', then LDV >= N.
  268. *> \endverbatim
  269. *>
  270. *> \param[out] WORK
  271. *> \verbatim
  272. *> WORK is REAL array, dimension at least LWORK.
  273. *> On exit,
  274. *> WORK(1) = SCALE = WORK(2) / WORK(1) is the scaling factor such
  275. *> that SCALE*SVA(1:N) are the computed singular values
  276. *> of A. (See the description of SVA().)
  277. *> WORK(2) = See the description of WORK(1).
  278. *> WORK(3) = SCONDA is an estimate for the condition number of
  279. *> column equilibrated A. (If JOBA .EQ. 'E' or 'G')
  280. *> SCONDA is an estimate of SQRT(||(R^t * R)^(-1)||_1).
  281. *> It is computed using SPOCON. It holds
  282. *> N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA
  283. *> where R is the triangular factor from the QRF of A.
  284. *> However, if R is truncated and the numerical rank is
  285. *> determined to be strictly smaller than N, SCONDA is
  286. *> returned as -1, thus indicating that the smallest
  287. *> singular values might be lost.
  288. *>
  289. *> If full SVD is needed, the following two condition numbers are
  290. *> useful for the analysis of the algorithm. They are provied for
  291. *> a developer/implementer who is familiar with the details of
  292. *> the method.
  293. *>
  294. *> WORK(4) = an estimate of the scaled condition number of the
  295. *> triangular factor in the first QR factorization.
  296. *> WORK(5) = an estimate of the scaled condition number of the
  297. *> triangular factor in the second QR factorization.
  298. *> The following two parameters are computed if JOBT .EQ. 'T'.
  299. *> They are provided for a developer/implementer who is familiar
  300. *> with the details of the method.
  301. *>
  302. *> WORK(6) = the entropy of A^t*A :: this is the Shannon entropy
  303. *> of diag(A^t*A) / Trace(A^t*A) taken as point in the
  304. *> probability simplex.
  305. *> WORK(7) = the entropy of A*A^t.
  306. *> \endverbatim
  307. *>
  308. *> \param[in] LWORK
  309. *> \verbatim
  310. *> LWORK is INTEGER
  311. *> Length of WORK to confirm proper allocation of work space.
  312. *> LWORK depends on the job:
  313. *>
  314. *> If only SIGMA is needed ( JOBU.EQ.'N', JOBV.EQ.'N' ) and
  315. *> -> .. no scaled condition estimate required (JOBE.EQ.'N'):
  316. *> LWORK >= max(2*M+N,4*N+1,7). This is the minimal requirement.
  317. *> ->> For optimal performance (blocked code) the optimal value
  318. *> is LWORK >= max(2*M+N,3*N+(N+1)*NB,7). Here NB is the optimal
  319. *> block size for DGEQP3 and DGEQRF.
  320. *> In general, optimal LWORK is computed as
  321. *> LWORK >= max(2*M+N,N+LWORK(DGEQP3),N+LWORK(DGEQRF), 7).
  322. *> -> .. an estimate of the scaled condition number of A is
  323. *> required (JOBA='E', 'G'). In this case, LWORK is the maximum
  324. *> of the above and N*N+4*N, i.e. LWORK >= max(2*M+N,N*N+4*N,7).
  325. *> ->> For optimal performance (blocked code) the optimal value
  326. *> is LWORK >= max(2*M+N,3*N+(N+1)*NB, N*N+4*N, 7).
  327. *> In general, the optimal length LWORK is computed as
  328. *> LWORK >= max(2*M+N,N+LWORK(DGEQP3),N+LWORK(DGEQRF),
  329. *> N+N*N+LWORK(DPOCON),7).
  330. *>
  331. *> If SIGMA and the right singular vectors are needed (JOBV.EQ.'V'),
  332. *> -> the minimal requirement is LWORK >= max(2*M+N,4*N+1,7).
  333. *> -> For optimal performance, LWORK >= max(2*M+N,3*N+(N+1)*NB,7),
  334. *> where NB is the optimal block size for DGEQP3, DGEQRF, DGELQ,
  335. *> DORMLQ. In general, the optimal length LWORK is computed as
  336. *> LWORK >= max(2*M+N,N+LWORK(DGEQP3), N+LWORK(DPOCON),
  337. *> N+LWORK(DGELQ), 2*N+LWORK(DGEQRF), N+LWORK(DORMLQ)).
  338. *>
  339. *> If SIGMA and the left singular vectors are needed
  340. *> -> the minimal requirement is LWORK >= max(2*M+N,4*N+1,7).
  341. *> -> For optimal performance:
  342. *> if JOBU.EQ.'U' :: LWORK >= max(2*M+N,3*N+(N+1)*NB,7),
  343. *> if JOBU.EQ.'F' :: LWORK >= max(2*M+N,3*N+(N+1)*NB,N+M*NB,7),
  344. *> where NB is the optimal block size for DGEQP3, DGEQRF, DORMQR.
  345. *> In general, the optimal length LWORK is computed as
  346. *> LWORK >= max(2*M+N,N+LWORK(DGEQP3),N+LWORK(DPOCON),
  347. *> 2*N+LWORK(DGEQRF), N+LWORK(DORMQR)).
  348. *> Here LWORK(DORMQR) equals N*NB (for JOBU.EQ.'U') or
  349. *> M*NB (for JOBU.EQ.'F').
  350. *>
  351. *> If the full SVD is needed: (JOBU.EQ.'U' or JOBU.EQ.'F') and
  352. *> -> if JOBV.EQ.'V'
  353. *> the minimal requirement is LWORK >= max(2*M+N,6*N+2*N*N).
  354. *> -> if JOBV.EQ.'J' the minimal requirement is
  355. *> LWORK >= max(2*M+N, 4*N+N*N,2*N+N*N+6).
  356. *> -> For optimal performance, LWORK should be additionally
  357. *> larger than N+M*NB, where NB is the optimal block size
  358. *> for DORMQR.
  359. *> \endverbatim
  360. *>
  361. *> \param[out] IWORK
  362. *> \verbatim
  363. *> IWORK is INTEGER array, dimension M+3*N.
  364. *> On exit,
  365. *> IWORK(1) = the numerical rank determined after the initial
  366. *> QR factorization with pivoting. See the descriptions
  367. *> of JOBA and JOBR.
  368. *> IWORK(2) = the number of the computed nonzero singular values
  369. *> IWORK(3) = if nonzero, a warning message:
  370. *> If IWORK(3).EQ.1 then some of the column norms of A
  371. *> were denormalized floats. The requested high accuracy
  372. *> is not warranted by the data.
  373. *> \endverbatim
  374. *>
  375. *> \param[out] INFO
  376. *> \verbatim
  377. *> INFO is INTEGER
  378. *> < 0 : if INFO = -i, then the i-th argument had an illegal value.
  379. *> = 0 : successfull exit;
  380. *> > 0 : SGEJSV did not converge in the maximal allowed number
  381. *> of sweeps. The computed values may be inaccurate.
  382. *> \endverbatim
  383. *
  384. * Authors:
  385. * ========
  386. *
  387. *> \author Univ. of Tennessee
  388. *> \author Univ. of California Berkeley
  389. *> \author Univ. of Colorado Denver
  390. *> \author NAG Ltd.
  391. *
  392. *> \date September 2012
  393. *
  394. *> \ingroup realGEsing
  395. *
  396. *> \par Further Details:
  397. * =====================
  398. *>
  399. *> \verbatim
  400. *>
  401. *> SGEJSV implements a preconditioned Jacobi SVD algorithm. It uses SGEQP3,
  402. *> SGEQRF, and SGELQF as preprocessors and preconditioners. Optionally, an
  403. *> additional row pivoting can be used as a preprocessor, which in some
  404. *> cases results in much higher accuracy. An example is matrix A with the
  405. *> structure A = D1 * C * D2, where D1, D2 are arbitrarily ill-conditioned
  406. *> diagonal matrices and C is well-conditioned matrix. In that case, complete
  407. *> pivoting in the first QR factorizations provides accuracy dependent on the
  408. *> condition number of C, and independent of D1, D2. Such higher accuracy is
  409. *> not completely understood theoretically, but it works well in practice.
  410. *> Further, if A can be written as A = B*D, with well-conditioned B and some
  411. *> diagonal D, then the high accuracy is guaranteed, both theoretically and
  412. *> in software, independent of D. For more details see [1], [2].
  413. *> The computational range for the singular values can be the full range
  414. *> ( UNDERFLOW,OVERFLOW ), provided that the machine arithmetic and the BLAS
  415. *> & LAPACK routines called by SGEJSV are implemented to work in that range.
  416. *> If that is not the case, then the restriction for safe computation with
  417. *> the singular values in the range of normalized IEEE numbers is that the
  418. *> spectral condition number kappa(A)=sigma_max(A)/sigma_min(A) does not
  419. *> overflow. This code (SGEJSV) is best used in this restricted range,
  420. *> meaning that singular values of magnitude below ||A||_2 / SLAMCH('O') are
  421. *> returned as zeros. See JOBR for details on this.
  422. *> Further, this implementation is somewhat slower than the one described
  423. *> in [1,2] due to replacement of some non-LAPACK components, and because
  424. *> the choice of some tuning parameters in the iterative part (SGESVJ) is
  425. *> left to the implementer on a particular machine.
  426. *> The rank revealing QR factorization (in this code: SGEQP3) should be
  427. *> implemented as in [3]. We have a new version of SGEQP3 under development
  428. *> that is more robust than the current one in LAPACK, with a cleaner cut in
  429. *> rank defficient cases. It will be available in the SIGMA library [4].
  430. *> If M is much larger than N, it is obvious that the inital QRF with
  431. *> column pivoting can be preprocessed by the QRF without pivoting. That
  432. *> well known trick is not used in SGEJSV because in some cases heavy row
  433. *> weighting can be treated with complete pivoting. The overhead in cases
  434. *> M much larger than N is then only due to pivoting, but the benefits in
  435. *> terms of accuracy have prevailed. The implementer/user can incorporate
  436. *> this extra QRF step easily. The implementer can also improve data movement
  437. *> (matrix transpose, matrix copy, matrix transposed copy) - this
  438. *> implementation of SGEJSV uses only the simplest, naive data movement.
  439. *> \endverbatim
  440. *
  441. *> \par Contributors:
  442. * ==================
  443. *>
  444. *> Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
  445. *
  446. *> \par References:
  447. * ================
  448. *>
  449. *> \verbatim
  450. *>
  451. *> [1] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I.
  452. *> SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342.
  453. *> LAPACK Working note 169.
  454. *> [2] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II.
  455. *> SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362.
  456. *> LAPACK Working note 170.
  457. *> [3] Z. Drmac and Z. Bujanovic: On the failure of rank-revealing QR
  458. *> factorization software - a case study.
  459. *> ACM Trans. math. Softw. Vol. 35, No 2 (2008), pp. 1-28.
  460. *> LAPACK Working note 176.
  461. *> [4] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV,
  462. *> QSVD, (H,K)-SVD computations.
  463. *> Department of Mathematics, University of Zagreb, 2008.
  464. *> \endverbatim
  465. *
  466. *> \par Bugs, examples and comments:
  467. * =================================
  468. *>
  469. *> Please report all bugs and send interesting examples and/or comments to
  470. *> drmac@math.hr. Thank you.
  471. *>
  472. * =====================================================================
  473. SUBROUTINE SGEJSV( JOBA, JOBU, JOBV, JOBR, JOBT, JOBP,
  474. $ M, N, A, LDA, SVA, U, LDU, V, LDV,
  475. $ WORK, LWORK, IWORK, INFO )
  476. *
  477. * -- LAPACK computational routine (version 3.4.2) --
  478. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  479. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  480. * September 2012
  481. *
  482. * .. Scalar Arguments ..
  483. IMPLICIT NONE
  484. INTEGER INFO, LDA, LDU, LDV, LWORK, M, N
  485. * ..
  486. * .. Array Arguments ..
  487. REAL A( LDA, * ), SVA( N ), U( LDU, * ), V( LDV, * ),
  488. $ WORK( LWORK )
  489. INTEGER IWORK( * )
  490. CHARACTER*1 JOBA, JOBP, JOBR, JOBT, JOBU, JOBV
  491. * ..
  492. *
  493. * ===========================================================================
  494. *
  495. * .. Local Parameters ..
  496. REAL ZERO, ONE
  497. PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
  498. * ..
  499. * .. Local Scalars ..
  500. REAL AAPP, AAQQ, AATMAX, AATMIN, BIG, BIG1, COND_OK,
  501. $ CONDR1, CONDR2, ENTRA, ENTRAT, EPSLN, MAXPRJ, SCALEM,
  502. $ SCONDA, SFMIN, SMALL, TEMP1, USCAL1, USCAL2, XSC
  503. INTEGER IERR, N1, NR, NUMRANK, p, q, WARNING
  504. LOGICAL ALMORT, DEFR, ERREST, GOSCAL, JRACC, KILL, LSVEC,
  505. $ L2ABER, L2KILL, L2PERT, L2RANK, L2TRAN,
  506. $ NOSCAL, ROWPIV, RSVEC, TRANSP
  507. * ..
  508. * .. Intrinsic Functions ..
  509. INTRINSIC ABS, ALOG, AMAX1, AMIN1, FLOAT,
  510. $ MAX0, MIN0, NINT, SIGN, SQRT
  511. * ..
  512. * .. External Functions ..
  513. REAL SLAMCH, SNRM2
  514. INTEGER ISAMAX
  515. LOGICAL LSAME
  516. EXTERNAL ISAMAX, LSAME, SLAMCH, SNRM2
  517. * ..
  518. * .. External Subroutines ..
  519. EXTERNAL SCOPY, SGELQF, SGEQP3, SGEQRF, SLACPY, SLASCL,
  520. $ SLASET, SLASSQ, SLASWP, SORGQR, SORMLQ,
  521. $ SORMQR, SPOCON, SSCAL, SSWAP, STRSM, XERBLA
  522. *
  523. EXTERNAL SGESVJ
  524. * ..
  525. *
  526. * Test the input arguments
  527. *
  528. LSVEC = LSAME( JOBU, 'U' ) .OR. LSAME( JOBU, 'F' )
  529. JRACC = LSAME( JOBV, 'J' )
  530. RSVEC = LSAME( JOBV, 'V' ) .OR. JRACC
  531. ROWPIV = LSAME( JOBA, 'F' ) .OR. LSAME( JOBA, 'G' )
  532. L2RANK = LSAME( JOBA, 'R' )
  533. L2ABER = LSAME( JOBA, 'A' )
  534. ERREST = LSAME( JOBA, 'E' ) .OR. LSAME( JOBA, 'G' )
  535. L2TRAN = LSAME( JOBT, 'T' )
  536. L2KILL = LSAME( JOBR, 'R' )
  537. DEFR = LSAME( JOBR, 'N' )
  538. L2PERT = LSAME( JOBP, 'P' )
  539. *
  540. IF ( .NOT.(ROWPIV .OR. L2RANK .OR. L2ABER .OR.
  541. $ ERREST .OR. LSAME( JOBA, 'C' ) )) THEN
  542. INFO = - 1
  543. ELSE IF ( .NOT.( LSVEC .OR. LSAME( JOBU, 'N' ) .OR.
  544. $ LSAME( JOBU, 'W' )) ) THEN
  545. INFO = - 2
  546. ELSE IF ( .NOT.( RSVEC .OR. LSAME( JOBV, 'N' ) .OR.
  547. $ LSAME( JOBV, 'W' )) .OR. ( JRACC .AND. (.NOT.LSVEC) ) ) THEN
  548. INFO = - 3
  549. ELSE IF ( .NOT. ( L2KILL .OR. DEFR ) ) THEN
  550. INFO = - 4
  551. ELSE IF ( .NOT. ( L2TRAN .OR. LSAME( JOBT, 'N' ) ) ) THEN
  552. INFO = - 5
  553. ELSE IF ( .NOT. ( L2PERT .OR. LSAME( JOBP, 'N' ) ) ) THEN
  554. INFO = - 6
  555. ELSE IF ( M .LT. 0 ) THEN
  556. INFO = - 7
  557. ELSE IF ( ( N .LT. 0 ) .OR. ( N .GT. M ) ) THEN
  558. INFO = - 8
  559. ELSE IF ( LDA .LT. M ) THEN
  560. INFO = - 10
  561. ELSE IF ( LSVEC .AND. ( LDU .LT. M ) ) THEN
  562. INFO = - 13
  563. ELSE IF ( RSVEC .AND. ( LDV .LT. N ) ) THEN
  564. INFO = - 14
  565. ELSE IF ( (.NOT.(LSVEC .OR. RSVEC .OR. ERREST).AND.
  566. $ (LWORK .LT. MAX0(7,4*N+1,2*M+N))) .OR.
  567. $ (.NOT.(LSVEC .OR. RSVEC) .AND. ERREST .AND.
  568. $ (LWORK .LT. MAX0(7,4*N+N*N,2*M+N))) .OR.
  569. $ (LSVEC .AND. (.NOT.RSVEC) .AND. (LWORK .LT. MAX0(7,2*M+N,4*N+1)))
  570. $ .OR.
  571. $ (RSVEC .AND. (.NOT.LSVEC) .AND. (LWORK .LT. MAX0(7,2*M+N,4*N+1)))
  572. $ .OR.
  573. $ (LSVEC .AND. RSVEC .AND. (.NOT.JRACC) .AND.
  574. $ (LWORK.LT.MAX0(2*M+N,6*N+2*N*N)))
  575. $ .OR. (LSVEC .AND. RSVEC .AND. JRACC .AND.
  576. $ LWORK.LT.MAX0(2*M+N,4*N+N*N,2*N+N*N+6)))
  577. $ THEN
  578. INFO = - 17
  579. ELSE
  580. * #:)
  581. INFO = 0
  582. END IF
  583. *
  584. IF ( INFO .NE. 0 ) THEN
  585. * #:(
  586. CALL XERBLA( 'SGEJSV', - INFO )
  587. RETURN
  588. END IF
  589. *
  590. * Quick return for void matrix (Y3K safe)
  591. * #:)
  592. IF ( ( M .EQ. 0 ) .OR. ( N .EQ. 0 ) ) RETURN
  593. *
  594. * Determine whether the matrix U should be M x N or M x M
  595. *
  596. IF ( LSVEC ) THEN
  597. N1 = N
  598. IF ( LSAME( JOBU, 'F' ) ) N1 = M
  599. END IF
  600. *
  601. * Set numerical parameters
  602. *
  603. *! NOTE: Make sure SLAMCH() does not fail on the target architecture.
  604. *
  605. EPSLN = SLAMCH('Epsilon')
  606. SFMIN = SLAMCH('SafeMinimum')
  607. SMALL = SFMIN / EPSLN
  608. BIG = SLAMCH('O')
  609. * BIG = ONE / SFMIN
  610. *
  611. * Initialize SVA(1:N) = diag( ||A e_i||_2 )_1^N
  612. *
  613. *(!) If necessary, scale SVA() to protect the largest norm from
  614. * overflow. It is possible that this scaling pushes the smallest
  615. * column norm left from the underflow threshold (extreme case).
  616. *
  617. SCALEM = ONE / SQRT(FLOAT(M)*FLOAT(N))
  618. NOSCAL = .TRUE.
  619. GOSCAL = .TRUE.
  620. DO 1874 p = 1, N
  621. AAPP = ZERO
  622. AAQQ = ONE
  623. CALL SLASSQ( M, A(1,p), 1, AAPP, AAQQ )
  624. IF ( AAPP .GT. BIG ) THEN
  625. INFO = - 9
  626. CALL XERBLA( 'SGEJSV', -INFO )
  627. RETURN
  628. END IF
  629. AAQQ = SQRT(AAQQ)
  630. IF ( ( AAPP .LT. (BIG / AAQQ) ) .AND. NOSCAL ) THEN
  631. SVA(p) = AAPP * AAQQ
  632. ELSE
  633. NOSCAL = .FALSE.
  634. SVA(p) = AAPP * ( AAQQ * SCALEM )
  635. IF ( GOSCAL ) THEN
  636. GOSCAL = .FALSE.
  637. CALL SSCAL( p-1, SCALEM, SVA, 1 )
  638. END IF
  639. END IF
  640. 1874 CONTINUE
  641. *
  642. IF ( NOSCAL ) SCALEM = ONE
  643. *
  644. AAPP = ZERO
  645. AAQQ = BIG
  646. DO 4781 p = 1, N
  647. AAPP = AMAX1( AAPP, SVA(p) )
  648. IF ( SVA(p) .NE. ZERO ) AAQQ = AMIN1( AAQQ, SVA(p) )
  649. 4781 CONTINUE
  650. *
  651. * Quick return for zero M x N matrix
  652. * #:)
  653. IF ( AAPP .EQ. ZERO ) THEN
  654. IF ( LSVEC ) CALL SLASET( 'G', M, N1, ZERO, ONE, U, LDU )
  655. IF ( RSVEC ) CALL SLASET( 'G', N, N, ZERO, ONE, V, LDV )
  656. WORK(1) = ONE
  657. WORK(2) = ONE
  658. IF ( ERREST ) WORK(3) = ONE
  659. IF ( LSVEC .AND. RSVEC ) THEN
  660. WORK(4) = ONE
  661. WORK(5) = ONE
  662. END IF
  663. IF ( L2TRAN ) THEN
  664. WORK(6) = ZERO
  665. WORK(7) = ZERO
  666. END IF
  667. IWORK(1) = 0
  668. IWORK(2) = 0
  669. IWORK(3) = 0
  670. RETURN
  671. END IF
  672. *
  673. * Issue warning if denormalized column norms detected. Override the
  674. * high relative accuracy request. Issue licence to kill columns
  675. * (set them to zero) whose norm is less than sigma_max / BIG (roughly).
  676. * #:(
  677. WARNING = 0
  678. IF ( AAQQ .LE. SFMIN ) THEN
  679. L2RANK = .TRUE.
  680. L2KILL = .TRUE.
  681. WARNING = 1
  682. END IF
  683. *
  684. * Quick return for one-column matrix
  685. * #:)
  686. IF ( N .EQ. 1 ) THEN
  687. *
  688. IF ( LSVEC ) THEN
  689. CALL SLASCL( 'G',0,0,SVA(1),SCALEM, M,1,A(1,1),LDA,IERR )
  690. CALL SLACPY( 'A', M, 1, A, LDA, U, LDU )
  691. * computing all M left singular vectors of the M x 1 matrix
  692. IF ( N1 .NE. N ) THEN
  693. CALL SGEQRF( M, N, U,LDU, WORK, WORK(N+1),LWORK-N,IERR )
  694. CALL SORGQR( M,N1,1, U,LDU,WORK,WORK(N+1),LWORK-N,IERR )
  695. CALL SCOPY( M, A(1,1), 1, U(1,1), 1 )
  696. END IF
  697. END IF
  698. IF ( RSVEC ) THEN
  699. V(1,1) = ONE
  700. END IF
  701. IF ( SVA(1) .LT. (BIG*SCALEM) ) THEN
  702. SVA(1) = SVA(1) / SCALEM
  703. SCALEM = ONE
  704. END IF
  705. WORK(1) = ONE / SCALEM
  706. WORK(2) = ONE
  707. IF ( SVA(1) .NE. ZERO ) THEN
  708. IWORK(1) = 1
  709. IF ( ( SVA(1) / SCALEM) .GE. SFMIN ) THEN
  710. IWORK(2) = 1
  711. ELSE
  712. IWORK(2) = 0
  713. END IF
  714. ELSE
  715. IWORK(1) = 0
  716. IWORK(2) = 0
  717. END IF
  718. IF ( ERREST ) WORK(3) = ONE
  719. IF ( LSVEC .AND. RSVEC ) THEN
  720. WORK(4) = ONE
  721. WORK(5) = ONE
  722. END IF
  723. IF ( L2TRAN ) THEN
  724. WORK(6) = ZERO
  725. WORK(7) = ZERO
  726. END IF
  727. RETURN
  728. *
  729. END IF
  730. *
  731. TRANSP = .FALSE.
  732. L2TRAN = L2TRAN .AND. ( M .EQ. N )
  733. *
  734. AATMAX = -ONE
  735. AATMIN = BIG
  736. IF ( ROWPIV .OR. L2TRAN ) THEN
  737. *
  738. * Compute the row norms, needed to determine row pivoting sequence
  739. * (in the case of heavily row weighted A, row pivoting is strongly
  740. * advised) and to collect information needed to compare the
  741. * structures of A * A^t and A^t * A (in the case L2TRAN.EQ..TRUE.).
  742. *
  743. IF ( L2TRAN ) THEN
  744. DO 1950 p = 1, M
  745. XSC = ZERO
  746. TEMP1 = ONE
  747. CALL SLASSQ( N, A(p,1), LDA, XSC, TEMP1 )
  748. * SLASSQ gets both the ell_2 and the ell_infinity norm
  749. * in one pass through the vector
  750. WORK(M+N+p) = XSC * SCALEM
  751. WORK(N+p) = XSC * (SCALEM*SQRT(TEMP1))
  752. AATMAX = AMAX1( AATMAX, WORK(N+p) )
  753. IF (WORK(N+p) .NE. ZERO) AATMIN = AMIN1(AATMIN,WORK(N+p))
  754. 1950 CONTINUE
  755. ELSE
  756. DO 1904 p = 1, M
  757. WORK(M+N+p) = SCALEM*ABS( A(p,ISAMAX(N,A(p,1),LDA)) )
  758. AATMAX = AMAX1( AATMAX, WORK(M+N+p) )
  759. AATMIN = AMIN1( AATMIN, WORK(M+N+p) )
  760. 1904 CONTINUE
  761. END IF
  762. *
  763. END IF
  764. *
  765. * For square matrix A try to determine whether A^t would be better
  766. * input for the preconditioned Jacobi SVD, with faster convergence.
  767. * The decision is based on an O(N) function of the vector of column
  768. * and row norms of A, based on the Shannon entropy. This should give
  769. * the right choice in most cases when the difference actually matters.
  770. * It may fail and pick the slower converging side.
  771. *
  772. ENTRA = ZERO
  773. ENTRAT = ZERO
  774. IF ( L2TRAN ) THEN
  775. *
  776. XSC = ZERO
  777. TEMP1 = ONE
  778. CALL SLASSQ( N, SVA, 1, XSC, TEMP1 )
  779. TEMP1 = ONE / TEMP1
  780. *
  781. ENTRA = ZERO
  782. DO 1113 p = 1, N
  783. BIG1 = ( ( SVA(p) / XSC )**2 ) * TEMP1
  784. IF ( BIG1 .NE. ZERO ) ENTRA = ENTRA + BIG1 * ALOG(BIG1)
  785. 1113 CONTINUE
  786. ENTRA = - ENTRA / ALOG(FLOAT(N))
  787. *
  788. * Now, SVA().^2/Trace(A^t * A) is a point in the probability simplex.
  789. * It is derived from the diagonal of A^t * A. Do the same with the
  790. * diagonal of A * A^t, compute the entropy of the corresponding
  791. * probability distribution. Note that A * A^t and A^t * A have the
  792. * same trace.
  793. *
  794. ENTRAT = ZERO
  795. DO 1114 p = N+1, N+M
  796. BIG1 = ( ( WORK(p) / XSC )**2 ) * TEMP1
  797. IF ( BIG1 .NE. ZERO ) ENTRAT = ENTRAT + BIG1 * ALOG(BIG1)
  798. 1114 CONTINUE
  799. ENTRAT = - ENTRAT / ALOG(FLOAT(M))
  800. *
  801. * Analyze the entropies and decide A or A^t. Smaller entropy
  802. * usually means better input for the algorithm.
  803. *
  804. TRANSP = ( ENTRAT .LT. ENTRA )
  805. *
  806. * If A^t is better than A, transpose A.
  807. *
  808. IF ( TRANSP ) THEN
  809. * In an optimal implementation, this trivial transpose
  810. * should be replaced with faster transpose.
  811. DO 1115 p = 1, N - 1
  812. DO 1116 q = p + 1, N
  813. TEMP1 = A(q,p)
  814. A(q,p) = A(p,q)
  815. A(p,q) = TEMP1
  816. 1116 CONTINUE
  817. 1115 CONTINUE
  818. DO 1117 p = 1, N
  819. WORK(M+N+p) = SVA(p)
  820. SVA(p) = WORK(N+p)
  821. 1117 CONTINUE
  822. TEMP1 = AAPP
  823. AAPP = AATMAX
  824. AATMAX = TEMP1
  825. TEMP1 = AAQQ
  826. AAQQ = AATMIN
  827. AATMIN = TEMP1
  828. KILL = LSVEC
  829. LSVEC = RSVEC
  830. RSVEC = KILL
  831. IF ( LSVEC ) N1 = N
  832. *
  833. ROWPIV = .TRUE.
  834. END IF
  835. *
  836. END IF
  837. * END IF L2TRAN
  838. *
  839. * Scale the matrix so that its maximal singular value remains less
  840. * than SQRT(BIG) -- the matrix is scaled so that its maximal column
  841. * has Euclidean norm equal to SQRT(BIG/N). The only reason to keep
  842. * SQRT(BIG) instead of BIG is the fact that SGEJSV uses LAPACK and
  843. * BLAS routines that, in some implementations, are not capable of
  844. * working in the full interval [SFMIN,BIG] and that they may provoke
  845. * overflows in the intermediate results. If the singular values spread
  846. * from SFMIN to BIG, then SGESVJ will compute them. So, in that case,
  847. * one should use SGESVJ instead of SGEJSV.
  848. *
  849. BIG1 = SQRT( BIG )
  850. TEMP1 = SQRT( BIG / FLOAT(N) )
  851. *
  852. CALL SLASCL( 'G', 0, 0, AAPP, TEMP1, N, 1, SVA, N, IERR )
  853. IF ( AAQQ .GT. (AAPP * SFMIN) ) THEN
  854. AAQQ = ( AAQQ / AAPP ) * TEMP1
  855. ELSE
  856. AAQQ = ( AAQQ * TEMP1 ) / AAPP
  857. END IF
  858. TEMP1 = TEMP1 * SCALEM
  859. CALL SLASCL( 'G', 0, 0, AAPP, TEMP1, M, N, A, LDA, IERR )
  860. *
  861. * To undo scaling at the end of this procedure, multiply the
  862. * computed singular values with USCAL2 / USCAL1.
  863. *
  864. USCAL1 = TEMP1
  865. USCAL2 = AAPP
  866. *
  867. IF ( L2KILL ) THEN
  868. * L2KILL enforces computation of nonzero singular values in
  869. * the restricted range of condition number of the initial A,
  870. * sigma_max(A) / sigma_min(A) approx. SQRT(BIG)/SQRT(SFMIN).
  871. XSC = SQRT( SFMIN )
  872. ELSE
  873. XSC = SMALL
  874. *
  875. * Now, if the condition number of A is too big,
  876. * sigma_max(A) / sigma_min(A) .GT. SQRT(BIG/N) * EPSLN / SFMIN,
  877. * as a precaution measure, the full SVD is computed using SGESVJ
  878. * with accumulated Jacobi rotations. This provides numerically
  879. * more robust computation, at the cost of slightly increased run
  880. * time. Depending on the concrete implementation of BLAS and LAPACK
  881. * (i.e. how they behave in presence of extreme ill-conditioning) the
  882. * implementor may decide to remove this switch.
  883. IF ( ( AAQQ.LT.SQRT(SFMIN) ) .AND. LSVEC .AND. RSVEC ) THEN
  884. JRACC = .TRUE.
  885. END IF
  886. *
  887. END IF
  888. IF ( AAQQ .LT. XSC ) THEN
  889. DO 700 p = 1, N
  890. IF ( SVA(p) .LT. XSC ) THEN
  891. CALL SLASET( 'A', M, 1, ZERO, ZERO, A(1,p), LDA )
  892. SVA(p) = ZERO
  893. END IF
  894. 700 CONTINUE
  895. END IF
  896. *
  897. * Preconditioning using QR factorization with pivoting
  898. *
  899. IF ( ROWPIV ) THEN
  900. * Optional row permutation (Bjoerck row pivoting):
  901. * A result by Cox and Higham shows that the Bjoerck's
  902. * row pivoting combined with standard column pivoting
  903. * has similar effect as Powell-Reid complete pivoting.
  904. * The ell-infinity norms of A are made nonincreasing.
  905. DO 1952 p = 1, M - 1
  906. q = ISAMAX( M-p+1, WORK(M+N+p), 1 ) + p - 1
  907. IWORK(2*N+p) = q
  908. IF ( p .NE. q ) THEN
  909. TEMP1 = WORK(M+N+p)
  910. WORK(M+N+p) = WORK(M+N+q)
  911. WORK(M+N+q) = TEMP1
  912. END IF
  913. 1952 CONTINUE
  914. CALL SLASWP( N, A, LDA, 1, M-1, IWORK(2*N+1), 1 )
  915. END IF
  916. *
  917. * End of the preparation phase (scaling, optional sorting and
  918. * transposing, optional flushing of small columns).
  919. *
  920. * Preconditioning
  921. *
  922. * If the full SVD is needed, the right singular vectors are computed
  923. * from a matrix equation, and for that we need theoretical analysis
  924. * of the Businger-Golub pivoting. So we use SGEQP3 as the first RR QRF.
  925. * In all other cases the first RR QRF can be chosen by other criteria
  926. * (eg speed by replacing global with restricted window pivoting, such
  927. * as in SGEQPX from TOMS # 782). Good results will be obtained using
  928. * SGEQPX with properly (!) chosen numerical parameters.
  929. * Any improvement of SGEQP3 improves overal performance of SGEJSV.
  930. *
  931. * A * P1 = Q1 * [ R1^t 0]^t:
  932. DO 1963 p = 1, N
  933. * .. all columns are free columns
  934. IWORK(p) = 0
  935. 1963 CONTINUE
  936. CALL SGEQP3( M,N,A,LDA, IWORK,WORK, WORK(N+1),LWORK-N, IERR )
  937. *
  938. * The upper triangular matrix R1 from the first QRF is inspected for
  939. * rank deficiency and possibilities for deflation, or possible
  940. * ill-conditioning. Depending on the user specified flag L2RANK,
  941. * the procedure explores possibilities to reduce the numerical
  942. * rank by inspecting the computed upper triangular factor. If
  943. * L2RANK or L2ABER are up, then SGEJSV will compute the SVD of
  944. * A + dA, where ||dA|| <= f(M,N)*EPSLN.
  945. *
  946. NR = 1
  947. IF ( L2ABER ) THEN
  948. * Standard absolute error bound suffices. All sigma_i with
  949. * sigma_i < N*EPSLN*||A|| are flushed to zero. This is an
  950. * agressive enforcement of lower numerical rank by introducing a
  951. * backward error of the order of N*EPSLN*||A||.
  952. TEMP1 = SQRT(FLOAT(N))*EPSLN
  953. DO 3001 p = 2, N
  954. IF ( ABS(A(p,p)) .GE. (TEMP1*ABS(A(1,1))) ) THEN
  955. NR = NR + 1
  956. ELSE
  957. GO TO 3002
  958. END IF
  959. 3001 CONTINUE
  960. 3002 CONTINUE
  961. ELSE IF ( L2RANK ) THEN
  962. * .. similarly as above, only slightly more gentle (less agressive).
  963. * Sudden drop on the diagonal of R1 is used as the criterion for
  964. * close-to-rank-defficient.
  965. TEMP1 = SQRT(SFMIN)
  966. DO 3401 p = 2, N
  967. IF ( ( ABS(A(p,p)) .LT. (EPSLN*ABS(A(p-1,p-1))) ) .OR.
  968. $ ( ABS(A(p,p)) .LT. SMALL ) .OR.
  969. $ ( L2KILL .AND. (ABS(A(p,p)) .LT. TEMP1) ) ) GO TO 3402
  970. NR = NR + 1
  971. 3401 CONTINUE
  972. 3402 CONTINUE
  973. *
  974. ELSE
  975. * The goal is high relative accuracy. However, if the matrix
  976. * has high scaled condition number the relative accuracy is in
  977. * general not feasible. Later on, a condition number estimator
  978. * will be deployed to estimate the scaled condition number.
  979. * Here we just remove the underflowed part of the triangular
  980. * factor. This prevents the situation in which the code is
  981. * working hard to get the accuracy not warranted by the data.
  982. TEMP1 = SQRT(SFMIN)
  983. DO 3301 p = 2, N
  984. IF ( ( ABS(A(p,p)) .LT. SMALL ) .OR.
  985. $ ( L2KILL .AND. (ABS(A(p,p)) .LT. TEMP1) ) ) GO TO 3302
  986. NR = NR + 1
  987. 3301 CONTINUE
  988. 3302 CONTINUE
  989. *
  990. END IF
  991. *
  992. ALMORT = .FALSE.
  993. IF ( NR .EQ. N ) THEN
  994. MAXPRJ = ONE
  995. DO 3051 p = 2, N
  996. TEMP1 = ABS(A(p,p)) / SVA(IWORK(p))
  997. MAXPRJ = AMIN1( MAXPRJ, TEMP1 )
  998. 3051 CONTINUE
  999. IF ( MAXPRJ**2 .GE. ONE - FLOAT(N)*EPSLN ) ALMORT = .TRUE.
  1000. END IF
  1001. *
  1002. *
  1003. SCONDA = - ONE
  1004. CONDR1 = - ONE
  1005. CONDR2 = - ONE
  1006. *
  1007. IF ( ERREST ) THEN
  1008. IF ( N .EQ. NR ) THEN
  1009. IF ( RSVEC ) THEN
  1010. * .. V is available as workspace
  1011. CALL SLACPY( 'U', N, N, A, LDA, V, LDV )
  1012. DO 3053 p = 1, N
  1013. TEMP1 = SVA(IWORK(p))
  1014. CALL SSCAL( p, ONE/TEMP1, V(1,p), 1 )
  1015. 3053 CONTINUE
  1016. CALL SPOCON( 'U', N, V, LDV, ONE, TEMP1,
  1017. $ WORK(N+1), IWORK(2*N+M+1), IERR )
  1018. ELSE IF ( LSVEC ) THEN
  1019. * .. U is available as workspace
  1020. CALL SLACPY( 'U', N, N, A, LDA, U, LDU )
  1021. DO 3054 p = 1, N
  1022. TEMP1 = SVA(IWORK(p))
  1023. CALL SSCAL( p, ONE/TEMP1, U(1,p), 1 )
  1024. 3054 CONTINUE
  1025. CALL SPOCON( 'U', N, U, LDU, ONE, TEMP1,
  1026. $ WORK(N+1), IWORK(2*N+M+1), IERR )
  1027. ELSE
  1028. CALL SLACPY( 'U', N, N, A, LDA, WORK(N+1), N )
  1029. DO 3052 p = 1, N
  1030. TEMP1 = SVA(IWORK(p))
  1031. CALL SSCAL( p, ONE/TEMP1, WORK(N+(p-1)*N+1), 1 )
  1032. 3052 CONTINUE
  1033. * .. the columns of R are scaled to have unit Euclidean lengths.
  1034. CALL SPOCON( 'U', N, WORK(N+1), N, ONE, TEMP1,
  1035. $ WORK(N+N*N+1), IWORK(2*N+M+1), IERR )
  1036. END IF
  1037. SCONDA = ONE / SQRT(TEMP1)
  1038. * SCONDA is an estimate of SQRT(||(R^t * R)^(-1)||_1).
  1039. * N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA
  1040. ELSE
  1041. SCONDA = - ONE
  1042. END IF
  1043. END IF
  1044. *
  1045. L2PERT = L2PERT .AND. ( ABS( A(1,1)/A(NR,NR) ) .GT. SQRT(BIG1) )
  1046. * If there is no violent scaling, artificial perturbation is not needed.
  1047. *
  1048. * Phase 3:
  1049. *
  1050. IF ( .NOT. ( RSVEC .OR. LSVEC ) ) THEN
  1051. *
  1052. * Singular Values only
  1053. *
  1054. * .. transpose A(1:NR,1:N)
  1055. DO 1946 p = 1, MIN0( N-1, NR )
  1056. CALL SCOPY( N-p, A(p,p+1), LDA, A(p+1,p), 1 )
  1057. 1946 CONTINUE
  1058. *
  1059. * The following two DO-loops introduce small relative perturbation
  1060. * into the strict upper triangle of the lower triangular matrix.
  1061. * Small entries below the main diagonal are also changed.
  1062. * This modification is useful if the computing environment does not
  1063. * provide/allow FLUSH TO ZERO underflow, for it prevents many
  1064. * annoying denormalized numbers in case of strongly scaled matrices.
  1065. * The perturbation is structured so that it does not introduce any
  1066. * new perturbation of the singular values, and it does not destroy
  1067. * the job done by the preconditioner.
  1068. * The licence for this perturbation is in the variable L2PERT, which
  1069. * should be .FALSE. if FLUSH TO ZERO underflow is active.
  1070. *
  1071. IF ( .NOT. ALMORT ) THEN
  1072. *
  1073. IF ( L2PERT ) THEN
  1074. * XSC = SQRT(SMALL)
  1075. XSC = EPSLN / FLOAT(N)
  1076. DO 4947 q = 1, NR
  1077. TEMP1 = XSC*ABS(A(q,q))
  1078. DO 4949 p = 1, N
  1079. IF ( ( (p.GT.q) .AND. (ABS(A(p,q)).LE.TEMP1) )
  1080. $ .OR. ( p .LT. q ) )
  1081. $ A(p,q) = SIGN( TEMP1, A(p,q) )
  1082. 4949 CONTINUE
  1083. 4947 CONTINUE
  1084. ELSE
  1085. CALL SLASET( 'U', NR-1,NR-1, ZERO,ZERO, A(1,2),LDA )
  1086. END IF
  1087. *
  1088. * .. second preconditioning using the QR factorization
  1089. *
  1090. CALL SGEQRF( N,NR, A,LDA, WORK, WORK(N+1),LWORK-N, IERR )
  1091. *
  1092. * .. and transpose upper to lower triangular
  1093. DO 1948 p = 1, NR - 1
  1094. CALL SCOPY( NR-p, A(p,p+1), LDA, A(p+1,p), 1 )
  1095. 1948 CONTINUE
  1096. *
  1097. END IF
  1098. *
  1099. * Row-cyclic Jacobi SVD algorithm with column pivoting
  1100. *
  1101. * .. again some perturbation (a "background noise") is added
  1102. * to drown denormals
  1103. IF ( L2PERT ) THEN
  1104. * XSC = SQRT(SMALL)
  1105. XSC = EPSLN / FLOAT(N)
  1106. DO 1947 q = 1, NR
  1107. TEMP1 = XSC*ABS(A(q,q))
  1108. DO 1949 p = 1, NR
  1109. IF ( ( (p.GT.q) .AND. (ABS(A(p,q)).LE.TEMP1) )
  1110. $ .OR. ( p .LT. q ) )
  1111. $ A(p,q) = SIGN( TEMP1, A(p,q) )
  1112. 1949 CONTINUE
  1113. 1947 CONTINUE
  1114. ELSE
  1115. CALL SLASET( 'U', NR-1, NR-1, ZERO, ZERO, A(1,2), LDA )
  1116. END IF
  1117. *
  1118. * .. and one-sided Jacobi rotations are started on a lower
  1119. * triangular matrix (plus perturbation which is ignored in
  1120. * the part which destroys triangular form (confusing?!))
  1121. *
  1122. CALL SGESVJ( 'L', 'NoU', 'NoV', NR, NR, A, LDA, SVA,
  1123. $ N, V, LDV, WORK, LWORK, INFO )
  1124. *
  1125. SCALEM = WORK(1)
  1126. NUMRANK = NINT(WORK(2))
  1127. *
  1128. *
  1129. ELSE IF ( RSVEC .AND. ( .NOT. LSVEC ) ) THEN
  1130. *
  1131. * -> Singular Values and Right Singular Vectors <-
  1132. *
  1133. IF ( ALMORT ) THEN
  1134. *
  1135. * .. in this case NR equals N
  1136. DO 1998 p = 1, NR
  1137. CALL SCOPY( N-p+1, A(p,p), LDA, V(p,p), 1 )
  1138. 1998 CONTINUE
  1139. CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
  1140. *
  1141. CALL SGESVJ( 'L','U','N', N, NR, V,LDV, SVA, NR, A,LDA,
  1142. $ WORK, LWORK, INFO )
  1143. SCALEM = WORK(1)
  1144. NUMRANK = NINT(WORK(2))
  1145. ELSE
  1146. *
  1147. * .. two more QR factorizations ( one QRF is not enough, two require
  1148. * accumulated product of Jacobi rotations, three are perfect )
  1149. *
  1150. CALL SLASET( 'Lower', NR-1, NR-1, ZERO, ZERO, A(2,1), LDA )
  1151. CALL SGELQF( NR, N, A, LDA, WORK, WORK(N+1), LWORK-N, IERR)
  1152. CALL SLACPY( 'Lower', NR, NR, A, LDA, V, LDV )
  1153. CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
  1154. CALL SGEQRF( NR, NR, V, LDV, WORK(N+1), WORK(2*N+1),
  1155. $ LWORK-2*N, IERR )
  1156. DO 8998 p = 1, NR
  1157. CALL SCOPY( NR-p+1, V(p,p), LDV, V(p,p), 1 )
  1158. 8998 CONTINUE
  1159. CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
  1160. *
  1161. CALL SGESVJ( 'Lower', 'U','N', NR, NR, V,LDV, SVA, NR, U,
  1162. $ LDU, WORK(N+1), LWORK-N, INFO )
  1163. SCALEM = WORK(N+1)
  1164. NUMRANK = NINT(WORK(N+2))
  1165. IF ( NR .LT. N ) THEN
  1166. CALL SLASET( 'A',N-NR, NR, ZERO,ZERO, V(NR+1,1), LDV )
  1167. CALL SLASET( 'A',NR, N-NR, ZERO,ZERO, V(1,NR+1), LDV )
  1168. CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE, V(NR+1,NR+1), LDV )
  1169. END IF
  1170. *
  1171. CALL SORMLQ( 'Left', 'Transpose', N, N, NR, A, LDA, WORK,
  1172. $ V, LDV, WORK(N+1), LWORK-N, IERR )
  1173. *
  1174. END IF
  1175. *
  1176. DO 8991 p = 1, N
  1177. CALL SCOPY( N, V(p,1), LDV, A(IWORK(p),1), LDA )
  1178. 8991 CONTINUE
  1179. CALL SLACPY( 'All', N, N, A, LDA, V, LDV )
  1180. *
  1181. IF ( TRANSP ) THEN
  1182. CALL SLACPY( 'All', N, N, V, LDV, U, LDU )
  1183. END IF
  1184. *
  1185. ELSE IF ( LSVEC .AND. ( .NOT. RSVEC ) ) THEN
  1186. *
  1187. * .. Singular Values and Left Singular Vectors ..
  1188. *
  1189. * .. second preconditioning step to avoid need to accumulate
  1190. * Jacobi rotations in the Jacobi iterations.
  1191. DO 1965 p = 1, NR
  1192. CALL SCOPY( N-p+1, A(p,p), LDA, U(p,p), 1 )
  1193. 1965 CONTINUE
  1194. CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, U(1,2), LDU )
  1195. *
  1196. CALL SGEQRF( N, NR, U, LDU, WORK(N+1), WORK(2*N+1),
  1197. $ LWORK-2*N, IERR )
  1198. *
  1199. DO 1967 p = 1, NR - 1
  1200. CALL SCOPY( NR-p, U(p,p+1), LDU, U(p+1,p), 1 )
  1201. 1967 CONTINUE
  1202. CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, U(1,2), LDU )
  1203. *
  1204. CALL SGESVJ( 'Lower', 'U', 'N', NR,NR, U, LDU, SVA, NR, A,
  1205. $ LDA, WORK(N+1), LWORK-N, INFO )
  1206. SCALEM = WORK(N+1)
  1207. NUMRANK = NINT(WORK(N+2))
  1208. *
  1209. IF ( NR .LT. M ) THEN
  1210. CALL SLASET( 'A', M-NR, NR,ZERO, ZERO, U(NR+1,1), LDU )
  1211. IF ( NR .LT. N1 ) THEN
  1212. CALL SLASET( 'A',NR, N1-NR, ZERO, ZERO, U(1,NR+1), LDU )
  1213. CALL SLASET( 'A',M-NR,N1-NR,ZERO,ONE,U(NR+1,NR+1), LDU )
  1214. END IF
  1215. END IF
  1216. *
  1217. CALL SORMQR( 'Left', 'No Tr', M, N1, N, A, LDA, WORK, U,
  1218. $ LDU, WORK(N+1), LWORK-N, IERR )
  1219. *
  1220. IF ( ROWPIV )
  1221. $ CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
  1222. *
  1223. DO 1974 p = 1, N1
  1224. XSC = ONE / SNRM2( M, U(1,p), 1 )
  1225. CALL SSCAL( M, XSC, U(1,p), 1 )
  1226. 1974 CONTINUE
  1227. *
  1228. IF ( TRANSP ) THEN
  1229. CALL SLACPY( 'All', N, N, U, LDU, V, LDV )
  1230. END IF
  1231. *
  1232. ELSE
  1233. *
  1234. * .. Full SVD ..
  1235. *
  1236. IF ( .NOT. JRACC ) THEN
  1237. *
  1238. IF ( .NOT. ALMORT ) THEN
  1239. *
  1240. * Second Preconditioning Step (QRF [with pivoting])
  1241. * Note that the composition of TRANSPOSE, QRF and TRANSPOSE is
  1242. * equivalent to an LQF CALL. Since in many libraries the QRF
  1243. * seems to be better optimized than the LQF, we do explicit
  1244. * transpose and use the QRF. This is subject to changes in an
  1245. * optimized implementation of SGEJSV.
  1246. *
  1247. DO 1968 p = 1, NR
  1248. CALL SCOPY( N-p+1, A(p,p), LDA, V(p,p), 1 )
  1249. 1968 CONTINUE
  1250. *
  1251. * .. the following two loops perturb small entries to avoid
  1252. * denormals in the second QR factorization, where they are
  1253. * as good as zeros. This is done to avoid painfully slow
  1254. * computation with denormals. The relative size of the perturbation
  1255. * is a parameter that can be changed by the implementer.
  1256. * This perturbation device will be obsolete on machines with
  1257. * properly implemented arithmetic.
  1258. * To switch it off, set L2PERT=.FALSE. To remove it from the
  1259. * code, remove the action under L2PERT=.TRUE., leave the ELSE part.
  1260. * The following two loops should be blocked and fused with the
  1261. * transposed copy above.
  1262. *
  1263. IF ( L2PERT ) THEN
  1264. XSC = SQRT(SMALL)
  1265. DO 2969 q = 1, NR
  1266. TEMP1 = XSC*ABS( V(q,q) )
  1267. DO 2968 p = 1, N
  1268. IF ( ( p .GT. q ) .AND. ( ABS(V(p,q)) .LE. TEMP1 )
  1269. $ .OR. ( p .LT. q ) )
  1270. $ V(p,q) = SIGN( TEMP1, V(p,q) )
  1271. IF ( p .LT. q ) V(p,q) = - V(p,q)
  1272. 2968 CONTINUE
  1273. 2969 CONTINUE
  1274. ELSE
  1275. CALL SLASET( 'U', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
  1276. END IF
  1277. *
  1278. * Estimate the row scaled condition number of R1
  1279. * (If R1 is rectangular, N > NR, then the condition number
  1280. * of the leading NR x NR submatrix is estimated.)
  1281. *
  1282. CALL SLACPY( 'L', NR, NR, V, LDV, WORK(2*N+1), NR )
  1283. DO 3950 p = 1, NR
  1284. TEMP1 = SNRM2(NR-p+1,WORK(2*N+(p-1)*NR+p),1)
  1285. CALL SSCAL(NR-p+1,ONE/TEMP1,WORK(2*N+(p-1)*NR+p),1)
  1286. 3950 CONTINUE
  1287. CALL SPOCON('Lower',NR,WORK(2*N+1),NR,ONE,TEMP1,
  1288. $ WORK(2*N+NR*NR+1),IWORK(M+2*N+1),IERR)
  1289. CONDR1 = ONE / SQRT(TEMP1)
  1290. * .. here need a second oppinion on the condition number
  1291. * .. then assume worst case scenario
  1292. * R1 is OK for inverse <=> CONDR1 .LT. FLOAT(N)
  1293. * more conservative <=> CONDR1 .LT. SQRT(FLOAT(N))
  1294. *
  1295. COND_OK = SQRT(FLOAT(NR))
  1296. *[TP] COND_OK is a tuning parameter.
  1297. IF ( CONDR1 .LT. COND_OK ) THEN
  1298. * .. the second QRF without pivoting. Note: in an optimized
  1299. * implementation, this QRF should be implemented as the QRF
  1300. * of a lower triangular matrix.
  1301. * R1^t = Q2 * R2
  1302. CALL SGEQRF( N, NR, V, LDV, WORK(N+1), WORK(2*N+1),
  1303. $ LWORK-2*N, IERR )
  1304. *
  1305. IF ( L2PERT ) THEN
  1306. XSC = SQRT(SMALL)/EPSLN
  1307. DO 3959 p = 2, NR
  1308. DO 3958 q = 1, p - 1
  1309. TEMP1 = XSC * AMIN1(ABS(V(p,p)),ABS(V(q,q)))
  1310. IF ( ABS(V(q,p)) .LE. TEMP1 )
  1311. $ V(q,p) = SIGN( TEMP1, V(q,p) )
  1312. 3958 CONTINUE
  1313. 3959 CONTINUE
  1314. END IF
  1315. *
  1316. IF ( NR .NE. N )
  1317. $ CALL SLACPY( 'A', N, NR, V, LDV, WORK(2*N+1), N )
  1318. * .. save ...
  1319. *
  1320. * .. this transposed copy should be better than naive
  1321. DO 1969 p = 1, NR - 1
  1322. CALL SCOPY( NR-p, V(p,p+1), LDV, V(p+1,p), 1 )
  1323. 1969 CONTINUE
  1324. *
  1325. CONDR2 = CONDR1
  1326. *
  1327. ELSE
  1328. *
  1329. * .. ill-conditioned case: second QRF with pivoting
  1330. * Note that windowed pivoting would be equaly good
  1331. * numerically, and more run-time efficient. So, in
  1332. * an optimal implementation, the next call to SGEQP3
  1333. * should be replaced with eg. CALL SGEQPX (ACM TOMS #782)
  1334. * with properly (carefully) chosen parameters.
  1335. *
  1336. * R1^t * P2 = Q2 * R2
  1337. DO 3003 p = 1, NR
  1338. IWORK(N+p) = 0
  1339. 3003 CONTINUE
  1340. CALL SGEQP3( N, NR, V, LDV, IWORK(N+1), WORK(N+1),
  1341. $ WORK(2*N+1), LWORK-2*N, IERR )
  1342. ** CALL SGEQRF( N, NR, V, LDV, WORK(N+1), WORK(2*N+1),
  1343. ** $ LWORK-2*N, IERR )
  1344. IF ( L2PERT ) THEN
  1345. XSC = SQRT(SMALL)
  1346. DO 3969 p = 2, NR
  1347. DO 3968 q = 1, p - 1
  1348. TEMP1 = XSC * AMIN1(ABS(V(p,p)),ABS(V(q,q)))
  1349. IF ( ABS(V(q,p)) .LE. TEMP1 )
  1350. $ V(q,p) = SIGN( TEMP1, V(q,p) )
  1351. 3968 CONTINUE
  1352. 3969 CONTINUE
  1353. END IF
  1354. *
  1355. CALL SLACPY( 'A', N, NR, V, LDV, WORK(2*N+1), N )
  1356. *
  1357. IF ( L2PERT ) THEN
  1358. XSC = SQRT(SMALL)
  1359. DO 8970 p = 2, NR
  1360. DO 8971 q = 1, p - 1
  1361. TEMP1 = XSC * AMIN1(ABS(V(p,p)),ABS(V(q,q)))
  1362. V(p,q) = - SIGN( TEMP1, V(q,p) )
  1363. 8971 CONTINUE
  1364. 8970 CONTINUE
  1365. ELSE
  1366. CALL SLASET( 'L',NR-1,NR-1,ZERO,ZERO,V(2,1),LDV )
  1367. END IF
  1368. * Now, compute R2 = L3 * Q3, the LQ factorization.
  1369. CALL SGELQF( NR, NR, V, LDV, WORK(2*N+N*NR+1),
  1370. $ WORK(2*N+N*NR+NR+1), LWORK-2*N-N*NR-NR, IERR )
  1371. * .. and estimate the condition number
  1372. CALL SLACPY( 'L',NR,NR,V,LDV,WORK(2*N+N*NR+NR+1),NR )
  1373. DO 4950 p = 1, NR
  1374. TEMP1 = SNRM2( p, WORK(2*N+N*NR+NR+p), NR )
  1375. CALL SSCAL( p, ONE/TEMP1, WORK(2*N+N*NR+NR+p), NR )
  1376. 4950 CONTINUE
  1377. CALL SPOCON( 'L',NR,WORK(2*N+N*NR+NR+1),NR,ONE,TEMP1,
  1378. $ WORK(2*N+N*NR+NR+NR*NR+1),IWORK(M+2*N+1),IERR )
  1379. CONDR2 = ONE / SQRT(TEMP1)
  1380. *
  1381. IF ( CONDR2 .GE. COND_OK ) THEN
  1382. * .. save the Householder vectors used for Q3
  1383. * (this overwrittes the copy of R2, as it will not be
  1384. * needed in this branch, but it does not overwritte the
  1385. * Huseholder vectors of Q2.).
  1386. CALL SLACPY( 'U', NR, NR, V, LDV, WORK(2*N+1), N )
  1387. * .. and the rest of the information on Q3 is in
  1388. * WORK(2*N+N*NR+1:2*N+N*NR+N)
  1389. END IF
  1390. *
  1391. END IF
  1392. *
  1393. IF ( L2PERT ) THEN
  1394. XSC = SQRT(SMALL)
  1395. DO 4968 q = 2, NR
  1396. TEMP1 = XSC * V(q,q)
  1397. DO 4969 p = 1, q - 1
  1398. * V(p,q) = - SIGN( TEMP1, V(q,p) )
  1399. V(p,q) = - SIGN( TEMP1, V(p,q) )
  1400. 4969 CONTINUE
  1401. 4968 CONTINUE
  1402. ELSE
  1403. CALL SLASET( 'U', NR-1,NR-1, ZERO,ZERO, V(1,2), LDV )
  1404. END IF
  1405. *
  1406. * Second preconditioning finished; continue with Jacobi SVD
  1407. * The input matrix is lower trinagular.
  1408. *
  1409. * Recover the right singular vectors as solution of a well
  1410. * conditioned triangular matrix equation.
  1411. *
  1412. IF ( CONDR1 .LT. COND_OK ) THEN
  1413. *
  1414. CALL SGESVJ( 'L','U','N',NR,NR,V,LDV,SVA,NR,U,
  1415. $ LDU,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,INFO )
  1416. SCALEM = WORK(2*N+N*NR+NR+1)
  1417. NUMRANK = NINT(WORK(2*N+N*NR+NR+2))
  1418. DO 3970 p = 1, NR
  1419. CALL SCOPY( NR, V(1,p), 1, U(1,p), 1 )
  1420. CALL SSCAL( NR, SVA(p), V(1,p), 1 )
  1421. 3970 CONTINUE
  1422. * .. pick the right matrix equation and solve it
  1423. *
  1424. IF ( NR .EQ. N ) THEN
  1425. * :)) .. best case, R1 is inverted. The solution of this matrix
  1426. * equation is Q2*V2 = the product of the Jacobi rotations
  1427. * used in SGESVJ, premultiplied with the orthogonal matrix
  1428. * from the second QR factorization.
  1429. CALL STRSM( 'L','U','N','N', NR,NR,ONE, A,LDA, V,LDV )
  1430. ELSE
  1431. * .. R1 is well conditioned, but non-square. Transpose(R2)
  1432. * is inverted to get the product of the Jacobi rotations
  1433. * used in SGESVJ. The Q-factor from the second QR
  1434. * factorization is then built in explicitly.
  1435. CALL STRSM('L','U','T','N',NR,NR,ONE,WORK(2*N+1),
  1436. $ N,V,LDV)
  1437. IF ( NR .LT. N ) THEN
  1438. CALL SLASET('A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV)
  1439. CALL SLASET('A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV)
  1440. CALL SLASET('A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV)
  1441. END IF
  1442. CALL SORMQR('L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
  1443. $ V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR)
  1444. END IF
  1445. *
  1446. ELSE IF ( CONDR2 .LT. COND_OK ) THEN
  1447. *
  1448. * :) .. the input matrix A is very likely a relative of
  1449. * the Kahan matrix :)
  1450. * The matrix R2 is inverted. The solution of the matrix equation
  1451. * is Q3^T*V3 = the product of the Jacobi rotations (appplied to
  1452. * the lower triangular L3 from the LQ factorization of
  1453. * R2=L3*Q3), pre-multiplied with the transposed Q3.
  1454. CALL SGESVJ( 'L', 'U', 'N', NR, NR, V, LDV, SVA, NR, U,
  1455. $ LDU, WORK(2*N+N*NR+NR+1), LWORK-2*N-N*NR-NR, INFO )
  1456. SCALEM = WORK(2*N+N*NR+NR+1)
  1457. NUMRANK = NINT(WORK(2*N+N*NR+NR+2))
  1458. DO 3870 p = 1, NR
  1459. CALL SCOPY( NR, V(1,p), 1, U(1,p), 1 )
  1460. CALL SSCAL( NR, SVA(p), U(1,p), 1 )
  1461. 3870 CONTINUE
  1462. CALL STRSM('L','U','N','N',NR,NR,ONE,WORK(2*N+1),N,U,LDU)
  1463. * .. apply the permutation from the second QR factorization
  1464. DO 873 q = 1, NR
  1465. DO 872 p = 1, NR
  1466. WORK(2*N+N*NR+NR+IWORK(N+p)) = U(p,q)
  1467. 872 CONTINUE
  1468. DO 874 p = 1, NR
  1469. U(p,q) = WORK(2*N+N*NR+NR+p)
  1470. 874 CONTINUE
  1471. 873 CONTINUE
  1472. IF ( NR .LT. N ) THEN
  1473. CALL SLASET( 'A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV )
  1474. CALL SLASET( 'A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV )
  1475. CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV )
  1476. END IF
  1477. CALL SORMQR( 'L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
  1478. $ V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR )
  1479. ELSE
  1480. * Last line of defense.
  1481. * #:( This is a rather pathological case: no scaled condition
  1482. * improvement after two pivoted QR factorizations. Other
  1483. * possibility is that the rank revealing QR factorization
  1484. * or the condition estimator has failed, or the COND_OK
  1485. * is set very close to ONE (which is unnecessary). Normally,
  1486. * this branch should never be executed, but in rare cases of
  1487. * failure of the RRQR or condition estimator, the last line of
  1488. * defense ensures that SGEJSV completes the task.
  1489. * Compute the full SVD of L3 using SGESVJ with explicit
  1490. * accumulation of Jacobi rotations.
  1491. CALL SGESVJ( 'L', 'U', 'V', NR, NR, V, LDV, SVA, NR, U,
  1492. $ LDU, WORK(2*N+N*NR+NR+1), LWORK-2*N-N*NR-NR, INFO )
  1493. SCALEM = WORK(2*N+N*NR+NR+1)
  1494. NUMRANK = NINT(WORK(2*N+N*NR+NR+2))
  1495. IF ( NR .LT. N ) THEN
  1496. CALL SLASET( 'A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV )
  1497. CALL SLASET( 'A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV )
  1498. CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV )
  1499. END IF
  1500. CALL SORMQR( 'L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
  1501. $ V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR )
  1502. *
  1503. CALL SORMLQ( 'L', 'T', NR, NR, NR, WORK(2*N+1), N,
  1504. $ WORK(2*N+N*NR+1), U, LDU, WORK(2*N+N*NR+NR+1),
  1505. $ LWORK-2*N-N*NR-NR, IERR )
  1506. DO 773 q = 1, NR
  1507. DO 772 p = 1, NR
  1508. WORK(2*N+N*NR+NR+IWORK(N+p)) = U(p,q)
  1509. 772 CONTINUE
  1510. DO 774 p = 1, NR
  1511. U(p,q) = WORK(2*N+N*NR+NR+p)
  1512. 774 CONTINUE
  1513. 773 CONTINUE
  1514. *
  1515. END IF
  1516. *
  1517. * Permute the rows of V using the (column) permutation from the
  1518. * first QRF. Also, scale the columns to make them unit in
  1519. * Euclidean norm. This applies to all cases.
  1520. *
  1521. TEMP1 = SQRT(FLOAT(N)) * EPSLN
  1522. DO 1972 q = 1, N
  1523. DO 972 p = 1, N
  1524. WORK(2*N+N*NR+NR+IWORK(p)) = V(p,q)
  1525. 972 CONTINUE
  1526. DO 973 p = 1, N
  1527. V(p,q) = WORK(2*N+N*NR+NR+p)
  1528. 973 CONTINUE
  1529. XSC = ONE / SNRM2( N, V(1,q), 1 )
  1530. IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
  1531. $ CALL SSCAL( N, XSC, V(1,q), 1 )
  1532. 1972 CONTINUE
  1533. * At this moment, V contains the right singular vectors of A.
  1534. * Next, assemble the left singular vector matrix U (M x N).
  1535. IF ( NR .LT. M ) THEN
  1536. CALL SLASET( 'A', M-NR, NR, ZERO, ZERO, U(NR+1,1), LDU )
  1537. IF ( NR .LT. N1 ) THEN
  1538. CALL SLASET('A',NR,N1-NR,ZERO,ZERO,U(1,NR+1),LDU)
  1539. CALL SLASET('A',M-NR,N1-NR,ZERO,ONE,U(NR+1,NR+1),LDU)
  1540. END IF
  1541. END IF
  1542. *
  1543. * The Q matrix from the first QRF is built into the left singular
  1544. * matrix U. This applies to all cases.
  1545. *
  1546. CALL SORMQR( 'Left', 'No_Tr', M, N1, N, A, LDA, WORK, U,
  1547. $ LDU, WORK(N+1), LWORK-N, IERR )
  1548. * The columns of U are normalized. The cost is O(M*N) flops.
  1549. TEMP1 = SQRT(FLOAT(M)) * EPSLN
  1550. DO 1973 p = 1, NR
  1551. XSC = ONE / SNRM2( M, U(1,p), 1 )
  1552. IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
  1553. $ CALL SSCAL( M, XSC, U(1,p), 1 )
  1554. 1973 CONTINUE
  1555. *
  1556. * If the initial QRF is computed with row pivoting, the left
  1557. * singular vectors must be adjusted.
  1558. *
  1559. IF ( ROWPIV )
  1560. $ CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
  1561. *
  1562. ELSE
  1563. *
  1564. * .. the initial matrix A has almost orthogonal columns and
  1565. * the second QRF is not needed
  1566. *
  1567. CALL SLACPY( 'Upper', N, N, A, LDA, WORK(N+1), N )
  1568. IF ( L2PERT ) THEN
  1569. XSC = SQRT(SMALL)
  1570. DO 5970 p = 2, N
  1571. TEMP1 = XSC * WORK( N + (p-1)*N + p )
  1572. DO 5971 q = 1, p - 1
  1573. WORK(N+(q-1)*N+p)=-SIGN(TEMP1,WORK(N+(p-1)*N+q))
  1574. 5971 CONTINUE
  1575. 5970 CONTINUE
  1576. ELSE
  1577. CALL SLASET( 'Lower',N-1,N-1,ZERO,ZERO,WORK(N+2),N )
  1578. END IF
  1579. *
  1580. CALL SGESVJ( 'Upper', 'U', 'N', N, N, WORK(N+1), N, SVA,
  1581. $ N, U, LDU, WORK(N+N*N+1), LWORK-N-N*N, INFO )
  1582. *
  1583. SCALEM = WORK(N+N*N+1)
  1584. NUMRANK = NINT(WORK(N+N*N+2))
  1585. DO 6970 p = 1, N
  1586. CALL SCOPY( N, WORK(N+(p-1)*N+1), 1, U(1,p), 1 )
  1587. CALL SSCAL( N, SVA(p), WORK(N+(p-1)*N+1), 1 )
  1588. 6970 CONTINUE
  1589. *
  1590. CALL STRSM( 'Left', 'Upper', 'NoTrans', 'No UD', N, N,
  1591. $ ONE, A, LDA, WORK(N+1), N )
  1592. DO 6972 p = 1, N
  1593. CALL SCOPY( N, WORK(N+p), N, V(IWORK(p),1), LDV )
  1594. 6972 CONTINUE
  1595. TEMP1 = SQRT(FLOAT(N))*EPSLN
  1596. DO 6971 p = 1, N
  1597. XSC = ONE / SNRM2( N, V(1,p), 1 )
  1598. IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
  1599. $ CALL SSCAL( N, XSC, V(1,p), 1 )
  1600. 6971 CONTINUE
  1601. *
  1602. * Assemble the left singular vector matrix U (M x N).
  1603. *
  1604. IF ( N .LT. M ) THEN
  1605. CALL SLASET( 'A', M-N, N, ZERO, ZERO, U(N+1,1), LDU )
  1606. IF ( N .LT. N1 ) THEN
  1607. CALL SLASET( 'A',N, N1-N, ZERO, ZERO, U(1,N+1),LDU )
  1608. CALL SLASET( 'A',M-N,N1-N, ZERO, ONE,U(N+1,N+1),LDU )
  1609. END IF
  1610. END IF
  1611. CALL SORMQR( 'Left', 'No Tr', M, N1, N, A, LDA, WORK, U,
  1612. $ LDU, WORK(N+1), LWORK-N, IERR )
  1613. TEMP1 = SQRT(FLOAT(M))*EPSLN
  1614. DO 6973 p = 1, N1
  1615. XSC = ONE / SNRM2( M, U(1,p), 1 )
  1616. IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
  1617. $ CALL SSCAL( M, XSC, U(1,p), 1 )
  1618. 6973 CONTINUE
  1619. *
  1620. IF ( ROWPIV )
  1621. $ CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
  1622. *
  1623. END IF
  1624. *
  1625. * end of the >> almost orthogonal case << in the full SVD
  1626. *
  1627. ELSE
  1628. *
  1629. * This branch deploys a preconditioned Jacobi SVD with explicitly
  1630. * accumulated rotations. It is included as optional, mainly for
  1631. * experimental purposes. It does perfom well, and can also be used.
  1632. * In this implementation, this branch will be automatically activated
  1633. * if the condition number sigma_max(A) / sigma_min(A) is predicted
  1634. * to be greater than the overflow threshold. This is because the
  1635. * a posteriori computation of the singular vectors assumes robust
  1636. * implementation of BLAS and some LAPACK procedures, capable of working
  1637. * in presence of extreme values. Since that is not always the case, ...
  1638. *
  1639. DO 7968 p = 1, NR
  1640. CALL SCOPY( N-p+1, A(p,p), LDA, V(p,p), 1 )
  1641. 7968 CONTINUE
  1642. *
  1643. IF ( L2PERT ) THEN
  1644. XSC = SQRT(SMALL/EPSLN)
  1645. DO 5969 q = 1, NR
  1646. TEMP1 = XSC*ABS( V(q,q) )
  1647. DO 5968 p = 1, N
  1648. IF ( ( p .GT. q ) .AND. ( ABS(V(p,q)) .LE. TEMP1 )
  1649. $ .OR. ( p .LT. q ) )
  1650. $ V(p,q) = SIGN( TEMP1, V(p,q) )
  1651. IF ( p .LT. q ) V(p,q) = - V(p,q)
  1652. 5968 CONTINUE
  1653. 5969 CONTINUE
  1654. ELSE
  1655. CALL SLASET( 'U', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
  1656. END IF
  1657. CALL SGEQRF( N, NR, V, LDV, WORK(N+1), WORK(2*N+1),
  1658. $ LWORK-2*N, IERR )
  1659. CALL SLACPY( 'L', N, NR, V, LDV, WORK(2*N+1), N )
  1660. *
  1661. DO 7969 p = 1, NR
  1662. CALL SCOPY( NR-p+1, V(p,p), LDV, U(p,p), 1 )
  1663. 7969 CONTINUE
  1664. IF ( L2PERT ) THEN
  1665. XSC = SQRT(SMALL/EPSLN)
  1666. DO 9970 q = 2, NR
  1667. DO 9971 p = 1, q - 1
  1668. TEMP1 = XSC * AMIN1(ABS(U(p,p)),ABS(U(q,q)))
  1669. U(p,q) = - SIGN( TEMP1, U(q,p) )
  1670. 9971 CONTINUE
  1671. 9970 CONTINUE
  1672. ELSE
  1673. CALL SLASET('U', NR-1, NR-1, ZERO, ZERO, U(1,2), LDU )
  1674. END IF
  1675. CALL SGESVJ( 'L', 'U', 'V', NR, NR, U, LDU, SVA,
  1676. $ N, V, LDV, WORK(2*N+N*NR+1), LWORK-2*N-N*NR, INFO )
  1677. SCALEM = WORK(2*N+N*NR+1)
  1678. NUMRANK = NINT(WORK(2*N+N*NR+2))
  1679. IF ( NR .LT. N ) THEN
  1680. CALL SLASET( 'A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV )
  1681. CALL SLASET( 'A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV )
  1682. CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV )
  1683. END IF
  1684. CALL SORMQR( 'L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
  1685. $ V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR )
  1686. *
  1687. * Permute the rows of V using the (column) permutation from the
  1688. * first QRF. Also, scale the columns to make them unit in
  1689. * Euclidean norm. This applies to all cases.
  1690. *
  1691. TEMP1 = SQRT(FLOAT(N)) * EPSLN
  1692. DO 7972 q = 1, N
  1693. DO 8972 p = 1, N
  1694. WORK(2*N+N*NR+NR+IWORK(p)) = V(p,q)
  1695. 8972 CONTINUE
  1696. DO 8973 p = 1, N
  1697. V(p,q) = WORK(2*N+N*NR+NR+p)
  1698. 8973 CONTINUE
  1699. XSC = ONE / SNRM2( N, V(1,q), 1 )
  1700. IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
  1701. $ CALL SSCAL( N, XSC, V(1,q), 1 )
  1702. 7972 CONTINUE
  1703. *
  1704. * At this moment, V contains the right singular vectors of A.
  1705. * Next, assemble the left singular vector matrix U (M x N).
  1706. *
  1707. IF ( NR .LT. M ) THEN
  1708. CALL SLASET( 'A', M-NR, NR, ZERO, ZERO, U(NR+1,1), LDU )
  1709. IF ( NR .LT. N1 ) THEN
  1710. CALL SLASET( 'A',NR, N1-NR, ZERO, ZERO, U(1,NR+1),LDU )
  1711. CALL SLASET( 'A',M-NR,N1-NR, ZERO, ONE,U(NR+1,NR+1),LDU )
  1712. END IF
  1713. END IF
  1714. *
  1715. CALL SORMQR( 'Left', 'No Tr', M, N1, N, A, LDA, WORK, U,
  1716. $ LDU, WORK(N+1), LWORK-N, IERR )
  1717. *
  1718. IF ( ROWPIV )
  1719. $ CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
  1720. *
  1721. *
  1722. END IF
  1723. IF ( TRANSP ) THEN
  1724. * .. swap U and V because the procedure worked on A^t
  1725. DO 6974 p = 1, N
  1726. CALL SSWAP( N, U(1,p), 1, V(1,p), 1 )
  1727. 6974 CONTINUE
  1728. END IF
  1729. *
  1730. END IF
  1731. * end of the full SVD
  1732. *
  1733. * Undo scaling, if necessary (and possible)
  1734. *
  1735. IF ( USCAL2 .LE. (BIG/SVA(1))*USCAL1 ) THEN
  1736. CALL SLASCL( 'G', 0, 0, USCAL1, USCAL2, NR, 1, SVA, N, IERR )
  1737. USCAL1 = ONE
  1738. USCAL2 = ONE
  1739. END IF
  1740. *
  1741. IF ( NR .LT. N ) THEN
  1742. DO 3004 p = NR+1, N
  1743. SVA(p) = ZERO
  1744. 3004 CONTINUE
  1745. END IF
  1746. *
  1747. WORK(1) = USCAL2 * SCALEM
  1748. WORK(2) = USCAL1
  1749. IF ( ERREST ) WORK(3) = SCONDA
  1750. IF ( LSVEC .AND. RSVEC ) THEN
  1751. WORK(4) = CONDR1
  1752. WORK(5) = CONDR2
  1753. END IF
  1754. IF ( L2TRAN ) THEN
  1755. WORK(6) = ENTRA
  1756. WORK(7) = ENTRAT
  1757. END IF
  1758. *
  1759. IWORK(1) = NR
  1760. IWORK(2) = NUMRANK
  1761. IWORK(3) = WARNING
  1762. *
  1763. RETURN
  1764. * ..
  1765. * .. END OF SGEJSV
  1766. * ..
  1767. END
  1768. *