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