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 complex c_b1 = {0.f,0.f};
00019 static complex c_b2 = {1.f,0.f};
00020 static integer c__16 = 16;
00021 static integer c__2 = 2;
00022 static integer c__1 = 1;
00023 static complex c_b22 = {2.f,0.f};
00024 static integer c__0 = 0;
00025
00026 int cqrt15_(integer *scale, integer *rksel, integer *m,
00027 integer *n, integer *nrhs, complex *a, integer *lda, complex *b,
00028 integer *ldb, real *s, integer *rank, real *norma, real *normb,
00029 integer *iseed, complex *work, integer *lwork)
00030 {
00031
00032 integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2;
00033 real r__1;
00034
00035
00036 integer j, mn;
00037 real eps;
00038 integer info;
00039 real temp;
00040 extern int cgemm_(char *, char *, integer *, integer *,
00041 integer *, complex *, complex *, integer *, complex *, integer *,
00042 complex *, complex *, integer *), clarf_(char *,
00043 integer *, integer *, complex *, integer *, complex *, complex *,
00044 integer *, complex *);
00045 extern doublereal sasum_(integer *, real *, integer *);
00046 real dummy[1];
00047 extern doublereal scnrm2_(integer *, complex *, integer *);
00048 extern int slabad_(real *, real *);
00049 extern doublereal clange_(char *, integer *, integer *, complex *,
00050 integer *, real *);
00051 extern int clascl_(char *, integer *, integer *, real *,
00052 real *, integer *, integer *, complex *, integer *, integer *);
00053 extern doublereal slamch_(char *);
00054 extern int csscal_(integer *, real *, complex *, integer
00055 *), claset_(char *, integer *, integer *, complex *, complex *,
00056 complex *, integer *), xerbla_(char *, integer *);
00057 real bignum;
00058 extern int claror_(char *, char *, integer *, integer *,
00059 complex *, integer *, integer *, complex *, integer *);
00060 extern doublereal slarnd_(integer *, integer *);
00061 extern int slaord_(char *, integer *, real *, integer *), clarnv_(integer *, integer *, integer *, complex *),
00062 slascl_(char *, integer *, integer *, real *, real *, integer *,
00063 integer *, real *, integer *, integer *);
00064 real smlnum;
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 a_dim1 = *lda;
00154 a_offset = 1 + a_dim1;
00155 a -= a_offset;
00156 b_dim1 = *ldb;
00157 b_offset = 1 + b_dim1;
00158 b -= b_offset;
00159 --s;
00160 --iseed;
00161 --work;
00162
00163
00164 mn = min(*m,*n);
00165
00166 i__1 = *m + mn, i__2 = mn * *nrhs, i__1 = max(i__1,i__2), i__2 = (*n << 1)
00167 + *m;
00168 if (*lwork < max(i__1,i__2)) {
00169 xerbla_("CQRT15", &c__16);
00170 return 0;
00171 }
00172
00173 smlnum = slamch_("Safe minimum");
00174 bignum = 1.f / smlnum;
00175 slabad_(&smlnum, &bignum);
00176 eps = slamch_("Epsilon");
00177 smlnum = smlnum / eps / eps;
00178 bignum = 1.f / smlnum;
00179
00180
00181
00182 if (*rksel == 1) {
00183 *rank = mn;
00184 } else if (*rksel == 2) {
00185 *rank = mn * 3 / 4;
00186 i__1 = mn;
00187 for (j = *rank + 1; j <= i__1; ++j) {
00188 s[j] = 0.f;
00189
00190 }
00191 } else {
00192 xerbla_("CQRT15", &c__2);
00193 }
00194
00195 if (*rank > 0) {
00196
00197
00198
00199 s[1] = 1.f;
00200 i__1 = *rank;
00201 for (j = 2; j <= i__1; ++j) {
00202 L20:
00203 temp = slarnd_(&c__1, &iseed[1]);
00204 if (temp > .1f) {
00205 s[j] = dabs(temp);
00206 } else {
00207 goto L20;
00208 }
00209
00210 }
00211 slaord_("Decreasing", rank, &s[1], &c__1);
00212
00213
00214
00215 clarnv_(&c__2, &iseed[1], m, &work[1]);
00216 r__1 = 1.f / scnrm2_(m, &work[1], &c__1);
00217 csscal_(m, &r__1, &work[1], &c__1);
00218 claset_("Full", m, rank, &c_b1, &c_b2, &a[a_offset], lda);
00219 clarf_("Left", m, rank, &work[1], &c__1, &c_b22, &a[a_offset], lda, &
00220 work[*m + 1]);
00221
00222
00223
00224
00225
00226 i__1 = *rank * *nrhs;
00227 clarnv_(&c__2, &iseed[1], &i__1, &work[1]);
00228 cgemm_("No transpose", "No transpose", m, nrhs, rank, &c_b2, &a[
00229 a_offset], lda, &work[1], rank, &c_b1, &b[b_offset], ldb);
00230
00231
00232
00233
00234
00235 i__1 = *rank;
00236 for (j = 1; j <= i__1; ++j) {
00237 csscal_(m, &s[j], &a[j * a_dim1 + 1], &c__1);
00238
00239 }
00240 if (*rank < *n) {
00241 i__1 = *n - *rank;
00242 claset_("Full", m, &i__1, &c_b1, &c_b1, &a[(*rank + 1) * a_dim1 +
00243 1], lda);
00244 }
00245 claror_("Right", "No initialization", m, n, &a[a_offset], lda, &iseed[
00246 1], &work[1], &info);
00247
00248 } else {
00249
00250
00251
00252
00253
00254 i__1 = mn;
00255 for (j = 1; j <= i__1; ++j) {
00256 s[j] = 0.f;
00257
00258 }
00259 claset_("Full", m, n, &c_b1, &c_b1, &a[a_offset], lda);
00260 claset_("Full", m, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
00261
00262 }
00263
00264
00265
00266 if (*scale != 1) {
00267 *norma = clange_("Max", m, n, &a[a_offset], lda, dummy);
00268 if (*norma != 0.f) {
00269 if (*scale == 2) {
00270
00271
00272
00273 clascl_("General", &c__0, &c__0, norma, &bignum, m, n, &a[
00274 a_offset], lda, &info);
00275 slascl_("General", &c__0, &c__0, norma, &bignum, &mn, &c__1, &
00276 s[1], &mn, &info);
00277 clascl_("General", &c__0, &c__0, norma, &bignum, m, nrhs, &b[
00278 b_offset], ldb, &info);
00279 } else if (*scale == 3) {
00280
00281
00282
00283 clascl_("General", &c__0, &c__0, norma, &smlnum, m, n, &a[
00284 a_offset], lda, &info);
00285 slascl_("General", &c__0, &c__0, norma, &smlnum, &mn, &c__1, &
00286 s[1], &mn, &info);
00287 clascl_("General", &c__0, &c__0, norma, &smlnum, m, nrhs, &b[
00288 b_offset], ldb, &info);
00289 } else {
00290 xerbla_("CQRT15", &c__1);
00291 return 0;
00292 }
00293 }
00294 }
00295
00296 *norma = sasum_(&mn, &s[1], &c__1);
00297 *normb = clange_("One-norm", m, nrhs, &b[b_offset], ldb, dummy)
00298 ;
00299
00300 return 0;
00301
00302
00303
00304 }