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 integer c_n1 = -1;
00020 static integer c__0 = 0;
00021 static doublereal c_b17 = 1.;
00022
00023 int dsyevd_(char *jobz, char *uplo, integer *n, doublereal *
00024 a, integer *lda, doublereal *w, doublereal *work, integer *lwork,
00025 integer *iwork, integer *liwork, integer *info)
00026 {
00027
00028 integer a_dim1, a_offset, i__1, i__2, i__3;
00029 doublereal d__1;
00030
00031
00032 double sqrt(doublereal);
00033
00034
00035 doublereal eps;
00036 integer inde;
00037 doublereal anrm, rmin, rmax;
00038 integer lopt;
00039 extern int dscal_(integer *, doublereal *, doublereal *,
00040 integer *);
00041 doublereal sigma;
00042 extern logical lsame_(char *, char *);
00043 integer iinfo, lwmin, liopt;
00044 logical lower, wantz;
00045 integer indwk2, llwrk2;
00046 extern doublereal dlamch_(char *);
00047 integer iscale;
00048 extern int dlascl_(char *, integer *, integer *,
00049 doublereal *, doublereal *, integer *, integer *, doublereal *,
00050 integer *, integer *), dstedc_(char *, integer *,
00051 doublereal *, doublereal *, doublereal *, integer *, doublereal *,
00052 integer *, integer *, integer *, integer *), dlacpy_(
00053 char *, integer *, integer *, doublereal *, integer *, doublereal
00054 *, integer *);
00055 doublereal safmin;
00056 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00057 integer *, integer *);
00058 extern int xerbla_(char *, integer *);
00059 doublereal bignum;
00060 integer indtau;
00061 extern int dsterf_(integer *, doublereal *, doublereal *,
00062 integer *);
00063 extern doublereal dlansy_(char *, char *, integer *, doublereal *,
00064 integer *, doublereal *);
00065 integer indwrk, liwmin;
00066 extern int dormtr_(char *, char *, char *, integer *,
00067 integer *, doublereal *, integer *, doublereal *, doublereal *,
00068 integer *, doublereal *, integer *, integer *), dsytrd_(char *, integer *, doublereal *, integer *,
00069 doublereal *, doublereal *, doublereal *, doublereal *, integer *,
00070 integer *);
00071 integer llwork;
00072 doublereal smlnum;
00073 logical lquery;
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 a_dim1 = *lda;
00205 a_offset = 1 + a_dim1;
00206 a -= a_offset;
00207 --w;
00208 --work;
00209 --iwork;
00210
00211
00212 wantz = lsame_(jobz, "V");
00213 lower = lsame_(uplo, "L");
00214 lquery = *lwork == -1 || *liwork == -1;
00215
00216 *info = 0;
00217 if (! (wantz || lsame_(jobz, "N"))) {
00218 *info = -1;
00219 } else if (! (lower || lsame_(uplo, "U"))) {
00220 *info = -2;
00221 } else if (*n < 0) {
00222 *info = -3;
00223 } else if (*lda < max(1,*n)) {
00224 *info = -5;
00225 }
00226
00227 if (*info == 0) {
00228 if (*n <= 1) {
00229 liwmin = 1;
00230 lwmin = 1;
00231 lopt = lwmin;
00232 liopt = liwmin;
00233 } else {
00234 if (wantz) {
00235 liwmin = *n * 5 + 3;
00236
00237 i__1 = *n;
00238 lwmin = *n * 6 + 1 + (i__1 * i__1 << 1);
00239 } else {
00240 liwmin = 1;
00241 lwmin = (*n << 1) + 1;
00242 }
00243
00244 i__1 = lwmin, i__2 = (*n << 1) + ilaenv_(&c__1, "DSYTRD", uplo, n,
00245 &c_n1, &c_n1, &c_n1);
00246 lopt = max(i__1,i__2);
00247 liopt = liwmin;
00248 }
00249 work[1] = (doublereal) lopt;
00250 iwork[1] = liopt;
00251
00252 if (*lwork < lwmin && ! lquery) {
00253 *info = -8;
00254 } else if (*liwork < liwmin && ! lquery) {
00255 *info = -10;
00256 }
00257 }
00258
00259 if (*info != 0) {
00260 i__1 = -(*info);
00261 xerbla_("DSYEVD", &i__1);
00262 return 0;
00263 } else if (lquery) {
00264 return 0;
00265 }
00266
00267
00268
00269 if (*n == 0) {
00270 return 0;
00271 }
00272
00273 if (*n == 1) {
00274 w[1] = a[a_dim1 + 1];
00275 if (wantz) {
00276 a[a_dim1 + 1] = 1.;
00277 }
00278 return 0;
00279 }
00280
00281
00282
00283 safmin = dlamch_("Safe minimum");
00284 eps = dlamch_("Precision");
00285 smlnum = safmin / eps;
00286 bignum = 1. / smlnum;
00287 rmin = sqrt(smlnum);
00288 rmax = sqrt(bignum);
00289
00290
00291
00292 anrm = dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]);
00293 iscale = 0;
00294 if (anrm > 0. && anrm < rmin) {
00295 iscale = 1;
00296 sigma = rmin / anrm;
00297 } else if (anrm > rmax) {
00298 iscale = 1;
00299 sigma = rmax / anrm;
00300 }
00301 if (iscale == 1) {
00302 dlascl_(uplo, &c__0, &c__0, &c_b17, &sigma, n, n, &a[a_offset], lda,
00303 info);
00304 }
00305
00306
00307
00308 inde = 1;
00309 indtau = inde + *n;
00310 indwrk = indtau + *n;
00311 llwork = *lwork - indwrk + 1;
00312 indwk2 = indwrk + *n * *n;
00313 llwrk2 = *lwork - indwk2 + 1;
00314
00315 dsytrd_(uplo, n, &a[a_offset], lda, &w[1], &work[inde], &work[indtau], &
00316 work[indwrk], &llwork, &iinfo);
00317 lopt = (integer) ((*n << 1) + work[indwrk]);
00318
00319
00320
00321
00322
00323
00324 if (! wantz) {
00325 dsterf_(n, &w[1], &work[inde], info);
00326 } else {
00327 dstedc_("I", n, &w[1], &work[inde], &work[indwrk], n, &work[indwk2], &
00328 llwrk2, &iwork[1], liwork, info);
00329 dormtr_("L", uplo, "N", n, n, &a[a_offset], lda, &work[indtau], &work[
00330 indwrk], n, &work[indwk2], &llwrk2, &iinfo);
00331 dlacpy_("A", n, n, &work[indwrk], n, &a[a_offset], lda);
00332
00333
00334 i__3 = *n;
00335 i__1 = lopt, i__2 = *n * 6 + 1 + (i__3 * i__3 << 1);
00336 lopt = max(i__1,i__2);
00337 }
00338
00339
00340
00341 if (iscale == 1) {
00342 d__1 = 1. / sigma;
00343 dscal_(n, &d__1, &w[1], &c__1);
00344 }
00345
00346 work[1] = (doublereal) lopt;
00347 iwork[1] = liopt;
00348
00349 return 0;
00350
00351
00352
00353 }