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