LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
subroutine chetf2 ( character  UPLO,
integer  N,
complex, dimension( lda, * )  A,
integer  LDA,
integer, dimension( * )  IPIV,
integer  INFO 
)

CHETF2 computes the factorization of a complex Hermitian matrix, using the diagonal pivoting method (unblocked algorithm calling Level 2 BLAS).

Download CHETF2 + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 CHETF2 computes the factorization of a complex Hermitian matrix A
 using the Bunch-Kaufman diagonal pivoting method:

    A = U*D*U**H  or  A = L*D*L**H

 where U (or L) is a product of permutation and unit upper (lower)
 triangular matrices, U**H is the conjugate transpose of U, and D is
 Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal blocks.

 This is the unblocked version of the algorithm, calling Level 2 BLAS.
Parameters
[in]UPLO
          UPLO is CHARACTER*1
          Specifies whether the upper or lower triangular part of the
          Hermitian matrix A is stored:
          = 'U':  Upper triangular
          = 'L':  Lower triangular
[in]N
          N is INTEGER
          The order of the matrix A.  N >= 0.
[in,out]A
          A is COMPLEX array, dimension (LDA,N)
          On entry, the Hermitian matrix A.  If UPLO = 'U', the leading
          n-by-n upper triangular part of A contains the upper
          triangular part of the matrix A, and the strictly lower
          triangular part of A is not referenced.  If UPLO = 'L', the
          leading n-by-n lower triangular part of A contains the lower
          triangular part of the matrix A, and the strictly upper
          triangular part of A is not referenced.

          On exit, the block diagonal matrix D and the multipliers used
          to obtain the factor U or L (see below for further details).
[in]LDA
          LDA is INTEGER
          The leading dimension of the array A.  LDA >= max(1,N).
[out]IPIV
          IPIV is INTEGER array, dimension (N)
          Details of the interchanges and the block structure of D.

          If UPLO = 'U':
             If IPIV(k) > 0, then rows and columns k and IPIV(k) were
             interchanged and D(k,k) is a 1-by-1 diagonal block.

             If IPIV(k) = IPIV(k-1) < 0, then rows and columns
             k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
             is a 2-by-2 diagonal block.

          If UPLO = 'L':
             If IPIV(k) > 0, then rows and columns k and IPIV(k) were
             interchanged and D(k,k) is a 1-by-1 diagonal block.

             If IPIV(k) = IPIV(k+1) < 0, then rows and columns
             k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1)
             is a 2-by-2 diagonal block.
[out]INFO
          INFO is INTEGER
          = 0: successful exit
          < 0: if INFO = -k, the k-th argument had an illegal value
          > 0: if INFO = k, D(k,k) is exactly zero.  The factorization
               has been completed, but the block diagonal matrix D is
               exactly singular, and division by zero will occur if it
               is used to solve a system of equations.
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Date
November 2013
Further Details:
  09-29-06 - patch from
    Bobby Cheng, MathWorks

    Replace l.210 and l.392
         IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
    by
         IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. SISNAN(ABSAKK) ) THEN

  01-01-96 - Based on modifications by
    J. Lewis, Boeing Computer Services Company
    A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA

  If UPLO = 'U', then A = U*D*U**H, where
     U = P(n)*U(n)* ... *P(k)U(k)* ...,
  i.e., U is a product of terms P(k)*U(k), where k decreases from n to
  1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as
  defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
  that if the diagonal block D(k) is of order s (s = 1 or 2), then

             (   I    v    0   )   k-s
     U(k) =  (   0    I    0   )   s
             (   0    0    I   )   n-k
                k-s   s   n-k

  If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
  If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
  and A(k,k), and v overwrites A(1:k-2,k-1:k).

  If UPLO = 'L', then A = L*D*L**H, where
     L = P(1)*L(1)* ... *P(k)*L(k)* ...,
  i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
  n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as
  defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
  that if the diagonal block D(k) is of order s (s = 1 or 2), then

             (   I    0     0   )  k-1
     L(k) =  (   0    I     0   )  s
             (   0    v     I   )  n-k-s+1
                k-1   s  n-k-s+1

  If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
  If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
  and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).

