LAPACK  3.10.0
LAPACK: Linear Algebra PACKage

◆ chetf2()

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.
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 185 of file chetf2.f.

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