3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZHPTRS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhptrs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhptrs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhptrs.f">
21 * SUBROUTINE ZHPTRS( UPLO, N, NRHS, AP, IPIV, B, LDB, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, LDB, N, NRHS
27 * .. Array Arguments ..
29 * COMPLEX*16 AP( * ), B( LDB, * )
38 *> ZHPTRS solves a system of linear equations A*X = B with a complex
39 *> Hermitian matrix A stored in packed format using the factorization
40 *> A = U*D*U**H or A = L*D*L**H computed by ZHPTRF.
48 *> UPLO is CHARACTER*1
49 *> Specifies whether the details of the factorization are stored
50 *> as an upper or lower triangular matrix.
51 *> = 'U': Upper triangular, form is A = U*D*U**H;
52 *> = 'L': Lower triangular, form is A = L*D*L**H.
58 *> The order of the matrix A. N >= 0.
64 *> The number of right hand sides, i.e., the number of columns
65 *> of the matrix B. NRHS >= 0.
70 *> AP is COMPLEX*16 array, dimension (N*(N+1)/2)
71 *> The block diagonal matrix D and the multipliers used to
72 *> obtain the factor U or L as computed by ZHPTRF, stored as a
73 *> packed triangular matrix.
78 *> IPIV is INTEGER array, dimension (N)
79 *> Details of the interchanges and the block structure of D
80 *> as determined by ZHPTRF.
85 *> B is COMPLEX*16 array, dimension (LDB,NRHS)
86 *> On entry, the right hand side matrix B.
87 *> On exit, the solution matrix X.
93 *> The leading dimension of the array B. LDB >= max(1,N).
99 *> = 0: successful exit
100 *> < 0: if INFO = -i, the i-th argument had an illegal value
106 *> \author Univ. of Tennessee
107 *> \author Univ. of California Berkeley
108 *> \author Univ. of Colorado Denver
111 *> \date November 2011
113 *> \ingroup complex16OTHERcomputational
115 * =====================================================================
116 SUBROUTINE ZHPTRS( UPLO, N, NRHS, AP, IPIV, B, LDB, INFO )
118 * -- LAPACK computational routine (version 3.4.0) --
119 * -- LAPACK is a software package provided by Univ. of Tennessee, --
120 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
123 * .. Scalar Arguments ..
125 INTEGER INFO, LDB, N, NRHS
127 * .. Array Arguments ..
129 COMPLEX*16 AP( * ), B( LDB, * )
132 * =====================================================================
136 PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) )
138 * .. Local Scalars ..
142 COMPLEX*16 AK, AKM1, AKM1K, BK, BKM1, DENOM
144 * .. External Functions ..
148 * .. External Subroutines ..
149 EXTERNAL XERBLA, ZDSCAL, ZGEMV, ZGERU, ZLACGV, ZSWAP
151 * .. Intrinsic Functions ..
152 INTRINSIC DBLE, DCONJG, MAX
154 * .. Executable Statements ..
157 UPPER = LSAME( UPLO, 'U' )
158 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
160 ELSE IF( N.LT.0 ) THEN
162 ELSE IF( NRHS.LT.0 ) THEN
164 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
168 CALL XERBLA( 'ZHPTRS', -INFO )
172 * Quick return if possible
174 IF( N.EQ.0 .OR. NRHS.EQ.0 )
179 * Solve A*X = B, where A = U*D*U**H.
181 * First solve U*D*X = B, overwriting B with X.
183 * K is the main loop index, decreasing from N to 1 in steps of
184 * 1 or 2, depending on the size of the diagonal blocks.
187 KC = N*( N+1 ) / 2 + 1
190 * If K < 1, exit from loop.
196 IF( IPIV( K ).GT.0 ) THEN
198 * 1 x 1 diagonal block
200 * Interchange rows K and IPIV(K).
204 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
206 * Multiply by inv(U(K)), where U(K) is the transformation
207 * stored in column K of A.
209 CALL ZGERU( K-1, NRHS, -ONE, AP( KC ), 1, B( K, 1 ), LDB,
212 * Multiply by the inverse of the diagonal block.
214 S = DBLE( ONE ) / DBLE( AP( KC+K-1 ) )
215 CALL ZDSCAL( NRHS, S, B( K, 1 ), LDB )
219 * 2 x 2 diagonal block
221 * Interchange rows K-1 and -IPIV(K).
225 $ CALL ZSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ), LDB )
227 * Multiply by inv(U(K)), where U(K) is the transformation
228 * stored in columns K-1 and K of A.
230 CALL ZGERU( K-2, NRHS, -ONE, AP( KC ), 1, B( K, 1 ), LDB,
232 CALL ZGERU( K-2, NRHS, -ONE, AP( KC-( K-1 ) ), 1,
233 $ B( K-1, 1 ), LDB, B( 1, 1 ), LDB )
235 * Multiply by the inverse of the diagonal block.
238 AKM1 = AP( KC-1 ) / AKM1K
239 AK = AP( KC+K-1 ) / DCONJG( AKM1K )
240 DENOM = AKM1*AK - ONE
242 BKM1 = B( K-1, J ) / AKM1K
243 BK = B( K, J ) / DCONJG( AKM1K )
244 B( K-1, J ) = ( AK*BKM1-BK ) / DENOM
245 B( K, J ) = ( AKM1*BK-BKM1 ) / DENOM
254 * Next solve U**H *X = B, overwriting B with X.
256 * K is the main loop index, increasing from 1 to N in steps of
257 * 1 or 2, depending on the size of the diagonal blocks.
263 * If K > N, exit from loop.
268 IF( IPIV( K ).GT.0 ) THEN
270 * 1 x 1 diagonal block
272 * Multiply by inv(U**H(K)), where U(K) is the transformation
273 * stored in column K of A.
276 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
277 CALL ZGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
278 $ LDB, AP( KC ), 1, ONE, B( K, 1 ), LDB )
279 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
282 * Interchange rows K and IPIV(K).
286 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
291 * 2 x 2 diagonal block
293 * Multiply by inv(U**H(K+1)), where U(K+1) is the transformation
294 * stored in columns K and K+1 of A.
297 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
298 CALL ZGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
299 $ LDB, AP( KC ), 1, ONE, B( K, 1 ), LDB )
300 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
302 CALL ZLACGV( NRHS, B( K+1, 1 ), LDB )
303 CALL ZGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
304 $ LDB, AP( KC+K ), 1, ONE, B( K+1, 1 ), LDB )
305 CALL ZLACGV( NRHS, B( K+1, 1 ), LDB )
308 * Interchange rows K and -IPIV(K).
312 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
322 * Solve A*X = B, where A = L*D*L**H.
324 * First solve L*D*X = B, overwriting B with X.
326 * K is the main loop index, increasing from 1 to N in steps of
327 * 1 or 2, depending on the size of the diagonal blocks.
333 * If K > N, exit from loop.
338 IF( IPIV( K ).GT.0 ) THEN
340 * 1 x 1 diagonal block
342 * Interchange rows K and IPIV(K).
346 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
348 * Multiply by inv(L(K)), where L(K) is the transformation
349 * stored in column K of A.
352 $ CALL ZGERU( N-K, NRHS, -ONE, AP( KC+1 ), 1, B( K, 1 ),
353 $ LDB, B( K+1, 1 ), LDB )
355 * Multiply by the inverse of the diagonal block.
357 S = DBLE( ONE ) / DBLE( AP( KC ) )
358 CALL ZDSCAL( NRHS, S, B( K, 1 ), LDB )
363 * 2 x 2 diagonal block
365 * Interchange rows K+1 and -IPIV(K).
369 $ CALL ZSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ), LDB )
371 * Multiply by inv(L(K)), where L(K) is the transformation
372 * stored in columns K and K+1 of A.
375 CALL ZGERU( N-K-1, NRHS, -ONE, AP( KC+2 ), 1, B( K, 1 ),
376 $ LDB, B( K+2, 1 ), LDB )
377 CALL ZGERU( N-K-1, NRHS, -ONE, AP( KC+N-K+2 ), 1,
378 $ B( K+1, 1 ), LDB, B( K+2, 1 ), LDB )
381 * Multiply by the inverse of the diagonal block.
384 AKM1 = AP( KC ) / DCONJG( AKM1K )
385 AK = AP( KC+N-K+1 ) / AKM1K
386 DENOM = AKM1*AK - ONE
388 BKM1 = B( K, J ) / DCONJG( AKM1K )
389 BK = B( K+1, J ) / AKM1K
390 B( K, J ) = ( AK*BKM1-BK ) / DENOM
391 B( K+1, J ) = ( AKM1*BK-BKM1 ) / DENOM
393 KC = KC + 2*( N-K ) + 1
400 * Next solve L**H *X = B, overwriting B with X.
402 * K is the main loop index, decreasing from N to 1 in steps of
403 * 1 or 2, depending on the size of the diagonal blocks.
406 KC = N*( N+1 ) / 2 + 1
409 * If K < 1, exit from loop.
415 IF( IPIV( K ).GT.0 ) THEN
417 * 1 x 1 diagonal block
419 * Multiply by inv(L**H(K)), where L(K) is the transformation
420 * stored in column K of A.
423 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
424 CALL ZGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
425 $ B( K+1, 1 ), LDB, AP( KC+1 ), 1, ONE,
427 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
430 * Interchange rows K and IPIV(K).
434 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
438 * 2 x 2 diagonal block
440 * Multiply by inv(L**H(K-1)), where L(K-1) is the transformation
441 * stored in columns K-1 and K of A.
444 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
445 CALL ZGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
446 $ B( K+1, 1 ), LDB, AP( KC+1 ), 1, ONE,
448 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
450 CALL ZLACGV( NRHS, B( K-1, 1 ), LDB )
451 CALL ZGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
452 $ B( K+1, 1 ), LDB, AP( KC-( N-K ) ), 1, ONE,
454 CALL ZLACGV( NRHS, B( K-1, 1 ), LDB )
457 * Interchange rows K and -IPIV(K).
461 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )