LAPACK 3.3.1 Linear Algebra PACKage

# sgqrts.f

Go to the documentation of this file.
```00001       SUBROUTINE SGQRTS( N, M, P, A, AF, Q, R, LDA, TAUA, B, BF, Z, T,
00002      \$                   BWK, LDB, TAUB, WORK, LWORK, RWORK, RESULT )
00003 *
00004 *  -- LAPACK test routine (version 3.1) --
00005 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
00006 *     November 2006
00007 *
00008 *     .. Scalar Arguments ..
00009       INTEGER            LDA, LDB, LWORK, M, P, N
00010 *     ..
00011 *     .. Array Arguments ..
00012       REAL               A( LDA, * ), AF( LDA, * ), R( LDA, * ),
00013      \$                   Q( LDA, * ), B( LDB, * ), BF( LDB, * ),
00014      \$                   T( LDB, * ), Z( LDB, * ), BWK( LDB, * ),
00015      \$                   TAUA( * ), TAUB( * ), RESULT( 4 ),
00016      \$                   RWORK( * ), WORK( LWORK )
00017 *     ..
00018 *
00019 *  Purpose
00020 *  =======
00021 *
00022 *  SGQRTS tests SGGQRF, which computes the GQR factorization of an
00023 *  N-by-M matrix A and a N-by-P matrix B: A = Q*R and B = Q*T*Z.
00024 *
00025 *  Arguments
00026 *  =========
00027 *
00028 *  N       (input) INTEGER
00029 *          The number of rows of the matrices A and B.  N >= 0.
00030 *
00031 *  M       (input) INTEGER
00032 *          The number of columns of the matrix A.  M >= 0.
00033 *
00034 *  P       (input) INTEGER
00035 *          The number of columns of the matrix B.  P >= 0.
00036 *
00037 *  A       (input) REAL array, dimension (LDA,M)
00038 *          The N-by-M matrix A.
00039 *
00040 *  AF      (output) REAL array, dimension (LDA,N)
00041 *          Details of the GQR factorization of A and B, as returned
00042 *          by SGGQRF, see SGGQRF for further details.
00043 *
00044 *  Q       (output) REAL array, dimension (LDA,N)
00045 *          The M-by-M orthogonal matrix Q.
00046 *
00047 *  R       (workspace) REAL array, dimension (LDA,MAX(M,N))
00048 *
00049 *  LDA     (input) INTEGER
00050 *          The leading dimension of the arrays A, AF, R and Q.
00051 *          LDA >= max(M,N).
00052 *
00053 *  TAUA    (output) REAL array, dimension (min(M,N))
00054 *          The scalar factors of the elementary reflectors, as returned
00055 *          by SGGQRF.
00056 *
00057 *  B       (input) REAL array, dimension (LDB,P)
00058 *          On entry, the N-by-P matrix A.
00059 *
00060 *  BF      (output) REAL array, dimension (LDB,N)
00061 *          Details of the GQR factorization of A and B, as returned
00062 *          by SGGQRF, see SGGQRF for further details.
00063 *
00064 *  Z       (output) REAL array, dimension (LDB,P)
00065 *          The P-by-P orthogonal matrix Z.
00066 *
00067 *  T       (workspace) REAL array, dimension (LDB,max(P,N))
00068 *
00069 *  BWK     (workspace) REAL array, dimension (LDB,N)
00070 *
00071 *  LDB     (input) INTEGER
00072 *          The leading dimension of the arrays B, BF, Z and T.
00073 *          LDB >= max(P,N).
00074 *
00075 *  TAUB    (output) REAL array, dimension (min(P,N))
00076 *          The scalar factors of the elementary reflectors, as returned
00077 *          by SGGRQF.
00078 *
00079 *  WORK    (workspace) REAL array, dimension (LWORK)
00080 *
00081 *  LWORK   (input) INTEGER
00082 *          The dimension of the array WORK, LWORK >= max(N,M,P)**2.
00083 *
00084 *  RWORK   (workspace) REAL array, dimension (max(N,M,P))
00085 *
00086 *  RESULT  (output) REAL array, dimension (4)
00087 *          The test ratios:
00088 *            RESULT(1) = norm( R - Q'*A ) / ( MAX(M,N)*norm(A)*ULP)
00089 *            RESULT(2) = norm( T*Z - Q'*B ) / (MAX(P,N)*norm(B)*ULP)
00090 *            RESULT(3) = norm( I - Q'*Q ) / ( M*ULP )
00091 *            RESULT(4) = norm( I - Z'*Z ) / ( P*ULP )
00092 *
00093 *  =====================================================================
00094 *
00095 *     .. Parameters ..
00096       REAL               ZERO, ONE
00097       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
00098       REAL               ROGUE
00099       PARAMETER          ( ROGUE = -1.0E+10 )
00100 *     ..
00101 *     .. Local Scalars ..
00102       INTEGER            INFO
00103       REAL               ANORM, BNORM, ULP, UNFL, RESID
00104 *     ..
00105 *     .. External Functions ..
00106       REAL               SLAMCH, SLANGE, SLANSY
00107       EXTERNAL           SLAMCH, SLANGE, SLANSY
00108 *     ..
00109 *     .. External Subroutines ..
00110       EXTERNAL           SGEMM, SLACPY, SLASET, SORGQR,
00111      \$                   SORGRQ, SSYRK
00112 *     ..
00113 *     .. Intrinsic Functions ..
00114       INTRINSIC          MAX, MIN, REAL
00115 *     ..
00116 *     .. Executable Statements ..
00117 *
00118       ULP = SLAMCH( 'Precision' )
00119       UNFL = SLAMCH( 'Safe minimum' )
00120 *
00121 *     Copy the matrix A to the array AF.
00122 *
00123       CALL SLACPY( 'Full', N, M, A, LDA, AF, LDA )
00124       CALL SLACPY( 'Full', N, P, B, LDB, BF, LDB )
00125 *
00126       ANORM = MAX( SLANGE( '1', N, M, A, LDA, RWORK ), UNFL )
00127       BNORM = MAX( SLANGE( '1', N, P, B, LDB, RWORK ), UNFL )
00128 *
00129 *     Factorize the matrices A and B in the arrays AF and BF.
00130 *
00131       CALL SGGQRF( N, M, P, AF, LDA, TAUA, BF, LDB, TAUB, WORK,
00132      \$             LWORK, INFO )
00133 *
00134 *     Generate the N-by-N matrix Q
00135 *
00136       CALL SLASET( 'Full', N, N, ROGUE, ROGUE, Q, LDA )
00137       CALL SLACPY( 'Lower', N-1, M, AF( 2,1 ), LDA, Q( 2,1 ), LDA )
00138       CALL SORGQR( N, N, MIN( N, M ), Q, LDA, TAUA, WORK, LWORK, INFO )
00139 *
00140 *     Generate the P-by-P matrix Z
00141 *
00142       CALL SLASET( 'Full', P, P, ROGUE, ROGUE, Z, LDB )
00143       IF( N.LE.P ) THEN
00144          IF( N.GT.0 .AND. N.LT.P )
00145      \$      CALL SLACPY( 'Full', N, P-N, BF, LDB, Z( P-N+1, 1 ), LDB )
00146          IF( N.GT.1 )
00147      \$      CALL SLACPY( 'Lower', N-1, N-1, BF( 2, P-N+1 ), LDB,
00148      \$                    Z( P-N+2, P-N+1 ), LDB )
00149       ELSE
00150          IF( P.GT.1)
00151      \$      CALL SLACPY( 'Lower', P-1, P-1, BF( N-P+2, 1 ), LDB,
00152      \$                    Z( 2, 1 ), LDB )
00153       END IF
00154       CALL SORGRQ( P, P, MIN( N, P ), Z, LDB, TAUB, WORK, LWORK, INFO )
00155 *
00156 *     Copy R
00157 *
00158       CALL SLASET( 'Full', N, M, ZERO, ZERO, R, LDA )
00159       CALL SLACPY( 'Upper', N, M, AF, LDA, R, LDA )
00160 *
00161 *     Copy T
00162 *
00163       CALL SLASET( 'Full', N, P, ZERO, ZERO, T, LDB )
00164       IF( N.LE.P ) THEN
00165          CALL SLACPY( 'Upper', N, N, BF( 1, P-N+1 ), LDB, T( 1, P-N+1 ),
00166      \$                LDB )
00167       ELSE
00168          CALL SLACPY( 'Full', N-P, P, BF, LDB, T, LDB )
00169          CALL SLACPY( 'Upper', P, P, BF( N-P+1, 1 ), LDB, T( N-P+1, 1 ),
00170      \$                LDB )
00171       END IF
00172 *
00173 *     Compute R - Q'*A
00174 *
00175       CALL SGEMM( 'Transpose', 'No transpose', N, M, N, -ONE, Q, LDA, A,
00176      \$            LDA, ONE, R, LDA )
00177 *
00178 *     Compute norm( R - Q'*A ) / ( MAX(M,N)*norm(A)*ULP ) .
00179 *
00180       RESID = SLANGE( '1', N, M, R, LDA, RWORK )
00181       IF( ANORM.GT.ZERO ) THEN
00182          RESULT( 1 ) = ( ( RESID / REAL( MAX(1,M,N) ) ) / ANORM ) / ULP
00183       ELSE
00184          RESULT( 1 ) = ZERO
00185       END IF
00186 *
00187 *     Compute T*Z - Q'*B
00188 *
00189       CALL SGEMM( 'No Transpose', 'No transpose', N, P, P, ONE, T, LDB,
00190      \$            Z, LDB, ZERO, BWK, LDB )
00191       CALL SGEMM( 'Transpose', 'No transpose', N, P, N, -ONE, Q, LDA,
00192      \$            B, LDB, ONE, BWK, LDB )
00193 *
00194 *     Compute norm( T*Z - Q'*B ) / ( MAX(P,N)*norm(A)*ULP ) .
00195 *
00196       RESID = SLANGE( '1', N, P, BWK, LDB, RWORK )
00197       IF( BNORM.GT.ZERO ) THEN
00198          RESULT( 2 ) = ( ( RESID / REAL( MAX(1,P,N ) ) )/BNORM ) / ULP
00199       ELSE
00200          RESULT( 2 ) = ZERO
00201       END IF
00202 *
00203 *     Compute I - Q'*Q
00204 *
00205       CALL SLASET( 'Full', N, N, ZERO, ONE, R, LDA )
00206       CALL SSYRK( 'Upper', 'Transpose', N, N, -ONE, Q, LDA, ONE, R,
00207      \$            LDA )
00208 *
00209 *     Compute norm( I - Q'*Q ) / ( N * ULP ) .
00210 *
00211       RESID = SLANSY( '1', 'Upper', N, R, LDA, RWORK )
00212       RESULT( 3 ) = ( RESID / REAL( MAX( 1, N ) ) ) / ULP
00213 *
00214 *     Compute I - Z'*Z
00215 *
00216       CALL SLASET( 'Full', P, P, ZERO, ONE, T, LDB )
00217       CALL SSYRK( 'Upper', 'Transpose', P, P, -ONE, Z, LDB, ONE, T,
00218      \$            LDB )
00219 *
00220 *     Compute norm( I - Z'*Z ) / ( P*ULP ) .
00221 *
00222       RESID = SLANSY( '1', 'Upper', P, T, LDB, RWORK )
00223       RESULT( 4 ) = ( RESID / REAL( MAX( 1, P ) ) ) / ULP
00224 *
00225       RETURN
00226 *
00227 *     End of SGQRTS
00228 *
00229       END
```