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