LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
dspt21.f
Go to the documentation of this file.
1 *> \brief \b DSPT21
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 * Definition:
9 * ===========
10 *
11 * SUBROUTINE DSPT21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,
12 * TAU, WORK, RESULT )
13 *
14 * .. Scalar Arguments ..
15 * CHARACTER UPLO
16 * INTEGER ITYPE, KBAND, LDU, N
17 * ..
18 * .. Array Arguments ..
19 * DOUBLE PRECISION AP( * ), D( * ), E( * ), RESULT( 2 ), TAU( * ),
20 * $ U( LDU, * ), VP( * ), WORK( * )
21 * ..
22 *
23 *
24 *> \par Purpose:
25 * =============
26 *>
27 *> \verbatim
28 *>
29 *> DSPT21 generally checks a decomposition of the form
30 *>
31 *> A = U S U'
32 *>
33 *> where ' means transpose, A is symmetric (stored in packed format), U
34 *> is orthogonal, and S is diagonal (if KBAND=0) or symmetric
35 *> tridiagonal (if KBAND=1). If ITYPE=1, then U is represented as a
36 *> dense matrix, otherwise the U is expressed as a product of
37 *> Householder transformations, whose vectors are stored in the array
38 *> "V" and whose scaling constants are in "TAU"; we shall use the
39 *> letter "V" to refer to the product of Householder transformations
40 *> (which should be equal to U).
41 *>
42 *> Specifically, if ITYPE=1, then:
43 *>
44 *> RESULT(1) = | A - U S U' | / ( |A| n ulp ) *andC> RESULT(2) = | I - UU' | / ( n ulp )
45 *>
46 *> If ITYPE=2, then:
47 *>
48 *> RESULT(1) = | A - V S V' | / ( |A| n ulp )
49 *>
50 *> If ITYPE=3, then:
51 *>
52 *> RESULT(1) = | I - VU' | / ( n ulp )
53 *>
54 *> Packed storage means that, for example, if UPLO='U', then the columns
55 *> of the upper triangle of A are stored one after another, so that
56 *> A(1,j+1) immediately follows A(j,j) in the array AP. Similarly, if
57 *> UPLO='L', then the columns of the lower triangle of A are stored one
58 *> after another in AP, so that A(j+1,j+1) immediately follows A(n,j)
59 *> in the array AP. This means that A(i,j) is stored in:
60 *>
61 *> AP( i + j*(j-1)/2 ) if UPLO='U'
62 *>
63 *> AP( i + (2*n-j)*(j-1)/2 ) if UPLO='L'
64 *>
65 *> The array VP bears the same relation to the matrix V that A does to
66 *> AP.
67 *>
68 *> For ITYPE > 1, the transformation U is expressed as a product
69 *> of Householder transformations:
70 *>
71 *> If UPLO='U', then V = H(n-1)...H(1), where
72 *>
73 *> H(j) = I - tau(j) v(j) v(j)'
74 *>
75 *> and the first j-1 elements of v(j) are stored in V(1:j-1,j+1),
76 *> (i.e., VP( j*(j+1)/2 + 1 : j*(j+1)/2 + j-1 ) ),
77 *> the j-th element is 1, and the last n-j elements are 0.
78 *>
79 *> If UPLO='L', then V = H(1)...H(n-1), where
80 *>
81 *> H(j) = I - tau(j) v(j) v(j)'
82 *>
83 *> and the first j elements of v(j) are 0, the (j+1)-st is 1, and the
84 *> (j+2)-nd through n-th elements are stored in V(j+2:n,j) (i.e.,
85 *> in VP( (2*n-j)*(j-1)/2 + j+2 : (2*n-j)*(j-1)/2 + n ) .)
86 *> \endverbatim
87 *
88 * Arguments:
89 * ==========
90 *
91 *> \param[in] ITYPE
92 *> \verbatim
93 *> ITYPE is INTEGER
94 *> Specifies the type of tests to be performed.
95 *> 1: U expressed as a dense orthogonal matrix:
96 *> RESULT(1) = | A - U S U' | / ( |A| n ulp ) *andC> RESULT(2) = | I - UU' | / ( n ulp )
97 *>
98 *> 2: U expressed as a product V of Housholder transformations:
99 *> RESULT(1) = | A - V S V' | / ( |A| n ulp )
100 *>
101 *> 3: U expressed both as a dense orthogonal matrix and
102 *> as a product of Housholder transformations:
103 *> RESULT(1) = | I - VU' | / ( n ulp )
104 *> \endverbatim
105 *>
106 *> \param[in] UPLO
107 *> \verbatim
108 *> UPLO is CHARACTER
109 *> If UPLO='U', AP and VP are considered to contain the upper
110 *> triangle of A and V.
111 *> If UPLO='L', AP and VP are considered to contain the lower
112 *> triangle of A and V.
113 *> \endverbatim
114 *>
115 *> \param[in] N
116 *> \verbatim
117 *> N is INTEGER
118 *> The size of the matrix. If it is zero, DSPT21 does nothing.
119 *> It must be at least zero.
120 *> \endverbatim
121 *>
122 *> \param[in] KBAND
123 *> \verbatim
124 *> KBAND is INTEGER
125 *> The bandwidth of the matrix. It may only be zero or one.
126 *> If zero, then S is diagonal, and E is not referenced. If
127 *> one, then S is symmetric tri-diagonal.
128 *> \endverbatim
129 *>
130 *> \param[in] AP
131 *> \verbatim
132 *> AP is DOUBLE PRECISION array, dimension (N*(N+1)/2)
133 *> The original (unfactored) matrix. It is assumed to be
134 *> symmetric, and contains the columns of just the upper
135 *> triangle (UPLO='U') or only the lower triangle (UPLO='L'),
136 *> packed one after another.
137 *> \endverbatim
138 *>
139 *> \param[in] D
140 *> \verbatim
141 *> D is DOUBLE PRECISION array, dimension (N)
142 *> The diagonal of the (symmetric tri-) diagonal matrix.
143 *> \endverbatim
144 *>
145 *> \param[in] E
146 *> \verbatim
147 *> E is DOUBLE PRECISION array, dimension (N-1)
148 *> The off-diagonal of the (symmetric tri-) diagonal matrix.
149 *> E(1) is the (1,2) and (2,1) element, E(2) is the (2,3) and
150 *> (3,2) element, etc.
151 *> Not referenced if KBAND=0.
152 *> \endverbatim
153 *>
154 *> \param[in] U
155 *> \verbatim
156 *> U is DOUBLE PRECISION array, dimension (LDU, N)
157 *> If ITYPE=1 or 3, this contains the orthogonal matrix in
158 *> the decomposition, expressed as a dense matrix. If ITYPE=2,
159 *> then it is not referenced.
160 *> \endverbatim
161 *>
162 *> \param[in] LDU
163 *> \verbatim
164 *> LDU is INTEGER
165 *> The leading dimension of U. LDU must be at least N and
166 *> at least 1.
167 *> \endverbatim
168 *>
169 *> \param[in] VP
170 *> \verbatim
171 *> VP is DOUBLE PRECISION array, dimension (N*(N+1)/2)
172 *> If ITYPE=2 or 3, the columns of this array contain the
173 *> Householder vectors used to describe the orthogonal matrix
174 *> in the decomposition, as described in purpose.
175 *> *NOTE* If ITYPE=2 or 3, V is modified and restored. The
176 *> subdiagonal (if UPLO='L') or the superdiagonal (if UPLO='U')
177 *> is set to one, and later reset to its original value, during
178 *> the course of the calculation.
179 *> If ITYPE=1, then it is neither referenced nor modified.
180 *> \endverbatim
181 *>
182 *> \param[in] TAU
183 *> \verbatim
184 *> TAU is DOUBLE PRECISION array, dimension (N)
185 *> If ITYPE >= 2, then TAU(j) is the scalar factor of
186 *> v(j) v(j)' in the Householder transformation H(j) of
187 *> the product U = H(1)...H(n-2)
188 *> If ITYPE < 2, then TAU is not referenced.
189 *> \endverbatim
190 *>
191 *> \param[out] WORK
192 *> \verbatim
193 *> WORK is DOUBLE PRECISION array, dimension (N**2+N)
194 *> Workspace.
195 *> \endverbatim
196 *>
197 *> \param[out] RESULT
198 *> \verbatim
199 *> RESULT is DOUBLE PRECISION array, dimension (2)
200 *> The values computed by the two tests described above. The
201 *> values are currently limited to 1/ulp, to avoid overflow.
202 *> RESULT(1) is always modified. RESULT(2) is modified only
203 *> if ITYPE=1.
204 *> \endverbatim
205 *
206 * Authors:
207 * ========
208 *
209 *> \author Univ. of Tennessee
210 *> \author Univ. of California Berkeley
211 *> \author Univ. of Colorado Denver
212 *> \author NAG Ltd.
213 *
214 *> \date November 2011
215 *
216 *> \ingroup double_eig
217 *
218 * =====================================================================
219  SUBROUTINE dspt21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,
220  $ tau, work, result )
221 *
222 * -- LAPACK test routine (version 3.4.0) --
223 * -- LAPACK is a software package provided by Univ. of Tennessee, --
224 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
225 * November 2011
226 *
227 * .. Scalar Arguments ..
228  CHARACTER UPLO
229  INTEGER ITYPE, KBAND, LDU, N
230 * ..
231 * .. Array Arguments ..
232  DOUBLE PRECISION AP( * ), D( * ), E( * ), RESULT( 2 ), TAU( * ),
233  $ u( ldu, * ), vp( * ), work( * )
234 * ..
235 *
236 * =====================================================================
237 *
238 * .. Parameters ..
239  DOUBLE PRECISION ZERO, ONE, TEN
240  parameter ( zero = 0.0d0, one = 1.0d0, ten = 10.0d0 )
241  DOUBLE PRECISION HALF
242  parameter ( half = 1.0d+0 / 2.0d+0 )
243 * ..
244 * .. Local Scalars ..
245  LOGICAL LOWER
246  CHARACTER CUPLO
247  INTEGER IINFO, J, JP, JP1, JR, LAP
248  DOUBLE PRECISION ANORM, TEMP, ULP, UNFL, VSAVE, WNORM
249 * ..
250 * .. External Functions ..
251  LOGICAL LSAME
252  DOUBLE PRECISION DDOT, DLAMCH, DLANGE, DLANSP
253  EXTERNAL lsame, ddot, dlamch, dlange, dlansp
254 * ..
255 * .. External Subroutines ..
256  EXTERNAL daxpy, dcopy, dgemm, dlacpy, dlaset, dopmtr,
257  $ dspmv, dspr, dspr2
258 * ..
259 * .. Intrinsic Functions ..
260  INTRINSIC dble, max, min
261 * ..
262 * .. Executable Statements ..
263 *
264 * 1) Constants
265 *
266  result( 1 ) = zero
267  IF( itype.EQ.1 )
268  $ result( 2 ) = zero
269  IF( n.LE.0 )
270  $ RETURN
271 *
272  lap = ( n*( n+1 ) ) / 2
273 *
274  IF( lsame( uplo, 'U' ) ) THEN
275  lower = .false.
276  cuplo = 'U'
277  ELSE
278  lower = .true.
279  cuplo = 'L'
280  END IF
281 *
282  unfl = dlamch( 'Safe minimum' )
283  ulp = dlamch( 'Epsilon' )*dlamch( 'Base' )
284 *
285 * Some Error Checks
286 *
287  IF( itype.LT.1 .OR. itype.GT.3 ) THEN
288  result( 1 ) = ten / ulp
289  RETURN
290  END IF
291 *
292 * Do Test 1
293 *
294 * Norm of A:
295 *
296  IF( itype.EQ.3 ) THEN
297  anorm = one
298  ELSE
299  anorm = max( dlansp( '1', cuplo, n, ap, work ), unfl )
300  END IF
301 *
302 * Compute error matrix:
303 *
304  IF( itype.EQ.1 ) THEN
305 *
306 * ITYPE=1: error = A - U S U'
307 *
308  CALL dlaset( 'Full', n, n, zero, zero, work, n )
309  CALL dcopy( lap, ap, 1, work, 1 )
310 *
311  DO 10 j = 1, n
312  CALL dspr( cuplo, n, -d( j ), u( 1, j ), 1, work )
313  10 CONTINUE
314 *
315  IF( n.GT.1 .AND. kband.EQ.1 ) THEN
316  DO 20 j = 1, n - 1
317  CALL dspr2( cuplo, n, -e( j ), u( 1, j ), 1, u( 1, j+1 ),
318  $ 1, work )
319  20 CONTINUE
320  END IF
321  wnorm = dlansp( '1', cuplo, n, work, work( n**2+1 ) )
322 *
323  ELSE IF( itype.EQ.2 ) THEN
324 *
325 * ITYPE=2: error = V S V' - A
326 *
327  CALL dlaset( 'Full', n, n, zero, zero, work, n )
328 *
329  IF( lower ) THEN
330  work( lap ) = d( n )
331  DO 40 j = n - 1, 1, -1
332  jp = ( ( 2*n-j )*( j-1 ) ) / 2
333  jp1 = jp + n - j
334  IF( kband.EQ.1 ) THEN
335  work( jp+j+1 ) = ( one-tau( j ) )*e( j )
336  DO 30 jr = j + 2, n
337  work( jp+jr ) = -tau( j )*e( j )*vp( jp+jr )
338  30 CONTINUE
339  END IF
340 *
341  IF( tau( j ).NE.zero ) THEN
342  vsave = vp( jp+j+1 )
343  vp( jp+j+1 ) = one
344  CALL dspmv( 'L', n-j, one, work( jp1+j+1 ),
345  $ vp( jp+j+1 ), 1, zero, work( lap+1 ), 1 )
346  temp = -half*tau( j )*ddot( n-j, work( lap+1 ), 1,
347  $ vp( jp+j+1 ), 1 )
348  CALL daxpy( n-j, temp, vp( jp+j+1 ), 1, work( lap+1 ),
349  $ 1 )
350  CALL dspr2( 'L', n-j, -tau( j ), vp( jp+j+1 ), 1,
351  $ work( lap+1 ), 1, work( jp1+j+1 ) )
352  vp( jp+j+1 ) = vsave
353  END IF
354  work( jp+j ) = d( j )
355  40 CONTINUE
356  ELSE
357  work( 1 ) = d( 1 )
358  DO 60 j = 1, n - 1
359  jp = ( j*( j-1 ) ) / 2
360  jp1 = jp + j
361  IF( kband.EQ.1 ) THEN
362  work( jp1+j ) = ( one-tau( j ) )*e( j )
363  DO 50 jr = 1, j - 1
364  work( jp1+jr ) = -tau( j )*e( j )*vp( jp1+jr )
365  50 CONTINUE
366  END IF
367 *
368  IF( tau( j ).NE.zero ) THEN
369  vsave = vp( jp1+j )
370  vp( jp1+j ) = one
371  CALL dspmv( 'U', j, one, work, vp( jp1+1 ), 1, zero,
372  $ work( lap+1 ), 1 )
373  temp = -half*tau( j )*ddot( j, work( lap+1 ), 1,
374  $ vp( jp1+1 ), 1 )
375  CALL daxpy( j, temp, vp( jp1+1 ), 1, work( lap+1 ),
376  $ 1 )
377  CALL dspr2( 'U', j, -tau( j ), vp( jp1+1 ), 1,
378  $ work( lap+1 ), 1, work )
379  vp( jp1+j ) = vsave
380  END IF
381  work( jp1+j+1 ) = d( j+1 )
382  60 CONTINUE
383  END IF
384 *
385  DO 70 j = 1, lap
386  work( j ) = work( j ) - ap( j )
387  70 CONTINUE
388  wnorm = dlansp( '1', cuplo, n, work, work( lap+1 ) )
389 *
390  ELSE IF( itype.EQ.3 ) THEN
391 *
392 * ITYPE=3: error = U V' - I
393 *
394  IF( n.LT.2 )
395  $ RETURN
396  CALL dlacpy( ' ', n, n, u, ldu, work, n )
397  CALL dopmtr( 'R', cuplo, 'T', n, n, vp, tau, work, n,
398  $ work( n**2+1 ), iinfo )
399  IF( iinfo.NE.0 ) THEN
400  result( 1 ) = ten / ulp
401  RETURN
402  END IF
403 *
404  DO 80 j = 1, n
405  work( ( n+1 )*( j-1 )+1 ) = work( ( n+1 )*( j-1 )+1 ) - one
406  80 CONTINUE
407 *
408  wnorm = dlange( '1', n, n, work, n, work( n**2+1 ) )
409  END IF
410 *
411  IF( anorm.GT.wnorm ) THEN
412  result( 1 ) = ( wnorm / anorm ) / ( n*ulp )
413  ELSE
414  IF( anorm.LT.one ) THEN
415  result( 1 ) = ( min( wnorm, n*anorm ) / anorm ) / ( n*ulp )
416  ELSE
417  result( 1 ) = min( wnorm / anorm, dble( n ) ) / ( n*ulp )
418  END IF
419  END IF
420 *
421 * Do Test 2
422 *
423 * Compute UU' - I
424 *
425  IF( itype.EQ.1 ) THEN
426  CALL dgemm( 'N', 'C', n, n, n, one, u, ldu, u, ldu, zero, work,
427  $ n )
428 *
429  DO 90 j = 1, n
430  work( ( n+1 )*( j-1 )+1 ) = work( ( n+1 )*( j-1 )+1 ) - one
431  90 CONTINUE
432 *
433  result( 2 ) = min( dlange( '1', n, n, work, n,
434  $ work( n**2+1 ) ), dble( n ) ) / ( n*ulp )
435  END IF
436 *
437  RETURN
438 *
439 * End of DSPT21
440 *
441  END
subroutine dlaset(UPLO, M, N, ALPHA, BETA, A, LDA)
DLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values...
Definition: dlaset.f:112
subroutine dcopy(N, DX, INCX, DY, INCY)
DCOPY
Definition: dcopy.f:53
subroutine dopmtr(SIDE, UPLO, TRANS, M, N, AP, TAU, C, LDC, WORK, INFO)
DOPMTR
Definition: dopmtr.f:152
subroutine dlacpy(UPLO, M, N, A, LDA, B, LDB)
DLACPY copies all or part of one two-dimensional array to another.
Definition: dlacpy.f:105
subroutine dspmv(UPLO, N, ALPHA, AP, X, INCX, BETA, Y, INCY)
DSPMV
Definition: dspmv.f:149
subroutine daxpy(N, DA, DX, INCX, DY, INCY)
DAXPY
Definition: daxpy.f:54
subroutine dgemm(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
DGEMM
Definition: dgemm.f:189
subroutine dspt21(ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP, TAU, WORK, RESULT)
DSPT21
Definition: dspt21.f:221
subroutine dspr(UPLO, N, ALPHA, X, INCX, AP)
DSPR
Definition: dspr.f:129
subroutine dspr2(UPLO, N, ALPHA, X, INCX, Y, INCY, AP)
DSPR2
Definition: dspr2.f:144