LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
subroutine chptrf ( character  UPLO,
integer  N,
complex, dimension( * )  AP,
integer, dimension( * )  IPIV,
integer  INFO 
)

CHPTRF

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

Purpose:
 CHPTRF computes the factorization of a complex Hermitian packed
 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, and D is Hermitian and block diagonal with
 1-by-1 and 2-by-2 diagonal blocks.
Parameters
[in]UPLO
          UPLO is CHARACTER*1
          = 'U':  Upper triangle of A is stored;
          = 'L':  Lower triangle of A is stored.
[in]N
          N is INTEGER
          The order of the matrix A.  N >= 0.
[in,out]AP
          AP is COMPLEX array, dimension (N*(N+1)/2)
          On entry, the upper or lower triangle of the Hermitian matrix
          A, packed columnwise in a linear array.  The j-th column of A
          is stored in the array AP as follows:
          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.

          On exit, the block diagonal matrix D and the multipliers used
          to obtain the factor U or L, stored as a packed triangular
          matrix overwriting A (see below for further details).
[out]IPIV
          IPIV is INTEGER array, dimension (N)
          Details of the interchanges and the block structure of D.
          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 UPLO = 'U' and 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' and 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 = -i, the i-th argument had an illegal value
          > 0: if INFO = i, D(i,i) 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 2011
Further Details:
  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).
Contributors:
J. Lewis, Boeing Computer Services Company

Definition at line 161 of file chptrf.f.

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