numeric-linalg
Educational material on the SciPy implementation of numerical linear algebra algorithms
Name | Size | Mode | |
.. | |||
lapack/TESTING/EIG/dbdt04.f | 6628B | -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
*> \brief \b DBDT04 * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE DBDT04( UPLO, N, D, E, S, NS, U, LDU, VT, LDVT, * WORK, RESID ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER LDU, LDVT, N, NS * DOUBLE PRECISION RESID * .. * .. Array Arguments .. * DOUBLE PRECISION D( * ), E( * ), S( * ), U( LDU, * ), * $ VT( LDVT, * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DBDT04 reconstructs a bidiagonal matrix B from its (partial) SVD: *> S = U' * B * V *> where U and V are orthogonal matrices and S is diagonal. *> *> The test ratio to test the singular value decomposition is *> RESID = norm( S - U' * B * V ) / ( n * norm(B) * EPS ) *> where VT = V' and EPS is the machine precision. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> Specifies whether the matrix B is upper or lower bidiagonal. *> = 'U': Upper bidiagonal *> = 'L': Lower bidiagonal *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix B. *> \endverbatim *> *> \param[in] D *> \verbatim *> D is DOUBLE PRECISION array, dimension (N) *> The n diagonal elements of the bidiagonal matrix B. *> \endverbatim *> *> \param[in] E *> \verbatim *> E is DOUBLE PRECISION array, dimension (N-1) *> The (n-1) superdiagonal elements of the bidiagonal matrix B *> if UPLO = 'U', or the (n-1) subdiagonal elements of B if *> UPLO = 'L'. *> \endverbatim *> *> \param[in] S *> \verbatim *> S is DOUBLE PRECISION array, dimension (NS) *> The singular values from the (partial) SVD of B, sorted in *> decreasing order. *> \endverbatim *> *> \param[in] NS *> \verbatim *> NS is INTEGER *> The number of singular values/vectors from the (partial) *> SVD of B. *> \endverbatim *> *> \param[in] U *> \verbatim *> U is DOUBLE PRECISION array, dimension (LDU,NS) *> The n by ns orthogonal matrix U in S = U' * B * V. *> \endverbatim *> *> \param[in] LDU *> \verbatim *> LDU is INTEGER *> The leading dimension of the array U. LDU >= max(1,N) *> \endverbatim *> *> \param[in] VT *> \verbatim *> VT is DOUBLE PRECISION array, dimension (LDVT,N) *> The n by ns orthogonal matrix V in S = U' * B * V. *> \endverbatim *> *> \param[in] LDVT *> \verbatim *> LDVT is INTEGER *> The leading dimension of the array VT. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension (2*N) *> \endverbatim *> *> \param[out] RESID *> \verbatim *> RESID is DOUBLE PRECISION *> The test ratio: norm(S - U' * B * V) / ( n * norm(B) * EPS ) *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup double_eig * * ===================================================================== SUBROUTINE DBDT04( UPLO, N, D, E, S, NS, U, LDU, VT, LDVT, WORK, $ RESID ) * * -- 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 .. CHARACTER UPLO INTEGER LDU, LDVT, N, NS DOUBLE PRECISION RESID * .. * .. Array Arguments .. DOUBLE PRECISION D( * ), E( * ), S( * ), U( LDU, * ), $ VT( LDVT, * ), WORK( * ) * .. * * ====================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) * .. * .. Local Scalars .. INTEGER I, J, K DOUBLE PRECISION BNORM, EPS * .. * .. External Functions .. LOGICAL LSAME INTEGER IDAMAX DOUBLE PRECISION DASUM, DLAMCH EXTERNAL LSAME, IDAMAX, DASUM, DLAMCH * .. * .. External Subroutines .. EXTERNAL DGEMM * .. * .. Intrinsic Functions .. INTRINSIC ABS, DBLE, MAX, MIN * .. * .. Executable Statements .. * * Quick return if possible. * RESID = ZERO IF( N.LE.0 .OR. NS.LE.0 ) $ RETURN * EPS = DLAMCH( 'Precision' ) * * Compute S - U' * B * V. * BNORM = ZERO * IF( LSAME( UPLO, 'U' ) ) THEN * * B is upper bidiagonal. * K = 0 DO 20 I = 1, NS DO 10 J = 1, N-1 K = K + 1 WORK( K ) = D( J )*VT( I, J ) + E( J )*VT( I, J+1 ) 10 CONTINUE K = K + 1 WORK( K ) = D( N )*VT( I, N ) 20 CONTINUE BNORM = ABS( D( 1 ) ) DO 30 I = 2, N BNORM = MAX( BNORM, ABS( D( I ) )+ABS( E( I-1 ) ) ) 30 CONTINUE ELSE * * B is lower bidiagonal. * K = 0 DO 50 I = 1, NS K = K + 1 WORK( K ) = D( 1 )*VT( I, 1 ) DO 40 J = 1, N-1 K = K + 1 WORK( K ) = E( J )*VT( I, J ) + D( J+1 )*VT( I, J+1 ) 40 CONTINUE 50 CONTINUE BNORM = ABS( D( N ) ) DO 60 I = 1, N-1 BNORM = MAX( BNORM, ABS( D( I ) )+ABS( E( I ) ) ) 60 CONTINUE END IF * CALL DGEMM( 'T', 'N', NS, NS, N, -ONE, U, LDU, WORK( 1 ), $ N, ZERO, WORK( 1+N*NS ), NS ) * * norm(S - U' * B * V) * K = N*NS DO 70 I = 1, NS WORK( K+I ) = WORK( K+I ) + S( I ) RESID = MAX( RESID, DASUM( NS, WORK( K+1 ), 1 ) ) K = K + NS 70 CONTINUE * IF( BNORM.LE.ZERO ) THEN IF( RESID.NE.ZERO ) $ RESID = ONE / EPS ELSE IF( BNORM.GE.RESID ) THEN RESID = ( RESID / BNORM ) / ( DBLE( N )*EPS ) ELSE IF( BNORM.LT.ONE ) THEN RESID = ( MIN( RESID, DBLE( N )*BNORM ) / BNORM ) / $ ( DBLE( N )*EPS ) ELSE RESID = MIN( RESID / BNORM, DBLE( N ) ) / $ ( DBLE( N )*EPS ) END IF END IF END IF * RETURN * * End of DBDT04 * END