00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__1 = 1;
00019 static doublereal c_b8 = -1.;
00020 static doublereal c_b9 = 1.;
00021
00022 int dlasyf_(char *uplo, integer *n, integer *nb, integer *kb,
00023 doublereal *a, integer *lda, integer *ipiv, doublereal *w, integer *
00024 ldw, integer *info)
00025 {
00026
00027 integer a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3, i__4, i__5;
00028 doublereal d__1, d__2, d__3;
00029
00030
00031 double sqrt(doublereal);
00032
00033
00034 integer j, k;
00035 doublereal t, r1, d11, d21, d22;
00036 integer jb, jj, kk, jp, kp, kw, kkw, imax, jmax;
00037 doublereal alpha;
00038 extern int dscal_(integer *, doublereal *, doublereal *,
00039 integer *), dgemm_(char *, char *, integer *, integer *, integer *
00040 , doublereal *, doublereal *, integer *, doublereal *, integer *,
00041 doublereal *, doublereal *, integer *);
00042 extern logical lsame_(char *, char *);
00043 extern int dgemv_(char *, integer *, integer *,
00044 doublereal *, doublereal *, integer *, doublereal *, integer *,
00045 doublereal *, doublereal *, integer *), dcopy_(integer *,
00046 doublereal *, integer *, doublereal *, integer *), dswap_(integer
00047 *, doublereal *, integer *, doublereal *, integer *);
00048 integer kstep;
00049 doublereal absakk;
00050 extern integer idamax_(integer *, doublereal *, integer *);
00051 doublereal colmax, rowmax;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 a_dim1 = *lda;
00157 a_offset = 1 + a_dim1;
00158 a -= a_offset;
00159 --ipiv;
00160 w_dim1 = *ldw;
00161 w_offset = 1 + w_dim1;
00162 w -= w_offset;
00163
00164
00165 *info = 0;
00166
00167
00168
00169 alpha = (sqrt(17.) + 1.) / 8.;
00170
00171 if (lsame_(uplo, "U")) {
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 k = *n;
00182 L10:
00183 kw = *nb + k - *n;
00184
00185
00186
00187 if (k <= *n - *nb + 1 && *nb < *n || k < 1) {
00188 goto L30;
00189 }
00190
00191
00192
00193 dcopy_(&k, &a[k * a_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &c__1);
00194 if (k < *n) {
00195 i__1 = *n - k;
00196 dgemv_("No transpose", &k, &i__1, &c_b8, &a[(k + 1) * a_dim1 + 1],
00197 lda, &w[k + (kw + 1) * w_dim1], ldw, &c_b9, &w[kw *
00198 w_dim1 + 1], &c__1);
00199 }
00200
00201 kstep = 1;
00202
00203
00204
00205
00206 absakk = (d__1 = w[k + kw * w_dim1], abs(d__1));
00207
00208
00209
00210
00211 if (k > 1) {
00212 i__1 = k - 1;
00213 imax = idamax_(&i__1, &w[kw * w_dim1 + 1], &c__1);
00214 colmax = (d__1 = w[imax + kw * w_dim1], abs(d__1));
00215 } else {
00216 colmax = 0.;
00217 }
00218
00219 if (max(absakk,colmax) == 0.) {
00220
00221
00222
00223 if (*info == 0) {
00224 *info = k;
00225 }
00226 kp = k;
00227 } else {
00228 if (absakk >= alpha * colmax) {
00229
00230
00231
00232 kp = k;
00233 } else {
00234
00235
00236
00237 dcopy_(&imax, &a[imax * a_dim1 + 1], &c__1, &w[(kw - 1) *
00238 w_dim1 + 1], &c__1);
00239 i__1 = k - imax;
00240 dcopy_(&i__1, &a[imax + (imax + 1) * a_dim1], lda, &w[imax +
00241 1 + (kw - 1) * w_dim1], &c__1);
00242 if (k < *n) {
00243 i__1 = *n - k;
00244 dgemv_("No transpose", &k, &i__1, &c_b8, &a[(k + 1) *
00245 a_dim1 + 1], lda, &w[imax + (kw + 1) * w_dim1],
00246 ldw, &c_b9, &w[(kw - 1) * w_dim1 + 1], &c__1);
00247 }
00248
00249
00250
00251
00252 i__1 = k - imax;
00253 jmax = imax + idamax_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1],
00254 &c__1);
00255 rowmax = (d__1 = w[jmax + (kw - 1) * w_dim1], abs(d__1));
00256 if (imax > 1) {
00257 i__1 = imax - 1;
00258 jmax = idamax_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
00259
00260 d__2 = rowmax, d__3 = (d__1 = w[jmax + (kw - 1) * w_dim1],
00261 abs(d__1));
00262 rowmax = max(d__2,d__3);
00263 }
00264
00265 if (absakk >= alpha * colmax * (colmax / rowmax)) {
00266
00267
00268
00269 kp = k;
00270 } else if ((d__1 = w[imax + (kw - 1) * w_dim1], abs(d__1)) >=
00271 alpha * rowmax) {
00272
00273
00274
00275
00276 kp = imax;
00277
00278
00279
00280 dcopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw *
00281 w_dim1 + 1], &c__1);
00282 } else {
00283
00284
00285
00286
00287 kp = imax;
00288 kstep = 2;
00289 }
00290 }
00291
00292 kk = k - kstep + 1;
00293 kkw = *nb + kk - *n;
00294
00295
00296
00297 if (kp != kk) {
00298
00299
00300
00301 a[kp + k * a_dim1] = a[kk + k * a_dim1];
00302 i__1 = k - 1 - kp;
00303 dcopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp +
00304 1) * a_dim1], lda);
00305 dcopy_(&kp, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1], &
00306 c__1);
00307
00308
00309
00310 i__1 = *n - kk + 1;
00311 dswap_(&i__1, &a[kk + kk * a_dim1], lda, &a[kp + kk * a_dim1],
00312 lda);
00313 i__1 = *n - kk + 1;
00314 dswap_(&i__1, &w[kk + kkw * w_dim1], ldw, &w[kp + kkw *
00315 w_dim1], ldw);
00316 }
00317
00318 if (kstep == 1) {
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 dcopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &
00329 c__1);
00330 r1 = 1. / a[k + k * a_dim1];
00331 i__1 = k - 1;
00332 dscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
00333 } else {
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 if (k > 2) {
00344
00345
00346
00347 d21 = w[k - 1 + kw * w_dim1];
00348 d11 = w[k + kw * w_dim1] / d21;
00349 d22 = w[k - 1 + (kw - 1) * w_dim1] / d21;
00350 t = 1. / (d11 * d22 - 1.);
00351 d21 = t / d21;
00352 i__1 = k - 2;
00353 for (j = 1; j <= i__1; ++j) {
00354 a[j + (k - 1) * a_dim1] = d21 * (d11 * w[j + (kw - 1)
00355 * w_dim1] - w[j + kw * w_dim1]);
00356 a[j + k * a_dim1] = d21 * (d22 * w[j + kw * w_dim1] -
00357 w[j + (kw - 1) * w_dim1]);
00358
00359 }
00360 }
00361
00362
00363
00364 a[k - 1 + (k - 1) * a_dim1] = w[k - 1 + (kw - 1) * w_dim1];
00365 a[k - 1 + k * a_dim1] = w[k - 1 + kw * w_dim1];
00366 a[k + k * a_dim1] = w[k + kw * w_dim1];
00367 }
00368 }
00369
00370
00371
00372 if (kstep == 1) {
00373 ipiv[k] = kp;
00374 } else {
00375 ipiv[k] = -kp;
00376 ipiv[k - 1] = -kp;
00377 }
00378
00379
00380
00381 k -= kstep;
00382 goto L10;
00383
00384 L30:
00385
00386
00387
00388
00389
00390
00391
00392 i__1 = -(*nb);
00393 for (j = (k - 1) / *nb * *nb + 1; i__1 < 0 ? j >= 1 : j <= 1; j +=
00394 i__1) {
00395
00396 i__2 = *nb, i__3 = k - j + 1;
00397 jb = min(i__2,i__3);
00398
00399
00400
00401 i__2 = j + jb - 1;
00402 for (jj = j; jj <= i__2; ++jj) {
00403 i__3 = jj - j + 1;
00404 i__4 = *n - k;
00405 dgemv_("No transpose", &i__3, &i__4, &c_b8, &a[j + (k + 1) *
00406 a_dim1], lda, &w[jj + (kw + 1) * w_dim1], ldw, &c_b9,
00407 &a[j + jj * a_dim1], &c__1);
00408
00409 }
00410
00411
00412
00413 i__2 = j - 1;
00414 i__3 = *n - k;
00415 dgemm_("No transpose", "Transpose", &i__2, &jb, &i__3, &c_b8, &a[(
00416 k + 1) * a_dim1 + 1], lda, &w[j + (kw + 1) * w_dim1], ldw,
00417 &c_b9, &a[j * a_dim1 + 1], lda);
00418
00419 }
00420
00421
00422
00423
00424 j = k + 1;
00425 L60:
00426 jj = j;
00427 jp = ipiv[j];
00428 if (jp < 0) {
00429 jp = -jp;
00430 ++j;
00431 }
00432 ++j;
00433 if (jp != jj && j <= *n) {
00434 i__1 = *n - j + 1;
00435 dswap_(&i__1, &a[jp + j * a_dim1], lda, &a[jj + j * a_dim1], lda);
00436 }
00437 if (j <= *n) {
00438 goto L60;
00439 }
00440
00441
00442
00443 *kb = *n - k;
00444
00445 } else {
00446
00447
00448
00449
00450
00451
00452
00453 k = 1;
00454 L70:
00455
00456
00457
00458 if (k >= *nb && *nb < *n || k > *n) {
00459 goto L90;
00460 }
00461
00462
00463
00464 i__1 = *n - k + 1;
00465 dcopy_(&i__1, &a[k + k * a_dim1], &c__1, &w[k + k * w_dim1], &c__1);
00466 i__1 = *n - k + 1;
00467 i__2 = k - 1;
00468 dgemv_("No transpose", &i__1, &i__2, &c_b8, &a[k + a_dim1], lda, &w[k
00469 + w_dim1], ldw, &c_b9, &w[k + k * w_dim1], &c__1);
00470
00471 kstep = 1;
00472
00473
00474
00475
00476 absakk = (d__1 = w[k + k * w_dim1], abs(d__1));
00477
00478
00479
00480
00481 if (k < *n) {
00482 i__1 = *n - k;
00483 imax = k + idamax_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
00484 colmax = (d__1 = w[imax + k * w_dim1], abs(d__1));
00485 } else {
00486 colmax = 0.;
00487 }
00488
00489 if (max(absakk,colmax) == 0.) {
00490
00491
00492
00493 if (*info == 0) {
00494 *info = k;
00495 }
00496 kp = k;
00497 } else {
00498 if (absakk >= alpha * colmax) {
00499
00500
00501
00502 kp = k;
00503 } else {
00504
00505
00506
00507 i__1 = imax - k;
00508 dcopy_(&i__1, &a[imax + k * a_dim1], lda, &w[k + (k + 1) *
00509 w_dim1], &c__1);
00510 i__1 = *n - imax + 1;
00511 dcopy_(&i__1, &a[imax + imax * a_dim1], &c__1, &w[imax + (k +
00512 1) * w_dim1], &c__1);
00513 i__1 = *n - k + 1;
00514 i__2 = k - 1;
00515 dgemv_("No transpose", &i__1, &i__2, &c_b8, &a[k + a_dim1],
00516 lda, &w[imax + w_dim1], ldw, &c_b9, &w[k + (k + 1) *
00517 w_dim1], &c__1);
00518
00519
00520
00521
00522 i__1 = imax - k;
00523 jmax = k - 1 + idamax_(&i__1, &w[k + (k + 1) * w_dim1], &c__1)
00524 ;
00525 rowmax = (d__1 = w[jmax + (k + 1) * w_dim1], abs(d__1));
00526 if (imax < *n) {
00527 i__1 = *n - imax;
00528 jmax = imax + idamax_(&i__1, &w[imax + 1 + (k + 1) *
00529 w_dim1], &c__1);
00530
00531 d__2 = rowmax, d__3 = (d__1 = w[jmax + (k + 1) * w_dim1],
00532 abs(d__1));
00533 rowmax = max(d__2,d__3);
00534 }
00535
00536 if (absakk >= alpha * colmax * (colmax / rowmax)) {
00537
00538
00539
00540 kp = k;
00541 } else if ((d__1 = w[imax + (k + 1) * w_dim1], abs(d__1)) >=
00542 alpha * rowmax) {
00543
00544
00545
00546
00547 kp = imax;
00548
00549
00550
00551 i__1 = *n - k + 1;
00552 dcopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k *
00553 w_dim1], &c__1);
00554 } else {
00555
00556
00557
00558
00559 kp = imax;
00560 kstep = 2;
00561 }
00562 }
00563
00564 kk = k + kstep - 1;
00565
00566
00567
00568 if (kp != kk) {
00569
00570
00571
00572 a[kp + k * a_dim1] = a[kk + k * a_dim1];
00573 i__1 = kp - k - 1;
00574 dcopy_(&i__1, &a[k + 1 + kk * a_dim1], &c__1, &a[kp + (k + 1)
00575 * a_dim1], lda);
00576 i__1 = *n - kp + 1;
00577 dcopy_(&i__1, &a[kp + kk * a_dim1], &c__1, &a[kp + kp *
00578 a_dim1], &c__1);
00579
00580
00581
00582 dswap_(&kk, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda);
00583 dswap_(&kk, &w[kk + w_dim1], ldw, &w[kp + w_dim1], ldw);
00584 }
00585
00586 if (kstep == 1) {
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596 i__1 = *n - k + 1;
00597 dcopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
00598 c__1);
00599 if (k < *n) {
00600 r1 = 1. / a[k + k * a_dim1];
00601 i__1 = *n - k;
00602 dscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
00603 }
00604 } else {
00605
00606
00607
00608
00609
00610
00611
00612
00613 if (k < *n - 1) {
00614
00615
00616
00617 d21 = w[k + 1 + k * w_dim1];
00618 d11 = w[k + 1 + (k + 1) * w_dim1] / d21;
00619 d22 = w[k + k * w_dim1] / d21;
00620 t = 1. / (d11 * d22 - 1.);
00621 d21 = t / d21;
00622 i__1 = *n;
00623 for (j = k + 2; j <= i__1; ++j) {
00624 a[j + k * a_dim1] = d21 * (d11 * w[j + k * w_dim1] -
00625 w[j + (k + 1) * w_dim1]);
00626 a[j + (k + 1) * a_dim1] = d21 * (d22 * w[j + (k + 1) *
00627 w_dim1] - w[j + k * w_dim1]);
00628
00629 }
00630 }
00631
00632
00633
00634 a[k + k * a_dim1] = w[k + k * w_dim1];
00635 a[k + 1 + k * a_dim1] = w[k + 1 + k * w_dim1];
00636 a[k + 1 + (k + 1) * a_dim1] = w[k + 1 + (k + 1) * w_dim1];
00637 }
00638 }
00639
00640
00641
00642 if (kstep == 1) {
00643 ipiv[k] = kp;
00644 } else {
00645 ipiv[k] = -kp;
00646 ipiv[k + 1] = -kp;
00647 }
00648
00649
00650
00651 k += kstep;
00652 goto L70;
00653
00654 L90:
00655
00656
00657
00658
00659
00660
00661
00662 i__1 = *n;
00663 i__2 = *nb;
00664 for (j = k; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00665
00666 i__3 = *nb, i__4 = *n - j + 1;
00667 jb = min(i__3,i__4);
00668
00669
00670
00671 i__3 = j + jb - 1;
00672 for (jj = j; jj <= i__3; ++jj) {
00673 i__4 = j + jb - jj;
00674 i__5 = k - 1;
00675 dgemv_("No transpose", &i__4, &i__5, &c_b8, &a[jj + a_dim1],
00676 lda, &w[jj + w_dim1], ldw, &c_b9, &a[jj + jj * a_dim1]
00677 , &c__1);
00678
00679 }
00680
00681
00682
00683 if (j + jb <= *n) {
00684 i__3 = *n - j - jb + 1;
00685 i__4 = k - 1;
00686 dgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &c_b8,
00687 &a[j + jb + a_dim1], lda, &w[j + w_dim1], ldw, &c_b9,
00688 &a[j + jb + j * a_dim1], lda);
00689 }
00690
00691 }
00692
00693
00694
00695
00696 j = k - 1;
00697 L120:
00698 jj = j;
00699 jp = ipiv[j];
00700 if (jp < 0) {
00701 jp = -jp;
00702 --j;
00703 }
00704 --j;
00705 if (jp != jj && j >= 1) {
00706 dswap_(&j, &a[jp + a_dim1], lda, &a[jj + a_dim1], lda);
00707 }
00708 if (j >= 1) {
00709 goto L120;
00710 }
00711
00712
00713
00714 *kb = k - 1;
00715
00716 }
00717 return 0;
00718
00719
00720
00721 }