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