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 complex c_b2 = {-1.f,0.f};
00020 static integer c__1 = 1;
00021
00022 int cgetrf_(integer *m, integer *n, complex *a, integer *lda,
00023 integer *ipiv, integer *info)
00024 {
00025
00026 integer a_dim1, a_offset, i__1, i__2, i__3;
00027 complex q__1;
00028
00029
00030 double c_abs(complex *);
00031 void c_div(complex *, complex *, complex *);
00032
00033
00034 integer i__, j, ipivstart, jpivstart, jp;
00035 complex tmp;
00036 extern int cscal_(integer *, complex *, complex *,
00037 integer *), cgemm_(char *, char *, integer *, integer *, integer *
00038 , complex *, complex *, integer *, complex *, integer *, complex *
00039 , complex *, integer *);
00040 integer kcols;
00041 real sfmin;
00042 extern int ctrsm_(char *, char *, char *, char *,
00043 integer *, integer *, complex *, complex *, integer *, complex *,
00044 integer *);
00045 integer nstep, kahead;
00046 extern integer icamax_(integer *, complex *, integer *);
00047 extern doublereal slamch_(char *);
00048 extern int xerbla_(char *, integer *);
00049 real pivmag;
00050 integer npived;
00051 extern int claswp_(integer *, complex *, integer *,
00052 integer *, integer *, integer *, integer *);
00053 extern logical sisnan_(real *);
00054 integer kstart, ntopiv;
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 a_dim1 = *lda;
00161 a_offset = 1 + a_dim1;
00162 a -= a_offset;
00163 --ipiv;
00164
00165
00166 *info = 0;
00167 if (*m < 0) {
00168 *info = -1;
00169 } else if (*n < 0) {
00170 *info = -2;
00171 } else if (*lda < max(1,*m)) {
00172 *info = -4;
00173 }
00174 if (*info != 0) {
00175 i__1 = -(*info);
00176 xerbla_("CGETRF", &i__1);
00177 return 0;
00178 }
00179
00180
00181
00182 if (*m == 0 || *n == 0) {
00183 return 0;
00184 }
00185
00186
00187
00188 sfmin = slamch_("S");
00189
00190 nstep = min(*m,*n);
00191 i__1 = nstep;
00192 for (j = 1; j <= i__1; ++j) {
00193 kahead = j & -j;
00194 kstart = j + 1 - kahead;
00195
00196 i__2 = kahead, i__3 = *m - j;
00197 kcols = min(i__2,i__3);
00198
00199
00200
00201 i__2 = *m - j + 1;
00202 jp = j - 1 + icamax_(&i__2, &a[j + j * a_dim1], &c__1);
00203 ipiv[j] = jp;
00204
00205 if (jp != j) {
00206 i__2 = j + j * a_dim1;
00207 tmp.r = a[i__2].r, tmp.i = a[i__2].i;
00208 i__2 = j + j * a_dim1;
00209 i__3 = jp + j * a_dim1;
00210 a[i__2].r = a[i__3].r, a[i__2].i = a[i__3].i;
00211 i__2 = jp + j * a_dim1;
00212 a[i__2].r = tmp.r, a[i__2].i = tmp.i;
00213 }
00214
00215 ntopiv = 1;
00216 ipivstart = j;
00217 jpivstart = j - ntopiv;
00218 while(ntopiv < kahead) {
00219 claswp_(&ntopiv, &a[jpivstart * a_dim1 + 1], lda, &ipivstart, &j,
00220 &ipiv[1], &c__1);
00221 ipivstart -= ntopiv;
00222 ntopiv <<= 1;
00223 jpivstart -= ntopiv;
00224 }
00225
00226 claswp_(&kcols, &a[(j + 1) * a_dim1 + 1], lda, &kstart, &j, &ipiv[1],
00227 &c__1);
00228
00229 pivmag = c_abs(&a[j + j * a_dim1]);
00230 if (pivmag != 0.f && ! sisnan_(&pivmag)) {
00231 if (pivmag >= sfmin) {
00232 i__2 = *m - j;
00233 c_div(&q__1, &c_b1, &a[j + j * a_dim1]);
00234 cscal_(&i__2, &q__1, &a[j + 1 + j * a_dim1], &c__1);
00235 } else {
00236 i__2 = *m - j;
00237 for (i__ = 1; i__ <= i__2; ++i__) {
00238 i__3 = j + i__ + j * a_dim1;
00239 c_div(&q__1, &a[j + i__ + j * a_dim1], &a[j + j * a_dim1])
00240 ;
00241 a[i__3].r = q__1.r, a[i__3].i = q__1.i;
00242 }
00243 }
00244 } else if (pivmag == 0.f && *info == 0) {
00245 *info = j;
00246 }
00247
00248 ctrsm_("Left", "Lower", "No transpose", "Unit", &kahead, &kcols, &
00249 c_b1, &a[kstart + kstart * a_dim1], lda, &a[kstart + (j + 1) *
00250 a_dim1], lda);
00251
00252 i__2 = *m - j;
00253 cgemm_("No transpose", "No transpose", &i__2, &kcols, &kahead, &c_b2,
00254 &a[j + 1 + kstart * a_dim1], lda, &a[kstart + (j + 1) *
00255 a_dim1], lda, &c_b1, &a[j + 1 + (j + 1) * a_dim1], lda);
00256 }
00257
00258 npived = nstep & -nstep;
00259 j = nstep - npived;
00260 while(j > 0) {
00261 ntopiv = j & -j;
00262 i__1 = j + 1;
00263 claswp_(&ntopiv, &a[(j - ntopiv + 1) * a_dim1 + 1], lda, &i__1, &
00264 nstep, &ipiv[1], &c__1);
00265 j -= ntopiv;
00266 }
00267
00268 if (*m < *n) {
00269 i__1 = *n - *m;
00270 claswp_(&i__1, &a[(*m + kcols + 1) * a_dim1 + 1], lda, &c__1, m, &
00271 ipiv[1], &c__1);
00272 i__1 = *n - *m;
00273 ctrsm_("Left", "Lower", "No transpose", "Unit", m, &i__1, &c_b1, &a[
00274 a_offset], lda, &a[(*m + kcols + 1) * a_dim1 + 1], lda);
00275 }
00276 return 0;
00277
00278
00279
00280 }