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