113
114
115
116
117
118
119 CHARACTER UPLO
120 INTEGER INFO, LDB, N, NRHS
121
122
123 INTEGER IPIV( * )
124 DOUBLE PRECISION AP( * ), B( LDB, * )
125
126
127
128
129
130 DOUBLE PRECISION ONE
131 parameter( one = 1.0d+0 )
132
133
134 LOGICAL UPPER
135 INTEGER J, K, KC, KP
136 DOUBLE PRECISION AK, AKM1, AKM1K, BK, BKM1, DENOM
137
138
139 LOGICAL LSAME
141
142
144
145
146 INTRINSIC max
147
148
149
150 info = 0
151 upper =
lsame( uplo,
'U' )
152 IF( .NOT.upper .AND. .NOT.
lsame( uplo,
'L' ) )
THEN
153 info = -1
154 ELSE IF( n.LT.0 ) THEN
155 info = -2
156 ELSE IF( nrhs.LT.0 ) THEN
157 info = -3
158 ELSE IF( ldb.LT.max( 1, n ) ) THEN
159 info = -7
160 END IF
161 IF( info.NE.0 ) THEN
162 CALL xerbla(
'DSPTRS', -info )
163 RETURN
164 END IF
165
166
167
168 IF( n.EQ.0 .OR. nrhs.EQ.0 )
169 $ RETURN
170
171 IF( upper ) THEN
172
173
174
175
176
177
178
179
180 k = n
181 kc = n*( n+1 ) / 2 + 1
182 10 CONTINUE
183
184
185
186 IF( k.LT.1 )
187 $ GO TO 30
188
189 kc = kc - k
190 IF( ipiv( k ).GT.0 ) THEN
191
192
193
194
195
196 kp = ipiv( k )
197 IF( kp.NE.k )
198 $
CALL dswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
199
200
201
202
203 CALL dger( k-1, nrhs, -one, ap( kc ), 1, b( k, 1 ), ldb,
204 $ b( 1, 1 ), ldb )
205
206
207
208 CALL dscal( nrhs, one / ap( kc+k-1 ), b( k, 1 ), ldb )
209 k = k - 1
210 ELSE
211
212
213
214
215
216 kp = -ipiv( k )
217 IF( kp.NE.k-1 )
218 $
CALL dswap( nrhs, b( k-1, 1 ), ldb, b( kp, 1 ), ldb )
219
220
221
222
223 CALL dger( k-2, nrhs, -one, ap( kc ), 1, b( k, 1 ), ldb,
224 $ b( 1, 1 ), ldb )
225 CALL dger( k-2, nrhs, -one, ap( kc-( k-1 ) ), 1,
226 $ b( k-1, 1 ), ldb, b( 1, 1 ), ldb )
227
228
229
230 akm1k = ap( kc+k-2 )
231 akm1 = ap( kc-1 ) / akm1k
232 ak = ap( kc+k-1 ) / akm1k
233 denom = akm1*ak - one
234 DO 20 j = 1, nrhs
235 bkm1 = b( k-1, j ) / akm1k
236 bk = b( k, j ) / akm1k
237 b( k-1, j ) = ( ak*bkm1-bk ) / denom
238 b( k, j ) = ( akm1*bk-bkm1 ) / denom
239 20 CONTINUE
240 kc = kc - k + 1
241 k = k - 2
242 END IF
243
244 GO TO 10
245 30 CONTINUE
246
247
248
249
250
251
252 k = 1
253 kc = 1
254 40 CONTINUE
255
256
257
258 IF( k.GT.n )
259 $ GO TO 50
260
261 IF( ipiv( k ).GT.0 ) THEN
262
263
264
265
266
267
268 CALL dgemv(
'Transpose', k-1, nrhs, -one, b, ldb,
269 $ ap( kc ),
270 $ 1, one, b( k, 1 ), ldb )
271
272
273
274 kp = ipiv( k )
275 IF( kp.NE.k )
276 $
CALL dswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
277 kc = kc + k
278 k = k + 1
279 ELSE
280
281
282
283
284
285
286 CALL dgemv(
'Transpose', k-1, nrhs, -one, b, ldb,
287 $ ap( kc ),
288 $ 1, one, b( k, 1 ), ldb )
289 CALL dgemv(
'Transpose', k-1, nrhs, -one, b, ldb,
290 $ ap( kc+k ), 1, one, b( k+1, 1 ), ldb )
291
292
293
294 kp = -ipiv( k )
295 IF( kp.NE.k )
296 $
CALL dswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
297 kc = kc + 2*k + 1
298 k = k + 2
299 END IF
300
301 GO TO 40
302 50 CONTINUE
303
304 ELSE
305
306
307
308
309
310
311
312
313 k = 1
314 kc = 1
315 60 CONTINUE
316
317
318
319 IF( k.GT.n )
320 $ GO TO 80
321
322 IF( ipiv( k ).GT.0 ) THEN
323
324
325
326
327
328 kp = ipiv( k )
329 IF( kp.NE.k )
330 $
CALL dswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
331
332
333
334
335 IF( k.LT.n )
336 $
CALL dger( n-k, nrhs, -one, ap( kc+1 ), 1, b( k, 1 ),
337 $ ldb, b( k+1, 1 ), ldb )
338
339
340
341 CALL dscal( nrhs, one / ap( kc ), b( k, 1 ), ldb )
342 kc = kc + n - k + 1
343 k = k + 1
344 ELSE
345
346
347
348
349
350 kp = -ipiv( k )
351 IF( kp.NE.k+1 )
352 $
CALL dswap( nrhs, b( k+1, 1 ), ldb, b( kp, 1 ), ldb )
353
354
355
356
357 IF( k.LT.n-1 ) THEN
358 CALL dger( n-k-1, nrhs, -one, ap( kc+2 ), 1, b( k,
359 $ 1 ),
360 $ ldb, b( k+2, 1 ), ldb )
361 CALL dger( n-k-1, nrhs, -one, ap( kc+n-k+2 ), 1,
362 $ b( k+1, 1 ), ldb, b( k+2, 1 ), ldb )
363 END IF
364
365
366
367 akm1k = ap( kc+1 )
368 akm1 = ap( kc ) / akm1k
369 ak = ap( kc+n-k+1 ) / akm1k
370 denom = akm1*ak - one
371 DO 70 j = 1, nrhs
372 bkm1 = b( k, j ) / akm1k
373 bk = b( k+1, j ) / akm1k
374 b( k, j ) = ( ak*bkm1-bk ) / denom
375 b( k+1, j ) = ( akm1*bk-bkm1 ) / denom
376 70 CONTINUE
377 kc = kc + 2*( n-k ) + 1
378 k = k + 2
379 END IF
380
381 GO TO 60
382 80 CONTINUE
383
384
385
386
387
388
389 k = n
390 kc = n*( n+1 ) / 2 + 1
391 90 CONTINUE
392
393
394
395 IF( k.LT.1 )
396 $ GO TO 100
397
398 kc = kc - ( n-k+1 )
399 IF( ipiv( k ).GT.0 ) THEN
400
401
402
403
404
405
406 IF( k.LT.n )
407 $
CALL dgemv(
'Transpose', n-k, nrhs, -one, b( k+1, 1 ),
408 $ ldb, ap( kc+1 ), 1, one, b( k, 1 ), ldb )
409
410
411
412 kp = ipiv( k )
413 IF( kp.NE.k )
414 $
CALL dswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
415 k = k - 1
416 ELSE
417
418
419
420
421
422
423 IF( k.LT.n ) THEN
424 CALL dgemv(
'Transpose', n-k, nrhs, -one, b( k+1, 1 ),
425 $ ldb, ap( kc+1 ), 1, one, b( k, 1 ), ldb )
426 CALL dgemv(
'Transpose', n-k, nrhs, -one, b( k+1, 1 ),
427 $ ldb, ap( kc-( n-k ) ), 1, one, b( k-1, 1 ),
428 $ ldb )
429 END IF
430
431
432
433 kp = -ipiv( k )
434 IF( kp.NE.k )
435 $
CALL dswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
436 kc = kc - ( n-k+2 )
437 k = k - 2
438 END IF
439
440 GO TO 90
441 100 CONTINUE
442 END IF
443
444 RETURN
445
446
447
subroutine xerbla(srname, info)
subroutine dgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
DGEMV
subroutine dger(m, n, alpha, x, incx, y, incy, a, lda)
DGER
logical function lsame(ca, cb)
LSAME
subroutine dscal(n, da, dx, incx)
DSCAL
subroutine dswap(n, dx, incx, dy, incy)
DSWAP