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 = {1.f,0.f};
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021
00022 int cgglse_(integer *m, integer *n, integer *p, complex *a,
00023 integer *lda, complex *b, integer *ldb, complex *c__, complex *d__,
00024 complex *x, complex *work, integer *lwork, integer *info)
00025 {
00026
00027 integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
00028 complex q__1;
00029
00030
00031 integer nb, mn, nr, nb1, nb2, nb3, nb4, lopt;
00032 extern int cgemv_(char *, integer *, integer *, complex *
00033 , complex *, integer *, complex *, integer *, complex *, complex *
00034 , integer *), ccopy_(integer *, complex *, integer *,
00035 complex *, integer *), caxpy_(integer *, complex *, complex *,
00036 integer *, complex *, integer *), ctrmv_(char *, char *, char *,
00037 integer *, complex *, integer *, complex *, integer *), cggrqf_(integer *, integer *, integer *, complex
00038 *, integer *, complex *, complex *, integer *, complex *, complex
00039 *, integer *, integer *), xerbla_(char *, integer *);
00040 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00041 integer *, integer *);
00042 integer lwkmin;
00043 extern int cunmqr_(char *, char *, integer *, integer *,
00044 integer *, complex *, integer *, complex *, complex *, integer *,
00045 complex *, integer *, integer *), cunmrq_(char *,
00046 char *, integer *, integer *, integer *, complex *, integer *,
00047 complex *, complex *, integer *, complex *, integer *, integer *);
00048 integer lwkopt;
00049 logical lquery;
00050 extern int ctrtrs_(char *, char *, char *, integer *,
00051 integer *, complex *, integer *, complex *, integer *, integer *);
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
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 a_dim1 = *lda;
00173 a_offset = 1 + a_dim1;
00174 a -= a_offset;
00175 b_dim1 = *ldb;
00176 b_offset = 1 + b_dim1;
00177 b -= b_offset;
00178 --c__;
00179 --d__;
00180 --x;
00181 --work;
00182
00183
00184 *info = 0;
00185 mn = min(*m,*n);
00186 lquery = *lwork == -1;
00187 if (*m < 0) {
00188 *info = -1;
00189 } else if (*n < 0) {
00190 *info = -2;
00191 } else if (*p < 0 || *p > *n || *p < *n - *m) {
00192 *info = -3;
00193 } else if (*lda < max(1,*m)) {
00194 *info = -5;
00195 } else if (*ldb < max(1,*p)) {
00196 *info = -7;
00197 }
00198
00199
00200
00201 if (*info == 0) {
00202 if (*n == 0) {
00203 lwkmin = 1;
00204 lwkopt = 1;
00205 } else {
00206 nb1 = ilaenv_(&c__1, "CGEQRF", " ", m, n, &c_n1, &c_n1);
00207 nb2 = ilaenv_(&c__1, "CGERQF", " ", m, n, &c_n1, &c_n1);
00208 nb3 = ilaenv_(&c__1, "CUNMQR", " ", m, n, p, &c_n1);
00209 nb4 = ilaenv_(&c__1, "CUNMRQ", " ", m, n, p, &c_n1);
00210
00211 i__1 = max(nb1,nb2), i__1 = max(i__1,nb3);
00212 nb = max(i__1,nb4);
00213 lwkmin = *m + *n + *p;
00214 lwkopt = *p + mn + max(*m,*n) * nb;
00215 }
00216 work[1].r = (real) lwkopt, work[1].i = 0.f;
00217
00218 if (*lwork < lwkmin && ! lquery) {
00219 *info = -12;
00220 }
00221 }
00222
00223 if (*info != 0) {
00224 i__1 = -(*info);
00225 xerbla_("CGGLSE", &i__1);
00226 return 0;
00227 } else if (lquery) {
00228 return 0;
00229 }
00230
00231
00232
00233 if (*n == 0) {
00234 return 0;
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 i__1 = *lwork - *p - mn;
00247 cggrqf_(p, m, n, &b[b_offset], ldb, &work[1], &a[a_offset], lda, &work[*p
00248 + 1], &work[*p + mn + 1], &i__1, info);
00249 i__1 = *p + mn + 1;
00250 lopt = work[i__1].r;
00251
00252
00253
00254
00255 i__1 = max(1,*m);
00256 i__2 = *lwork - *p - mn;
00257 cunmqr_("Left", "Conjugate Transpose", m, &c__1, &mn, &a[a_offset], lda, &
00258 work[*p + 1], &c__[1], &i__1, &work[*p + mn + 1], &i__2, info);
00259
00260 i__3 = *p + mn + 1;
00261 i__1 = lopt, i__2 = (integer) work[i__3].r;
00262 lopt = max(i__1,i__2);
00263
00264
00265
00266 if (*p > 0) {
00267 ctrtrs_("Upper", "No transpose", "Non-unit", p, &c__1, &b[(*n - *p +
00268 1) * b_dim1 + 1], ldb, &d__[1], p, info);
00269
00270 if (*info > 0) {
00271 *info = 1;
00272 return 0;
00273 }
00274
00275
00276
00277 ccopy_(p, &d__[1], &c__1, &x[*n - *p + 1], &c__1);
00278
00279
00280
00281 i__1 = *n - *p;
00282 q__1.r = -1.f, q__1.i = -0.f;
00283 cgemv_("No transpose", &i__1, p, &q__1, &a[(*n - *p + 1) * a_dim1 + 1]
00284 , lda, &d__[1], &c__1, &c_b1, &c__[1], &c__1);
00285 }
00286
00287
00288
00289 if (*n > *p) {
00290 i__1 = *n - *p;
00291 i__2 = *n - *p;
00292 ctrtrs_("Upper", "No transpose", "Non-unit", &i__1, &c__1, &a[
00293 a_offset], lda, &c__[1], &i__2, info);
00294
00295 if (*info > 0) {
00296 *info = 2;
00297 return 0;
00298 }
00299
00300
00301
00302 i__1 = *n - *p;
00303 ccopy_(&i__1, &c__[1], &c__1, &x[1], &c__1);
00304 }
00305
00306
00307
00308 if (*m < *n) {
00309 nr = *m + *p - *n;
00310 if (nr > 0) {
00311 i__1 = *n - *m;
00312 q__1.r = -1.f, q__1.i = -0.f;
00313 cgemv_("No transpose", &nr, &i__1, &q__1, &a[*n - *p + 1 + (*m +
00314 1) * a_dim1], lda, &d__[nr + 1], &c__1, &c_b1, &c__[*n - *
00315 p + 1], &c__1);
00316 }
00317 } else {
00318 nr = *p;
00319 }
00320 if (nr > 0) {
00321 ctrmv_("Upper", "No transpose", "Non unit", &nr, &a[*n - *p + 1 + (*n
00322 - *p + 1) * a_dim1], lda, &d__[1], &c__1);
00323 q__1.r = -1.f, q__1.i = -0.f;
00324 caxpy_(&nr, &q__1, &d__[1], &c__1, &c__[*n - *p + 1], &c__1);
00325 }
00326
00327
00328
00329 i__1 = *lwork - *p - mn;
00330 cunmrq_("Left", "Conjugate Transpose", n, &c__1, p, &b[b_offset], ldb, &
00331 work[1], &x[1], n, &work[*p + mn + 1], &i__1, info);
00332
00333 i__4 = *p + mn + 1;
00334 i__2 = lopt, i__3 = (integer) work[i__4].r;
00335 i__1 = *p + mn + max(i__2,i__3);
00336 work[1].r = (real) i__1, work[1].i = 0.f;
00337
00338 return 0;
00339
00340
00341
00342 }