LAPACK 3.3.1 Linear Algebra PACKage

# dgqrts.f

Go to the documentation of this file.
```00001       SUBROUTINE DGQRTS( 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, N, P
00010 *     ..
00011 *     .. Array Arguments ..
00012       DOUBLE PRECISION   A( LDA, * ), AF( LDA, * ), B( LDB, * ),
00013      \$                   BF( LDB, * ), BWK( LDB, * ), Q( LDA, * ),
00014      \$                   R( LDA, * ), RESULT( 4 ), RWORK( * ),
00015      \$                   T( LDB, * ), TAUA( * ), TAUB( * ),
00016      \$                   WORK( LWORK ), Z( LDB, * )
00017 *     ..
00018 *
00019 *  Purpose
00020 *  =======
00021 *
00022 *  DGQRTS tests DGGQRF, 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) DOUBLE PRECISION array, dimension (LDA,M)
00038 *          The N-by-M matrix A.
00039 *
00040 *  AF      (output) DOUBLE PRECISION array, dimension (LDA,N)
00041 *          Details of the GQR factorization of A and B, as returned
00042 *          by DGGQRF, see SGGQRF for further details.
00043 *
00044 *  Q       (output) DOUBLE PRECISION array, dimension (LDA,N)
00045 *          The M-by-M orthogonal matrix Q.
00046 *
00047 *  R       (workspace) DOUBLE PRECISION 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) DOUBLE PRECISION array, dimension (min(M,N))
00054 *          The scalar factors of the elementary reflectors, as returned
00055 *          by DGGQRF.
00056 *
00057 *  B       (input) DOUBLE PRECISION array, dimension (LDB,P)
00058 *          On entry, the N-by-P matrix A.
00059 *
00060 *  BF      (output) DOUBLE PRECISION array, dimension (LDB,N)
00061 *          Details of the GQR factorization of A and B, as returned
00062 *          by DGGQRF, see SGGQRF for further details.
00063 *
00064 *  Z       (output) DOUBLE PRECISION array, dimension (LDB,P)
00065 *          The P-by-P orthogonal matrix Z.
00066 *
00067 *  T       (workspace) DOUBLE PRECISION array, dimension (LDB,max(P,N))
00068 *
00069 *  BWK     (workspace) DOUBLE PRECISION 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) DOUBLE PRECISION array, dimension (min(P,N))
00076 *          The scalar factors of the elementary reflectors, as returned
00077 *          by DGGRQF.
00078 *
00079 *  WORK    (workspace) DOUBLE PRECISION 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) DOUBLE PRECISION array, dimension (max(N,M,P))
00085 *
00086 *  RESULT  (output) DOUBLE PRECISION 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       DOUBLE PRECISION   ZERO, ONE
00097       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00098       DOUBLE PRECISION   ROGUE
00099       PARAMETER          ( ROGUE = -1.0D+10 )
00100 *     ..
00101 *     .. Local Scalars ..
00102       INTEGER            INFO
00103       DOUBLE PRECISION   ANORM, BNORM, RESID, ULP, UNFL
00104 *     ..
00105 *     .. External Functions ..
00106       DOUBLE PRECISION   DLAMCH, DLANGE, DLANSY
00107       EXTERNAL           DLAMCH, DLANGE, DLANSY
00108 *     ..
00109 *     .. External Subroutines ..
00110       EXTERNAL           DGEMM, DGGQRF, DLACPY, DLASET, DORGQR, DORGRQ,
00111      \$                   DSYRK
00112 *     ..
00113 *     .. Intrinsic Functions ..
00114       INTRINSIC          DBLE, MAX, MIN
00115 *     ..
00116 *     .. Executable Statements ..
00117 *
00118       ULP = DLAMCH( 'Precision' )
00119       UNFL = DLAMCH( 'Safe minimum' )
00120 *
00121 *     Copy the matrix A to the array AF.
00122 *
00123       CALL DLACPY( 'Full', N, M, A, LDA, AF, LDA )
00124       CALL DLACPY( 'Full', N, P, B, LDB, BF, LDB )
00125 *
00126       ANORM = MAX( DLANGE( '1', N, M, A, LDA, RWORK ), UNFL )
00127       BNORM = MAX( DLANGE( '1', N, P, B, LDB, RWORK ), UNFL )
00128 *
00129 *     Factorize the matrices A and B in the arrays AF and BF.
00130 *
00131       CALL DGGQRF( N, M, P, AF, LDA, TAUA, BF, LDB, TAUB, WORK, LWORK,
00132      \$             INFO )
00133 *
00134 *     Generate the N-by-N matrix Q
00135 *
00136       CALL DLASET( 'Full', N, N, ROGUE, ROGUE, Q, LDA )
00137       CALL DLACPY( 'Lower', N-1, M, AF( 2, 1 ), LDA, Q( 2, 1 ), LDA )
00138       CALL DORGQR( N, N, MIN( N, M ), Q, LDA, TAUA, WORK, LWORK, INFO )
00139 *
00140 *     Generate the P-by-P matrix Z
00141 *
00142       CALL DLASET( 'Full', P, P, ROGUE, ROGUE, Z, LDB )
00143       IF( N.LE.P ) THEN
00144          IF( N.GT.0 .AND. N.LT.P )
00145      \$      CALL DLACPY( 'Full', N, P-N, BF, LDB, Z( P-N+1, 1 ), LDB )
00146          IF( N.GT.1 )
00147      \$      CALL DLACPY( '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 DLACPY( 'Lower', P-1, P-1, BF( N-P+2, 1 ), LDB,
00152      \$                   Z( 2, 1 ), LDB )
00153       END IF
00154       CALL DORGRQ( P, P, MIN( N, P ), Z, LDB, TAUB, WORK, LWORK, INFO )
00155 *
00156 *     Copy R
00157 *
00158       CALL DLASET( 'Full', N, M, ZERO, ZERO, R, LDA )
00159       CALL DLACPY( 'Upper', N, M, AF, LDA, R, LDA )
00160 *
00161 *     Copy T
00162 *
00163       CALL DLASET( 'Full', N, P, ZERO, ZERO, T, LDB )
00164       IF( N.LE.P ) THEN
00165          CALL DLACPY( 'Upper', N, N, BF( 1, P-N+1 ), LDB, T( 1, P-N+1 ),
00166      \$                LDB )
00167       ELSE
00168          CALL DLACPY( 'Full', N-P, P, BF, LDB, T, LDB )
00169          CALL DLACPY( '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 DGEMM( '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 = DLANGE( '1', N, M, R, LDA, RWORK )
00181       IF( ANORM.GT.ZERO ) THEN
00182          RESULT( 1 ) = ( ( RESID / DBLE( MAX( 1, M, N ) ) ) / ANORM ) /
00183      \$                 ULP
00184       ELSE
00185          RESULT( 1 ) = ZERO
00186       END IF
00187 *
00188 *     Compute T*Z - Q'*B
00189 *
00190       CALL DGEMM( 'No Transpose', 'No transpose', N, P, P, ONE, T, LDB,
00191      \$            Z, LDB, ZERO, BWK, LDB )
00192       CALL DGEMM( 'Transpose', 'No transpose', N, P, N, -ONE, Q, LDA, B,
00193      \$            LDB, ONE, BWK, LDB )
00194 *
00195 *     Compute norm( T*Z - Q'*B ) / ( MAX(P,N)*norm(A)*ULP ) .
00196 *
00197       RESID = DLANGE( '1', N, P, BWK, LDB, RWORK )
00198       IF( BNORM.GT.ZERO ) THEN
00199          RESULT( 2 ) = ( ( RESID / DBLE( MAX( 1, P, N ) ) ) / BNORM ) /
00200      \$                 ULP
00201       ELSE
00202          RESULT( 2 ) = ZERO
00203       END IF
00204 *
00205 *     Compute I - Q'*Q
00206 *
00207       CALL DLASET( 'Full', N, N, ZERO, ONE, R, LDA )
00208       CALL DSYRK( 'Upper', 'Transpose', N, N, -ONE, Q, LDA, ONE, R,
00209      \$            LDA )
00210 *
00211 *     Compute norm( I - Q'*Q ) / ( N * ULP ) .
00212 *
00213       RESID = DLANSY( '1', 'Upper', N, R, LDA, RWORK )
00214       RESULT( 3 ) = ( RESID / DBLE( MAX( 1, N ) ) ) / ULP
00215 *
00216 *     Compute I - Z'*Z
00217 *
00218       CALL DLASET( 'Full', P, P, ZERO, ONE, T, LDB )
00219       CALL DSYRK( 'Upper', 'Transpose', P, P, -ONE, Z, LDB, ONE, T,
00220      \$            LDB )
00221 *
00222 *     Compute norm( I - Z'*Z ) / ( P*ULP ) .
00223 *
00224       RESID = DLANSY( '1', 'Upper', P, T, LDB, RWORK )
00225       RESULT( 4 ) = ( RESID / DBLE( MAX( 1, P ) ) ) / ULP
00226 *
00227       RETURN
00228 *
00229 *     End of DGQRTS
00230 *
00231       END
```