numeric-linalg
Educational material on the SciPy implementation of numerical linear algebra algorithms
Name | Size | Mode | |
.. | |||
lapack/TESTING/LIN/dorhr_col01.f | 11575B | -rw-r--r-- |
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
*> \brief \b DORHR_COL01 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE DORHR_COL01( M, N, MB1, NB1, NB2, RESULT ) * * .. Scalar Arguments .. * INTEGER M, N, MB1, NB1, NB2 * .. Return values .. * DOUBLE PRECISION RESULT(6) * * *> \par Purpose: * ============= *> *> \verbatim *> *> DORHR_COL01 tests DORGTSQR and DORHR_COL using DLATSQR, DGEMQRT. *> Therefore, DLATSQR (part of DGEQR), DGEMQRT (part of DGEMQR) *> have to be tested before this test. *> *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> Number of rows in test matrix. *> \endverbatim *> \param[in] N *> \verbatim *> N is INTEGER *> Number of columns in test matrix. *> \endverbatim *> \param[in] MB1 *> \verbatim *> MB1 is INTEGER *> Number of row in row block in an input test matrix. *> \endverbatim *> *> \param[in] NB1 *> \verbatim *> NB1 is INTEGER *> Number of columns in column block an input test matrix. *> \endverbatim *> *> \param[in] NB2 *> \verbatim *> NB2 is INTEGER *> Number of columns in column block in an output test matrix. *> \endverbatim *> *> \param[out] RESULT *> \verbatim *> RESULT is DOUBLE PRECISION array, dimension (6) *> Results of each of the six tests below. *> *> A is a m-by-n test input matrix to be factored. *> so that A = Q_gr * ( R ) *> ( 0 ), *> *> Q_qr is an implicit m-by-m orthogonal Q matrix, the result *> of factorization in blocked WY-representation, *> stored in ZGEQRT output format. *> *> R is a n-by-n upper-triangular matrix, *> *> 0 is a (m-n)-by-n zero matrix, *> *> Q is an explicit m-by-m orthogonal matrix Q = Q_gr * I *> *> C is an m-by-n random matrix, *> *> D is an n-by-m random matrix. *> *> The six tests are: *> *> RESULT(1) = |R - (Q**H) * A| / ( eps * m * |A| ) *> is equivalent to test for | A - Q * R | / (eps * m * |A|), *> *> RESULT(2) = |I - (Q**H) * Q| / ( eps * m ), *> *> RESULT(3) = | Q_qr * C - Q * C | / (eps * m * |C|), *> *> RESULT(4) = | (Q_gr**H) * C - (Q**H) * C | / (eps * m * |C|) *> *> RESULT(5) = | D * Q_qr - D * Q | / (eps * m * |D|) *> *> RESULT(6) = | D * (Q_qr**H) - D * (Q**H) | / (eps * m * |D|), *> *> where: *> Q_qr * C, (Q_gr**H) * C, D * Q_qr, D * (Q_qr**H) are *> computed using DGEMQRT, *> *> Q * C, (Q**H) * C, D * Q, D * (Q**H) are *> computed using DGEMM. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup double_lin * * ===================================================================== SUBROUTINE DORHR_COL01( M, N, MB1, NB1, NB2, RESULT ) IMPLICIT NONE * * -- LAPACK test routine -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * * .. Scalar Arguments .. INTEGER M, N, MB1, NB1, NB2 * .. Return values .. DOUBLE PRECISION RESULT(6) * * ===================================================================== * * .. * .. Local allocatable arrays DOUBLE PRECISION, ALLOCATABLE :: A(:,:), AF(:,:), Q(:,:), R(:,:), $ RWORK(:), WORK( : ), T1(:,:), T2(:,:), DIAG(:), $ C(:,:), CF(:,:), D(:,:), DF(:,:) * * .. Parameters .. DOUBLE PRECISION ONE, ZERO PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) * .. * .. Local Scalars .. LOGICAL TESTZEROS INTEGER INFO, I, J, K, L, LWORK, NB1_UB, NB2_UB, NRB DOUBLE PRECISION ANORM, EPS, RESID, CNORM, DNORM * .. * .. Local Arrays .. INTEGER ISEED( 4 ) DOUBLE PRECISION WORKQUERY( 1 ) * .. * .. External Functions .. DOUBLE PRECISION DLAMCH, DLANGE, DLANSY EXTERNAL DLAMCH, DLANGE, DLANSY * .. * .. External Subroutines .. EXTERNAL DLACPY, DLARNV, DLASET, DLATSQR, DORHR_COL, $ DORGTSQR, DSCAL, DGEMM, DGEMQRT, DSYRK * .. * .. Intrinsic Functions .. INTRINSIC CEILING, DBLE, MAX, MIN * .. * .. Scalars in Common .. CHARACTER(LEN=32) SRNAMT * .. * .. Common blocks .. COMMON / SRMNAMC / SRNAMT * .. * .. Data statements .. DATA ISEED / 1988, 1989, 1990, 1991 / * * TEST MATRICES WITH HALF OF MATRIX BEING ZEROS * TESTZEROS = .FALSE. * EPS = DLAMCH( 'Epsilon' ) K = MIN( M, N ) L = MAX( M, N, 1) * * Dynamically allocate local arrays * ALLOCATE ( A(M,N), AF(M,N), Q(L,L), R(M,L), RWORK(L), $ C(M,N), CF(M,N), $ D(N,M), DF(N,M) ) * * Put random numbers into A and copy to AF * DO J = 1, N CALL DLARNV( 2, ISEED, M, A( 1, J ) ) END DO IF( TESTZEROS ) THEN IF( M.GE.4 ) THEN DO J = 1, N CALL DLARNV( 2, ISEED, M/2, A( M/4, J ) ) END DO END IF END IF CALL DLACPY( 'Full', M, N, A, M, AF, M ) * * Number of row blocks in DLATSQR * NRB = MAX( 1, CEILING( DBLE( M - N ) / DBLE( MB1 - N ) ) ) * ALLOCATE ( T1( NB1, N * NRB ) ) ALLOCATE ( T2( NB2, N ) ) ALLOCATE ( DIAG( N ) ) * * Begin determine LWORK for the array WORK and allocate memory. * * DLATSQR requires NB1 to be bounded by N. * NB1_UB = MIN( NB1, N) * * DGEMQRT requires NB2 to be bounded by N. * NB2_UB = MIN( NB2, N) * CALL DLATSQR( M, N, MB1, NB1_UB, AF, M, T1, NB1, $ WORKQUERY, -1, INFO ) LWORK = INT( WORKQUERY( 1 ) ) CALL DORGTSQR( M, N, MB1, NB1, AF, M, T1, NB1, WORKQUERY, -1, $ INFO ) LWORK = MAX( LWORK, INT( WORKQUERY( 1 ) ) ) * * In DGEMQRT, WORK is N*NB2_UB if SIDE = 'L', * or M*NB2_UB if SIDE = 'R'. * LWORK = MAX( LWORK, NB2_UB * N, NB2_UB * M ) * ALLOCATE ( WORK( LWORK ) ) * * End allocate memory for WORK. * * * Begin Householder reconstruction routines * * Factor the matrix A in the array AF. * SRNAMT = 'DLATSQR' CALL DLATSQR( M, N, MB1, NB1_UB, AF, M, T1, NB1, WORK, LWORK, $ INFO ) * * Copy the factor R into the array R. * SRNAMT = 'DLACPY' CALL DLACPY( 'U', N, N, AF, M, R, M ) * * Reconstruct the orthogonal matrix Q. * SRNAMT = 'DORGTSQR' CALL DORGTSQR( M, N, MB1, NB1, AF, M, T1, NB1, WORK, LWORK, $ INFO ) * * Perform the Householder reconstruction, the result is stored * the arrays AF and T2. * SRNAMT = 'DORHR_COL' CALL DORHR_COL( M, N, NB2, AF, M, T2, NB2, DIAG, INFO ) * * Compute the factor R_hr corresponding to the Householder * reconstructed Q_hr and place it in the upper triangle of AF to * match the Q storage format in DGEQRT. R_hr = R_tsqr * S, * this means changing the sign of I-th row of the matrix R_tsqr * according to sign of of I-th diagonal element DIAG(I) of the * matrix S. * SRNAMT = 'DLACPY' CALL DLACPY( 'U', N, N, R, M, AF, M ) * DO I = 1, N IF( DIAG( I ).EQ.-ONE ) THEN CALL DSCAL( N+1-I, -ONE, AF( I, I ), M ) END IF END DO * * End Householder reconstruction routines. * * * Generate the m-by-m matrix Q * CALL DLASET( 'Full', M, M, ZERO, ONE, Q, M ) * SRNAMT = 'DGEMQRT' CALL DGEMQRT( 'L', 'N', M, M, K, NB2_UB, AF, M, T2, NB2, Q, M, $ WORK, INFO ) * * Copy R * CALL DLASET( 'Full', M, N, ZERO, ZERO, R, M ) * CALL DLACPY( 'Upper', M, N, AF, M, R, M ) * * TEST 1 * Compute |R - (Q**T)*A| / ( eps * m * |A| ) and store in RESULT(1) * CALL DGEMM( 'T', 'N', M, N, M, -ONE, Q, M, A, M, ONE, R, M ) * ANORM = DLANGE( '1', M, N, A, M, RWORK ) RESID = DLANGE( '1', M, N, R, M, RWORK ) IF( ANORM.GT.ZERO ) THEN RESULT( 1 ) = RESID / ( EPS * MAX( 1, M ) * ANORM ) ELSE RESULT( 1 ) = ZERO END IF * * TEST 2 * Compute |I - (Q**T)*Q| / ( eps * m ) and store in RESULT(2) * CALL DLASET( 'Full', M, M, ZERO, ONE, R, M ) CALL DSYRK( 'U', 'T', M, M, -ONE, Q, M, ONE, R, M ) RESID = DLANSY( '1', 'Upper', M, R, M, RWORK ) RESULT( 2 ) = RESID / ( EPS * MAX( 1, M ) ) * * Generate random m-by-n matrix C * DO J = 1, N CALL DLARNV( 2, ISEED, M, C( 1, J ) ) END DO CNORM = DLANGE( '1', M, N, C, M, RWORK ) CALL DLACPY( 'Full', M, N, C, M, CF, M ) * * Apply Q to C as Q*C = CF * SRNAMT = 'DGEMQRT' CALL DGEMQRT( 'L', 'N', M, N, K, NB2_UB, AF, M, T2, NB2, CF, M, $ WORK, INFO ) * * TEST 3 * Compute |CF - Q*C| / ( eps * m * |C| ) * CALL DGEMM( 'N', 'N', M, N, M, -ONE, Q, M, C, M, ONE, CF, M ) RESID = DLANGE( '1', M, N, CF, M, RWORK ) IF( CNORM.GT.ZERO ) THEN RESULT( 3 ) = RESID / ( EPS * MAX( 1, M ) * CNORM ) ELSE RESULT( 3 ) = ZERO END IF * * Copy C into CF again * CALL DLACPY( 'Full', M, N, C, M, CF, M ) * * Apply Q to C as (Q**T)*C = CF * SRNAMT = 'DGEMQRT' CALL DGEMQRT( 'L', 'T', M, N, K, NB2_UB, AF, M, T2, NB2, CF, M, $ WORK, INFO ) * * TEST 4 * Compute |CF - (Q**T)*C| / ( eps * m * |C|) * CALL DGEMM( 'T', 'N', M, N, M, -ONE, Q, M, C, M, ONE, CF, M ) RESID = DLANGE( '1', M, N, CF, M, RWORK ) IF( CNORM.GT.ZERO ) THEN RESULT( 4 ) = RESID / ( EPS * MAX( 1, M ) * CNORM ) ELSE RESULT( 4 ) = ZERO END IF * * Generate random n-by-m matrix D and a copy DF * DO J = 1, M CALL DLARNV( 2, ISEED, N, D( 1, J ) ) END DO DNORM = DLANGE( '1', N, M, D, N, RWORK ) CALL DLACPY( 'Full', N, M, D, N, DF, N ) * * Apply Q to D as D*Q = DF * SRNAMT = 'DGEMQRT' CALL DGEMQRT( 'R', 'N', N, M, K, NB2_UB, AF, M, T2, NB2, DF, N, $ WORK, INFO ) * * TEST 5 * Compute |DF - D*Q| / ( eps * m * |D| ) * CALL DGEMM( 'N', 'N', N, M, M, -ONE, D, N, Q, M, ONE, DF, N ) RESID = DLANGE( '1', N, M, DF, N, RWORK ) IF( DNORM.GT.ZERO ) THEN RESULT( 5 ) = RESID / ( EPS * MAX( 1, M ) * DNORM ) ELSE RESULT( 5 ) = ZERO END IF * * Copy D into DF again * CALL DLACPY( 'Full', N, M, D, N, DF, N ) * * Apply Q to D as D*QT = DF * SRNAMT = 'DGEMQRT' CALL DGEMQRT( 'R', 'T', N, M, K, NB2_UB, AF, M, T2, NB2, DF, N, $ WORK, INFO ) * * TEST 6 * Compute |DF - D*(Q**T)| / ( eps * m * |D| ) * CALL DGEMM( 'N', 'T', N, M, M, -ONE, D, N, Q, M, ONE, DF, N ) RESID = DLANGE( '1', N, M, DF, N, RWORK ) IF( DNORM.GT.ZERO ) THEN RESULT( 6 ) = RESID / ( EPS * MAX( 1, M ) * DNORM ) ELSE RESULT( 6 ) = ZERO END IF * * Deallocate all arrays * DEALLOCATE ( A, AF, Q, R, RWORK, WORK, T1, T2, DIAG, $ C, D, CF, DF ) * RETURN * * End of DORHR_COL01 * END