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__0 = 0;
00020 static real c_b13 = 1.f;
00021 static real c_b26 = 0.f;
00022
00023 int slasd3_(integer *nl, integer *nr, integer *sqre, integer
00024 *k, real *d__, real *q, integer *ldq, real *dsigma, real *u, integer *
00025 ldu, real *u2, integer *ldu2, real *vt, integer *ldvt, real *vt2,
00026 integer *ldvt2, integer *idxc, integer *ctot, real *z__, integer *
00027 info)
00028 {
00029
00030 integer q_dim1, q_offset, u_dim1, u_offset, u2_dim1, u2_offset, vt_dim1,
00031 vt_offset, vt2_dim1, vt2_offset, i__1, i__2;
00032 real r__1, r__2;
00033
00034
00035 double sqrt(doublereal), r_sign(real *, real *);
00036
00037
00038 integer i__, j, m, n, jc;
00039 real rho;
00040 integer nlp1, nlp2, nrp1;
00041 real temp;
00042 extern doublereal snrm2_(integer *, real *, integer *);
00043 integer ctemp;
00044 extern int sgemm_(char *, char *, integer *, integer *,
00045 integer *, real *, real *, integer *, real *, integer *, real *,
00046 real *, integer *);
00047 integer ktemp;
00048 extern int scopy_(integer *, real *, integer *, real *,
00049 integer *);
00050 extern doublereal slamc3_(real *, real *);
00051 extern int slasd4_(integer *, integer *, real *, real *,
00052 real *, real *, real *, real *, integer *), xerbla_(char *,
00053 integer *), slascl_(char *, integer *, integer *, real *,
00054 real *, integer *, integer *, real *, integer *, integer *), slacpy_(char *, integer *, integer *, real *, integer *,
00055 real *, integer *);
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
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 --d__;
00197 q_dim1 = *ldq;
00198 q_offset = 1 + q_dim1;
00199 q -= q_offset;
00200 --dsigma;
00201 u_dim1 = *ldu;
00202 u_offset = 1 + u_dim1;
00203 u -= u_offset;
00204 u2_dim1 = *ldu2;
00205 u2_offset = 1 + u2_dim1;
00206 u2 -= u2_offset;
00207 vt_dim1 = *ldvt;
00208 vt_offset = 1 + vt_dim1;
00209 vt -= vt_offset;
00210 vt2_dim1 = *ldvt2;
00211 vt2_offset = 1 + vt2_dim1;
00212 vt2 -= vt2_offset;
00213 --idxc;
00214 --ctot;
00215 --z__;
00216
00217
00218 *info = 0;
00219
00220 if (*nl < 1) {
00221 *info = -1;
00222 } else if (*nr < 1) {
00223 *info = -2;
00224 } else if (*sqre != 1 && *sqre != 0) {
00225 *info = -3;
00226 }
00227
00228 n = *nl + *nr + 1;
00229 m = n + *sqre;
00230 nlp1 = *nl + 1;
00231 nlp2 = *nl + 2;
00232
00233 if (*k < 1 || *k > n) {
00234 *info = -4;
00235 } else if (*ldq < *k) {
00236 *info = -7;
00237 } else if (*ldu < n) {
00238 *info = -10;
00239 } else if (*ldu2 < n) {
00240 *info = -12;
00241 } else if (*ldvt < m) {
00242 *info = -14;
00243 } else if (*ldvt2 < m) {
00244 *info = -16;
00245 }
00246 if (*info != 0) {
00247 i__1 = -(*info);
00248 xerbla_("SLASD3", &i__1);
00249 return 0;
00250 }
00251
00252
00253
00254 if (*k == 1) {
00255 d__[1] = dabs(z__[1]);
00256 scopy_(&m, &vt2[vt2_dim1 + 1], ldvt2, &vt[vt_dim1 + 1], ldvt);
00257 if (z__[1] > 0.f) {
00258 scopy_(&n, &u2[u2_dim1 + 1], &c__1, &u[u_dim1 + 1], &c__1);
00259 } else {
00260 i__1 = n;
00261 for (i__ = 1; i__ <= i__1; ++i__) {
00262 u[i__ + u_dim1] = -u2[i__ + u2_dim1];
00263
00264 }
00265 }
00266 return 0;
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 i__1 = *k;
00287 for (i__ = 1; i__ <= i__1; ++i__) {
00288 dsigma[i__] = slamc3_(&dsigma[i__], &dsigma[i__]) - dsigma[i__];
00289
00290 }
00291
00292
00293
00294 scopy_(k, &z__[1], &c__1, &q[q_offset], &c__1);
00295
00296
00297
00298 rho = snrm2_(k, &z__[1], &c__1);
00299 slascl_("G", &c__0, &c__0, &rho, &c_b13, k, &c__1, &z__[1], k, info);
00300 rho *= rho;
00301
00302
00303
00304 i__1 = *k;
00305 for (j = 1; j <= i__1; ++j) {
00306 slasd4_(k, &j, &dsigma[1], &z__[1], &u[j * u_dim1 + 1], &rho, &d__[j],
00307 &vt[j * vt_dim1 + 1], info);
00308
00309
00310
00311 if (*info != 0) {
00312 return 0;
00313 }
00314
00315 }
00316
00317
00318
00319 i__1 = *k;
00320 for (i__ = 1; i__ <= i__1; ++i__) {
00321 z__[i__] = u[i__ + *k * u_dim1] * vt[i__ + *k * vt_dim1];
00322 i__2 = i__ - 1;
00323 for (j = 1; j <= i__2; ++j) {
00324 z__[i__] *= u[i__ + j * u_dim1] * vt[i__ + j * vt_dim1] / (dsigma[
00325 i__] - dsigma[j]) / (dsigma[i__] + dsigma[j]);
00326
00327 }
00328 i__2 = *k - 1;
00329 for (j = i__; j <= i__2; ++j) {
00330 z__[i__] *= u[i__ + j * u_dim1] * vt[i__ + j * vt_dim1] / (dsigma[
00331 i__] - dsigma[j + 1]) / (dsigma[i__] + dsigma[j + 1]);
00332
00333 }
00334 r__2 = sqrt((r__1 = z__[i__], dabs(r__1)));
00335 z__[i__] = r_sign(&r__2, &q[i__ + q_dim1]);
00336
00337 }
00338
00339
00340
00341
00342 i__1 = *k;
00343 for (i__ = 1; i__ <= i__1; ++i__) {
00344 vt[i__ * vt_dim1 + 1] = z__[1] / u[i__ * u_dim1 + 1] / vt[i__ *
00345 vt_dim1 + 1];
00346 u[i__ * u_dim1 + 1] = -1.f;
00347 i__2 = *k;
00348 for (j = 2; j <= i__2; ++j) {
00349 vt[j + i__ * vt_dim1] = z__[j] / u[j + i__ * u_dim1] / vt[j + i__
00350 * vt_dim1];
00351 u[j + i__ * u_dim1] = dsigma[j] * vt[j + i__ * vt_dim1];
00352
00353 }
00354 temp = snrm2_(k, &u[i__ * u_dim1 + 1], &c__1);
00355 q[i__ * q_dim1 + 1] = u[i__ * u_dim1 + 1] / temp;
00356 i__2 = *k;
00357 for (j = 2; j <= i__2; ++j) {
00358 jc = idxc[j];
00359 q[j + i__ * q_dim1] = u[jc + i__ * u_dim1] / temp;
00360
00361 }
00362
00363 }
00364
00365
00366
00367 if (*k == 2) {
00368 sgemm_("N", "N", &n, k, k, &c_b13, &u2[u2_offset], ldu2, &q[q_offset],
00369 ldq, &c_b26, &u[u_offset], ldu);
00370 goto L100;
00371 }
00372 if (ctot[1] > 0) {
00373 sgemm_("N", "N", nl, k, &ctot[1], &c_b13, &u2[(u2_dim1 << 1) + 1],
00374 ldu2, &q[q_dim1 + 2], ldq, &c_b26, &u[u_dim1 + 1], ldu);
00375 if (ctot[3] > 0) {
00376 ktemp = ctot[1] + 2 + ctot[2];
00377 sgemm_("N", "N", nl, k, &ctot[3], &c_b13, &u2[ktemp * u2_dim1 + 1]
00378 , ldu2, &q[ktemp + q_dim1], ldq, &c_b13, &u[u_dim1 + 1],
00379 ldu);
00380 }
00381 } else if (ctot[3] > 0) {
00382 ktemp = ctot[1] + 2 + ctot[2];
00383 sgemm_("N", "N", nl, k, &ctot[3], &c_b13, &u2[ktemp * u2_dim1 + 1],
00384 ldu2, &q[ktemp + q_dim1], ldq, &c_b26, &u[u_dim1 + 1], ldu);
00385 } else {
00386 slacpy_("F", nl, k, &u2[u2_offset], ldu2, &u[u_offset], ldu);
00387 }
00388 scopy_(k, &q[q_dim1 + 1], ldq, &u[nlp1 + u_dim1], ldu);
00389 ktemp = ctot[1] + 2;
00390 ctemp = ctot[2] + ctot[3];
00391 sgemm_("N", "N", nr, k, &ctemp, &c_b13, &u2[nlp2 + ktemp * u2_dim1], ldu2,
00392 &q[ktemp + q_dim1], ldq, &c_b26, &u[nlp2 + u_dim1], ldu);
00393
00394
00395
00396 L100:
00397 i__1 = *k;
00398 for (i__ = 1; i__ <= i__1; ++i__) {
00399 temp = snrm2_(k, &vt[i__ * vt_dim1 + 1], &c__1);
00400 q[i__ + q_dim1] = vt[i__ * vt_dim1 + 1] / temp;
00401 i__2 = *k;
00402 for (j = 2; j <= i__2; ++j) {
00403 jc = idxc[j];
00404 q[i__ + j * q_dim1] = vt[jc + i__ * vt_dim1] / temp;
00405
00406 }
00407
00408 }
00409
00410
00411
00412 if (*k == 2) {
00413 sgemm_("N", "N", k, &m, k, &c_b13, &q[q_offset], ldq, &vt2[vt2_offset]
00414 , ldvt2, &c_b26, &vt[vt_offset], ldvt);
00415 return 0;
00416 }
00417 ktemp = ctot[1] + 1;
00418 sgemm_("N", "N", k, &nlp1, &ktemp, &c_b13, &q[q_dim1 + 1], ldq, &vt2[
00419 vt2_dim1 + 1], ldvt2, &c_b26, &vt[vt_dim1 + 1], ldvt);
00420 ktemp = ctot[1] + 2 + ctot[2];
00421 if (ktemp <= *ldvt2) {
00422 sgemm_("N", "N", k, &nlp1, &ctot[3], &c_b13, &q[ktemp * q_dim1 + 1],
00423 ldq, &vt2[ktemp + vt2_dim1], ldvt2, &c_b13, &vt[vt_dim1 + 1],
00424 ldvt);
00425 }
00426
00427 ktemp = ctot[1] + 1;
00428 nrp1 = *nr + *sqre;
00429 if (ktemp > 1) {
00430 i__1 = *k;
00431 for (i__ = 1; i__ <= i__1; ++i__) {
00432 q[i__ + ktemp * q_dim1] = q[i__ + q_dim1];
00433
00434 }
00435 i__1 = m;
00436 for (i__ = nlp2; i__ <= i__1; ++i__) {
00437 vt2[ktemp + i__ * vt2_dim1] = vt2[i__ * vt2_dim1 + 1];
00438
00439 }
00440 }
00441 ctemp = ctot[2] + 1 + ctot[3];
00442 sgemm_("N", "N", k, &nrp1, &ctemp, &c_b13, &q[ktemp * q_dim1 + 1], ldq, &
00443 vt2[ktemp + nlp2 * vt2_dim1], ldvt2, &c_b26, &vt[nlp2 * vt_dim1 +
00444 1], ldvt);
00445
00446 return 0;
00447
00448
00449
00450 }