LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
ssytf2.f
Go to the documentation of this file.
1 *> \brief \b SSYTF2 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 SSYTF2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytf2.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytf2.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytf2.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE SSYTF2( 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 * REAL A( LDA, * )
30 * ..
31 *
32 *
33 *> \par Purpose:
34 * =============
35 *>
36 *> \verbatim
37 *>
38 *> SSYTF2 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 REAL 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 realSYcomputational
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. SISNAN(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 *>
184 *> \endverbatim
185 *
186 * =====================================================================
187  SUBROUTINE ssytf2( UPLO, N, A, LDA, IPIV, INFO )
188 *
189 * -- LAPACK computational routine (version 3.4.2) --
190 * -- LAPACK is a software package provided by Univ. of Tennessee, --
191 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
192 * September 2012
193 *
194 * .. Scalar Arguments ..
195  CHARACTER uplo
196  INTEGER info, lda, n
197 * ..
198 * .. Array Arguments ..
199  INTEGER ipiv( * )
200  REAL a( lda, * )
201 * ..
202 *
203 * =====================================================================
204 *
205 * .. Parameters ..
206  REAL zero, one
207  parameter( zero = 0.0e+0, one = 1.0e+0 )
208  REAL eight, sevten
209  parameter( eight = 8.0e+0, sevten = 17.0e+0 )
210 * ..
211 * .. Local Scalars ..
212  LOGICAL upper
213  INTEGER i, imax, j, jmax, k, kk, kp, kstep
214  REAL absakk, alpha, colmax, d11, d12, d21, d22, r1,
215  $ rowmax, t, wk, wkm1, wkp1
216 * ..
217 * .. External Functions ..
218  LOGICAL lsame, sisnan
219  INTEGER isamax
220  EXTERNAL lsame, isamax, sisnan
221 * ..
222 * .. External Subroutines ..
223  EXTERNAL sscal, sswap, ssyr, xerbla
224 * ..
225 * .. Intrinsic Functions ..
226  INTRINSIC abs, max, sqrt
227 * ..
228 * .. Executable Statements ..
229 *
230 * Test the input parameters.
231 *
232  info = 0
233  upper = lsame( uplo, 'U' )
234  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
235  info = -1
236  ELSE IF( n.LT.0 ) THEN
237  info = -2
238  ELSE IF( lda.LT.max( 1, n ) ) THEN
239  info = -4
240  END IF
241  IF( info.NE.0 ) THEN
242  CALL xerbla( 'SSYTF2', -info )
243  return
244  END IF
245 *
246 * Initialize ALPHA for use in choosing pivot block size.
247 *
248  alpha = ( one+sqrt( sevten ) ) / eight
249 *
250  IF( upper ) THEN
251 *
252 * Factorize A as U*D*U**T using the upper triangle of A
253 *
254 * K is the main loop index, decreasing from N to 1 in steps of
255 * 1 or 2
256 *
257  k = n
258  10 continue
259 *
260 * If K < 1, exit from loop
261 *
262  IF( k.LT.1 )
263  $ go to 70
264  kstep = 1
265 *
266 * Determine rows and columns to be interchanged and whether
267 * a 1-by-1 or 2-by-2 pivot block will be used
268 *
269  absakk = abs( a( k, k ) )
270 *
271 * IMAX is the row-index of the largest off-diagonal element in
272 * column K, and COLMAX is its absolute value
273 *
274  IF( k.GT.1 ) THEN
275  imax = isamax( k-1, a( 1, k ), 1 )
276  colmax = abs( a( imax, k ) )
277  ELSE
278  colmax = zero
279  END IF
280 *
281  IF( (max( absakk, colmax ).EQ.zero) .OR. sisnan(absakk) ) THEN
282 *
283 * Column K is zero or contains a NaN: set INFO and continue
284 *
285  IF( info.EQ.0 )
286  $ info = k
287  kp = k
288  ELSE
289  IF( absakk.GE.alpha*colmax ) THEN
290 *
291 * no interchange, use 1-by-1 pivot block
292 *
293  kp = k
294  ELSE
295 *
296 * JMAX is the column-index of the largest off-diagonal
297 * element in row IMAX, and ROWMAX is its absolute value
298 *
299  jmax = imax + isamax( k-imax, a( imax, imax+1 ), lda )
300  rowmax = abs( a( imax, jmax ) )
301  IF( imax.GT.1 ) THEN
302  jmax = isamax( imax-1, a( 1, imax ), 1 )
303  rowmax = max( rowmax, abs( a( jmax, imax ) ) )
304  END IF
305 *
306  IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
307 *
308 * no interchange, use 1-by-1 pivot block
309 *
310  kp = k
311  ELSE IF( abs( a( imax, imax ) ).GE.alpha*rowmax ) THEN
312 *
313 * interchange rows and columns K and IMAX, use 1-by-1
314 * pivot block
315 *
316  kp = imax
317  ELSE
318 *
319 * interchange rows and columns K-1 and IMAX, use 2-by-2
320 * pivot block
321 *
322  kp = imax
323  kstep = 2
324  END IF
325  END IF
326 *
327  kk = k - kstep + 1
328  IF( kp.NE.kk ) THEN
329 *
330 * Interchange rows and columns KK and KP in the leading
331 * submatrix A(1:k,1:k)
332 *
333  CALL sswap( kp-1, a( 1, kk ), 1, a( 1, kp ), 1 )
334  CALL sswap( kk-kp-1, a( kp+1, kk ), 1, a( kp, kp+1 ),
335  $ lda )
336  t = a( kk, kk )
337  a( kk, kk ) = a( kp, kp )
338  a( kp, kp ) = t
339  IF( kstep.EQ.2 ) THEN
340  t = a( k-1, k )
341  a( k-1, k ) = a( kp, k )
342  a( kp, k ) = t
343  END IF
344  END IF
345 *
346 * Update the leading submatrix
347 *
348  IF( kstep.EQ.1 ) THEN
349 *
350 * 1-by-1 pivot block D(k): column k now holds
351 *
352 * W(k) = U(k)*D(k)
353 *
354 * where U(k) is the k-th column of U
355 *
356 * Perform a rank-1 update of A(1:k-1,1:k-1) as
357 *
358 * A := A - U(k)*D(k)*U(k)**T = A - W(k)*1/D(k)*W(k)**T
359 *
360  r1 = one / a( k, k )
361  CALL ssyr( uplo, k-1, -r1, a( 1, k ), 1, a, lda )
362 *
363 * Store U(k) in column k
364 *
365  CALL sscal( k-1, r1, a( 1, k ), 1 )
366  ELSE
367 *
368 * 2-by-2 pivot block D(k): columns k and k-1 now hold
369 *
370 * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
371 *
372 * where U(k) and U(k-1) are the k-th and (k-1)-th columns
373 * of U
374 *
375 * Perform a rank-2 update of A(1:k-2,1:k-2) as
376 *
377 * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T
378 * = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**T
379 *
380  IF( k.GT.2 ) THEN
381 *
382  d12 = a( k-1, k )
383  d22 = a( k-1, k-1 ) / d12
384  d11 = a( k, k ) / d12
385  t = one / ( d11*d22-one )
386  d12 = t / d12
387 *
388  DO 30 j = k - 2, 1, -1
389  wkm1 = d12*( d11*a( j, k-1 )-a( j, k ) )
390  wk = d12*( d22*a( j, k )-a( j, k-1 ) )
391  DO 20 i = j, 1, -1
392  a( i, j ) = a( i, j ) - a( i, k )*wk -
393  $ a( i, k-1 )*wkm1
394  20 continue
395  a( j, k ) = wk
396  a( j, k-1 ) = wkm1
397  30 continue
398 *
399  END IF
400 *
401  END IF
402  END IF
403 *
404 * Store details of the interchanges in IPIV
405 *
406  IF( kstep.EQ.1 ) THEN
407  ipiv( k ) = kp
408  ELSE
409  ipiv( k ) = -kp
410  ipiv( k-1 ) = -kp
411  END IF
412 *
413 * Decrease K and return to the start of the main loop
414 *
415  k = k - kstep
416  go to 10
417 *
418  ELSE
419 *
420 * Factorize A as L*D*L**T using the lower triangle of A
421 *
422 * K is the main loop index, increasing from 1 to N in steps of
423 * 1 or 2
424 *
425  k = 1
426  40 continue
427 *
428 * If K > N, exit from loop
429 *
430  IF( k.GT.n )
431  $ go to 70
432  kstep = 1
433 *
434 * Determine rows and columns to be interchanged and whether
435 * a 1-by-1 or 2-by-2 pivot block will be used
436 *
437  absakk = abs( a( k, k ) )
438 *
439 * IMAX is the row-index of the largest off-diagonal element in
440 * column K, and COLMAX is its absolute value
441 *
442  IF( k.LT.n ) THEN
443  imax = k + isamax( n-k, a( k+1, k ), 1 )
444  colmax = abs( a( imax, k ) )
445  ELSE
446  colmax = zero
447  END IF
448 *
449  IF( (max( absakk, colmax ).EQ.zero) .OR. sisnan(absakk) ) THEN
450 *
451 * Column K is zero or contains a NaN: set INFO and continue
452 *
453  IF( info.EQ.0 )
454  $ info = k
455  kp = k
456  ELSE
457  IF( absakk.GE.alpha*colmax ) THEN
458 *
459 * no interchange, use 1-by-1 pivot block
460 *
461  kp = k
462  ELSE
463 *
464 * JMAX is the column-index of the largest off-diagonal
465 * element in row IMAX, and ROWMAX is its absolute value
466 *
467  jmax = k - 1 + isamax( imax-k, a( imax, k ), lda )
468  rowmax = abs( a( imax, jmax ) )
469  IF( imax.LT.n ) THEN
470  jmax = imax + isamax( n-imax, a( imax+1, imax ), 1 )
471  rowmax = max( rowmax, abs( a( jmax, imax ) ) )
472  END IF
473 *
474  IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
475 *
476 * no interchange, use 1-by-1 pivot block
477 *
478  kp = k
479  ELSE IF( abs( a( imax, imax ) ).GE.alpha*rowmax ) THEN
480 *
481 * interchange rows and columns K and IMAX, use 1-by-1
482 * pivot block
483 *
484  kp = imax
485  ELSE
486 *
487 * interchange rows and columns K+1 and IMAX, use 2-by-2
488 * pivot block
489 *
490  kp = imax
491  kstep = 2
492  END IF
493  END IF
494 *
495  kk = k + kstep - 1
496  IF( kp.NE.kk ) THEN
497 *
498 * Interchange rows and columns KK and KP in the trailing
499 * submatrix A(k:n,k:n)
500 *
501  IF( kp.LT.n )
502  $ CALL sswap( n-kp, a( kp+1, kk ), 1, a( kp+1, kp ), 1 )
503  CALL sswap( kp-kk-1, a( kk+1, kk ), 1, a( kp, kk+1 ),
504  $ lda )
505  t = a( kk, kk )
506  a( kk, kk ) = a( kp, kp )
507  a( kp, kp ) = t
508  IF( kstep.EQ.2 ) THEN
509  t = a( k+1, k )
510  a( k+1, k ) = a( kp, k )
511  a( kp, k ) = t
512  END IF
513  END IF
514 *
515 * Update the trailing submatrix
516 *
517  IF( kstep.EQ.1 ) THEN
518 *
519 * 1-by-1 pivot block D(k): column k now holds
520 *
521 * W(k) = L(k)*D(k)
522 *
523 * where L(k) is the k-th column of L
524 *
525  IF( k.LT.n ) THEN
526 *
527 * Perform a rank-1 update of A(k+1:n,k+1:n) as
528 *
529 * A := A - L(k)*D(k)*L(k)**T = A - W(k)*(1/D(k))*W(k)**T
530 *
531  d11 = one / a( k, k )
532  CALL ssyr( uplo, n-k, -d11, a( k+1, k ), 1,
533  $ a( k+1, k+1 ), lda )
534 *
535 * Store L(k) in column K
536 *
537  CALL sscal( n-k, d11, a( k+1, k ), 1 )
538  END IF
539  ELSE
540 *
541 * 2-by-2 pivot block D(k)
542 *
543  IF( k.LT.n-1 ) THEN
544 *
545 * Perform a rank-2 update of A(k+2:n,k+2:n) as
546 *
547 * A := A - ( (A(k) A(k+1))*D(k)**(-1) ) * (A(k) A(k+1))**T
548 *
549 * where L(k) and L(k+1) are the k-th and (k+1)-th
550 * columns of L
551 *
552  d21 = a( k+1, k )
553  d11 = a( k+1, k+1 ) / d21
554  d22 = a( k, k ) / d21
555  t = one / ( d11*d22-one )
556  d21 = t / d21
557 *
558  DO 60 j = k + 2, n
559 *
560  wk = d21*( d11*a( j, k )-a( j, k+1 ) )
561  wkp1 = d21*( d22*a( j, k+1 )-a( j, k ) )
562 *
563  DO 50 i = j, n
564  a( i, j ) = a( i, j ) - a( i, k )*wk -
565  $ a( i, k+1 )*wkp1
566  50 continue
567 *
568  a( j, k ) = wk
569  a( j, k+1 ) = wkp1
570 *
571  60 continue
572  END IF
573  END IF
574  END IF
575 *
576 * Store details of the interchanges in IPIV
577 *
578  IF( kstep.EQ.1 ) THEN
579  ipiv( k ) = kp
580  ELSE
581  ipiv( k ) = -kp
582  ipiv( k+1 ) = -kp
583  END IF
584 *
585 * Increase K and return to the start of the main loop
586 *
587  k = k + kstep
588  go to 40
589 *
590  END IF
591 *
592  70 continue
593 *
594  return
595 *
596 * End of SSYTF2
597 *
598  END