Definition at line 188 of file chetf2.f.

188 *
189 * -- LAPACK computational routine (version 3.5.0) --
190 * -- LAPACK is a software package provided by Univ. of Tennessee, --
191 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
192 * November 2013
193 *
194 * .. Scalar Arguments ..
195  CHARACTER uplo
196  INTEGER info, lda, n
197 * ..
198 * .. Array Arguments ..
199  INTEGER ipiv( * )
200  COMPLEX 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, d, d11, d22, r1, rowmax,
215  $ tt
216  COMPLEX d12, d21, t, wk, wkm1, wkp1, zdum
217 * ..
218 * .. External Functions ..
219  LOGICAL lsame, sisnan
220  INTEGER icamax
221  REAL slapy2
222  EXTERNAL lsame, icamax, slapy2, sisnan
223 * ..
224 * .. External Subroutines ..
225  EXTERNAL cher, csscal, cswap, xerbla
226 * ..
227 * .. Intrinsic Functions ..
228  INTRINSIC abs, aimag, cmplx, conjg, max, REAL, sqrt
229 * ..
230 * .. Statement Functions ..
231  REAL cabs1
232 * ..
233 * .. Statement Function definitions ..
234  cabs1( zdum ) = abs( REAL( ZDUM ) ) + abs( aimag( zdum ) )
235 * ..
236 * .. Executable Statements ..
237 *
238 * Test the input parameters.
239 *
240  info = 0
241  upper = lsame( uplo, 'U' )
242  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
243  info = -1
244  ELSE IF( n.LT.0 ) THEN
245  info = -2
246  ELSE IF( lda.LT.max( 1, n ) ) THEN
247  info = -4
248  END IF
249  IF( info.NE.0 ) THEN
250  CALL xerbla( 'CHETF2', -info )
251  RETURN
252  END IF
253 *
254 * Initialize ALPHA for use in choosing pivot block size.
255 *
256  alpha = ( one+sqrt( sevten ) ) / eight
257 *
258  IF( upper ) THEN
259 *
260 * Factorize A as U*D*U**H using the upper triangle of A
261 *
262 * K is the main loop index, decreasing from N to 1 in steps of
263 * 1 or 2
264 *
265  k = n
266  10 CONTINUE
267 *
268 * If K < 1, exit from loop
269 *
270  IF( k.LT.1 )
271  $ GO TO 90
272  kstep = 1
273 *
274 * Determine rows and columns to be interchanged and whether
275 * a 1-by-1 or 2-by-2 pivot block will be used
276 *
277  absakk = abs( REAL( A( K, K ) ) )
278 *
279 * IMAX is the row-index of the largest off-diagonal element in
280 * column K, and COLMAX is its absolute value.
281 * Determine both COLMAX and IMAX.
282 *
283  IF( k.GT.1 ) THEN
284  imax = icamax( k-1, a( 1, k ), 1 )
285  colmax = cabs1( a( imax, k ) )
286  ELSE
287  colmax = zero
288  END IF
289 *
290  IF( (max( absakk, colmax ).EQ.zero) .OR. sisnan(absakk) ) THEN
291 *
292 * Column K is or underflow, or contains a NaN:
293 * set INFO and continue
294 *
295  IF( info.EQ.0 )
296  $ info = k
297  kp = k
298  a( k, k ) = REAL( A( K, K ) )
299  ELSE
300  IF( absakk.GE.alpha*colmax ) THEN
301 *
302 * no interchange, use 1-by-1 pivot block
303 *
304  kp = k
305  ELSE
306 *
307 * JMAX is the column-index of the largest off-diagonal
308 * element in row IMAX, and ROWMAX is its absolute value
309 *
310  jmax = imax + icamax( k-imax, a( imax, imax+1 ), lda )
311  rowmax = cabs1( a( imax, jmax ) )
312  IF( imax.GT.1 ) THEN
313  jmax = icamax( imax-1, a( 1, imax ), 1 )
314  rowmax = max( rowmax, cabs1( a( jmax, imax ) ) )
315  END IF
316 *
317  IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
318 *
319 * no interchange, use 1-by-1 pivot block
320 *
321  kp = k
322  ELSE IF( abs( REAL( A( IMAX, IMAX ) ) ).GE.alpha*rowmax )
323  $ THEN
324 *
325 * interchange rows and columns K and IMAX, use 1-by-1
326 * pivot block
327 *
328  kp = imax
329  ELSE
330 *
331 * interchange rows and columns K-1 and IMAX, use 2-by-2
332 * pivot block
333 *
334  kp = imax
335  kstep = 2
336  END IF
337  END IF
338 *
339  kk = k - kstep + 1
340  IF( kp.NE.kk ) THEN
341 *
342 * Interchange rows and columns KK and KP in the leading
343 * submatrix A(1:k,1:k)
344 *
345  CALL cswap( kp-1, a( 1, kk ), 1, a( 1, kp ), 1 )
346  DO 20 j = kp + 1, kk - 1
347  t = conjg( a( j, kk ) )
348  a( j, kk ) = conjg( a( kp, j ) )
349  a( kp, j ) = t
350  20 CONTINUE
351  a( kp, kk ) = conjg( a( kp, kk ) )
352  r1 = REAL( A( KK, KK ) )
353  a( kk, kk ) = REAL( A( KP, KP ) )
354  a( kp, kp ) = r1
355  IF( kstep.EQ.2 ) THEN
356  a( k, k ) = REAL( A( K, K ) )
357  t = a( k-1, k )
358  a( k-1, k ) = a( kp, k )
359  a( kp, k ) = t
360  END IF
361  ELSE
362  a( k, k ) = REAL( A( K, K ) )
363  IF( kstep.EQ.2 )
364  $ a( k-1, k-1 ) = REAL( A( K-1, K-1 ) )
365  END IF
366 *
367 * Update the leading submatrix
368 *
369  IF( kstep.EQ.1 ) THEN
370 *
371 * 1-by-1 pivot block D(k): column k now holds
372 *
373 * W(k) = U(k)*D(k)
374 *
375 * where U(k) is the k-th column of U
376 *
377 * Perform a rank-1 update of A(1:k-1,1:k-1) as
378 *
379 * A := A - U(k)*D(k)*U(k)**H = A - W(k)*1/D(k)*W(k)**H
380 *
381  r1 = one / REAL( A( K, K ) )
382  CALL cher( uplo, k-1, -r1, a( 1, k ), 1, a, lda )
383 *
384 * Store U(k) in column k
385 *
386  CALL csscal( k-1, r1, a( 1, k ), 1 )
387  ELSE
388 *
389 * 2-by-2 pivot block D(k): columns k and k-1 now hold
390 *
391 * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
392 *
393 * where U(k) and U(k-1) are the k-th and (k-1)-th columns
394 * of U
395 *
396 * Perform a rank-2 update of A(1:k-2,1:k-2) as
397 *
398 * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**H
399 * = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**H
400 *
401  IF( k.GT.2 ) THEN
402 *
403  d = slapy2( REAL( A( K-1, K ) ),
404  $ aimag( a( k-1, k ) ) )
405  d22 = REAL( A( K-1, K-1 ) ) / d
406  d11 = REAL( A( K, K ) ) / d
407  tt = one / ( d11*d22-one )
408  d12 = a( k-1, k ) / d
409  d = tt / d
410 *
411  DO 40 j = k - 2, 1, -1
412  wkm1 = d*( d11*a( j, k-1 )-conjg( d12 )*a( j, k ) )
413  wk = d*( d22*a( j, k )-d12*a( j, k-1 ) )
414  DO 30 i = j, 1, -1
415  a( i, j ) = a( i, j ) - a( i, k )*conjg( wk ) -
416  $ a( i, k-1 )*conjg( wkm1 )
417  30 CONTINUE
418  a( j, k ) = wk
419  a( j, k-1 ) = wkm1
420  a( j, j ) = cmplx( REAL( A( J, J ) ), 0.0e+0 )
421  40 CONTINUE
422 *
423  END IF
424 *
425  END IF
426  END IF
427 *
428 * Store details of the interchanges in IPIV
429 *
430  IF( kstep.EQ.1 ) THEN
431  ipiv( k ) = kp
432  ELSE
433  ipiv( k ) = -kp
434  ipiv( k-1 ) = -kp
435  END IF
436 *
437 * Decrease K and return to the start of the main loop
438 *
439  k = k - kstep
440  GO TO 10
441 *
442  ELSE
443 *
444 * Factorize A as L*D*L**H using the lower triangle of A
445 *
446 * K is the main loop index, increasing from 1 to N in steps of
447 * 1 or 2
448 *
449  k = 1
450  50 CONTINUE
451 *
452 * If K > N, exit from loop
453 *
454  IF( k.GT.n )
455  $ GO TO 90
456  kstep = 1
457 *
458 * Determine rows and columns to be interchanged and whether
459 * a 1-by-1 or 2-by-2 pivot block will be used
460 *
461  absakk = abs( REAL( A( K, K ) ) )
462 *
463 * IMAX is the row-index of the largest off-diagonal element in
464 * column K, and COLMAX is its absolute value.
465 * Determine both COLMAX and IMAX.
466 *
467  IF( k.LT.n ) THEN
468  imax = k + icamax( n-k, a( k+1, k ), 1 )
469  colmax = cabs1( a( imax, k ) )
470  ELSE
471  colmax = zero
472  END IF
473 *
474  IF( (max( absakk, colmax ).EQ.zero) .OR. sisnan(absakk) ) THEN
475 *
476 * Column K is zero or underflow, contains a NaN:
477 * set INFO and continue
478 *
479  IF( info.EQ.0 )
480  $ info = k
481  kp = k
482  a( k, k ) = REAL( A( K, K ) )
483  ELSE
484  IF( absakk.GE.alpha*colmax ) THEN
485 *
486 * no interchange, use 1-by-1 pivot block
487 *
488  kp = k
489  ELSE
490 *
491 * JMAX is the column-index of the largest off-diagonal
492 * element in row IMAX, and ROWMAX is its absolute value
493 *
494  jmax = k - 1 + icamax( imax-k, a( imax, k ), lda )
495  rowmax = cabs1( a( imax, jmax ) )
496  IF( imax.LT.n ) THEN
497  jmax = imax + icamax( n-imax, a( imax+1, imax ), 1 )
498  rowmax = max( rowmax, cabs1( a( jmax, imax ) ) )
499  END IF
500 *
501  IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
502 *
503 * no interchange, use 1-by-1 pivot block
504 *
505  kp = k
506  ELSE IF( abs( REAL( A( IMAX, IMAX ) ) ).GE.alpha*rowmax )
507  $ THEN
508 *
509 * interchange rows and columns K and IMAX, use 1-by-1
510 * pivot block
511 *
512  kp = imax
513  ELSE
514 *
515 * interchange rows and columns K+1 and IMAX, use 2-by-2
516 * pivot block
517 *
518  kp = imax
519  kstep = 2
520  END IF
521  END IF
522 *
523  kk = k + kstep - 1
524  IF( kp.NE.kk ) THEN
525 *
526 * Interchange rows and columns KK and KP in the trailing
527 * submatrix A(k:n,k:n)
528 *
529  IF( kp.LT.n )
530  $ CALL cswap( n-kp, a( kp+1, kk ), 1, a( kp+1, kp ), 1 )
531  DO 60 j = kk + 1, kp - 1
532  t = conjg( a( j, kk ) )
533  a( j, kk ) = conjg( a( kp, j ) )
534  a( kp, j ) = t
535  60 CONTINUE
536  a( kp, kk ) = conjg( a( kp, kk ) )
537  r1 = REAL( A( KK, KK ) )
538  a( kk, kk ) = REAL( A( KP, KP ) )
539  a( kp, kp ) = r1
540  IF( kstep.EQ.2 ) THEN
541  a( k, k ) = REAL( A( K, K ) )
542  t = a( k+1, k )
543  a( k+1, k ) = a( kp, k )
544  a( kp, k ) = t
545  END IF
546  ELSE
547  a( k, k ) = REAL( A( K, K ) )
548  IF( kstep.EQ.2 )
549  $ a( k+1, k+1 ) = REAL( A( K+1, K+1 ) )
550  END IF
551 *
552 * Update the trailing submatrix
553 *
554  IF( kstep.EQ.1 ) THEN
555 *
556 * 1-by-1 pivot block D(k): column k now holds
557 *
558 * W(k) = L(k)*D(k)
559 *
560 * where L(k) is the k-th column of L
561 *
562  IF( k.LT.n ) THEN
563 *
564 * Perform a rank-1 update of A(k+1:n,k+1:n) as
565 *
566 * A := A - L(k)*D(k)*L(k)**H = A - W(k)*(1/D(k))*W(k)**H
567 *
568  r1 = one / REAL( A( K, K ) )
569  CALL cher( uplo, n-k, -r1, a( k+1, k ), 1,
570  $ a( k+1, k+1 ), lda )
571 *
572 * Store L(k) in column K
573 *
574  CALL csscal( n-k, r1, a( k+1, k ), 1 )
575  END IF
576  ELSE
577 *
578 * 2-by-2 pivot block D(k)
579 *
580  IF( k.LT.n-1 ) THEN
581 *
582 * Perform a rank-2 update of A(k+2:n,k+2:n) as
583 *
584 * A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**H
585 * = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**H
586 *
587 * where L(k) and L(k+1) are the k-th and (k+1)-th
588 * columns of L
589 *
590  d = slapy2( REAL( A( K+1, K ) ),
591  $ aimag( a( k+1, k ) ) )
592  d11 = REAL( A( K+1, K+1 ) ) / d
593  d22 = REAL( A( K, K ) ) / d
594  tt = one / ( d11*d22-one )
595  d21 = a( k+1, k ) / d
596  d = tt / d
597 *
598  DO 80 j = k + 2, n
599  wk = d*( d11*a( j, k )-d21*a( j, k+1 ) )
600  wkp1 = d*( d22*a( j, k+1 )-conjg( d21 )*a( j, k ) )
601  DO 70 i = j, n
602  a( i, j ) = a( i, j ) - a( i, k )*conjg( wk ) -
603  $ a( i, k+1 )*conjg( wkp1 )
604  70 CONTINUE
605  a( j, k ) = wk
606  a( j, k+1 ) = wkp1
607  a( j, j ) = cmplx( REAL( A( J, J ) ), 0.0e+0 )
608  80 CONTINUE
609  END IF
610  END IF
611  END IF
612 *
613 * Store details of the interchanges in IPIV
614 *
615  IF( kstep.EQ.1 ) THEN
616  ipiv( k ) = kp
617  ELSE
618  ipiv( k ) = -kp
619  ipiv( k+1 ) = -kp
620  END IF
621 *
622 * Increase K and return to the start of the main loop
623 *
624  k = k + kstep
625  GO TO 50
626 *
627  END IF
628 *
629  90 CONTINUE
630  RETURN
631 *
632 * End of CHETF2
633 *
logical function sisnan(SIN)
SISNAN tests input for NaN.
Definition: sisnan.f:61
subroutine cher(UPLO, N, ALPHA, X, INCX, A, LDA)
CHER
Definition: cher.f:137
real function slapy2(X, Y)
SLAPY2 returns sqrt(x2+y2).
Definition: slapy2.f:65
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
integer function icamax(N, CX, INCX)
ICAMAX
Definition: icamax.f:53
subroutine cswap(N, CX, INCX, CY, INCY)
CSWAP
Definition: cswap.f:52
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:55
subroutine csscal(N, SA, CX, INCX)
CSSCAL
Definition: csscal.f:54

Here is the call graph for this function:

Here is the caller graph for this function: