LAPACK 3.3.1
Linear Algebra PACKage

sgsvj0.f

Go to the documentation of this file.
00001       SUBROUTINE SGSVJ0( JOBV, M, N, A, LDA, D, SVA, MV, V, LDV, EPS,
00002      $                   SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
00003 *
00004 *  -- LAPACK routine (version 3.3.1)                                  --
00005 *
00006 *  -- Contributed by Zlatko Drmac of the University of Zagreb and     --
00007 *  -- Kresimir Veselic of the Fernuniversitaet Hagen                  --
00008 *  -- April 2011                                                      --
00009 *
00010 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00011 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00012 *
00013 * This routine is also part of SIGMA (version 1.23, October 23. 2008.)
00014 * SIGMA is a library of algorithms for highly accurate algorithms for
00015 * computation of SVD, PSVD, QSVD, (H,K)-SVD, and for solution of the
00016 * eigenvalue problems Hx = lambda M x, H M x = lambda x with H, M > 0.
00017 *
00018       IMPLICIT           NONE
00019 *     ..
00020 *     .. Scalar Arguments ..
00021       INTEGER            INFO, LDA, LDV, LWORK, M, MV, N, NSWEEP
00022       REAL               EPS, SFMIN, TOL
00023       CHARACTER*1        JOBV
00024 *     ..
00025 *     .. Array Arguments ..
00026       REAL               A( LDA, * ), SVA( N ), D( N ), V( LDV, * ),
00027      $                   WORK( LWORK )
00028 *     ..
00029 *
00030 *  Purpose
00031 *  =======
00032 *
00033 *  SGSVJ0 is called from SGESVJ as a pre-processor and that is its main
00034 *  purpose. It applies Jacobi rotations in the same way as SGESVJ does, but
00035 *  it does not check convergence (stopping criterion). Few tuning
00036 *  parameters (marked by [TP]) are available for the implementer.
00037 *
00038 *  Further Details
00039 *  ~~~~~~~~~~~~~~~
00040 *  SGSVJ0 is used just to enable SGESVJ to call a simplified version of
00041 *  itself to work on a submatrix of the original matrix.
00042 *
00043 *  Contributors
00044 *  ~~~~~~~~~~~~
00045 *  Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
00046 *
00047 *  Bugs, Examples and Comments
00048 *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
00049 *  Please report all bugs and send interesting test examples and comments to
00050 *  drmac@math.hr. Thank you.
00051 *
00052 *  Arguments
00053 *  =========
00054 *
00055 *  JOBV    (input) CHARACTER*1
00056 *          Specifies whether the output from this procedure is used
00057 *          to compute the matrix V:
00058 *          = 'V': the product of the Jacobi rotations is accumulated
00059 *                 by postmulyiplying the N-by-N array V.
00060 *                (See the description of V.)
00061 *          = 'A': the product of the Jacobi rotations is accumulated
00062 *                 by postmulyiplying the MV-by-N array V.
00063 *                (See the descriptions of MV and V.)
00064 *          = 'N': the Jacobi rotations are not accumulated.
00065 *
00066 *  M       (input) INTEGER
00067 *          The number of rows of the input matrix A.  M >= 0.
00068 *
00069 *  N       (input) INTEGER
00070 *          The number of columns of the input matrix A.
00071 *          M >= N >= 0.
00072 *
00073 *  A       (input/output) REAL array, dimension (LDA,N)
00074 *          On entry, M-by-N matrix A, such that A*diag(D) represents
00075 *          the input matrix.
00076 *          On exit,
00077 *          A_onexit * D_onexit represents the input matrix A*diag(D)
00078 *          post-multiplied by a sequence of Jacobi rotations, where the
00079 *          rotation threshold and the total number of sweeps are given in
00080 *          TOL and NSWEEP, respectively.
00081 *          (See the descriptions of D, TOL and NSWEEP.)
00082 *
00083 *  LDA     (input) INTEGER
00084 *          The leading dimension of the array A.  LDA >= max(1,M).
00085 *
00086 *  D       (input/workspace/output) REAL array, dimension (N)
00087 *          The array D accumulates the scaling factors from the fast scaled
00088 *          Jacobi rotations.
00089 *          On entry, A*diag(D) represents the input matrix.
00090 *          On exit, A_onexit*diag(D_onexit) represents the input matrix
00091 *          post-multiplied by a sequence of Jacobi rotations, where the
00092 *          rotation threshold and the total number of sweeps are given in
00093 *          TOL and NSWEEP, respectively.
00094 *          (See the descriptions of A, TOL and NSWEEP.)
00095 *
00096 *  SVA     (input/workspace/output) REAL array, dimension (N)
00097 *          On entry, SVA contains the Euclidean norms of the columns of
00098 *          the matrix A*diag(D).
00099 *          On exit, SVA contains the Euclidean norms of the columns of
00100 *          the matrix onexit*diag(D_onexit).
00101 *
00102 *  MV      (input) INTEGER
00103 *          If JOBV .EQ. 'A', then MV rows of V are post-multipled by a
00104 *                           sequence of Jacobi rotations.
00105 *          If JOBV = 'N',   then MV is not referenced.
00106 *
00107 *  V       (input/output) REAL array, dimension (LDV,N)
00108 *          If JOBV .EQ. 'V' then N rows of V are post-multipled by a
00109 *                           sequence of Jacobi rotations.
00110 *          If JOBV .EQ. 'A' then MV rows of V are post-multipled by a
00111 *                           sequence of Jacobi rotations.
00112 *          If JOBV = 'N',   then V is not referenced.
00113 *
00114 *  LDV     (input) INTEGER
00115 *          The leading dimension of the array V,  LDV >= 1.
00116 *          If JOBV = 'V', LDV .GE. N.
00117 *          If JOBV = 'A', LDV .GE. MV.
00118 *
00119 *  EPS     (input) INTEGER
00120 *          EPS = SLAMCH('Epsilon')
00121 *
00122 *  SFMIN   (input) INTEGER
00123 *          SFMIN = SLAMCH('Safe Minimum')
00124 *
00125 *  TOL     (input) REAL
00126 *          TOL is the threshold for Jacobi rotations. For a pair
00127 *          A(:,p), A(:,q) of pivot columns, the Jacobi rotation is
00128 *          applied only if ABS(COS(angle(A(:,p),A(:,q)))) .GT. TOL.
00129 *
00130 *  NSWEEP  (input) INTEGER
00131 *          NSWEEP is the number of sweeps of Jacobi rotations to be
00132 *          performed.
00133 *
00134 *  WORK    (workspace) REAL array, dimension LWORK.
00135 *
00136 *  LWORK   (input) INTEGER
00137 *          LWORK is the dimension of WORK. LWORK .GE. M.
00138 *
00139 *  INFO    (output) INTEGER
00140 *          = 0 : successful exit.
00141 *          < 0 : if INFO = -i, then the i-th argument had an illegal value
00142 *
00143 *  =====================================================================
00144 *
00145 *     .. Local Parameters ..
00146       REAL               ZERO, HALF, ONE, TWO
00147       PARAMETER          ( ZERO = 0.0E0, HALF = 0.5E0, ONE = 1.0E0,
00148      $                   TWO = 2.0E0 )
00149 *     ..
00150 *     .. Local Scalars ..
00151       REAL               AAPP, AAPP0, AAPQ, AAQQ, APOAQ, AQOAP, BIG,
00152      $                   BIGTHETA, CS, MXAAPQ, MXSINJ, ROOTBIG, ROOTEPS,
00153      $                   ROOTSFMIN, ROOTTOL, SMALL, SN, T, TEMP1, THETA,
00154      $                   THSIGN
00155       INTEGER            BLSKIP, EMPTSW, i, ibr, IERR, igl, IJBLSK, ir1,
00156      $                   ISWROT, jbc, jgl, KBL, LKAHEAD, MVL, NBL,
00157      $                   NOTROT, p, PSKIPPED, q, ROWSKIP, SWBAND
00158       LOGICAL            APPLV, ROTOK, RSVEC
00159 *     ..
00160 *     .. Local Arrays ..
00161       REAL               FASTR( 5 )
00162 *     ..
00163 *     .. Intrinsic Functions ..
00164       INTRINSIC          ABS, AMAX1, AMIN1, FLOAT, MIN0, SIGN, SQRT
00165 *     ..
00166 *     .. External Functions ..
00167       REAL               SDOT, SNRM2
00168       INTEGER            ISAMAX
00169       LOGICAL            LSAME
00170       EXTERNAL           ISAMAX, LSAME, SDOT, SNRM2
00171 *     ..
00172 *     .. External Subroutines ..
00173       EXTERNAL           SAXPY, SCOPY, SLASCL, SLASSQ, SROTM, SSWAP
00174 *     ..
00175 *     .. Executable Statements ..
00176 *
00177 *     Test the input parameters.
00178 *
00179       APPLV = LSAME( JOBV, 'A' )
00180       RSVEC = LSAME( JOBV, 'V' )
00181       IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
00182          INFO = -1
00183       ELSE IF( M.LT.0 ) THEN
00184          INFO = -2
00185       ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
00186          INFO = -3
00187       ELSE IF( LDA.LT.M ) THEN
00188          INFO = -5
00189       ELSE IF( ( RSVEC.OR.APPLV ) .AND. ( MV.LT.0 ) ) THEN
00190          INFO = -8
00191       ELSE IF( ( RSVEC.AND.( LDV.LT.N ) ).OR. 
00192      $         ( APPLV.AND.( LDV.LT.MV ) ) ) THEN
00193          INFO = -10
00194       ELSE IF( TOL.LE.EPS ) THEN
00195          INFO = -13
00196       ELSE IF( NSWEEP.LT.0 ) THEN
00197          INFO = -14
00198       ELSE IF( LWORK.LT.M ) THEN
00199          INFO = -16
00200       ELSE
00201          INFO = 0
00202       END IF
00203 *
00204 *     #:(
00205       IF( INFO.NE.0 ) THEN
00206          CALL XERBLA( 'SGSVJ0', -INFO )
00207          RETURN
00208       END IF
00209 *
00210       IF( RSVEC ) THEN
00211          MVL = N
00212       ELSE IF( APPLV ) THEN
00213          MVL = MV
00214       END IF
00215       RSVEC = RSVEC .OR. APPLV
00216 
00217       ROOTEPS = SQRT( EPS )
00218       ROOTSFMIN = SQRT( SFMIN )
00219       SMALL = SFMIN / EPS
00220       BIG = ONE / SFMIN
00221       ROOTBIG = ONE / ROOTSFMIN
00222       BIGTHETA = ONE / ROOTEPS
00223       ROOTTOL = SQRT( TOL )
00224 *
00225 *     .. Row-cyclic Jacobi SVD algorithm with column pivoting ..
00226 *
00227       EMPTSW = ( N*( N-1 ) ) / 2
00228       NOTROT = 0
00229       FASTR( 1 ) = ZERO
00230 *
00231 *     .. Row-cyclic pivot strategy with de Rijk's pivoting ..
00232 *
00233 
00234       SWBAND = 0
00235 *[TP] SWBAND is a tuning parameter. It is meaningful and effective
00236 *     if SGESVJ is used as a computational routine in the preconditioned
00237 *     Jacobi SVD algorithm SGESVJ. For sweeps i=1:SWBAND the procedure
00238 *     ......
00239 
00240       KBL = MIN0( 8, N )
00241 *[TP] KBL is a tuning parameter that defines the tile size in the
00242 *     tiling of the p-q loops of pivot pairs. In general, an optimal
00243 *     value of KBL depends on the matrix dimensions and on the
00244 *     parameters of the computer's memory.
00245 *
00246       NBL = N / KBL
00247       IF( ( NBL*KBL ).NE.N )NBL = NBL + 1
00248 
00249       BLSKIP = ( KBL**2 ) + 1
00250 *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
00251 
00252       ROWSKIP = MIN0( 5, KBL )
00253 *[TP] ROWSKIP is a tuning parameter.
00254 
00255       LKAHEAD = 1
00256 *[TP] LKAHEAD is a tuning parameter.
00257       SWBAND = 0
00258       PSKIPPED = 0
00259 *
00260       DO 1993 i = 1, NSWEEP
00261 *     .. go go go ...
00262 *
00263          MXAAPQ = ZERO
00264          MXSINJ = ZERO
00265          ISWROT = 0
00266 *
00267          NOTROT = 0
00268          PSKIPPED = 0
00269 *
00270          DO 2000 ibr = 1, NBL
00271 
00272             igl = ( ibr-1 )*KBL + 1
00273 *
00274             DO 1002 ir1 = 0, MIN0( LKAHEAD, NBL-ibr )
00275 *
00276                igl = igl + ir1*KBL
00277 *
00278                DO 2001 p = igl, MIN0( igl+KBL-1, N-1 )
00279 
00280 *     .. de Rijk's pivoting
00281                   q = ISAMAX( N-p+1, SVA( p ), 1 ) + p - 1
00282                   IF( p.NE.q ) THEN
00283                      CALL SSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
00284                      IF( RSVEC )CALL SSWAP( MVL, V( 1, p ), 1,
00285      $                                      V( 1, q ), 1 )
00286                      TEMP1 = SVA( p )
00287                      SVA( p ) = SVA( q )
00288                      SVA( q ) = TEMP1
00289                      TEMP1 = D( p )
00290                      D( p ) = D( q )
00291                      D( q ) = TEMP1
00292                   END IF
00293 *
00294                   IF( ir1.EQ.0 ) THEN
00295 *
00296 *        Column norms are periodically updated by explicit
00297 *        norm computation.
00298 *        Caveat:
00299 *        Some BLAS implementations compute SNRM2(M,A(1,p),1)
00300 *        as SQRT(SDOT(M,A(1,p),1,A(1,p),1)), which may result in
00301 *        overflow for ||A(:,p)||_2 > SQRT(overflow_threshold), and
00302 *        undeflow for ||A(:,p)||_2 < SQRT(underflow_threshold).
00303 *        Hence, SNRM2 cannot be trusted, not even in the case when
00304 *        the true norm is far from the under(over)flow boundaries.
00305 *        If properly implemented SNRM2 is available, the IF-THEN-ELSE
00306 *        below should read "AAPP = SNRM2( M, A(1,p), 1 ) * D(p)".
00307 *
00308                      IF( ( SVA( p ).LT.ROOTBIG ) .AND.
00309      $                   ( SVA( p ).GT.ROOTSFMIN ) ) THEN
00310                         SVA( p ) = SNRM2( M, A( 1, p ), 1 )*D( p )
00311                      ELSE
00312                         TEMP1 = ZERO
00313                         AAPP = ONE
00314                         CALL SLASSQ( M, A( 1, p ), 1, TEMP1, AAPP )
00315                         SVA( p ) = TEMP1*SQRT( AAPP )*D( p )
00316                      END IF
00317                      AAPP = SVA( p )
00318                   ELSE
00319                      AAPP = SVA( p )
00320                   END IF
00321 
00322 *
00323                   IF( AAPP.GT.ZERO ) THEN
00324 *
00325                      PSKIPPED = 0
00326 *
00327                      DO 2002 q = p + 1, MIN0( igl+KBL-1, N )
00328 *
00329                         AAQQ = SVA( q )
00330 
00331                         IF( AAQQ.GT.ZERO ) THEN
00332 *
00333                            AAPP0 = AAPP
00334                            IF( AAQQ.GE.ONE ) THEN
00335                               ROTOK = ( SMALL*AAPP ).LE.AAQQ
00336                               IF( AAPP.LT.( BIG / AAQQ ) ) THEN
00337                                  AAPQ = ( SDOT( M, A( 1, p ), 1, A( 1,
00338      $                                  q ), 1 )*D( p )*D( q ) / AAQQ )
00339      $                                  / AAPP
00340                               ELSE
00341                                  CALL SCOPY( M, A( 1, p ), 1, WORK, 1 )
00342                                  CALL SLASCL( 'G', 0, 0, AAPP, D( p ),
00343      $                                        M, 1, WORK, LDA, IERR )
00344                                  AAPQ = SDOT( M, WORK, 1, A( 1, q ),
00345      $                                  1 )*D( q ) / AAQQ
00346                               END IF
00347                            ELSE
00348                               ROTOK = AAPP.LE.( AAQQ / SMALL )
00349                               IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
00350                                  AAPQ = ( SDOT( M, A( 1, p ), 1, A( 1,
00351      $                                  q ), 1 )*D( p )*D( q ) / AAQQ )
00352      $                                  / AAPP
00353                               ELSE
00354                                  CALL SCOPY( M, A( 1, q ), 1, WORK, 1 )
00355                                  CALL SLASCL( 'G', 0, 0, AAQQ, D( q ),
00356      $                                        M, 1, WORK, LDA, IERR )
00357                                  AAPQ = SDOT( M, WORK, 1, A( 1, p ),
00358      $                                  1 )*D( p ) / AAPP
00359                               END IF
00360                            END IF
00361 *
00362                            MXAAPQ = AMAX1( MXAAPQ, ABS( AAPQ ) )
00363 *
00364 *        TO rotate or NOT to rotate, THAT is the question ...
00365 *
00366                            IF( ABS( AAPQ ).GT.TOL ) THEN
00367 *
00368 *           .. rotate
00369 *           ROTATED = ROTATED + ONE
00370 *
00371                               IF( ir1.EQ.0 ) THEN
00372                                  NOTROT = 0
00373                                  PSKIPPED = 0
00374                                  ISWROT = ISWROT + 1
00375                               END IF
00376 *
00377                               IF( ROTOK ) THEN
00378 *
00379                                  AQOAP = AAQQ / AAPP
00380                                  APOAQ = AAPP / AAQQ
00381                                  THETA = -HALF*ABS( AQOAP-APOAQ ) / AAPQ
00382 *
00383                                  IF( ABS( THETA ).GT.BIGTHETA ) THEN
00384 *
00385                                     T = HALF / THETA
00386                                     FASTR( 3 ) = T*D( p ) / D( q )
00387                                     FASTR( 4 ) = -T*D( q ) / D( p )
00388                                     CALL SROTM( M, A( 1, p ), 1,
00389      $                                          A( 1, q ), 1, FASTR )
00390                                     IF( RSVEC )CALL SROTM( MVL,
00391      $                                              V( 1, p ), 1,
00392      $                                              V( 1, q ), 1,
00393      $                                              FASTR )
00394                                     SVA( q ) = AAQQ*SQRT( AMAX1( ZERO,
00395      $                                         ONE+T*APOAQ*AAPQ ) )
00396                                     AAPP = AAPP*SQRT( AMAX1( ZERO, 
00397      $                                         ONE-T*AQOAP*AAPQ ) )
00398                                     MXSINJ = AMAX1( MXSINJ, ABS( T ) )
00399 *
00400                                  ELSE
00401 *
00402 *                 .. choose correct signum for THETA and rotate
00403 *
00404                                     THSIGN = -SIGN( ONE, AAPQ )
00405                                     T = ONE / ( THETA+THSIGN*
00406      $                                  SQRT( ONE+THETA*THETA ) )
00407                                     CS = SQRT( ONE / ( ONE+T*T ) )
00408                                     SN = T*CS
00409 *
00410                                     MXSINJ = AMAX1( MXSINJ, ABS( SN ) )
00411                                     SVA( q ) = AAQQ*SQRT( AMAX1( ZERO,
00412      $                                         ONE+T*APOAQ*AAPQ ) )
00413                                     AAPP = AAPP*SQRT( AMAX1( ZERO,
00414      $                                     ONE-T*AQOAP*AAPQ ) )
00415 *
00416                                     APOAQ = D( p ) / D( q )
00417                                     AQOAP = D( q ) / D( p )
00418                                     IF( D( p ).GE.ONE ) THEN
00419                                        IF( D( q ).GE.ONE ) THEN
00420                                           FASTR( 3 ) = T*APOAQ
00421                                           FASTR( 4 ) = -T*AQOAP
00422                                           D( p ) = D( p )*CS
00423                                           D( q ) = D( q )*CS
00424                                           CALL SROTM( M, A( 1, p ), 1,
00425      $                                                A( 1, q ), 1,
00426      $                                                FASTR )
00427                                           IF( RSVEC )CALL SROTM( MVL,
00428      $                                        V( 1, p ), 1, V( 1, q ),
00429      $                                        1, FASTR )
00430                                        ELSE
00431                                           CALL SAXPY( M, -T*AQOAP,
00432      $                                                A( 1, q ), 1,
00433      $                                                A( 1, p ), 1 )
00434                                           CALL SAXPY( M, CS*SN*APOAQ,
00435      $                                                A( 1, p ), 1,
00436      $                                                A( 1, q ), 1 )
00437                                           D( p ) = D( p )*CS
00438                                           D( q ) = D( q ) / CS
00439                                           IF( RSVEC ) THEN
00440                                              CALL SAXPY( MVL, -T*AQOAP,
00441      $                                                   V( 1, q ), 1,
00442      $                                                   V( 1, p ), 1 )
00443                                              CALL SAXPY( MVL,
00444      $                                                   CS*SN*APOAQ,
00445      $                                                   V( 1, p ), 1,
00446      $                                                   V( 1, q ), 1 )
00447                                           END IF
00448                                        END IF
00449                                     ELSE
00450                                        IF( D( q ).GE.ONE ) THEN
00451                                           CALL SAXPY( M, T*APOAQ,
00452      $                                                A( 1, p ), 1,
00453      $                                                A( 1, q ), 1 )
00454                                           CALL SAXPY( M, -CS*SN*AQOAP,
00455      $                                                A( 1, q ), 1,
00456      $                                                A( 1, p ), 1 )
00457                                           D( p ) = D( p ) / CS
00458                                           D( q ) = D( q )*CS
00459                                           IF( RSVEC ) THEN
00460                                              CALL SAXPY( MVL, T*APOAQ,
00461      $                                                   V( 1, p ), 1,
00462      $                                                   V( 1, q ), 1 )
00463                                              CALL SAXPY( MVL,
00464      $                                                   -CS*SN*AQOAP,
00465      $                                                   V( 1, q ), 1,
00466      $                                                   V( 1, p ), 1 )
00467                                           END IF
00468                                        ELSE
00469                                           IF( D( p ).GE.D( q ) ) THEN
00470                                              CALL SAXPY( M, -T*AQOAP,
00471      $                                                   A( 1, q ), 1,
00472      $                                                   A( 1, p ), 1 )
00473                                              CALL SAXPY( M, CS*SN*APOAQ,
00474      $                                                   A( 1, p ), 1,
00475      $                                                   A( 1, q ), 1 )
00476                                              D( p ) = D( p )*CS
00477                                              D( q ) = D( q ) / CS
00478                                              IF( RSVEC ) THEN
00479                                                 CALL SAXPY( MVL,
00480      $                                               -T*AQOAP,
00481      $                                               V( 1, q ), 1,
00482      $                                               V( 1, p ), 1 )
00483                                                 CALL SAXPY( MVL,
00484      $                                               CS*SN*APOAQ,
00485      $                                               V( 1, p ), 1,
00486      $                                               V( 1, q ), 1 )
00487                                              END IF
00488                                           ELSE
00489                                              CALL SAXPY( M, T*APOAQ,
00490      $                                                   A( 1, p ), 1,
00491      $                                                   A( 1, q ), 1 )
00492                                              CALL SAXPY( M,
00493      $                                                   -CS*SN*AQOAP,
00494      $                                                   A( 1, q ), 1,
00495      $                                                   A( 1, p ), 1 )
00496                                              D( p ) = D( p ) / CS
00497                                              D( q ) = D( q )*CS
00498                                              IF( RSVEC ) THEN
00499                                                 CALL SAXPY( MVL,
00500      $                                               T*APOAQ, V( 1, p ),
00501      $                                               1, V( 1, q ), 1 )
00502                                                 CALL SAXPY( MVL,
00503      $                                               -CS*SN*AQOAP,
00504      $                                               V( 1, q ), 1,
00505      $                                               V( 1, p ), 1 )
00506                                              END IF
00507                                           END IF
00508                                        END IF
00509                                     END IF
00510                                  END IF
00511 *
00512                               ELSE
00513 *              .. have to use modified Gram-Schmidt like transformation
00514                                  CALL SCOPY( M, A( 1, p ), 1, WORK, 1 )
00515                                  CALL SLASCL( 'G', 0, 0, AAPP, ONE, M,
00516      $                                        1, WORK, LDA, IERR )
00517                                  CALL SLASCL( 'G', 0, 0, AAQQ, ONE, M,
00518      $                                        1, A( 1, q ), LDA, IERR )
00519                                  TEMP1 = -AAPQ*D( p ) / D( q )
00520                                  CALL SAXPY( M, TEMP1, WORK, 1,
00521      $                                       A( 1, q ), 1 )
00522                                  CALL SLASCL( 'G', 0, 0, ONE, AAQQ, M,
00523      $                                        1, A( 1, q ), LDA, IERR )
00524                                  SVA( q ) = AAQQ*SQRT( AMAX1( ZERO,
00525      $                                      ONE-AAPQ*AAPQ ) )
00526                                  MXSINJ = AMAX1( MXSINJ, SFMIN )
00527                               END IF
00528 *           END IF ROTOK THEN ... ELSE
00529 *
00530 *           In the case of cancellation in updating SVA(q), SVA(p)
00531 *           recompute SVA(q), SVA(p).
00532                               IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
00533      $                            THEN
00534                                  IF( ( AAQQ.LT.ROOTBIG ) .AND.
00535      $                               ( AAQQ.GT.ROOTSFMIN ) ) THEN
00536                                     SVA( q ) = SNRM2( M, A( 1, q ), 1 )*
00537      $                                         D( q )
00538                                  ELSE
00539                                     T = ZERO
00540                                     AAQQ = ONE
00541                                     CALL SLASSQ( M, A( 1, q ), 1, T,
00542      $                                           AAQQ )
00543                                     SVA( q ) = T*SQRT( AAQQ )*D( q )
00544                                  END IF
00545                               END IF
00546                               IF( ( AAPP / AAPP0 ).LE.ROOTEPS ) THEN
00547                                  IF( ( AAPP.LT.ROOTBIG ) .AND.
00548      $                               ( AAPP.GT.ROOTSFMIN ) ) THEN
00549                                     AAPP = SNRM2( M, A( 1, p ), 1 )*
00550      $                                     D( p )
00551                                  ELSE
00552                                     T = ZERO
00553                                     AAPP = ONE
00554                                     CALL SLASSQ( M, A( 1, p ), 1, T,
00555      $                                           AAPP )
00556                                     AAPP = T*SQRT( AAPP )*D( p )
00557                                  END IF
00558                                  SVA( p ) = AAPP
00559                               END IF
00560 *
00561                            ELSE
00562 *        A(:,p) and A(:,q) already numerically orthogonal
00563                               IF( ir1.EQ.0 )NOTROT = NOTROT + 1
00564                               PSKIPPED = PSKIPPED + 1
00565                            END IF
00566                         ELSE
00567 *        A(:,q) is zero column
00568                            IF( ir1.EQ.0 )NOTROT = NOTROT + 1
00569                            PSKIPPED = PSKIPPED + 1
00570                         END IF
00571 *
00572                         IF( ( i.LE.SWBAND ) .AND.
00573      $                      ( PSKIPPED.GT.ROWSKIP ) ) THEN
00574                            IF( ir1.EQ.0 )AAPP = -AAPP
00575                            NOTROT = 0
00576                            GO TO 2103
00577                         END IF
00578 *
00579  2002                CONTINUE
00580 *     END q-LOOP
00581 *
00582  2103                CONTINUE
00583 *     bailed out of q-loop
00584 
00585                      SVA( p ) = AAPP
00586 
00587                   ELSE
00588                      SVA( p ) = AAPP
00589                      IF( ( ir1.EQ.0 ) .AND. ( AAPP.EQ.ZERO ) )
00590      $                   NOTROT = NOTROT + MIN0( igl+KBL-1, N ) - p
00591                   END IF
00592 *
00593  2001          CONTINUE
00594 *     end of the p-loop
00595 *     end of doing the block ( ibr, ibr )
00596  1002       CONTINUE
00597 *     end of ir1-loop
00598 *
00599 *........................................................
00600 * ... go to the off diagonal blocks
00601 *
00602             igl = ( ibr-1 )*KBL + 1
00603 *
00604             DO 2010 jbc = ibr + 1, NBL
00605 *
00606                jgl = ( jbc-1 )*KBL + 1
00607 *
00608 *        doing the block at ( ibr, jbc )
00609 *
00610                IJBLSK = 0
00611                DO 2100 p = igl, MIN0( igl+KBL-1, N )
00612 *
00613                   AAPP = SVA( p )
00614 *
00615                   IF( AAPP.GT.ZERO ) THEN
00616 *
00617                      PSKIPPED = 0
00618 *
00619                      DO 2200 q = jgl, MIN0( jgl+KBL-1, N )
00620 *
00621                         AAQQ = SVA( q )
00622 *
00623                         IF( AAQQ.GT.ZERO ) THEN
00624                            AAPP0 = AAPP
00625 *
00626 *     .. M x 2 Jacobi SVD ..
00627 *
00628 *        .. Safe Gram matrix computation ..
00629 *
00630                            IF( AAQQ.GE.ONE ) THEN
00631                               IF( AAPP.GE.AAQQ ) THEN
00632                                  ROTOK = ( SMALL*AAPP ).LE.AAQQ
00633                               ELSE
00634                                  ROTOK = ( SMALL*AAQQ ).LE.AAPP
00635                               END IF
00636                               IF( AAPP.LT.( BIG / AAQQ ) ) THEN
00637                                  AAPQ = ( SDOT( M, A( 1, p ), 1, A( 1,
00638      $                                  q ), 1 )*D( p )*D( q ) / AAQQ )
00639      $                                  / AAPP
00640                               ELSE
00641                                  CALL SCOPY( M, A( 1, p ), 1, WORK, 1 )
00642                                  CALL SLASCL( 'G', 0, 0, AAPP, D( p ),
00643      $                                        M, 1, WORK, LDA, IERR )
00644                                  AAPQ = SDOT( M, WORK, 1, A( 1, q ),
00645      $                                  1 )*D( q ) / AAQQ
00646                               END IF
00647                            ELSE
00648                               IF( AAPP.GE.AAQQ ) THEN
00649                                  ROTOK = AAPP.LE.( AAQQ / SMALL )
00650                               ELSE
00651                                  ROTOK = AAQQ.LE.( AAPP / SMALL )
00652                               END IF
00653                               IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
00654                                  AAPQ = ( SDOT( M, A( 1, p ), 1, A( 1,
00655      $                                  q ), 1 )*D( p )*D( q ) / AAQQ )
00656      $                                  / AAPP
00657                               ELSE
00658                                  CALL SCOPY( M, A( 1, q ), 1, WORK, 1 )
00659                                  CALL SLASCL( 'G', 0, 0, AAQQ, D( q ),
00660      $                                        M, 1, WORK, LDA, IERR )
00661                                  AAPQ = SDOT( M, WORK, 1, A( 1, p ),
00662      $                                  1 )*D( p ) / AAPP
00663                               END IF
00664                            END IF
00665 *
00666                            MXAAPQ = AMAX1( MXAAPQ, ABS( AAPQ ) )
00667 *
00668 *        TO rotate or NOT to rotate, THAT is the question ...
00669 *
00670                            IF( ABS( AAPQ ).GT.TOL ) THEN
00671                               NOTROT = 0
00672 *           ROTATED  = ROTATED + 1
00673                               PSKIPPED = 0
00674                               ISWROT = ISWROT + 1
00675 *
00676                               IF( ROTOK ) THEN
00677 *
00678                                  AQOAP = AAQQ / AAPP
00679                                  APOAQ = AAPP / AAQQ
00680                                  THETA = -HALF*ABS( AQOAP-APOAQ ) / AAPQ
00681                                  IF( AAQQ.GT.AAPP0 )THETA = -THETA
00682 *
00683                                  IF( ABS( THETA ).GT.BIGTHETA ) THEN
00684                                     T = HALF / THETA
00685                                     FASTR( 3 ) = T*D( p ) / D( q )
00686                                     FASTR( 4 ) = -T*D( q ) / D( p )
00687                                     CALL SROTM( M, A( 1, p ), 1,
00688      $                                          A( 1, q ), 1, FASTR )
00689                                     IF( RSVEC )CALL SROTM( MVL,
00690      $                                              V( 1, p ), 1,
00691      $                                              V( 1, q ), 1,
00692      $                                              FASTR )
00693                                     SVA( q ) = AAQQ*SQRT( AMAX1( ZERO,
00694      $                                         ONE+T*APOAQ*AAPQ ) )
00695                                     AAPP = AAPP*SQRT( AMAX1( ZERO,
00696      $                                     ONE-T*AQOAP*AAPQ ) )
00697                                     MXSINJ = AMAX1( MXSINJ, ABS( T ) )
00698                                  ELSE
00699 *
00700 *                 .. choose correct signum for THETA and rotate
00701 *
00702                                     THSIGN = -SIGN( ONE, AAPQ )
00703                                     IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
00704                                     T = ONE / ( THETA+THSIGN*
00705      $                                  SQRT( ONE+THETA*THETA ) )
00706                                     CS = SQRT( ONE / ( ONE+T*T ) )
00707                                     SN = T*CS
00708                                     MXSINJ = AMAX1( MXSINJ, ABS( SN ) )
00709                                     SVA( q ) = AAQQ*SQRT( AMAX1( ZERO,
00710      $                                         ONE+T*APOAQ*AAPQ ) )
00711                                     AAPP = AAPP*SQRT( AMAX1( ZERO, 
00712      $                                         ONE-T*AQOAP*AAPQ ) )
00713 *
00714                                     APOAQ = D( p ) / D( q )
00715                                     AQOAP = D( q ) / D( p )
00716                                     IF( D( p ).GE.ONE ) THEN
00717 *
00718                                        IF( D( q ).GE.ONE ) THEN
00719                                           FASTR( 3 ) = T*APOAQ
00720                                           FASTR( 4 ) = -T*AQOAP
00721                                           D( p ) = D( p )*CS
00722                                           D( q ) = D( q )*CS
00723                                           CALL SROTM( M, A( 1, p ), 1,
00724      $                                                A( 1, q ), 1,
00725      $                                                FASTR )
00726                                           IF( RSVEC )CALL SROTM( MVL,
00727      $                                        V( 1, p ), 1, V( 1, q ),
00728      $                                        1, FASTR )
00729                                        ELSE
00730                                           CALL SAXPY( M, -T*AQOAP,
00731      $                                                A( 1, q ), 1,
00732      $                                                A( 1, p ), 1 )
00733                                           CALL SAXPY( M, CS*SN*APOAQ,
00734      $                                                A( 1, p ), 1,
00735      $                                                A( 1, q ), 1 )
00736                                           IF( RSVEC ) THEN
00737                                              CALL SAXPY( MVL, -T*AQOAP,
00738      $                                                   V( 1, q ), 1,
00739      $                                                   V( 1, p ), 1 )
00740                                              CALL SAXPY( MVL,
00741      $                                                   CS*SN*APOAQ,
00742      $                                                   V( 1, p ), 1,
00743      $                                                   V( 1, q ), 1 )
00744                                           END IF
00745                                           D( p ) = D( p )*CS
00746                                           D( q ) = D( q ) / CS
00747                                        END IF
00748                                     ELSE
00749                                        IF( D( q ).GE.ONE ) THEN
00750                                           CALL SAXPY( M, T*APOAQ,
00751      $                                                A( 1, p ), 1,
00752      $                                                A( 1, q ), 1 )
00753                                           CALL SAXPY( M, -CS*SN*AQOAP,
00754      $                                                A( 1, q ), 1,
00755      $                                                A( 1, p ), 1 )
00756                                           IF( RSVEC ) THEN
00757                                              CALL SAXPY( MVL, T*APOAQ,
00758      $                                                   V( 1, p ), 1,
00759      $                                                   V( 1, q ), 1 )
00760                                              CALL SAXPY( MVL,
00761      $                                                   -CS*SN*AQOAP,
00762      $                                                   V( 1, q ), 1,
00763      $                                                   V( 1, p ), 1 )
00764                                           END IF
00765                                           D( p ) = D( p ) / CS
00766                                           D( q ) = D( q )*CS
00767                                        ELSE
00768                                           IF( D( p ).GE.D( q ) ) THEN
00769                                              CALL SAXPY( M, -T*AQOAP,
00770      $                                                   A( 1, q ), 1,
00771      $                                                   A( 1, p ), 1 )
00772                                              CALL SAXPY( M, CS*SN*APOAQ,
00773      $                                                   A( 1, p ), 1,
00774      $                                                   A( 1, q ), 1 )
00775                                              D( p ) = D( p )*CS
00776                                              D( q ) = D( q ) / CS
00777                                              IF( RSVEC ) THEN
00778                                                 CALL SAXPY( MVL,
00779      $                                               -T*AQOAP,
00780      $                                               V( 1, q ), 1,
00781      $                                               V( 1, p ), 1 )
00782                                                 CALL SAXPY( MVL,
00783      $                                               CS*SN*APOAQ,
00784      $                                               V( 1, p ), 1,
00785      $                                               V( 1, q ), 1 )
00786                                              END IF
00787                                           ELSE
00788                                              CALL SAXPY( M, T*APOAQ,
00789      $                                                   A( 1, p ), 1,
00790      $                                                   A( 1, q ), 1 )
00791                                              CALL SAXPY( M,
00792      $                                                   -CS*SN*AQOAP,
00793      $                                                   A( 1, q ), 1,
00794      $                                                   A( 1, p ), 1 )
00795                                              D( p ) = D( p ) / CS
00796                                              D( q ) = D( q )*CS
00797                                              IF( RSVEC ) THEN
00798                                                 CALL SAXPY( MVL,
00799      $                                               T*APOAQ, V( 1, p ),
00800      $                                               1, V( 1, q ), 1 )
00801                                                 CALL SAXPY( MVL,
00802      $                                               -CS*SN*AQOAP,
00803      $                                               V( 1, q ), 1,
00804      $                                               V( 1, p ), 1 )
00805                                              END IF
00806                                           END IF
00807                                        END IF
00808                                     END IF
00809                                  END IF
00810 *
00811                               ELSE
00812                                  IF( AAPP.GT.AAQQ ) THEN
00813                                     CALL SCOPY( M, A( 1, p ), 1, WORK,
00814      $                                          1 )
00815                                     CALL SLASCL( 'G', 0, 0, AAPP, ONE,
00816      $                                           M, 1, WORK, LDA, IERR )
00817                                     CALL SLASCL( 'G', 0, 0, AAQQ, ONE,
00818      $                                           M, 1, A( 1, q ), LDA,
00819      $                                           IERR )
00820                                     TEMP1 = -AAPQ*D( p ) / D( q )
00821                                     CALL SAXPY( M, TEMP1, WORK, 1,
00822      $                                          A( 1, q ), 1 )
00823                                     CALL SLASCL( 'G', 0, 0, ONE, AAQQ,
00824      $                                           M, 1, A( 1, q ), LDA,
00825      $                                           IERR )
00826                                     SVA( q ) = AAQQ*SQRT( AMAX1( ZERO,
00827      $                                         ONE-AAPQ*AAPQ ) )
00828                                     MXSINJ = AMAX1( MXSINJ, SFMIN )
00829                                  ELSE
00830                                     CALL SCOPY( M, A( 1, q ), 1, WORK,
00831      $                                          1 )
00832                                     CALL SLASCL( 'G', 0, 0, AAQQ, ONE,
00833      $                                           M, 1, WORK, LDA, IERR )
00834                                     CALL SLASCL( 'G', 0, 0, AAPP, ONE,
00835      $                                           M, 1, A( 1, p ), LDA,
00836      $                                           IERR )
00837                                     TEMP1 = -AAPQ*D( q ) / D( p )
00838                                     CALL SAXPY( M, TEMP1, WORK, 1,
00839      $                                          A( 1, p ), 1 )
00840                                     CALL SLASCL( 'G', 0, 0, ONE, AAPP,
00841      $                                           M, 1, A( 1, p ), LDA,
00842      $                                           IERR )
00843                                     SVA( p ) = AAPP*SQRT( AMAX1( ZERO,
00844      $                                         ONE-AAPQ*AAPQ ) )
00845                                     MXSINJ = AMAX1( MXSINJ, SFMIN )
00846                                  END IF
00847                               END IF
00848 *           END IF ROTOK THEN ... ELSE
00849 *
00850 *           In the case of cancellation in updating SVA(q)
00851 *           .. recompute SVA(q)
00852                               IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
00853      $                            THEN
00854                                  IF( ( AAQQ.LT.ROOTBIG ) .AND.
00855      $                               ( AAQQ.GT.ROOTSFMIN ) ) THEN
00856                                     SVA( q ) = SNRM2( M, A( 1, q ), 1 )*
00857      $                                         D( q )
00858                                  ELSE
00859                                     T = ZERO
00860                                     AAQQ = ONE
00861                                     CALL SLASSQ( M, A( 1, q ), 1, T,
00862      $                                           AAQQ )
00863                                     SVA( q ) = T*SQRT( AAQQ )*D( q )
00864                                  END IF
00865                               END IF
00866                               IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
00867                                  IF( ( AAPP.LT.ROOTBIG ) .AND.
00868      $                               ( AAPP.GT.ROOTSFMIN ) ) THEN
00869                                     AAPP = SNRM2( M, A( 1, p ), 1 )*
00870      $                                     D( p )
00871                                  ELSE
00872                                     T = ZERO
00873                                     AAPP = ONE
00874                                     CALL SLASSQ( M, A( 1, p ), 1, T,
00875      $                                           AAPP )
00876                                     AAPP = T*SQRT( AAPP )*D( p )
00877                                  END IF
00878                                  SVA( p ) = AAPP
00879                               END IF
00880 *              end of OK rotation
00881                            ELSE
00882                               NOTROT = NOTROT + 1
00883                               PSKIPPED = PSKIPPED + 1
00884                               IJBLSK = IJBLSK + 1
00885                            END IF
00886                         ELSE
00887                            NOTROT = NOTROT + 1
00888                            PSKIPPED = PSKIPPED + 1
00889                            IJBLSK = IJBLSK + 1
00890                         END IF
00891 *
00892                         IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
00893      $                      THEN
00894                            SVA( p ) = AAPP
00895                            NOTROT = 0
00896                            GO TO 2011
00897                         END IF
00898                         IF( ( i.LE.SWBAND ) .AND.
00899      $                      ( PSKIPPED.GT.ROWSKIP ) ) THEN
00900                            AAPP = -AAPP
00901                            NOTROT = 0
00902                            GO TO 2203
00903                         END IF
00904 *
00905  2200                CONTINUE
00906 *        end of the q-loop
00907  2203                CONTINUE
00908 *
00909                      SVA( p ) = AAPP
00910 *
00911                   ELSE
00912                      IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
00913      $                   MIN0( jgl+KBL-1, N ) - jgl + 1
00914                      IF( AAPP.LT.ZERO )NOTROT = 0
00915                   END IF
00916 
00917  2100          CONTINUE
00918 *     end of the p-loop
00919  2010       CONTINUE
00920 *     end of the jbc-loop
00921  2011       CONTINUE
00922 *2011 bailed out of the jbc-loop
00923             DO 2012 p = igl, MIN0( igl+KBL-1, N )
00924                SVA( p ) = ABS( SVA( p ) )
00925  2012       CONTINUE
00926 *
00927  2000    CONTINUE
00928 *2000 :: end of the ibr-loop
00929 *
00930 *     .. update SVA(N)
00931          IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
00932      $       THEN
00933             SVA( N ) = SNRM2( M, A( 1, N ), 1 )*D( N )
00934          ELSE
00935             T = ZERO
00936             AAPP = ONE
00937             CALL SLASSQ( M, A( 1, N ), 1, T, AAPP )
00938             SVA( N ) = T*SQRT( AAPP )*D( N )
00939          END IF
00940 *
00941 *     Additional steering devices
00942 *
00943          IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
00944      $       ( ISWROT.LE.N ) ) )SWBAND = i
00945 *
00946          IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.FLOAT( N )*TOL ) .AND.
00947      $       ( FLOAT( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
00948             GO TO 1994
00949          END IF
00950 *
00951          IF( NOTROT.GE.EMPTSW )GO TO 1994
00952 
00953  1993 CONTINUE
00954 *     end i=1:NSWEEP loop
00955 * #:) Reaching this point means that the procedure has comleted the given
00956 *     number of iterations.
00957       INFO = NSWEEP - 1
00958       GO TO 1995
00959  1994 CONTINUE
00960 * #:) Reaching this point means that during the i-th sweep all pivots were
00961 *     below the given tolerance, causing early exit.
00962 *
00963       INFO = 0
00964 * #:) INFO = 0 confirms successful iterations.
00965  1995 CONTINUE
00966 *
00967 *     Sort the vector D.
00968       DO 5991 p = 1, N - 1
00969          q = ISAMAX( N-p+1, SVA( p ), 1 ) + p - 1
00970          IF( p.NE.q ) THEN
00971             TEMP1 = SVA( p )
00972             SVA( p ) = SVA( q )
00973             SVA( q ) = TEMP1
00974             TEMP1 = D( p )
00975             D( p ) = D( q )
00976             D( q ) = TEMP1
00977             CALL SSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
00978             IF( RSVEC )CALL SSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
00979          END IF
00980  5991 CONTINUE
00981 *
00982       RETURN
00983 *     ..
00984 *     .. END OF SGSVJ0
00985 *     ..
00986       END
 All Files Functions