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