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