129
130
131
132
133
134
135 CHARACTER UPLO
136 INTEGER INFO, LDA, N
137
138
139 INTEGER IPIV( * )
140 COMPLEX*16 A( LDA, * ), WORK( * )
141
142
143
144
145
146 COMPLEX*16 CONE, CZERO
147 parameter( cone = ( 1.0d+0, 0.0d+0 ),
148 $ czero = ( 0.0d+0, 0.0d+0 ) )
149
150
151 LOGICAL UPPER
152 INTEGER K, KP, KSTEP
153 COMPLEX*16 AK, AKKP1, AKP1, D, T, TEMP
154
155
156 LOGICAL LSAME
157 COMPLEX*16 ZDOTU
159
160
162
163
164 INTRINSIC max
165
166
167
168
169
170 info = 0
171 upper =
lsame( uplo,
'U' )
172 IF( .NOT.upper .AND. .NOT.
lsame( uplo,
'L' ) )
THEN
173 info = -1
174 ELSE IF( n.LT.0 ) THEN
175 info = -2
176 ELSE IF( lda.LT.max( 1, n ) ) THEN
177 info = -4
178 END IF
179 IF( info.NE.0 ) THEN
180 CALL xerbla(
'ZSYTRI_ROOK', -info )
181 RETURN
182 END IF
183
184
185
186 IF( n.EQ.0 )
187 $ RETURN
188
189
190
191 IF( upper ) THEN
192
193
194
195 DO 10 info = n, 1, -1
196 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.czero )
197 $ RETURN
198 10 CONTINUE
199 ELSE
200
201
202
203 DO 20 info = 1, n
204 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.czero )
205 $ RETURN
206 20 CONTINUE
207 END IF
208 info = 0
209
210 IF( upper ) THEN
211
212
213
214
215
216
217 k = 1
218 30 CONTINUE
219
220
221
222 IF( k.GT.n )
223 $ GO TO 40
224
225 IF( ipiv( k ).GT.0 ) THEN
226
227
228
229
230
231 a( k, k ) = cone / a( k, k )
232
233
234
235 IF( k.GT.1 ) THEN
236 CALL zcopy( k-1, a( 1, k ), 1, work, 1 )
237 CALL zsymv( uplo, k-1, -cone, a, lda, work, 1, czero,
238 $ a( 1, k ), 1 )
239 a( k, k ) = a( k, k ) -
zdotu( k-1, work, 1, a( 1, k ),
240 $ 1 )
241 END IF
242 kstep = 1
243 ELSE
244
245
246
247
248
249 t = a( k, k+1 )
250 ak = a( k, k ) / t
251 akp1 = a( k+1, k+1 ) / t
252 akkp1 = a( k, k+1 ) / t
253 d = t*( ak*akp1-cone )
254 a( k, k ) = akp1 / d
255 a( k+1, k+1 ) = ak / d
256 a( k, k+1 ) = -akkp1 / d
257
258
259
260 IF( k.GT.1 ) THEN
261 CALL zcopy( k-1, a( 1, k ), 1, work, 1 )
262 CALL zsymv( uplo, k-1, -cone, a, lda, work, 1, czero,
263 $ a( 1, k ), 1 )
264 a( k, k ) = a( k, k ) -
zdotu( k-1, work, 1, a( 1, k ),
265 $ 1 )
266 a( k, k+1 ) = a( k, k+1 ) -
267 $
zdotu( k-1, a( 1, k ), 1, a( 1, k+1 ), 1 )
268 CALL zcopy( k-1, a( 1, k+1 ), 1, work, 1 )
269 CALL zsymv( uplo, k-1, -cone, a, lda, work, 1, czero,
270 $ a( 1, k+1 ), 1 )
271 a( k+1, k+1 ) = a( k+1, k+1 ) -
272 $
zdotu( k-1, work, 1, a( 1, k+1 ), 1 )
273 END IF
274 kstep = 2
275 END IF
276
277 IF( kstep.EQ.1 ) THEN
278
279
280
281
282 kp = ipiv( k )
283 IF( kp.NE.k ) THEN
284 IF( kp.GT.1 )
285 $
CALL zswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
286 CALL zswap( k-kp-1, a( kp+1, k ), 1, a( kp, kp+1 ), lda )
287 temp = a( k, k )
288 a( k, k ) = a( kp, kp )
289 a( kp, kp ) = temp
290 END IF
291 ELSE
292
293
294
295
296 kp = -ipiv( k )
297 IF( kp.NE.k ) THEN
298 IF( kp.GT.1 )
299 $
CALL zswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
300 CALL zswap( k-kp-1, a( kp+1, k ), 1, a( kp, kp+1 ), lda )
301
302 temp = a( k, k )
303 a( k, k ) = a( kp, kp )
304 a( kp, kp ) = temp
305 temp = a( k, k+1 )
306 a( k, k+1 ) = a( kp, k+1 )
307 a( kp, k+1 ) = temp
308 END IF
309
310 k = k + 1
311 kp = -ipiv( k )
312 IF( kp.NE.k ) THEN
313 IF( kp.GT.1 )
314 $
CALL zswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
315 CALL zswap( k-kp-1, a( kp+1, k ), 1, a( kp, kp+1 ), lda )
316 temp = a( k, k )
317 a( k, k ) = a( kp, kp )
318 a( kp, kp ) = temp
319 END IF
320 END IF
321
322 k = k + 1
323 GO TO 30
324 40 CONTINUE
325
326 ELSE
327
328
329
330
331
332
333 k = n
334 50 CONTINUE
335
336
337
338 IF( k.LT.1 )
339 $ GO TO 60
340
341 IF( ipiv( k ).GT.0 ) THEN
342
343
344
345
346
347 a( k, k ) = cone / a( k, k )
348
349
350
351 IF( k.LT.n ) THEN
352 CALL zcopy( n-k, a( k+1, k ), 1, work, 1 )
353 CALL zsymv( uplo, n-k,-cone, a( k+1, k+1 ), lda, work, 1,
354 $ czero, a( k+1, k ), 1 )
355 a( k, k ) = a( k, k ) -
zdotu( n-k, work, 1, a( k+1, k ),
356 $ 1 )
357 END IF
358 kstep = 1
359 ELSE
360
361
362
363
364
365 t = a( k, k-1 )
366 ak = a( k-1, k-1 ) / t
367 akp1 = a( k, k ) / t
368 akkp1 = a( k, k-1 ) / t
369 d = t*( ak*akp1-cone )
370 a( k-1, k-1 ) = akp1 / d
371 a( k, k ) = ak / d
372 a( k, k-1 ) = -akkp1 / d
373
374
375
376 IF( k.LT.n ) THEN
377 CALL zcopy( n-k, a( k+1, k ), 1, work, 1 )
378 CALL zsymv( uplo, n-k,-cone, a( k+1, k+1 ), lda, work, 1,
379 $ czero, a( k+1, k ), 1 )
380 a( k, k ) = a( k, k ) -
zdotu( n-k, work, 1, a( k+1, k ),
381 $ 1 )
382 a( k, k-1 ) = a( k, k-1 ) -
383 $
zdotu( n-k, a( k+1, k ), 1, a( k+1, k-1 ),
384 $ 1 )
385 CALL zcopy( n-k, a( k+1, k-1 ), 1, work, 1 )
386 CALL zsymv( uplo, n-k,-cone, a( k+1, k+1 ), lda, work, 1,
387 $ czero, a( k+1, k-1 ), 1 )
388 a( k-1, k-1 ) = a( k-1, k-1 ) -
389 $
zdotu( n-k, work, 1, a( k+1, k-1 ), 1 )
390 END IF
391 kstep = 2
392 END IF
393
394 IF( kstep.EQ.1 ) THEN
395
396
397
398
399 kp = ipiv( k )
400 IF( kp.NE.k ) THEN
401 IF( kp.LT.n )
402 $
CALL zswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ), 1 )
403 CALL zswap( kp-k-1, a( k+1, k ), 1, a( kp, k+1 ), lda )
404 temp = a( k, k )
405 a( k, k ) = a( kp, kp )
406 a( kp, kp ) = temp
407 END IF
408 ELSE
409
410
411
412
413 kp = -ipiv( k )
414 IF( kp.NE.k ) THEN
415 IF( kp.LT.n )
416 $
CALL zswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ), 1 )
417 CALL zswap( kp-k-1, a( k+1, k ), 1, a( kp, k+1 ), lda )
418
419 temp = a( k, k )
420 a( k, k ) = a( kp, kp )
421 a( kp, kp ) = temp
422 temp = a( k, k-1 )
423 a( k, k-1 ) = a( kp, k-1 )
424 a( kp, k-1 ) = temp
425 END IF
426
427 k = k - 1
428 kp = -ipiv( k )
429 IF( kp.NE.k ) THEN
430 IF( kp.LT.n )
431 $
CALL zswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ), 1 )
432 CALL zswap( kp-k-1, a( k+1, k ), 1, a( kp, k+1 ), lda )
433 temp = a( k, k )
434 a( k, k ) = a( kp, kp )
435 a( kp, kp ) = temp
436 END IF
437 END IF
438
439 k = k - 1
440 GO TO 50
441 60 CONTINUE
442 END IF
443
444 RETURN
445
446
447
subroutine xerbla(srname, info)
subroutine zcopy(n, zx, incx, zy, incy)
ZCOPY
complex *16 function zdotu(n, zx, incx, zy, incy)
ZDOTU
subroutine zsymv(uplo, n, alpha, a, lda, x, incx, beta, y, incy)
ZSYMV computes a matrix-vector product for a complex symmetric matrix.
logical function lsame(ca, cb)
LSAME
subroutine zswap(n, zx, incx, zy, incy)
ZSWAP