LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
sbdt04.f
Go to the documentation of this file.
1 * =========== DOCUMENTATION ===========
2 *
3 * Online html documentation available at
4 * http://www.netlib.org/lapack/explore-html/
5 *
6 * Definition:
7 * ===========
8 *
9 * SUBROUTINE SBDT04( UPLO, N, D, E, S, NS, U, LDU, VT, LDVT,
10 * WORK, RESID )
11 *
12 * .. Scalar Arguments ..
13 * CHARACTER UPLO
14 * INTEGER LDU, LDVT, N, NS
15 * REAL RESID
16 * ..
17 * .. Array Arguments ..
18 * REAL D( * ), E( * ), S( * ), U( LDU, * ),
19 * $ VT( LDVT, * ), WORK( * )
20 * ..
21 *
22 *
23 *> \par Purpose:
24 * =============
25 *>
26 *> \verbatim
27 *>
28 *> SBDT04 reconstructs a bidiagonal matrix B from its (partial) SVD:
29 *> S = U' * B * V
30 *> where U and V are orthogonal matrices and S is diagonal.
31 *>
32 *> The test ratio to test the singular value decomposition is
33 *> RESID = norm( S - U' * B * V ) / ( n * norm(B) * EPS )
34 *> where VT = V' and EPS is the machine precision.
35 *> \endverbatim
36 *
37 * Arguments:
38 * ==========
39 *
40 *> \param[in] UPLO
41 *> \verbatim
42 *> UPLO is CHARACTER*1
43 *> Specifies whether the matrix B is upper or lower bidiagonal.
44 *> = 'U': Upper bidiagonal
45 *> = 'L': Lower bidiagonal
46 *> \endverbatim
47 *>
48 *> \param[in] N
49 *> \verbatim
50 *> N is INTEGER
51 *> The order of the matrix B.
52 *> \endverbatim
53 *>
54 *> \param[in] D
55 *> \verbatim
56 *> D is REAL array, dimension (N)
57 *> The n diagonal elements of the bidiagonal matrix B.
58 *> \endverbatim
59 *>
60 *> \param[in] E
61 *> \verbatim
62 *> E is REAL array, dimension (N-1)
63 *> The (n-1) superdiagonal elements of the bidiagonal matrix B
64 *> if UPLO = 'U', or the (n-1) subdiagonal elements of B if
65 *> UPLO = 'L'.
66 *> \endverbatim
67 *>
68 *> \param[in] S
69 *> \verbatim
70 *> S is REAL array, dimension (NS)
71 *> The singular values from the (partial) SVD of B, sorted in
72 *> decreasing order.
73 *> \endverbatim
74 *>
75 *> \param[in] NS
76 *> \verbatim
77 *> NS is INTEGER
78 *> The number of singular values/vectors from the (partial)
79 *> SVD of B.
80 *> \endverbatim
81 *>
82 *> \param[in] U
83 *> \verbatim
84 *> U is REAL array, dimension (LDU,NS)
85 *> The n by ns orthogonal matrix U in S = U' * B * V.
86 *> \endverbatim
87 *>
88 *> \param[in] LDU
89 *> \verbatim
90 *> LDU is INTEGER
91 *> The leading dimension of the array U. LDU >= max(1,N)
92 *> \endverbatim
93 *>
94 *> \param[in] VT
95 *> \verbatim
96 *> VT is REAL array, dimension (LDVT,N)
97 *> The n by ns orthogonal matrix V in S = U' * B * V.
98 *> \endverbatim
99 *>
100 *> \param[in] LDVT
101 *> \verbatim
102 *> LDVT is INTEGER
103 *> The leading dimension of the array VT.
104 *> \endverbatim
105 *>
106 *> \param[out] WORK
107 *> \verbatim
108 *> WORK is REAL array, dimension (2*N)
109 *> \endverbatim
110 *>
111 *> \param[out] RESID
112 *> \verbatim
113 *> RESID is REAL
114 *> The test ratio: norm(S - U' * B * V) / ( n * norm(B) * EPS )
115 *> \endverbatim
116 *
117 * Authors:
118 * ========
119 *
120 *> \author Univ. of Tennessee
121 *> \author Univ. of California Berkeley
122 *> \author Univ. of Colorado Denver
123 *> \author NAG Ltd.
124 *
125 *> \date November 2011
126 *
127 *> \ingroup double_eig
128 *
129 * =====================================================================
130  SUBROUTINE sbdt04( UPLO, N, D, E, S, NS, U, LDU, VT, LDVT, WORK,
131  $ resid )
132 *
133 * -- LAPACK test routine (version 3.4.0) --
134 * -- LAPACK is a software package provided by Univ. of Tennessee, --
135 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
136 * November 2011
137 *
138 * .. Scalar Arguments ..
139  CHARACTER UPLO
140  INTEGER LDU, LDVT, N, NS
141  REAL RESID
142 * ..
143 * .. Array Arguments ..
144  REAL D( * ), E( * ), S( * ), U( ldu, * ),
145  $ vt( ldvt, * ), work( * )
146 * ..
147 *
148 * ======================================================================
149 *
150 * .. Parameters ..
151  REAL ZERO, ONE
152  parameter ( zero = 0.0e+0, one = 1.0e+0 )
153 * ..
154 * .. Local Scalars ..
155  INTEGER I, J, K
156  REAL BNORM, EPS
157 * ..
158 * .. External Functions ..
159  LOGICAL LSAME
160  INTEGER ISAMAX
161  REAL SASUM, SLAMCH
162  EXTERNAL lsame, isamax, sasum, slamch
163 * ..
164 * .. External Subroutines ..
165  EXTERNAL sgemm
166 * ..
167 * .. Intrinsic Functions ..
168  INTRINSIC abs, REAL, MAX, MIN
169 * ..
170 * .. Executable Statements ..
171 *
172 * Quick return if possible.
173 *
174  resid = zero
175  IF( n.LE.0 .OR. ns.LE.0 )
176  $ RETURN
177 *
178  eps = slamch( 'Precision' )
179 *
180 * Compute S - U' * B * V.
181 *
182  bnorm = zero
183 *
184  IF( lsame( uplo, 'U' ) ) THEN
185 *
186 * B is upper bidiagonal.
187 *
188  k = 0
189  DO 20 i = 1, ns
190  DO 10 j = 1, n-1
191  k = k + 1
192  work( k ) = d( j )*vt( i, j ) + e( j )*vt( i, j+1 )
193  10 CONTINUE
194  k = k + 1
195  work( k ) = d( n )*vt( i, n )
196  20 CONTINUE
197  bnorm = abs( d( 1 ) )
198  DO 30 i = 2, n
199  bnorm = max( bnorm, abs( d( i ) )+abs( e( i-1 ) ) )
200  30 CONTINUE
201  ELSE
202 *
203 * B is lower bidiagonal.
204 *
205  k = 0
206  DO 50 i = 1, ns
207  k = k + 1
208  work( k ) = d( 1 )*vt( i, 1 )
209  DO 40 j = 1, n-1
210  k = k + 1
211  work( k ) = e( j )*vt( i, j ) + d( j+1 )*vt( i, j+1 )
212  40 CONTINUE
213  50 CONTINUE
214  bnorm = abs( d( n ) )
215  DO 60 i = 1, n-1
216  bnorm = max( bnorm, abs( d( i ) )+abs( e( i ) ) )
217  60 CONTINUE
218  END IF
219 *
220  CALL sgemm( 'T', 'N', ns, ns, n, -one, u, ldu, work( 1 ),
221  $ n, zero, work( 1+n*ns ), ns )
222 *
223 * norm(S - U' * B * V)
224 *
225  k = n*ns
226  DO 70 i = 1, ns
227  work( k+i ) = work( k+i ) + s( i )
228  resid = max( resid, sasum( ns, work( k+1 ), 1 ) )
229  k = k + ns
230  70 CONTINUE
231 *
232  IF( bnorm.LE.zero ) THEN
233  IF( resid.NE.zero )
234  $ resid = one / eps
235  ELSE
236  IF( bnorm.GE.resid ) THEN
237  resid = ( resid / bnorm ) / ( REAL( n )*EPS )
238  ELSE
239  IF( bnorm.LT.one ) THEN
240  resid = ( min( resid, REAL( n )*BNORM ) / bnorm ) /
241  $ ( REAL( n )*EPS )
242  ELSE
243  resid = min( resid / bnorm, REAL( N ) ) /
244  $ ( REAL( n )*EPS )
245  END IF
246  END IF
247  END IF
248 *
249  RETURN
250 *
251 * End of SBDT04
252 *
253  END
subroutine sbdt04(UPLO, N, D, E, S, NS, U, LDU, VT, LDVT, WORK, RESID)
Definition: sbdt04.f:132
subroutine sgemm(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
SGEMM
Definition: sgemm.f:189