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__10 = 10;
00019 static integer c__1 = 1;
00020 static integer c__0 = 0;
00021 static real c_b15 = 1.f;
00022
00023 doublereal sqrt14_(char *trans, integer *m, integer *n, integer *nrhs, real *
00024 a, integer *lda, real *x, integer *ldx, real *work, integer *lwork)
00025 {
00026
00027 integer a_dim1, a_offset, x_dim1, x_offset, i__1, i__2, i__3;
00028 real ret_val, r__1, r__2, r__3;
00029
00030
00031 integer i__, j;
00032 real err;
00033 integer info;
00034 real anrm;
00035 logical tpsd;
00036 real xnrm;
00037 extern logical lsame_(char *, char *);
00038 real rwork[1];
00039 extern int sgelq2_(integer *, integer *, real *, integer
00040 *, real *, real *, integer *), sgeqr2_(integer *, integer *, real
00041 *, integer *, real *, real *, integer *);
00042 extern doublereal slamch_(char *), slange_(char *, integer *,
00043 integer *, real *, integer *, real *);
00044 extern int xerbla_(char *, integer *), slascl_(
00045 char *, integer *, integer *, real *, real *, integer *, integer *
00046 , real *, integer *, integer *), slacpy_(char *, integer *
00047 , integer *, real *, integer *, real *, integer *);
00048 integer ldwork;
00049
00050
00051
00052
00053
00054
00055
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 a_dim1 = *lda;
00125 a_offset = 1 + a_dim1;
00126 a -= a_offset;
00127 x_dim1 = *ldx;
00128 x_offset = 1 + x_dim1;
00129 x -= x_offset;
00130 --work;
00131
00132
00133 ret_val = 0.f;
00134 if (lsame_(trans, "N")) {
00135 ldwork = *m + *nrhs;
00136 tpsd = FALSE_;
00137 if (*lwork < (*m + *nrhs) * (*n + 2)) {
00138 xerbla_("SQRT14", &c__10);
00139 return ret_val;
00140 } else if (*n <= 0 || *nrhs <= 0) {
00141 return ret_val;
00142 }
00143 } else if (lsame_(trans, "T")) {
00144 ldwork = *m;
00145 tpsd = TRUE_;
00146 if (*lwork < (*n + *nrhs) * (*m + 2)) {
00147 xerbla_("SQRT14", &c__10);
00148 return ret_val;
00149 } else if (*m <= 0 || *nrhs <= 0) {
00150 return ret_val;
00151 }
00152 } else {
00153 xerbla_("SQRT14", &c__1);
00154 return ret_val;
00155 }
00156
00157
00158
00159 slacpy_("All", m, n, &a[a_offset], lda, &work[1], &ldwork);
00160 anrm = slange_("M", m, n, &work[1], &ldwork, rwork);
00161 if (anrm != 0.f) {
00162 slascl_("G", &c__0, &c__0, &anrm, &c_b15, m, n, &work[1], &ldwork, &
00163 info);
00164 }
00165
00166
00167
00168 if (tpsd) {
00169
00170
00171
00172 slacpy_("All", m, nrhs, &x[x_offset], ldx, &work[*n * ldwork + 1], &
00173 ldwork);
00174 xnrm = slange_("M", m, nrhs, &work[*n * ldwork + 1], &ldwork, rwork);
00175 if (xnrm != 0.f) {
00176 slascl_("G", &c__0, &c__0, &xnrm, &c_b15, m, nrhs, &work[*n *
00177 ldwork + 1], &ldwork, &info);
00178 }
00179 i__1 = *n + *nrhs;
00180 anrm = slange_("One-norm", m, &i__1, &work[1], &ldwork, rwork);
00181
00182
00183
00184 i__1 = *n + *nrhs;
00185
00186 i__2 = *m, i__3 = *n + *nrhs;
00187 sgeqr2_(m, &i__1, &work[1], &ldwork, &work[ldwork * (*n + *nrhs) + 1],
00188 &work[ldwork * (*n + *nrhs) + min(i__2, i__3)+ 1], &info);
00189
00190
00191
00192
00193 err = 0.f;
00194 i__1 = *n + *nrhs;
00195 for (j = *n + 1; j <= i__1; ++j) {
00196 i__2 = min(*m,j);
00197 for (i__ = *n + 1; i__ <= i__2; ++i__) {
00198
00199 r__2 = err, r__3 = (r__1 = work[i__ + (j - 1) * *m], dabs(
00200 r__1));
00201 err = dmax(r__2,r__3);
00202
00203 }
00204
00205 }
00206
00207 } else {
00208
00209
00210
00211 i__1 = *n;
00212 for (i__ = 1; i__ <= i__1; ++i__) {
00213 i__2 = *nrhs;
00214 for (j = 1; j <= i__2; ++j) {
00215 work[*m + j + (i__ - 1) * ldwork] = x[i__ + j * x_dim1];
00216
00217 }
00218
00219 }
00220
00221 xnrm = slange_("M", nrhs, n, &work[*m + 1], &ldwork, rwork)
00222 ;
00223 if (xnrm != 0.f) {
00224 slascl_("G", &c__0, &c__0, &xnrm, &c_b15, nrhs, n, &work[*m + 1],
00225 &ldwork, &info);
00226 }
00227
00228
00229
00230 sgelq2_(&ldwork, n, &work[1], &ldwork, &work[ldwork * *n + 1], &work[
00231 ldwork * (*n + 1) + 1], &info);
00232
00233
00234
00235
00236 err = 0.f;
00237 i__1 = *n;
00238 for (j = *m + 1; j <= i__1; ++j) {
00239 i__2 = ldwork;
00240 for (i__ = j; i__ <= i__2; ++i__) {
00241
00242 r__2 = err, r__3 = (r__1 = work[i__ + (j - 1) * ldwork], dabs(
00243 r__1));
00244 err = dmax(r__2,r__3);
00245
00246 }
00247
00248 }
00249
00250 }
00251
00252
00253 i__1 = max(*m,*n);
00254 ret_val = err / ((real) max(i__1,*nrhs) * slamch_("Epsilon"));
00255
00256 return ret_val;
00257
00258
00259
00260 }