112
113
114
115
116
117
118 CHARACTER UPLO
119 INTEGER INFO, LDA, N
120
121
122 INTEGER IPIV( * )
123 COMPLEX A( LDA, * ), WORK( * )
124
125
126
127
128
129 COMPLEX ONE, ZERO
130 parameter( one = ( 1.0e+0, 0.0e+0 ),
131 $ zero = ( 0.0e+0, 0.0e+0 ) )
132
133
134 LOGICAL UPPER
135 INTEGER K, KP, KSTEP
136 COMPLEX AK, AKKP1, AKP1, D, T, TEMP
137
138
139 LOGICAL LSAME
140 COMPLEX CDOTU
142
143
145
146
147 INTRINSIC abs, max
148
149
150
151
152
153 info = 0
154 upper =
lsame( uplo,
'U' )
155 IF( .NOT.upper .AND. .NOT.
lsame( uplo,
'L' ) )
THEN
156 info = -1
157 ELSE IF( n.LT.0 ) THEN
158 info = -2
159 ELSE IF( lda.LT.max( 1, n ) ) THEN
160 info = -4
161 END IF
162 IF( info.NE.0 ) THEN
163 CALL xerbla(
'CSYTRI', -info )
164 RETURN
165 END IF
166
167
168
169 IF( n.EQ.0 )
170 $ RETURN
171
172
173
174 IF( upper ) THEN
175
176
177
178 DO 10 info = n, 1, -1
179 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.zero )
180 $ RETURN
181 10 CONTINUE
182 ELSE
183
184
185
186 DO 20 info = 1, n
187 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.zero )
188 $ RETURN
189 20 CONTINUE
190 END IF
191 info = 0
192
193 IF( upper ) THEN
194
195
196
197
198
199
200 k = 1
201 30 CONTINUE
202
203
204
205 IF( k.GT.n )
206 $ GO TO 40
207
208 IF( ipiv( k ).GT.0 ) THEN
209
210
211
212
213
214 a( k, k ) = one / a( k, k )
215
216
217
218 IF( k.GT.1 ) THEN
219 CALL ccopy( k-1, a( 1, k ), 1, work, 1 )
220 CALL csymv( uplo, k-1, -one, a, lda, work, 1, zero,
221 $ a( 1, k ), 1 )
222 a( k, k ) = a( k, k ) -
cdotu( k-1, work, 1, a( 1,
223 $ k ),
224 $ 1 )
225 END IF
226 kstep = 1
227 ELSE
228
229
230
231
232
233 t = a( k, k+1 )
234 ak = a( k, k ) / t
235 akp1 = a( k+1, k+1 ) / t
236 akkp1 = a( k, k+1 ) / t
237 d = t*( ak*akp1-one )
238 a( k, k ) = akp1 / d
239 a( k+1, k+1 ) = ak / d
240 a( k, k+1 ) = -akkp1 / d
241
242
243
244 IF( k.GT.1 ) THEN
245 CALL ccopy( k-1, a( 1, k ), 1, work, 1 )
246 CALL csymv( uplo, k-1, -one, a, lda, work, 1, zero,
247 $ a( 1, k ), 1 )
248 a( k, k ) = a( k, k ) -
cdotu( k-1, work, 1, a( 1,
249 $ k ),
250 $ 1 )
251 a( k, k+1 ) = a( k, k+1 ) -
252 $
cdotu( k-1, a( 1, k ), 1, a( 1, k+1 ),
253 $ 1 )
254 CALL ccopy( k-1, a( 1, k+1 ), 1, work, 1 )
255 CALL csymv( uplo, k-1, -one, a, lda, work, 1, zero,
256 $ a( 1, k+1 ), 1 )
257 a( k+1, k+1 ) = a( k+1, k+1 ) -
258 $
cdotu( k-1, work, 1, a( 1, k+1 ), 1 )
259 END IF
260 kstep = 2
261 END IF
262
263 kp = abs( ipiv( k ) )
264 IF( kp.NE.k ) THEN
265
266
267
268
269 CALL cswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
270 CALL cswap( k-kp-1, a( kp+1, k ), 1, a( kp, kp+1 ), lda )
271 temp = a( k, k )
272 a( k, k ) = a( kp, kp )
273 a( kp, kp ) = temp
274 IF( kstep.EQ.2 ) THEN
275 temp = a( k, k+1 )
276 a( k, k+1 ) = a( kp, k+1 )
277 a( kp, k+1 ) = temp
278 END IF
279 END IF
280
281 k = k + kstep
282 GO TO 30
283 40 CONTINUE
284
285 ELSE
286
287
288
289
290
291
292 k = n
293 50 CONTINUE
294
295
296
297 IF( k.LT.1 )
298 $ GO TO 60
299
300 IF( ipiv( k ).GT.0 ) THEN
301
302
303
304
305
306 a( k, k ) = one / a( k, k )
307
308
309
310 IF( k.LT.n ) THEN
311 CALL ccopy( n-k, a( k+1, k ), 1, work, 1 )
312 CALL csymv( uplo, n-k, -one, a( k+1, k+1 ), lda, work,
313 $ 1,
314 $ zero, a( k+1, k ), 1 )
315 a( k, k ) = a( k, k ) -
cdotu( n-k, work, 1, a( k+1,
316 $ k ),
317 $ 1 )
318 END IF
319 kstep = 1
320 ELSE
321
322
323
324
325
326 t = a( k, k-1 )
327 ak = a( k-1, k-1 ) / t
328 akp1 = a( k, k ) / t
329 akkp1 = a( k, k-1 ) / t
330 d = t*( ak*akp1-one )
331 a( k-1, k-1 ) = akp1 / d
332 a( k, k ) = ak / d
333 a( k, k-1 ) = -akkp1 / d
334
335
336
337 IF( k.LT.n ) THEN
338 CALL ccopy( n-k, a( k+1, k ), 1, work, 1 )
339 CALL csymv( uplo, n-k, -one, a( k+1, k+1 ), lda, work,
340 $ 1,
341 $ zero, a( k+1, k ), 1 )
342 a( k, k ) = a( k, k ) -
cdotu( n-k, work, 1, a( k+1,
343 $ k ),
344 $ 1 )
345 a( k, k-1 ) = a( k, k-1 ) -
346 $
cdotu( n-k, a( k+1, k ), 1, a( k+1,
347 $ k-1 ),
348 $ 1 )
349 CALL ccopy( n-k, a( k+1, k-1 ), 1, work, 1 )
350 CALL csymv( uplo, n-k, -one, a( k+1, k+1 ), lda, work,
351 $ 1,
352 $ zero, a( k+1, k-1 ), 1 )
353 a( k-1, k-1 ) = a( k-1, k-1 ) -
354 $
cdotu( n-k, work, 1, a( k+1, k-1 ),
355 $ 1 )
356 END IF
357 kstep = 2
358 END IF
359
360 kp = abs( ipiv( k ) )
361 IF( kp.NE.k ) THEN
362
363
364
365
366 IF( kp.LT.n )
367 $
CALL cswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ), 1 )
368 CALL cswap( kp-k-1, a( k+1, k ), 1, a( kp, k+1 ), lda )
369 temp = a( k, k )
370 a( k, k ) = a( kp, kp )
371 a( kp, kp ) = temp
372 IF( kstep.EQ.2 ) THEN
373 temp = a( k, k-1 )
374 a( k, k-1 ) = a( kp, k-1 )
375 a( kp, k-1 ) = temp
376 END IF
377 END IF
378
379 k = k - kstep
380 GO TO 50
381 60 CONTINUE
382 END IF
383
384 RETURN
385
386
387
subroutine xerbla(srname, info)
subroutine ccopy(n, cx, incx, cy, incy)
CCOPY
complex function cdotu(n, cx, incx, cy, incy)
CDOTU
subroutine csymv(uplo, n, alpha, a, lda, x, incx, beta, y, incy)
CSYMV computes a matrix-vector product for a complex symmetric matrix.
logical function lsame(ca, cb)
LSAME
subroutine cswap(n, cx, incx, cy, incy)
CSWAP