LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
dsytf2.f
Go to the documentation of this file.
1 *> \brief \b DSYTF2 computes the factorization of a real symmetric indefinite matrix, using the diagonal pivoting method (unblocked algorithm).
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download DSYTF2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytf2.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytf2.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytf2.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE DSYTF2( UPLO, N, A, LDA, IPIV, INFO )
22 *
23 * .. Scalar Arguments ..
24 * CHARACTER UPLO
25 * INTEGER INFO, LDA, N
26 * ..
27 * .. Array Arguments ..
28 * INTEGER IPIV( * )
29 * DOUBLE PRECISION A( LDA, * )
30 * ..
31 *
32 *
33 *> \par Purpose:
34 * =============
35 *>
36 *> \verbatim
37 *>
38 *> DSYTF2 computes the factorization of a real symmetric matrix A using
39 *> the Bunch-Kaufman diagonal pivoting method:
40 *>
41 *> A = U*D*U**T or A = L*D*L**T
42 *>
43 *> where U (or L) is a product of permutation and unit upper (lower)
44 *> triangular matrices, U**T is the transpose of U, and D is symmetric and
45 *> block diagonal with 1-by-1 and 2-by-2 diagonal blocks.
46 *>
47 *> This is the unblocked version of the algorithm, calling Level 2 BLAS.
48 *> \endverbatim
49 *
50 * Arguments:
51 * ==========
52 *
53 *> \param[in] UPLO
54 *> \verbatim
55 *> UPLO is CHARACTER*1
56 *> Specifies whether the upper or lower triangular part of the
57 *> symmetric matrix A is stored:
58 *> = 'U': Upper triangular
59 *> = 'L': Lower triangular
60 *> \endverbatim
61 *>
62 *> \param[in] N
63 *> \verbatim
64 *> N is INTEGER
65 *> The order of the matrix A. N >= 0.
66 *> \endverbatim
67 *>
68 *> \param[in,out] A
69 *> \verbatim
70 *> A is DOUBLE PRECISION array, dimension (LDA,N)
71 *> On entry, the symmetric matrix A. If UPLO = 'U', the leading
72 *> n-by-n upper triangular part of A contains the upper
73 *> triangular part of the matrix A, and the strictly lower
74 *> triangular part of A is not referenced. If UPLO = 'L', the
75 *> leading n-by-n lower triangular part of A contains the lower
76 *> triangular part of the matrix A, and the strictly upper
77 *> triangular part of A is not referenced.
78 *>
79 *> On exit, the block diagonal matrix D and the multipliers used
80 *> to obtain the factor U or L (see below for further details).
81 *> \endverbatim
82 *>
83 *> \param[in] LDA
84 *> \verbatim
85 *> LDA is INTEGER
86 *> The leading dimension of the array A. LDA >= max(1,N).
87 *> \endverbatim
88 *>
89 *> \param[out] IPIV
90 *> \verbatim
91 *> IPIV is INTEGER array, dimension (N)
92 *> Details of the interchanges and the block structure of D.
93 *> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
94 *> interchanged and D(k,k) is a 1-by-1 diagonal block.
95 *> If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and
96 *> columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
97 *> is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) =
98 *> IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were
99 *> interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
100 *> \endverbatim
101 *>
102 *> \param[out] INFO
103 *> \verbatim
104 *> INFO is INTEGER
105 *> = 0: successful exit
106 *> < 0: if INFO = -k, the k-th argument had an illegal value
107 *> > 0: if INFO = k, D(k,k) is exactly zero. The factorization
108 *> has been completed, but the block diagonal matrix D is
109 *> exactly singular, and division by zero will occur if it
110 *> is used to solve a system of equations.
111 *> \endverbatim
112 *
113 * Authors:
114 * ========
115 *
116 *> \author Univ. of Tennessee
117 *> \author Univ. of California Berkeley
118 *> \author Univ. of Colorado Denver
119 *> \author NAG Ltd.
120 *
121 *> \date September 2012
122 *
123 *> \ingroup doubleSYcomputational
124 *
125 *> \par Further Details:
126 * =====================
127 *>
128 *> \verbatim
129 *>
130 *> If UPLO = 'U', then A = U*D*U**T, where
131 *> U = P(n)*U(n)* ... *P(k)U(k)* ...,
132 *> i.e., U is a product of terms P(k)*U(k), where k decreases from n to
133 *> 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
134 *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
135 *> defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
136 *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
137 *>
138 *> ( I v 0 ) k-s
139 *> U(k) = ( 0 I 0 ) s
140 *> ( 0 0 I ) n-k
141 *> k-s s n-k
142 *>
143 *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
144 *> If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
145 *> and A(k,k), and v overwrites A(1:k-2,k-1:k).
146 *>
147 *> If UPLO = 'L', then A = L*D*L**T, where
148 *> L = P(1)*L(1)* ... *P(k)*L(k)* ...,
149 *> i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
150 *> n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
151 *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
152 *> defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
153 *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
154 *>
155 *> ( I 0 0 ) k-1
156 *> L(k) = ( 0 I 0 ) s
157 *> ( 0 v I ) n-k-s+1
158 *> k-1 s n-k-s+1
159 *>
160 *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
161 *> If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
162 *> and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
163 *> \endverbatim
164 *
165 *> \par Contributors:
166 * ==================
167 *>
168 *> \verbatim
169 *>
170 *> 09-29-06 - patch from
171 *> Bobby Cheng, MathWorks
172 *>
173 *> Replace l.204 and l.372
174 *> IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
175 *> by
176 *> IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN
177 *>
178 *> 01-01-96 - Based on modifications by
179 *> J. Lewis, Boeing Computer Services Company
180 *> A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
181 *> 1-96 - Based on modifications by J. Lewis, Boeing Computer Services
182 *> Company
183 *> \endverbatim
184 *
185 * =====================================================================
186  SUBROUTINE dsytf2( UPLO, N, A, LDA, IPIV, INFO )
187 *
188 * -- LAPACK computational routine (version 3.4.2) --
189 * -- LAPACK is a software package provided by Univ. of Tennessee, --
190 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
191 * September 2012
192 *
193 * .. Scalar Arguments ..
194  CHARACTER uplo
195  INTEGER info, lda, n
196 * ..
197 * .. Array Arguments ..
198  INTEGER ipiv( * )
199  DOUBLE PRECISION a( lda, * )
200 * ..
201 *
202 * =====================================================================
203 *
204 * .. Parameters ..
205  DOUBLE PRECISION zero, one
206  parameter( zero = 0.0d+0, one = 1.0d+0 )
207  DOUBLE PRECISION eight, sevten
208  parameter( eight = 8.0d+0, sevten = 17.0d+0 )
209 * ..
210 * .. Local Scalars ..
211  LOGICAL upper
212  INTEGER i, imax, j, jmax, k, kk, kp, kstep
213  DOUBLE PRECISION absakk, alpha, colmax, d11, d12, d21, d22, r1,
214  $ rowmax, t, wk, wkm1, wkp1
215 * ..
216 * .. External Functions ..
217  LOGICAL lsame, disnan
218  INTEGER idamax
219  EXTERNAL lsame, idamax, disnan
220 * ..
221 * .. External Subroutines ..
222  EXTERNAL dscal, dswap, dsyr, xerbla
223 * ..
224 * .. Intrinsic Functions ..
225  INTRINSIC abs, max, sqrt
226 * ..
227 * .. Executable Statements ..
228 *
229 * Test the input parameters.
230 *
231  info = 0
232  upper = lsame( uplo, 'U' )
233  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
234  info = -1
235  ELSE IF( n.LT.0 ) THEN
236  info = -2
237  ELSE IF( lda.LT.max( 1, n ) ) THEN
238  info = -4
239  END IF
240  IF( info.NE.0 ) THEN
241  CALL xerbla( 'DSYTF2', -info )
242  return
243  END IF
244 *
245 * Initialize ALPHA for use in choosing pivot block size.
246 *
247  alpha = ( one+sqrt( sevten ) ) / eight
248 *
249  IF( upper ) THEN
250 *
251 * Factorize A as U*D*U**T using the upper triangle of A
252 *
253 * K is the main loop index, decreasing from N to 1 in steps of
254 * 1 or 2
255 *
256  k = n
257  10 continue
258 *
259 * If K < 1, exit from loop
260 *
261  IF( k.LT.1 )
262  $ go to 70
263  kstep = 1
264 *
265 * Determine rows and columns to be interchanged and whether
266 * a 1-by-1 or 2-by-2 pivot block will be used
267 *
268  absakk = abs( a( k, k ) )
269 *
270 * IMAX is the row-index of the largest off-diagonal element in
271 * column K, and COLMAX is its absolute value
272 *
273  IF( k.GT.1 ) THEN
274  imax = idamax( k-1, a( 1, k ), 1 )
275  colmax = abs( a( imax, k ) )
276  ELSE
277  colmax = zero
278  END IF
279 *
280  IF( (max( absakk, colmax ).EQ.zero) .OR. disnan(absakk) ) THEN
281 *
282 * Column K is zero or contains a NaN: set INFO and continue
283 *
284  IF( info.EQ.0 )
285  $ info = k
286  kp = k
287  ELSE
288  IF( absakk.GE.alpha*colmax ) THEN
289 *
290 * no interchange, use 1-by-1 pivot block
291 *
292  kp = k
293  ELSE
294 *
295 * JMAX is the column-index of the largest off-diagonal
296 * element in row IMAX, and ROWMAX is its absolute value
297 *
298  jmax = imax + idamax( k-imax, a( imax, imax+1 ), lda )
299  rowmax = abs( a( imax, jmax ) )
300  IF( imax.GT.1 ) THEN
301  jmax = idamax( imax-1, a( 1, imax ), 1 )
302  rowmax = max( rowmax, abs( a( jmax, imax ) ) )
303  END IF
304 *
305  IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
306 *
307 * no interchange, use 1-by-1 pivot block
308 *
309  kp = k
310  ELSE IF( abs( a( imax, imax ) ).GE.alpha*rowmax ) THEN
311 *
312 * interchange rows and columns K and IMAX, use 1-by-1
313 * pivot block
314 *
315  kp = imax
316  ELSE
317 *
318 * interchange rows and columns K-1 and IMAX, use 2-by-2
319 * pivot block
320 *
321  kp = imax
322  kstep = 2
323  END IF
324  END IF
325 *
326  kk = k - kstep + 1
327  IF( kp.NE.kk ) THEN
328 *
329 * Interchange rows and columns KK and KP in the leading
330 * submatrix A(1:k,1:k)
331 *
332  CALL dswap( kp-1, a( 1, kk ), 1, a( 1, kp ), 1 )
333  CALL dswap( kk-kp-1, a( kp+1, kk ), 1, a( kp, kp+1 ),
334  $ lda )
335  t = a( kk, kk )
336  a( kk, kk ) = a( kp, kp )
337  a( kp, kp ) = t
338  IF( kstep.EQ.2 ) THEN
339  t = a( k-1, k )
340  a( k-1, k ) = a( kp, k )
341  a( kp, k ) = t
342  END IF
343  END IF
344 *
345 * Update the leading submatrix
346 *
347  IF( kstep.EQ.1 ) THEN
348 *
349 * 1-by-1 pivot block D(k): column k now holds
350 *
351 * W(k) = U(k)*D(k)
352 *
353 * where U(k) is the k-th column of U
354 *
355 * Perform a rank-1 update of A(1:k-1,1:k-1) as
356 *
357 * A := A - U(k)*D(k)*U(k)**T = A - W(k)*1/D(k)*W(k)**T
358 *
359  r1 = one / a( k, k )
360  CALL dsyr( uplo, k-1, -r1, a( 1, k ), 1, a, lda )
361 *
362 * Store U(k) in column k
363 *
364  CALL dscal( k-1, r1, a( 1, k ), 1 )
365  ELSE
366 *
367 * 2-by-2 pivot block D(k): columns k and k-1 now hold
368 *
369 * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
370 *
371 * where U(k) and U(k-1) are the k-th and (k-1)-th columns
372 * of U
373 *
374 * Perform a rank-2 update of A(1:k-2,1:k-2) as
375 *
376 * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T
377 * = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**T
378 *
379  IF( k.GT.2 ) THEN
380 *
381  d12 = a( k-1, k )
382  d22 = a( k-1, k-1 ) / d12
383  d11 = a( k, k ) / d12
384  t = one / ( d11*d22-one )
385  d12 = t / d12
386 *
387  DO 30 j = k - 2, 1, -1
388  wkm1 = d12*( d11*a( j, k-1 )-a( j, k ) )
389  wk = d12*( d22*a( j, k )-a( j, k-1 ) )
390  DO 20 i = j, 1, -1
391  a( i, j ) = a( i, j ) - a( i, k )*wk -
392  $ a( i, k-1 )*wkm1
393  20 continue
394  a( j, k ) = wk
395  a( j, k-1 ) = wkm1
396  30 continue
397 *
398  END IF
399 *
400  END IF
401  END IF
402 *
403 * Store details of the interchanges in IPIV
404 *
405  IF( kstep.EQ.1 ) THEN
406  ipiv( k ) = kp
407  ELSE
408  ipiv( k ) = -kp
409  ipiv( k-1 ) = -kp
410  END IF
411 *
412 * Decrease K and return to the start of the main loop
413 *
414  k = k - kstep
415  go to 10
416 *
417  ELSE
418 *
419 * Factorize A as L*D*L**T using the lower triangle of A
420 *
421 * K is the main loop index, increasing from 1 to N in steps of
422 * 1 or 2
423 *
424  k = 1
425  40 continue
426 *
427 * If K > N, exit from loop
428 *
429  IF( k.GT.n )
430  $ go to 70
431  kstep = 1
432 *
433 * Determine rows and columns to be interchanged and whether
434 * a 1-by-1 or 2-by-2 pivot block will be used
435 *
436  absakk = abs( a( k, k ) )
437 *
438 * IMAX is the row-index of the largest off-diagonal element in
439 * column K, and COLMAX is its absolute value
440 *
441  IF( k.LT.n ) THEN
442  imax = k + idamax( n-k, a( k+1, k ), 1 )
443  colmax = abs( a( imax, k ) )
444  ELSE
445  colmax = zero
446  END IF
447 *
448  IF( (max( absakk, colmax ).EQ.zero) .OR. disnan(absakk) ) THEN
449 *
450 * Column K is zero or contains a NaN: set INFO and continue
451 *
452  IF( info.EQ.0 )
453  $ info = k
454  kp = k
455  ELSE
456  IF( absakk.GE.alpha*colmax ) THEN
457 *
458 * no interchange, use 1-by-1 pivot block
459 *
460  kp = k
461  ELSE
462 *
463 * JMAX is the column-index of the largest off-diagonal
464 * element in row IMAX, and ROWMAX is its absolute value
465 *
466  jmax = k - 1 + idamax( imax-k, a( imax, k ), lda )
467  rowmax = abs( a( imax, jmax ) )
468  IF( imax.LT.n ) THEN
469  jmax = imax + idamax( n-imax, a( imax+1, imax ), 1 )
470  rowmax = max( rowmax, abs( a( jmax, imax ) ) )
471  END IF
472 *
473  IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
474 *
475 * no interchange, use 1-by-1 pivot block
476 *
477  kp = k
478  ELSE IF( abs( a( imax, imax ) ).GE.alpha*rowmax ) THEN
479 *
480 * interchange rows and columns K and IMAX, use 1-by-1
481 * pivot block
482 *
483  kp = imax
484  ELSE
485 *
486 * interchange rows and columns K+1 and IMAX, use 2-by-2
487 * pivot block
488 *
489  kp = imax
490  kstep = 2
491  END IF
492  END IF
493 *
494  kk = k + kstep - 1
495  IF( kp.NE.kk ) THEN
496 *
497 * Interchange rows and columns KK and KP in the trailing
498 * submatrix A(k:n,k:n)
499 *
500  IF( kp.LT.n )
501  $ CALL dswap( n-kp, a( kp+1, kk ), 1, a( kp+1, kp ), 1 )
502  CALL dswap( kp-kk-1, a( kk+1, kk ), 1, a( kp, kk+1 ),
503  $ lda )
504  t = a( kk, kk )
505  a( kk, kk ) = a( kp, kp )
506  a( kp, kp ) = t
507  IF( kstep.EQ.2 ) THEN
508  t = a( k+1, k )
509  a( k+1, k ) = a( kp, k )
510  a( kp, k ) = t
511  END IF
512  END IF
513 *
514 * Update the trailing submatrix
515 *
516  IF( kstep.EQ.1 ) THEN
517 *
518 * 1-by-1 pivot block D(k): column k now holds
519 *
520 * W(k) = L(k)*D(k)
521 *
522 * where L(k) is the k-th column of L
523 *
524  IF( k.LT.n ) THEN
525 *
526 * Perform a rank-1 update of A(k+1:n,k+1:n) as
527 *
528 * A := A - L(k)*D(k)*L(k)**T = A - W(k)*(1/D(k))*W(k)**T
529 *
530  d11 = one / a( k, k )
531  CALL dsyr( uplo, n-k, -d11, a( k+1, k ), 1,
532  $ a( k+1, k+1 ), lda )
533 *
534 * Store L(k) in column K
535 *
536  CALL dscal( n-k, d11, a( k+1, k ), 1 )
537  END IF
538  ELSE
539 *
540 * 2-by-2 pivot block D(k)
541 *
542  IF( k.LT.n-1 ) THEN
543 *
544 * Perform a rank-2 update of A(k+2:n,k+2:n) as
545 *
546 * A := A - ( (A(k) A(k+1))*D(k)**(-1) ) * (A(k) A(k+1))**T
547 *
548 * where L(k) and L(k+1) are the k-th and (k+1)-th
549 * columns of L
550 *
551  d21 = a( k+1, k )
552  d11 = a( k+1, k+1 ) / d21
553  d22 = a( k, k ) / d21
554  t = one / ( d11*d22-one )
555  d21 = t / d21
556 *
557  DO 60 j = k + 2, n
558 *
559  wk = d21*( d11*a( j, k )-a( j, k+1 ) )
560  wkp1 = d21*( d22*a( j, k+1 )-a( j, k ) )
561 *
562  DO 50 i = j, n
563  a( i, j ) = a( i, j ) - a( i, k )*wk -
564  $ a( i, k+1 )*wkp1
565  50 continue
566 *
567  a( j, k ) = wk
568  a( j, k+1 ) = wkp1
569 *
570  60 continue
571  END IF
572  END IF
573  END IF
574 *
575 * Store details of the interchanges in IPIV
576 *
577  IF( kstep.EQ.1 ) THEN
578  ipiv( k ) = kp
579  ELSE
580  ipiv( k ) = -kp
581  ipiv( k+1 ) = -kp
582  END IF
583 *
584 * Increase K and return to the start of the main loop
585 *
586  k = k + kstep
587  go to 40
588 *
589  END IF
590 *
591  70 continue
592 *
593  return
594 *
595 * End of DSYTF2
596 *
597  END