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 complex c_b1 = {0.f,0.f};
00019 static complex c_b2 = {1.f,0.f};
00020 static integer c__1 = 1;
00021
00022 int chet21_(integer *itype, char *uplo, integer *n, integer *
00023 kband, complex *a, integer *lda, real *d__, real *e, complex *u,
00024 integer *ldu, complex *v, integer *ldv, complex *tau, complex *work,
00025 real *rwork, real *result)
00026 {
00027
00028 integer a_dim1, a_offset, u_dim1, u_offset, v_dim1, v_offset, i__1, i__2,
00029 i__3, i__4, i__5, i__6;
00030 real r__1, r__2;
00031 complex q__1, q__2, q__3;
00032
00033
00034 integer j, jr;
00035 real ulp;
00036 extern int cher_(char *, integer *, real *, complex *,
00037 integer *, complex *, integer *);
00038 integer jcol;
00039 real unfl;
00040 integer jrow;
00041 extern int cher2_(char *, integer *, complex *, complex *
00042 , integer *, complex *, integer *, complex *, integer *),
00043 cgemm_(char *, char *, integer *, integer *, integer *, complex *,
00044 complex *, integer *, complex *, integer *, complex *, complex *,
00045 integer *);
00046 extern logical lsame_(char *, char *);
00047 integer iinfo;
00048 real anorm;
00049 char cuplo[1];
00050 complex vsave;
00051 logical lower;
00052 real wnorm;
00053 extern int cunm2l_(char *, char *, integer *, integer *,
00054 integer *, complex *, integer *, complex *, complex *, integer *,
00055 complex *, integer *), cunm2r_(char *, char *,
00056 integer *, integer *, integer *, complex *, integer *, complex *,
00057 complex *, integer *, complex *, integer *);
00058 extern doublereal clange_(char *, integer *, integer *, complex *,
00059 integer *, real *), clanhe_(char *, char *, integer *,
00060 complex *, integer *, real *), slamch_(char *);
00061 extern int clacpy_(char *, integer *, integer *, complex
00062 *, integer *, complex *, integer *), claset_(char *,
00063 integer *, integer *, complex *, complex *, complex *, integer *), clarfy_(char *, integer *, complex *, integer *, complex
00064 *, complex *, integer *, complex *);
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
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 a_dim1 = *lda;
00217 a_offset = 1 + a_dim1;
00218 a -= a_offset;
00219 --d__;
00220 --e;
00221 u_dim1 = *ldu;
00222 u_offset = 1 + u_dim1;
00223 u -= u_offset;
00224 v_dim1 = *ldv;
00225 v_offset = 1 + v_dim1;
00226 v -= v_offset;
00227 --tau;
00228 --work;
00229 --rwork;
00230 --result;
00231
00232
00233 result[1] = 0.f;
00234 if (*itype == 1) {
00235 result[2] = 0.f;
00236 }
00237 if (*n <= 0) {
00238 return 0;
00239 }
00240
00241 if (lsame_(uplo, "U")) {
00242 lower = FALSE_;
00243 *(unsigned char *)cuplo = 'U';
00244 } else {
00245 lower = TRUE_;
00246 *(unsigned char *)cuplo = 'L';
00247 }
00248
00249 unfl = slamch_("Safe minimum");
00250 ulp = slamch_("Epsilon") * slamch_("Base");
00251
00252
00253
00254 if (*itype < 1 || *itype > 3) {
00255 result[1] = 10.f / ulp;
00256 return 0;
00257 }
00258
00259
00260
00261
00262
00263 if (*itype == 3) {
00264 anorm = 1.f;
00265 } else {
00266
00267 r__1 = clanhe_("1", cuplo, n, &a[a_offset], lda, &rwork[1]);
00268 anorm = dmax(r__1,unfl);
00269 }
00270
00271
00272
00273 if (*itype == 1) {
00274
00275
00276
00277 claset_("Full", n, n, &c_b1, &c_b1, &work[1], n);
00278 clacpy_(cuplo, n, n, &a[a_offset], lda, &work[1], n);
00279
00280 i__1 = *n;
00281 for (j = 1; j <= i__1; ++j) {
00282 r__1 = -d__[j];
00283 cher_(cuplo, n, &r__1, &u[j * u_dim1 + 1], &c__1, &work[1], n);
00284
00285 }
00286
00287 if (*n > 1 && *kband == 1) {
00288 i__1 = *n - 1;
00289 for (j = 1; j <= i__1; ++j) {
00290 i__2 = j;
00291 q__2.r = e[i__2], q__2.i = 0.f;
00292 q__1.r = -q__2.r, q__1.i = -q__2.i;
00293 cher2_(cuplo, n, &q__1, &u[j * u_dim1 + 1], &c__1, &u[(j - 1)
00294 * u_dim1 + 1], &c__1, &work[1], n);
00295
00296 }
00297 }
00298 wnorm = clanhe_("1", cuplo, n, &work[1], n, &rwork[1]);
00299
00300 } else if (*itype == 2) {
00301
00302
00303
00304 claset_("Full", n, n, &c_b1, &c_b1, &work[1], n);
00305
00306 if (lower) {
00307
00308 i__2 = *n;
00309 i__1 = i__2 * i__2;
00310 i__3 = *n;
00311 work[i__1].r = d__[i__3], work[i__1].i = 0.f;
00312 for (j = *n - 1; j >= 1; --j) {
00313 if (*kband == 1) {
00314 i__1 = (*n + 1) * (j - 1) + 2;
00315 i__2 = j;
00316 q__2.r = 1.f - tau[i__2].r, q__2.i = 0.f - tau[i__2].i;
00317 i__3 = j;
00318 q__1.r = e[i__3] * q__2.r, q__1.i = e[i__3] * q__2.i;
00319 work[i__1].r = q__1.r, work[i__1].i = q__1.i;
00320 i__1 = *n;
00321 for (jr = j + 2; jr <= i__1; ++jr) {
00322 i__2 = (j - 1) * *n + jr;
00323 i__3 = j;
00324 q__3.r = -tau[i__3].r, q__3.i = -tau[i__3].i;
00325 i__4 = j;
00326 q__2.r = e[i__4] * q__3.r, q__2.i = e[i__4] * q__3.i;
00327 i__5 = jr + j * v_dim1;
00328 q__1.r = q__2.r * v[i__5].r - q__2.i * v[i__5].i,
00329 q__1.i = q__2.r * v[i__5].i + q__2.i * v[i__5]
00330 .r;
00331 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00332
00333 }
00334 }
00335
00336 i__1 = j + 1 + j * v_dim1;
00337 vsave.r = v[i__1].r, vsave.i = v[i__1].i;
00338 i__1 = j + 1 + j * v_dim1;
00339 v[i__1].r = 1.f, v[i__1].i = 0.f;
00340 i__1 = *n - j;
00341
00342 i__2 = *n;
00343 clarfy_("L", &i__1, &v[j + 1 + j * v_dim1], &c__1, &tau[j], &
00344 work[(*n + 1) * j + 1], n, &work[i__2 * i__2 + 1]);
00345 i__1 = j + 1 + j * v_dim1;
00346 v[i__1].r = vsave.r, v[i__1].i = vsave.i;
00347 i__1 = (*n + 1) * (j - 1) + 1;
00348 i__2 = j;
00349 work[i__1].r = d__[i__2], work[i__1].i = 0.f;
00350
00351 }
00352 } else {
00353 work[1].r = d__[1], work[1].i = 0.f;
00354 i__1 = *n - 1;
00355 for (j = 1; j <= i__1; ++j) {
00356 if (*kband == 1) {
00357 i__2 = (*n + 1) * j;
00358 i__3 = j;
00359 q__2.r = 1.f - tau[i__3].r, q__2.i = 0.f - tau[i__3].i;
00360 i__4 = j;
00361 q__1.r = e[i__4] * q__2.r, q__1.i = e[i__4] * q__2.i;
00362 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00363 i__2 = j - 1;
00364 for (jr = 1; jr <= i__2; ++jr) {
00365 i__3 = j * *n + jr;
00366 i__4 = j;
00367 q__3.r = -tau[i__4].r, q__3.i = -tau[i__4].i;
00368 i__5 = j;
00369 q__2.r = e[i__5] * q__3.r, q__2.i = e[i__5] * q__3.i;
00370 i__6 = jr + (j + 1) * v_dim1;
00371 q__1.r = q__2.r * v[i__6].r - q__2.i * v[i__6].i,
00372 q__1.i = q__2.r * v[i__6].i + q__2.i * v[i__6]
00373 .r;
00374 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00375
00376 }
00377 }
00378
00379 i__2 = j + (j + 1) * v_dim1;
00380 vsave.r = v[i__2].r, vsave.i = v[i__2].i;
00381 i__2 = j + (j + 1) * v_dim1;
00382 v[i__2].r = 1.f, v[i__2].i = 0.f;
00383
00384 i__2 = *n;
00385 clarfy_("U", &j, &v[(j + 1) * v_dim1 + 1], &c__1, &tau[j], &
00386 work[1], n, &work[i__2 * i__2 + 1]);
00387 i__2 = j + (j + 1) * v_dim1;
00388 v[i__2].r = vsave.r, v[i__2].i = vsave.i;
00389 i__2 = (*n + 1) * j + 1;
00390 i__3 = j + 1;
00391 work[i__2].r = d__[i__3], work[i__2].i = 0.f;
00392
00393 }
00394 }
00395
00396 i__1 = *n;
00397 for (jcol = 1; jcol <= i__1; ++jcol) {
00398 if (lower) {
00399 i__2 = *n;
00400 for (jrow = jcol; jrow <= i__2; ++jrow) {
00401 i__3 = jrow + *n * (jcol - 1);
00402 i__4 = jrow + *n * (jcol - 1);
00403 i__5 = jrow + jcol * a_dim1;
00404 q__1.r = work[i__4].r - a[i__5].r, q__1.i = work[i__4].i
00405 - a[i__5].i;
00406 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00407
00408 }
00409 } else {
00410 i__2 = jcol;
00411 for (jrow = 1; jrow <= i__2; ++jrow) {
00412 i__3 = jrow + *n * (jcol - 1);
00413 i__4 = jrow + *n * (jcol - 1);
00414 i__5 = jrow + jcol * a_dim1;
00415 q__1.r = work[i__4].r - a[i__5].r, q__1.i = work[i__4].i
00416 - a[i__5].i;
00417 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00418
00419 }
00420 }
00421
00422 }
00423 wnorm = clanhe_("1", cuplo, n, &work[1], n, &rwork[1]);
00424
00425 } else if (*itype == 3) {
00426
00427
00428
00429 if (*n < 2) {
00430 return 0;
00431 }
00432 clacpy_(" ", n, n, &u[u_offset], ldu, &work[1], n);
00433 if (lower) {
00434 i__1 = *n - 1;
00435 i__2 = *n - 1;
00436
00437 i__3 = *n;
00438 cunm2r_("R", "C", n, &i__1, &i__2, &v[v_dim1 + 2], ldv, &tau[1], &
00439 work[*n + 1], n, &work[i__3 * i__3 + 1], &iinfo);
00440 } else {
00441 i__1 = *n - 1;
00442 i__2 = *n - 1;
00443
00444 i__3 = *n;
00445 cunm2l_("R", "C", n, &i__1, &i__2, &v[(v_dim1 << 1) + 1], ldv, &
00446 tau[1], &work[1], n, &work[i__3 * i__3 + 1], &iinfo);
00447 }
00448 if (iinfo != 0) {
00449 result[1] = 10.f / ulp;
00450 return 0;
00451 }
00452
00453 i__1 = *n;
00454 for (j = 1; j <= i__1; ++j) {
00455 i__2 = (*n + 1) * (j - 1) + 1;
00456 i__3 = (*n + 1) * (j - 1) + 1;
00457 q__1.r = work[i__3].r - 1.f, q__1.i = work[i__3].i - 0.f;
00458 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00459
00460 }
00461
00462 wnorm = clange_("1", n, n, &work[1], n, &rwork[1]);
00463 }
00464
00465 if (anorm > wnorm) {
00466 result[1] = wnorm / anorm / (*n * ulp);
00467 } else {
00468 if (anorm < 1.f) {
00469
00470 r__1 = wnorm, r__2 = *n * anorm;
00471 result[1] = dmin(r__1,r__2) / anorm / (*n * ulp);
00472 } else {
00473
00474 r__1 = wnorm / anorm, r__2 = (real) (*n);
00475 result[1] = dmin(r__1,r__2) / (*n * ulp);
00476 }
00477 }
00478
00479
00480
00481
00482
00483 if (*itype == 1) {
00484 cgemm_("N", "C", n, n, n, &c_b2, &u[u_offset], ldu, &u[u_offset], ldu,
00485 &c_b1, &work[1], n);
00486
00487 i__1 = *n;
00488 for (j = 1; j <= i__1; ++j) {
00489 i__2 = (*n + 1) * (j - 1) + 1;
00490 i__3 = (*n + 1) * (j - 1) + 1;
00491 q__1.r = work[i__3].r - 1.f, q__1.i = work[i__3].i - 0.f;
00492 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00493
00494 }
00495
00496
00497 r__1 = clange_("1", n, n, &work[1], n, &rwork[1]), r__2 = (
00498 real) (*n);
00499 result[2] = dmin(r__1,r__2) / (*n * ulp);
00500 }
00501
00502 return 0;
00503
00504
00505
00506 }