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 doublereal c_b17 = 1.;
00019 static doublereal c_b18 = 0.;
00020 static doublereal c_b44 = -1.;
00021 static integer c__1 = 1;
00022
00023 int dgsvts_(integer *m, integer *p, integer *n, doublereal *
00024 a, doublereal *af, integer *lda, doublereal *b, doublereal *bf,
00025 integer *ldb, doublereal *u, integer *ldu, doublereal *v, integer *
00026 ldv, doublereal *q, integer *ldq, doublereal *alpha, doublereal *beta,
00027 doublereal *r__, integer *ldr, integer *iwork, doublereal *work,
00028 integer *lwork, doublereal *rwork, doublereal *result)
00029 {
00030
00031 integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, bf_dim1,
00032 bf_offset, q_dim1, q_offset, r_dim1, r_offset, u_dim1, u_offset,
00033 v_dim1, v_offset, i__1, i__2;
00034 doublereal d__1;
00035
00036
00037 integer i__, j, k, l;
00038 doublereal ulp;
00039 integer info;
00040 doublereal unfl, temp;
00041 extern int dgemm_(char *, char *, integer *, integer *,
00042 integer *, doublereal *, doublereal *, integer *, doublereal *,
00043 integer *, doublereal *, doublereal *, integer *);
00044 doublereal resid, anorm, bnorm;
00045 extern int dcopy_(integer *, doublereal *, integer *,
00046 doublereal *, integer *), dsyrk_(char *, char *, integer *,
00047 integer *, doublereal *, doublereal *, integer *, doublereal *,
00048 doublereal *, integer *);
00049 extern doublereal dlamch_(char *), dlange_(char *, integer *,
00050 integer *, doublereal *, integer *, doublereal *);
00051 extern int dlacpy_(char *, integer *, integer *,
00052 doublereal *, integer *, doublereal *, integer *),
00053 dlaset_(char *, integer *, integer *, doublereal *, doublereal *,
00054 doublereal *, integer *), dggsvd_(char *, char *, char *,
00055 integer *, integer *, integer *, integer *, integer *, doublereal
00056 *, integer *, doublereal *, integer *, doublereal *, doublereal *,
00057 doublereal *, integer *, doublereal *, integer *, doublereal *,
00058 integer *, doublereal *, integer *, integer *);
00059 extern doublereal dlansy_(char *, char *, integer *, doublereal *,
00060 integer *, doublereal *);
00061 doublereal ulpinv;
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 af_dim1 = *lda;
00180 af_offset = 1 + af_dim1;
00181 af -= af_offset;
00182 a_dim1 = *lda;
00183 a_offset = 1 + a_dim1;
00184 a -= a_offset;
00185 bf_dim1 = *ldb;
00186 bf_offset = 1 + bf_dim1;
00187 bf -= bf_offset;
00188 b_dim1 = *ldb;
00189 b_offset = 1 + b_dim1;
00190 b -= b_offset;
00191 u_dim1 = *ldu;
00192 u_offset = 1 + u_dim1;
00193 u -= u_offset;
00194 v_dim1 = *ldv;
00195 v_offset = 1 + v_dim1;
00196 v -= v_offset;
00197 q_dim1 = *ldq;
00198 q_offset = 1 + q_dim1;
00199 q -= q_offset;
00200 --alpha;
00201 --beta;
00202 r_dim1 = *ldr;
00203 r_offset = 1 + r_dim1;
00204 r__ -= r_offset;
00205 --iwork;
00206 --work;
00207 --rwork;
00208 --result;
00209
00210
00211 ulp = dlamch_("Precision");
00212 ulpinv = 1. / ulp;
00213 unfl = dlamch_("Safe minimum");
00214
00215
00216
00217 dlacpy_("Full", m, n, &a[a_offset], lda, &af[af_offset], lda);
00218 dlacpy_("Full", p, n, &b[b_offset], ldb, &bf[bf_offset], ldb);
00219
00220
00221 d__1 = dlange_("1", m, n, &a[a_offset], lda, &rwork[1]);
00222 anorm = max(d__1,unfl);
00223
00224 d__1 = dlange_("1", p, n, &b[b_offset], ldb, &rwork[1]);
00225 bnorm = max(d__1,unfl);
00226
00227
00228
00229 dggsvd_("U", "V", "Q", m, n, p, &k, &l, &af[af_offset], lda, &bf[
00230 bf_offset], ldb, &alpha[1], &beta[1], &u[u_offset], ldu, &v[
00231 v_offset], ldv, &q[q_offset], ldq, &work[1], &iwork[1], &info);
00232
00233
00234
00235
00236 i__2 = k + l;
00237 i__1 = min(i__2,*m);
00238 for (i__ = 1; i__ <= i__1; ++i__) {
00239 i__2 = k + l;
00240 for (j = i__; j <= i__2; ++j) {
00241 r__[i__ + j * r_dim1] = af[i__ + (*n - k - l + j) * af_dim1];
00242
00243 }
00244
00245 }
00246
00247 if (*m - k - l < 0) {
00248 i__1 = k + l;
00249 for (i__ = *m + 1; i__ <= i__1; ++i__) {
00250 i__2 = k + l;
00251 for (j = i__; j <= i__2; ++j) {
00252 r__[i__ + j * r_dim1] = bf[i__ - k + (*n - k - l + j) *
00253 bf_dim1];
00254
00255 }
00256
00257 }
00258 }
00259
00260
00261
00262 dgemm_("No transpose", "No transpose", m, n, n, &c_b17, &a[a_offset], lda,
00263 &q[q_offset], ldq, &c_b18, &work[1], lda)
00264 ;
00265
00266 dgemm_("Transpose", "No transpose", m, n, m, &c_b17, &u[u_offset], ldu, &
00267 work[1], lda, &c_b18, &a[a_offset], lda);
00268
00269 i__1 = k;
00270 for (i__ = 1; i__ <= i__1; ++i__) {
00271 i__2 = k + l;
00272 for (j = i__; j <= i__2; ++j) {
00273 a[i__ + (*n - k - l + j) * a_dim1] -= r__[i__ + j * r_dim1];
00274
00275 }
00276
00277 }
00278
00279
00280 i__2 = k + l;
00281 i__1 = min(i__2,*m);
00282 for (i__ = k + 1; i__ <= i__1; ++i__) {
00283 i__2 = k + l;
00284 for (j = i__; j <= i__2; ++j) {
00285 a[i__ + (*n - k - l + j) * a_dim1] -= alpha[i__] * r__[i__ + j *
00286 r_dim1];
00287
00288 }
00289
00290 }
00291
00292
00293
00294 resid = dlange_("1", m, n, &a[a_offset], lda, &rwork[1]);
00295
00296 if (anorm > 0.) {
00297
00298 i__1 = max(1,*m);
00299 result[1] = resid / (doublereal) max(i__1,*n) / anorm / ulp;
00300 } else {
00301 result[1] = 0.;
00302 }
00303
00304
00305
00306 dgemm_("No transpose", "No transpose", p, n, n, &c_b17, &b[b_offset], ldb,
00307 &q[q_offset], ldq, &c_b18, &work[1], ldb)
00308 ;
00309
00310 dgemm_("Transpose", "No transpose", p, n, p, &c_b17, &v[v_offset], ldv, &
00311 work[1], ldb, &c_b18, &b[b_offset], ldb);
00312
00313 i__1 = l;
00314 for (i__ = 1; i__ <= i__1; ++i__) {
00315 i__2 = l;
00316 for (j = i__; j <= i__2; ++j) {
00317 b[i__ + (*n - l + j) * b_dim1] -= beta[k + i__] * r__[k + i__ + (
00318 k + j) * r_dim1];
00319
00320 }
00321
00322 }
00323
00324
00325
00326 resid = dlange_("1", p, n, &b[b_offset], ldb, &rwork[1]);
00327 if (bnorm > 0.) {
00328
00329 i__1 = max(1,*p);
00330 result[2] = resid / (doublereal) max(i__1,*n) / bnorm / ulp;
00331 } else {
00332 result[2] = 0.;
00333 }
00334
00335
00336
00337 dlaset_("Full", m, m, &c_b18, &c_b17, &work[1], ldq);
00338 dsyrk_("Upper", "Transpose", m, m, &c_b44, &u[u_offset], ldu, &c_b17, &
00339 work[1], ldu);
00340
00341
00342
00343 resid = dlansy_("1", "Upper", m, &work[1], ldu, &rwork[1]);
00344 result[3] = resid / (doublereal) max(1,*m) / ulp;
00345
00346
00347
00348 dlaset_("Full", p, p, &c_b18, &c_b17, &work[1], ldv);
00349 dsyrk_("Upper", "Transpose", p, p, &c_b44, &v[v_offset], ldv, &c_b17, &
00350 work[1], ldv);
00351
00352
00353
00354 resid = dlansy_("1", "Upper", p, &work[1], ldv, &rwork[1]);
00355 result[4] = resid / (doublereal) max(1,*p) / ulp;
00356
00357
00358
00359 dlaset_("Full", n, n, &c_b18, &c_b17, &work[1], ldq);
00360 dsyrk_("Upper", "Transpose", n, n, &c_b44, &q[q_offset], ldq, &c_b17, &
00361 work[1], ldq);
00362
00363
00364
00365 resid = dlansy_("1", "Upper", n, &work[1], ldq, &rwork[1]);
00366 result[5] = resid / (doublereal) max(1,*n) / ulp;
00367
00368
00369
00370 dcopy_(n, &alpha[1], &c__1, &work[1], &c__1);
00371
00372 i__2 = k + l;
00373 i__1 = min(i__2,*m);
00374 for (i__ = k + 1; i__ <= i__1; ++i__) {
00375 j = iwork[i__];
00376 if (i__ != j) {
00377 temp = work[i__];
00378 work[i__] = work[j];
00379 work[j] = temp;
00380 }
00381
00382 }
00383
00384 result[6] = 0.;
00385
00386 i__2 = k + l;
00387 i__1 = min(i__2,*m) - 1;
00388 for (i__ = k + 1; i__ <= i__1; ++i__) {
00389 if (work[i__] < work[i__ + 1]) {
00390 result[6] = ulpinv;
00391 }
00392
00393 }
00394
00395 return 0;
00396
00397
00398
00399 }